The models are all procedurally generated [aesthetics suck, cause I’m just testing functionality… ], and the ones labeled “incorrect” are the darkened ones, whereas the ones labeled “correct” are okay. Here is the code I use to flatten:
root_node.clearModelNodes()#<-for loaded models, not for the procedural ones.
I get a series of nodepaths with the same texture and then parent them to “root_node”. Then after that, I flatten the “root_node”. But after that, the now flattened “root_node” is darkened. Any ideas as to why this is happening?
This looks suspiciously like the bug I once reported for a Panda version prior to 1.9.1, where flattening a scaled model would lead to vertex normals being scaled instead of being normalized. If a model was scaled down before flattening it, the vertex normals (which affect how the model is lit) would end up being shorter than unit-length, hence the darker appearance of the model.
This bug was fixed in version 1.9.1, so perhaps you are using an older version?
Well calling getGeom() on “root_node” yielded an attribute error:
File "g_S.py", line 433, in cluster_instancer
vertex_data = root_node.node().getGeom(0).getVertexData()
AttributeError: 'panda3d.core.PandaNode' object has no attribute 'getGeom'
I suppose because of this:
and then re-parenting the actual procedural models onto it before flattening it. But calling flattenStrong() on an individual procedural model without re-parenting it, and then comparing the normal lengths, before and after shows this:
NORMAL LENGTH BEFORE FLATTENING: 0.999999970198
NORMAL LENGTH AFTER FLATTENING: 0.0300000133241
So the length becomes shorter after flattening. I really don’t know what to make of it though, or what to do with this information to fix the darkening. I am actually using version 1.10 [this one specifically I think: 2015-12-31T20:08:11Z - Add normal/depth information to box-box test to make it work with the pusher ].
Hmm, I can’t seem to reproduce the issue, either with a loaded smiley model or with a procedurally created cube, with that particular Panda version installed.
It might be worthwile to try and generate a very basic model (e.g. consisting of just a single box without anything else attached to it, like children or collision geometry) that has this issue. Then you could write it out to .bam (using NodePath.writeBamFile) and upload it so I can take a look at it.
And I’ve found the cause ! After some digging, it turned out that a custom GeomVertexFormat is the culprit.
It consists of 2 arrays; the first one has “vertex”, “normal” and “color” columns, while the second one has only a “texcoord” column.
If you change the vertex format of the GeomVertexData to the standard GeomVertexFormat.getV3n3cpt2(), the vertex normals are correctly normalized.
@Game_Starter: so for the time being you can solve the problem by doing:
In order to get scales correctly applied during flattens, you need to have your normal columns set to CNormal (and not CPoint or CVector) in the GeomVertexFormat. The default columns are configured correctly.