When using PShapes in Processing, I ran in the following issue:
PShape cubeShape;
PShape secondaryShape;
PImage cubeImage;
PImage blank;
float rotationX;
float rotationY;
float sX, sY;
int childs;
PFont questionFont, optionFont;
void setup(){
frameRate(60);
orientation(PORTRAIT);
fullScreen(P3D);
shapeMode(CORNER);
textAlign(CORNER);
smooth(5);
cubeShape = loadShape("Abc.obj");
cubeShape.setFill(color(255));
cubeShape.setTint(color(255));
secondaryShape = loadShape("Abc.obj");
secondaryShape.setFill(color(255));
secondaryShape.setTint(color(255,255,255));
cubeImage = loadImage("cubesite_front.PNG");
childs = cubeShape.getChildCount();
questionFont = createFont("cube.ttf",7);
optionFont = createFont("cube.ttf", 85);
textureWrap(REPEAT);
textureMode(IMAGE);
secondaryShape.setTexture(loadImage("cubesite_any.png"));
rotationX = 0.0f;
rotationY = 0.0f;
editSite(cubeImage, "Test", "Left", "Top", "Right", "Bottom");
cubeImage = getMirror(cubeImage);
}
void draw(){
cubeShape.setTexture(cubeImage);
Runtime runtime = Runtime.getRuntime();
float usedRam = 1.0f - (float) runtime.freeMemory() / (float) runtime.totalMemory();
int usedRamPercent = (int) (usedRam*100.0f);
background(255);
lights();
textSize(width/20);
fill(0,125,255);
text("Rotation X: " + String.valueOf(degrees(rotationX)).split("\\.")[0]+"°\n"+"Rotation Y: " + String.valueOf(degrees(rotationY)).split("\\.")[0]+"°",width/20,height/20);
String rightBar = "Touch X: " + String.valueOf(sX) + "\nTouch Y: " + String.valueOf(sY)
+ "\n\nRAM: " + usedRamPercent + "%"
+ "\nFPS: " + String.valueOf(frameRate).split("\\.")[0];
text(rightBar,width-width/20-textWidth(rightBar),height/20);
textSize(width/20);
fill(125,25,0);
text("",width/2,height/7);
if (rotationX>=TWO_PI||rotationX<=-TWO_PI) rotationX=0;
if (rotationY>=TWO_PI||rotationY<=-TWO_PI) rotationY=0;
for (int i = 0; i <childs; i++){
PShape currentChild = cubeShape.getChild(i);
PShape secondaryChild = secondaryShape.getChild(i);
boolean front = true;
for (int j = 0; j < currentChild.getVertexCount(); j++){
PVector currentVector = currentChild.getVertex(j);
front = !(currentVector.z<0.95);
}
pushMatrix();
translate(width/2,height/2,height/6);
scale(height/7);
rotateX(rotationX);
rotateY(rotationY);
shape(front ? currentChild : secondaryChild);
popMatrix();
}
}
PImage getMirror(PImage img) {
PGraphics pg = createGraphics(img.width, img.height, JAVA2D);
pg.beginDraw();
pg.smooth(4);
pg.scale(-1, 1);
pg.image(img, -img.width, 0);
pg.endDraw();
return pg.get();
}
private void editSite(PImage background, String center, String left, String top, String right, String bottom){
PGraphics siteGraphics = createGraphics(background.width,background.height);
imageMode(CORNER);
siteGraphics.beginDraw();
siteGraphics.image(background,0,0);
siteGraphics.textSize(width/10);
fittedText(siteGraphics,center,questionFont,siteGraphics.width/2,siteGraphics.height/2,siteGraphics.width-siteGraphics.width/6,siteGraphics.height-siteGraphics.height/6);
siteGraphics.pushMatrix();
siteGraphics.translate(0,0);
siteGraphics.rotate(-HALF_PI);
siteGraphics.textAlign(CENTER, CENTER);
siteGraphics.textFont(optionFont);
siteGraphics.text(left,-siteGraphics.height/2,siteGraphics.width/6/2);
siteGraphics.rotate(PI);
siteGraphics.text(right,siteGraphics.height/2,-siteGraphics.width+siteGraphics.width/6/2);
siteGraphics.rotate(-HALF_PI);
siteGraphics.text(top,siteGraphics.width/2,siteGraphics.height/6/2);
siteGraphics.text(bottom,siteGraphics.width/2,siteGraphics.height-siteGraphics.height/6/2); siteGraphics.popMatrix();
siteGraphics.endDraw();
cubeImage = siteGraphics.get();
}
private final char NEWLINE = '\n'; private final String SPACE_SEPARATOR = " "; private final String SPLIT_REGEXP= "\\s+"; String breakLines(String input, int maxLineLength) { String[] tokens = input.split(SPLIT_REGEXP); StringBuilder output = new StringBuilder(input.length()); int lineLen = 0; for (int i = 0; i < tokens.length; i++) { String word = tokens[i]; if (lineLen + (SPACE_SEPARATOR + word).length() > maxLineLength) { if (i > 0) output.append(NEWLINE); lineLen = 0; } if (i < tokens.length - 1 && (lineLen + (word + SPACE_SEPARATOR).length() + tokens[i + 1].length() <=maxLineLength)) word += SPACE_SEPARATOR; output.append(word); lineLen += word.length(); } return output.toString();}
void fittedText(PGraphics graphics,String text, PFont font, float posX, float posY, float fitX, float fitY){
text = breakLines(text, 15);
graphics.textFont(font);
graphics.textAlign(CENTER,CENTER);
graphics.textSize(min(font.getSize()*fitX/textWidth(text), fitY));
graphics.textLeading(graphics.textSize*1.1);
graphics.text(text, posX, posY);
}
void mousePressed(){
sX = mouseX;
sY = mouseY;
}
void mouseDragged(){
rotationX += (mouseY-sY)*(HALF_PI/(width));
sY = mouseY;
rotationY += (mouseX-sX)*(HALF_PI/(width));
sX = mouseX;
}
The above demo code functions perfectly when run via APDE, but the texture is just one solid ugly color when build/run from a windows machine via PDE or Android Studio:
Does anyone know why this is happening and how I can fix it?
If needed I will upload the model as well if it is relevant!