It's more a monologue than a thread, but maybe this post is useful to someone
What I've observed now is that the order in which my transformation are applied to the solid influence the length of the normals. I'm aware of the fact that the multiplication between 2 matrices is not commutative (A*B != B*A), but i think the length of the normals inside a mesh should not be scaled.
That's the code
root.set(branchDimension, branchLenght, radiusSegments, heightSegments, capSegments, false, OF_PRIMITIVE_TRIANGLES);
root.setPosition(0, 0, 0);
// if the roll transformation is applied first and the boom after,
// the transformed normal have length 1, as a normal should have.
// If the boom transformation is performed before the roll, my normals are
// scaled
bool boom_first = true;
if (boom_first) {
root.boom(branchLenght);
root.roll(theta);
}else{
root.roll(theta);
root.boom(branchLenght);
}
ofMatrix4x4 normalMatrix = root.getGlobalTransformMatrix().getInverse();
ofApp::debugMatrix(normalMatrix);
for(auto i: root.getMesh().getIndices()){
finalMesh.addIndex(i);
}
for(auto v: root.getMesh().getVertices()){
finalMesh.addVertex(v * root.getGlobalTransformMatrix());
}
for(auto i: root.getMesh().getNormals()){
ofVec3f normalVector = (normalMatrix * i);
// the length is one only when boom_first is false
cout << normalVector.length() << endl;
finalMesh.addNormal(normalVector);
}
the whole code is available here https://github.com/edap/normals-test
The first solution that I've tried was simply to normalize the vector before to insert it in the the finalMesh
, e.g. finalMesh.addNormal(normalVector.normalize)
, but not only it sounds strange, the position of the normal was still wrong.
How can i solve this problem? is there a way to preserve the normal of a of3DPrimitive after I've performed more transformation on it?