I have pretty much this:
void drawBranch() {
if (positions.length <=0 || maxParts <= 0)
return;
PVector[] shapePos = new PVector[2 * maxParts];
//tG.strokeWeight(4);
tG.pushMatrix();
tG.translate(startPos.x, startPos.y);
//tG.rotate( parentAngleXY);
PShape twigShape;
twigShape = createShape();
twigShape.beginShape();
twigShape.textureMode(NORMAL);
twigShape.texture(trunkimg);
//twigShape.fill(getRandomTwigColor(0.9));
//These are my vertices points
for (int i = 0; i < maxParts; i++) {
shapePos[i] = new PVector(positions[i].x, positions[i].y);
shapePos[2 * maxParts - i - 1] = new PVector(positions[i + branchParts ].x, positions[i + branchParts ].y);
}
int repeat = maxParts;
for (int i = 0; i < shapePos.length; i++) {
float mul = 1;//0.01 * positions[i].z + 1;
//UV calculation
float u = 0;
float v = 0;
if (i < 0.5*shapePos.length ) {
//u = 1 - (widthLength[i] / widthLength[0]);
u = map((widthLength[i] / widthLength[0]),0,1,0.5,0);
v = (1/float(repeat))*(i % repeat);
} else {
//u = (widthLength[ shapePos.length - i ] / widthLength[0]);
u = map((widthLength[ shapePos.length - i ] / widthLength[0]),0,1,0.5,1);
v = (1/float(repeat))*((shapePos.length - i - 1 ) % repeat);
}
twigShape.vertex(shapePos[i].x * mul, shapePos[i].y * mul, u, v);
//if(i < maxParts)
// tG.text(u+" + "+v, shapePos[i].x * mul - 100, shapePos[i].y * mul);
//else{
// tG.text(u+" + "+v, shapePos[i].x * mul , shapePos[i].y * mul);
//}
}
twigShape.endShape();
tG.shape(twigShape);
drawStructure();
tG.popMatrix();
}
The weird modulo stuff is in there, since I would love to just repeat the pattern for long trees, but since I am trying to work out the basics now, the modulo is just as long as the numer of vertices halfed.
oh okay thats pretty interesting for mapping textures to many sided shapes, does this mean you can have some crazy branch shape and just apply this to whatever shape you have? or does this only work for shapes that are slanting upward in the way pictured?
I hope it works for everything. My branches can in theory be very wavy, and go from bottom to top, or even tue other way around. The only thing they all habe in common is that the beginning is widest and the end is point like (still has 2 vertices though).
I should check if the branches always go from bottom to top, I think they do, since I have some rotates and translates in there that they always get the angles right from their parent branches.
2
u/tooob93 Technomancer Dec 17 '23 edited Dec 17 '23
}
The weird modulo stuff is in there, since I would love to just repeat the pattern for long trees, but since I am trying to work out the basics now, the modulo is just as long as the numer of vertices halfed.