Browse Source

initial commit

master
Victor Giers 4 months ago
commit
359499933a

BIN
data/.DS_Store View File


BIN
data/HEADLESS.blend View File


+ 1
- 0
data/bedroom.command View File

@@ -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"

BIN
data/compose on template/blanko.png View File


+ 2
- 0
data/compose on template/compose_picture_on_template.sh View File

@@ -0,0 +1,2 @@
#!/bin/bash
convert $1 $2 -background black -gravity center -compose over -composite result.png

BIN
data/compose on template/picture.png View File


BIN
data/compose on template/result.png View File


+ 0
- 0
data/convert_to_jpg.py View File


+ 1
- 0
data/livingroom.command View File

@@ -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"

BIN
data/pacman.png View File


+ 1
- 0
data/pictureonly.command View File

@@ -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"

+ 50
- 0
data/render.py View File

@@ -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)

+ 63
- 0
data/render_pictureonly.py View File

@@ -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)

BIN
data/result_close.png View File


+ 301
- 0
render_picture_for_webshop.pde View File

@@ -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/"

Loading…
Cancel
Save