New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to meshes transform baking and added flipFaces #579
Conversation
data = this.getVerticesData(VertexBuffer.NormalKind); | ||
temp = []; | ||
var temp_normal = new Vector3(0, 0, 0); // this vector is used to normalize the newly transformed normal | ||
for (index = 0; index < data.length; index += 3) { | ||
Vector3.TransformNormal(Vector3.FromArray(data, index), transform).toArray(temp, index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalizing does make sense! :-)
Doesn't this function already deliver a normal? You can simply add the normalize function between the TransformNormal and the toArray. Or did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right. I'll update the PR!
Changed the way the normal is normalized (thanks Raanan), although I'm realizing that whether the normal vector is normalized or not doesn't change much the final render. But I guess we'll all sleep better if normals are normals ;) |
public flipFaces(flipNormals: boolean = false): void { | ||
var vertex_data = VertexData.ExtractFromMesh(this); | ||
|
||
if (flipNormals) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should test for normal presence here
Hey can you rebase it? |
Nevermind..I'll merge it :D |
Oh ok, thanks! sorry I didn't do it in time! |
Added the following functions to the Mesh class:
bakeCurrentTransformIntoVertices()
: computes the world matrix of the mesh, bake it in its vertices and then clears all transformflipFaces(flipNormals: boolean)
: inverse all the faces of the mesh, and optionally scales all the normals by -1Modified the following function:
bakeTransformIntoVertices(...)
: this function now makes sure that transformed normals are kept normalized, and flip the faces of the mesh if necessaryShould make mirroring meshes much easier!