Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

jahow
Copy link
Contributor

@jahow jahow commented Jun 23, 2015

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 transform
  • flipFaces(flipNormals: boolean): inverse all the faces of the mesh, and optionally scales all the normals by -1

Modified the following function:

  • bakeTransformIntoVertices(...): this function now makes sure that transformed normals are kept normalized, and flip the faces of the mesh if necessary

Should make mirroring meshes much easier!

@jahow jahow changed the title Mesh bake patch Changes to meshes transform baking and added flipFaces Jun 23, 2015
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);
Copy link
Member

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?

Copy link
Contributor Author

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!

@jahow
Copy link
Contributor Author

jahow commented Jun 23, 2015

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) {
Copy link
Contributor

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

@deltakosh
Copy link
Contributor

Hey can you rebase it?

@deltakosh
Copy link
Contributor

Nevermind..I'll merge it :D

@deltakosh deltakosh closed this Jun 24, 2015
@jahow
Copy link
Contributor Author

jahow commented Jun 25, 2015

Oh ok, thanks! sorry I didn't do it in time!

@jahow jahow deleted the mesh_bake_patch branch Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants