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
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+34 −4
Diff settings

Always

Just for now

@@ -904,17 +904,26 @@
if (!this.isVerticesDataPresent(VertexBuffer.NormalKind)) {
return;
}
data = this.getVerticesData(VertexBuffer.NormalKind);
temp = [];
for (index = 0; index < data.length; index += 3) {
Vector3.TransformNormal(Vector3.FromArray(data, index), transform).toArray(temp, index);
Vector3.TransformNormal(Vector3.FromArray(data, index), transform).normalize().toArray(temp, index);
}
this.setVerticesData(VertexBuffer.NormalKind, temp, this.getVertexBuffer(VertexBuffer.NormalKind).isUpdatable());
// flip faces?
if (transform.m[0] * transform.m[5] * transform.m[10] < 0) { this.flipFaces(); }
}
// Will apply current transform to mesh and reset world matrix
public bakeCurrentTransformIntoVertices(): void {
this.bakeTransformIntoVertices(this.computeWorldMatrix(true));
this.scaling.copyFromFloats(1, 1, 1);
this.position.copyFromFloats(0, 0, 0);
this.rotation.copyFromFloats(0, 0, 0);
this.rotationQuaternion = Quaternion.Identity();
this._worldMatrix = Matrix.Identity();
}
// Cache
public _resetPointsArrayCache(): void {
@@ -1127,6 +1136,27 @@
this.synchronizeInstances();
}
// will inverse faces orientations, and invert normals too if specified
public flipFaces(flipNormals: boolean = false): void {
var vertex_data = VertexData.ExtractFromMesh(this);
if (flipNormals) {

This comment has been minimized.

@deltakosh

deltakosh Jun 23, 2015

Contributor

You should test for normal presence here

@deltakosh

deltakosh Jun 23, 2015

Contributor

You should test for normal presence here

for (var i = 0; i < vertex_data.normals.length; i++) {
vertex_data.normals[i] *= -1;
}
}
var temp;
for (var i = 0; i < vertex_data.indices.length; i += 3) {
// reassign indices
temp = vertex_data.indices[i + 1];
vertex_data.indices[i + 1] = vertex_data.indices[i + 2];
vertex_data.indices[i + 2] = temp;
}
vertex_data.applyToMesh(this);
}
// Instances
public createInstance(name: string): InstancedMesh {
return new InstancedMesh(name, this);
ProTip! Use n and p to navigate between commits in a pull request.