commit 359499933a41d1e96a958c97736c779b64d8495c Author: Victor Giers Date: Thu Jul 14 09:13:39 2022 +0200 initial commit diff --git a/data/.DS_Store b/data/.DS_Store new file mode 100644 index 0000000..1d0d9aa Binary files /dev/null and b/data/.DS_Store differ diff --git a/data/HEADLESS.blend b/data/HEADLESS.blend new file mode 100644 index 0000000..73b8d7a Binary files /dev/null and b/data/HEADLESS.blend differ diff --git a/data/bedroom.command b/data/bedroom.command new file mode 100755 index 0000000..4b338ed --- /dev/null +++ b/data/bedroom.command @@ -0,0 +1 @@ +blender -b "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/HEADLESS_BEDROOM.blend" --python "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/render.py" -- 80 80 "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/10/pictureonly.png" "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/10.7.2022 16-19-29/bedroom.png" diff --git a/data/compose on template/blanko.png b/data/compose on template/blanko.png new file mode 100644 index 0000000..d0500b9 Binary files /dev/null and b/data/compose on template/blanko.png differ diff --git a/data/compose on template/compose_picture_on_template.sh b/data/compose on template/compose_picture_on_template.sh new file mode 100644 index 0000000..68fa0d5 --- /dev/null +++ b/data/compose on template/compose_picture_on_template.sh @@ -0,0 +1,2 @@ +#!/bin/bash +convert $1 $2 -background black -gravity center -compose over -composite result.png diff --git a/data/compose on template/picture.png b/data/compose on template/picture.png new file mode 100644 index 0000000..029ac7e Binary files /dev/null and b/data/compose on template/picture.png differ diff --git a/data/compose on template/result.png b/data/compose on template/result.png new file mode 100644 index 0000000..cfe61cd Binary files /dev/null and b/data/compose on template/result.png differ diff --git a/data/convert_to_jpg.py b/data/convert_to_jpg.py new file mode 100644 index 0000000..e69de29 diff --git a/data/livingroom.command b/data/livingroom.command new file mode 100755 index 0000000..2ddbf1c --- /dev/null +++ b/data/livingroom.command @@ -0,0 +1 @@ +blender -b "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/HEADLESS_LIVINGROOM.blend" --python "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/render.py" -- 41 80 "/Users/giers/Documents/Glitch Art/Veräusserte Drucke/8942832.png" "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/12.7.2022 11-9-0/livingroom.png" diff --git a/data/pacman.png b/data/pacman.png new file mode 100644 index 0000000..9fb2f83 Binary files /dev/null and b/data/pacman.png differ diff --git a/data/pictureonly.command b/data/pictureonly.command new file mode 100755 index 0000000..4b15d80 --- /dev/null +++ b/data/pictureonly.command @@ -0,0 +1 @@ +blender -b "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/HEADLESS_PICTUREONLY.blend" --python "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/render_pictureonly.py" -- 41 80 "/Users/giers/Documents/Glitch Art/Veräusserte Drucke/8942832.png" "/Users/giers/Documents/Processing 3/render_picture_for_webshop/data/12.7.2022 11-9-0/pictureonly.png" diff --git a/data/render.py b/data/render.py new file mode 100644 index 0000000..3da27c7 --- /dev/null +++ b/data/render.py @@ -0,0 +1,50 @@ +import bpy +import sys +argv = sys.argv +argv = argv[argv.index("--") + 1:] + +width = int(argv[0]) +height = int(argv[1]) +imgpath = argv[2] +renderPath = argv[3] + +def selectObject(name): + ob = bpy.context.scene.objects[name] + bpy.ops.object.select_all(action='DESELECT') + bpy.context.view_layer.objects.active = ob + ob.select_set(True) + +def moveObject(name,x,y,z): + selectObject(name) + bpy.context.object.location = x, y, z + +def scaleObject(name,x,y,z): + selectObject(name) + bpy.context.object.dimensions = x, y, z + + +img = bpy.data.images.load(filepath = imgpath) +selectObject("Canvas") +bpy.context.object.material_slots[0].material.node_tree.nodes["Image Texture"].image = img + +moveObject("BarTop",0,0,height/100/2) +moveObject("BarBottom",0,0,-height/100/2) +moveObject("BarLeft",-width/100/2,0,0) +moveObject("BarRight",width/100/2,0,0) + +scaleObject("BarTop",width/100-0.06,0.019024,0.02) +scaleObject("BarBottom",width/100-0.06,0.019024,0.02) +scaleObject("BarLeft",height/100-0.06,0.019024,0.02) +scaleObject("BarRight",height/100-0.06,0.019024,0.02) + +moveObject("CornerTopRight", width/100/2,0,height/100/2) +moveObject("CornerTopLeft", -width/100/2,0,height/100/2) +moveObject("CornerBottomRight", width/100/2,0,-height/100/2) +moveObject("CornerBottomLeft", -width/100/2,0,-height/100/2) + +scaleObject("Glass", width/100,0.002037,height/100) +scaleObject("Canvas",width/100,0.0025,height/100) + + +bpy.context.scene.render.filepath = renderPath +bpy.ops.render.render(write_still = True) diff --git a/data/render_pictureonly.py b/data/render_pictureonly.py new file mode 100644 index 0000000..f9b73ee --- /dev/null +++ b/data/render_pictureonly.py @@ -0,0 +1,63 @@ +import bpy +import sys +import mathutils + +argv = sys.argv +argv = argv[argv.index("--") + 1:] + +width = int(argv[0]) +height = int(argv[1]) +imgpath = argv[2] +renderPath = argv[3] + +def selectObject(name): + ob = bpy.context.scene.objects[name] + bpy.ops.object.select_all(action='DESELECT') + bpy.context.view_layer.objects.active = ob + ob.select_set(True) + +def moveObject(name,x,y,z): + selectObject(name) + bpy.context.object.location = x, y, z + +def scaleObject(name,x,y,z): + selectObject(name) + bpy.context.object.dimensions = x, y, z + +def moveCamLocal(z): + cam = bpy.data.objects["Camera"] + vec = mathutils.Vector((0.0, 0.0, z)) + inv = cam.matrix_world.copy() + inv.invert() + vec_rot = vec @ inv + cam.location = cam.location + vec_rot + + +img = bpy.data.images.load(filepath = imgpath) +selectObject("Canvas") +bpy.context.object.material_slots[0].material.node_tree.nodes["Image Texture"].image = img + +diff = max(width,height) - 80 +moveCamLocal(diff/55) + +moveObject("BarTop",0,0,height/100/2) +moveObject("BarBottom",0,0,-height/100/2) +moveObject("BarLeft",-width/100/2,0,0) +moveObject("BarRight",width/100/2,0,0) + +scaleObject("BarTop",width/100-0.06,0.026024,0.02) +scaleObject("BarBottom",width/100-0.06,0.026024,0.02) +scaleObject("BarLeft",height/100-0.06,0.026024,0.02) +scaleObject("BarRight",height/100-0.06,0.026024,0.02) + +moveObject("CornerTopRight", width/100/2,0,height/100/2) +moveObject("CornerTopLeft", -width/100/2,0,height/100/2) +moveObject("CornerBottomRight", width/100/2,0,-height/100/2) +moveObject("CornerBottomLeft", -width/100/2,0,-height/100/2) + +scaleObject("Glass", width/100,0.002037,height/100) +scaleObject("Canvas",width/100,0.0025,height/100) + + +bpy.context.scene.render.filepath = renderPath +bpy.ops.render.render(write_still = True) diff --git a/data/result_close.png b/data/result_close.png new file mode 100644 index 0000000..aaa4393 Binary files /dev/null and b/data/result_close.png differ diff --git a/render_picture_for_webshop.pde b/render_picture_for_webshop.pde new file mode 100644 index 0000000..0976d8d --- /dev/null +++ b/render_picture_for_webshop.pde @@ -0,0 +1,301 @@ + +import java.io.IOException; +import java.awt.*; +import drop.*; +import controlP5.*; +SDrop drop; +ControlP5 cp5; +//SecondApplet gui; + +boolean passepartout, detail, framed, livingroom, bedroom; + +PGraphics renderer; +PImage img, pacman; +int maxImgLength = 900; +String widthInput, heightInput; +boolean imageLoaded, measuresKnown, detailAreaSet; +String foldername, imagePath; + + +void resetAll() { + imageLoaded = false; + measuresKnown = false; + detailAreaSet = false; + foldername = ""; + imagePath = ""; +} + +void dropEvent(DropEvent theDropEvent) { + imagePath = theDropEvent.filePath(); + img = loadImage(imagePath); + + imgw = img.width >= img.height ? maxImgLength : (int)map(img.width, 0, img.height, 0, maxImgLength); + imgh = img.height >= img.width ? maxImgLength : (int)map(img.height, 0, img.width, 0, maxImgLength); + foldername = day() + "." + month() + "." + year() + " " + hour() + "-" + minute() + "-" + second(); + measuresKnown = false; + widthInput = ""; + heightInput = ""; + cp5.get(Textfield.class, "width").show(); + cp5.get(Textfield.class, "height").show(); + cp5.get(Textfield.class, "width").setFocus(true); + cp5.get(Toggle.class, "passepartout").show(); + cp5.get(Toggle.class, "detail").show(); + cp5.get(Toggle.class, "framed").show(); + cp5.get(Toggle.class, "livingroom").show(); + cp5.get(Toggle.class, "bedroom").show(); + imageLoaded = true; +} +void settings() { + size(200, 200); +} +void setup() { + //size(200, 200); + OS = osSetup(); + println(OS); + renderer = createGraphics(1024, 1024); + detailGraphic = createGraphics(1024, 1024); + pacman = loadImage(dataPath("pacman.png")); + textSize(30); + drop = new SDrop(this); + + cp5 = new ControlP5(this); + + Textfield wInput = cp5.addTextfield("width") + .setPosition(20, 50) + .setColorValue(color(0, 0, 0)) + .setColorBackground(color(200, 200, 200)) + .setSize(70, 30) + .setFocus(true); + wInput.getCaptionLabel().setColor(color(0, 0, 0)); + + Textfield hInput = cp5.addTextfield("height") + .setPosition(110, 50) + .setColorValue(color(0, 0, 0)) + .setColorBackground(color(200, 200, 200)) + .setSize(70, 30); + hInput.getCaptionLabel().setColor(color(0, 0, 0)); + + Toggle renderPassepartout = cp5.addToggle("passepartout") + .setColorValue(color(0, 0, 0)) + .setColorBackground(color(200, 200, 200)) + .setSize(20, 20) + .setPosition(10, 110); + renderPassepartout.getCaptionLabel().setColor(color(0, 0, 0)); + Toggle renderDetail = cp5.addToggle("detail") + .setColorValue(color(0, 0, 0)) + .setColorBackground(color(200, 200, 200)) + .setSize(20, 20) + .setPosition(45, 120); + renderDetail.getCaptionLabel().setColor(color(0, 0, 0)); + Toggle renderPictureOnly = cp5.addToggle("framed") + .setColorValue(color(0, 0, 0)) + .setColorBackground(color(200, 200, 200)) + .setSize(20, 20) + .setPosition(80, 130); + renderPictureOnly.getCaptionLabel().setColor(color(0, 0, 0)); + Toggle renderLivingroom = cp5.addToggle("livingroom") + .setColorValue(color(0, 0, 0)) + .setColorBackground(color(200, 200, 200)) + .setSize(20, 20) + .setPosition(115, 140); + renderLivingroom.getCaptionLabel().setColor(color(0, 0, 0)); + Toggle renderBedroom = cp5.addToggle("bedroom") + .setColorValue(color(0, 0, 0)) + .setColorBackground(color(200, 200, 200)) + .setSize(20, 20) + .setPosition(150, 150); + renderBedroom.getCaptionLabel().setColor(color(0, 0, 0)); + + cp5.get(Textfield.class, "width").hide(); + cp5.get(Textfield.class, "height").hide(); + cp5.get(Toggle.class, "passepartout").hide(); + cp5.get(Toggle.class, "detail").hide(); + cp5.get(Toggle.class, "framed").hide(); + cp5.get(Toggle.class, "livingroom").hide(); + cp5.get(Toggle.class, "bedroom").hide(); +} + +int imgw, imgh; + +void draw() { + background(255); + if (imageLoaded && !measuresKnown) { + + text("SAG MAßE", 20, 30); + widthInput = cp5.get(Textfield.class, "width").getText(); + heightInput = cp5.get(Textfield.class, "height").getText(); + } else if (imageLoaded && measuresKnown) { + println(); + + renderer.noSmooth(); + renderer.beginDraw(); + renderer.imageMode(CENTER); + //renderer.clear(); + renderer.background(255); + renderer.image(img, renderer.width/2, renderer.height/2, imgw, imgh); + renderer.endDraw(); + image(renderer, 0, 0, width, height); + if (!detailAreaSet && detail) { + noFill(); + stroke(255, 0, 0); + strokeWeight(2); + rect(mouseX-detailAreaSize/5/2, mouseY-detailAreaSize/5/2, detailAreaSize/5, detailAreaSize/5); + fill(0); + noStroke(); + text("ZEIG DETAIL", 20, 30); + } + if (renderNow) { + renderNow = false; + + if (passepartout || detail || framed || livingroom || bedroom) { + createOutput(dataPath("") + "/" + foldername + "/."); + openRenderFolder(); + } + if (imageLoaded) { + if (passepartout) { + println("Saving passepartout image"); + renderer.save(dataPath("") + "/" + foldername + "/passepartout.png"); + } + if (measuresKnown) { + if (detail) { + println("Saving detail image"); + detailGraphic.noSmooth(); + detailGraphic.beginDraw(); + detailGraphic.image(temp, 0, 0, detailGraphic.width, detailGraphic.height); + detailGraphic.save(dataPath("") + "/" + foldername + "/detail.png"); + detailGraphic.endDraw(); + } + if (framed) { + println("Rendering framed image in blender (picture only)"); + String pictureonlycmd[] = {"blender -b \"" + dataPath("") + "/HEADLESS_PICTUREONLY.blend\" --python \"" + dataPath("") + "/render_pictureonly.py\" -- " + widthInput + " " + heightInput + " \"" + imagePath + "\" \"" + dataPath("") + "/" + foldername + "/pictureonly.png\""}; + if (OS == "mac") { + saveStrings(dataPath("") + "/pictureonly.command", pictureonlycmd); + launch(dataPath("") + "/pictureonly.command"); + } else if (OS == "windows") { + saveStrings(dataPath("") + "/pictureonly.cmd", pictureonlycmd); + launch(dataPath("") + "/pictureonly.cmd"); + } + } + if (bedroom) { + println("Rendering framed image in blender (bedroom)"); + String bedroomcmd[] = {"blender -b \"" + dataPath("") + "/HEADLESS_BEDROOM.blend\" --python \"" + dataPath("") + "/render.py\" -- " + widthInput + " " + heightInput + " \"" + imagePath + "\" \"" + dataPath("") + "/" + foldername + "/bedroom.png\""}; + if (OS == "mac") { + saveStrings(dataPath("") + "/bedroom.command", bedroomcmd); + launch(dataPath("") + "/bedroom.command"); + } else if (OS == "windows") { + saveStrings(dataPath("") + "/bedroom.cmd", bedroomcmd); + launch(dataPath("") + "/bedroom.cmd"); + } + } + if (livingroom) { + println("Rendering framed image in blender (livingroom)"); + String livingroomcmd[] = {"blender -b \"" + dataPath("") + "/HEADLESS_LIVINGROOM.blend\" --python \"" + dataPath("") + "/render.py\" -- " + widthInput + " " + heightInput + " \"" + imagePath + "\" \"" + dataPath("") + "/" + foldername + "/livingroom.png\""}; + if (OS == "mac") { + saveStrings(dataPath("") + "/livingroom.command", livingroomcmd); + launch(dataPath("") + "/livingroom.command"); + } else if (OS == "windows") { + saveStrings(dataPath("") + "/livingroom.cmd", livingroomcmd); + launch(dataPath("") + "/livingroom.cmd"); + } + } + } + } + println("done"); + resetAll(); + } + } else { + image(pacman, 0, 0, width, height); + fill(0); + text("GIB BILD", 20, 30); + } +} + + + +int detailAreaSize = 256; +int detailAreaX, detailAreaY; +int imgClickX, imgClickY, imgBiggerFactor, imgDetailSize; +PImage temp; +PGraphics detailGraphic; +void setDetailArea() { + detailAreaSet = true; + println("rendering detailed view"); + imgClickX = (int)map(map(mouseX, 0, width, 0, 1024), 512-imgw/2, 512+imgw/2, 0, img.width); + imgClickY = (int)map(map(mouseY, 0, height, 0, 1024), 512-imgh/2, 512+imgh/2, 0, img.height); + imgBiggerFactor = max(img.width, img.height)/max(imgw, imgh); + imgDetailSize = detailAreaSize * imgBiggerFactor; + temp = img.get(imgClickX - imgDetailSize/2, imgClickY - imgDetailSize/2, imgDetailSize, imgDetailSize); +} + + +String OS; + +void mouseClicked() { + if (mouseButton == LEFT && imageLoaded && measuresKnown && !detailAreaSet && detail) { + setDetailArea(); + renderNow = true; + } +} +boolean renderNow; +void openRenderFolder() { + String folderpath = sketchPath("") + "data/" + foldername + "/"; + Desktop desktop = Desktop.getDesktop(); + File dirToOpen = null; + try { + dirToOpen = new File(folderpath); + desktop.open(dirToOpen); + } + catch (IOException iae) { + System.out.println("File Not Found"); + } +} + +String osSetup () { + String os = System.getProperty("os.name"); + if (os.contains("Windows")) { + return "windows"; + } else if (os.contains("Mac")) { + return "mac"; + } else if (os.contains("Linux")) { + return "linux"; + } else { + return "other"; + } +} + +boolean focusHeight; +void keyPressed() { + if (key == ENTER) { + println(widthInput, heightInput); + if (imageLoaded && !measuresKnown && widthInput != "" && heightInput != "") { + if (int(widthInput) < 10 || int(heightInput) < 10 || int(widthInput) > 120 || int(heightInput) > 120) { + println("Nope"); + } else { + measuresKnown = true; + cp5.get(Textfield.class, "width").hide(); + cp5.get(Textfield.class, "height").hide(); + cp5.get(Toggle.class, "passepartout").hide(); + cp5.get(Toggle.class, "detail").hide(); + cp5.get(Toggle.class, "framed").hide(); + cp5.get(Toggle.class, "livingroom").hide(); + cp5.get(Toggle.class, "bedroom").hide(); + if (!detail) { + renderNow = true; + } + } + } + } + if (key == TAB) { + if (!measuresKnown && imageLoaded) { + if (!focusHeight) { + cp5.get(Textfield.class, "height").setFocus(true); + cp5.get(Textfield.class, "width").setFocus(false); + } else { + cp5.get(Textfield.class, "height").setFocus(false); + cp5.get(Textfield.class, "width").setFocus(true); + } + focusHeight = !focusHeight; + } + } +} +//working: blender -b "HEADLESS.blend" --python "render.py" -- 80 80 "/Users/giers/Documents/Render Image for Webshop/55.png" "/Users/giers/Documents/Render Image for Webshop/"