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