Hi everyone, just started learning Panda3d,
and I need to create procedural cubes with specified dimensions. I figured that I’ll only need 8 vertices for the entire Geom, and I could do with just two primitives. One t strip for the front, right and back face, and one for the top, left and bottom face. like this
The vertices are generated by looping through each of the 4 bottom vertices, and then writing one with a z component of 0, and one with the specified length.
for vert in [[0, 0], [x_len, 0], [0, y_len], [x_len, y_len]]:
for z in [0, z_len]:
self.ver_w.addData3f(vert[0], vert[1], z)
self.col_w.addData4f(col[0], col[1], col[2], col[3])
Normals were kind of an afterthought, I thought one per vertice should do the trick, probably pointing outwards from each of the adjacent edges at an 135 Angle.
Which as all of you probably know, results in a cube, shaded like a sphere or whatever… I should have known this from my blender work, but I only ever considered regular face vertices, and “winged” the vertex normals.
So I read up on vertex normals and discovered that the panda vertex normals are actually face normals, and that they should be pointing in the direction of the triangles face. Well I only have 8 of those…
I created my own array format, to see if it would even let me create 3 columns for normals, and I also made 3 new normal writers, and using a really crude, ugly and quick prototype, I looped through 3 nested loops using the zip method, extracting the appropriate vector component for each normal writer and adding them all together. It’s shit, I know.
for a, b, c in zip(self.n_l1, self.n_l2, self.n_l3):
self.nor1_w.addData3f(a[0], a[1], a[2])
self.nor2_w.addData3f(b[0], b[1], b[2])
self.nor3_w.addData3f(c[0], c[1], c[2])
n_l are the normal the lists containing all normals. If you want to, I can provide them
Only problem: It looks exactly the same, as if it had no normals at all, with or without a light, there’s no shading at all… Printing my vertex data however shows me this: pythonoutput . So the data is in there…
So my question: Should I give up on creating a rectangular prism / cube like it is in my code at the moment, and build it out of individual faces with their own vertices for a total of 4 * 8 = 36 vertices? Can I make my code work some other way?
Sorry for the long text… Thanks for taking your time
btw, the rest of the cube creation works fine, If you would like to see the code, I’ll post it, I documented it a lot, I just didn’t want to put out any more text…