We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to color 3D PShape. if I perform vertex.setEmissive(color) on each vertex this does color the object as expected but this is simply emissive color unaffected by the scene lighting. if instead I try to use .setFill() or .setTint() or .setAmbient() on each vertex I get a completely black and opaque object. if I don't do anything at all then the object has a white or gray fill that does respond to the scene lighting.
I don't understand what I'm doing wrong. How do I assign a color to each vertex in a PShape???
DETAILS: I read in a .obj file which creates a PShape object that is simple a list of GROUPs in which each group contains 3 verticies (a triangular face).
I then iterate over this list of lists setting the color of each vertex with the outcome described above.
My thinking is that I must not understand what setFill or setTint or setAmbient do. I'd like to know. But I'd also like to know how to do what I want which is to paint the faces.
here's a code snippet that I'm using:
sts = p.loadShape("stshuttle.obj");
sts.rotateZ(p.PI/2);
sts.rotateY(-p.PI/2);
// loop over the list of GROUP PShapes
// set odd faces red and even faces yellow
for (int i =0; i<sts.getChildCount();i++){
PShape foo = sts.getChild(i);
int colr2 = (0==i%2)? 0xFF1000 : 0xFFFF00;
// loop over all three of the verticies in the GROUP.
for (int j = 0; j<foo.getVertexCount();j++) {
foo.setFill(j,colr2); // This turns it black
// foo.setEmissive(j,colr2); // works as expected
// foo.setTint(j,colr2) // this turns it black.
}
}
Answers
this remains a mystery to me
At first glance 0xFF1000 and 0xFFFF00 are color values without any alpha information, thus fully transparent. While the setEmissive() function doesn't care about the alpha value, setFill() and setTint() do.
Use either Processing's color notation (will automatically add an opaque alpha channel):
Or add the alpha channel yourself:
Thanks! I'll try this. By the way, by what means should I have learned this fact. I've not see what you just told me documented. I didn't pick it up from the javadocs page for processing. So I must be missing some source of documentation.
No problem. Processing has a dedicated page about color: https://processing.org/reference/color_datatype.html
thanks again!