Explorar el Código

Better decal positioning

David Catuhe hace 10 años
padre
commit
b67abe59fe

+ 1 - 1
Babylon/Materials/babylon.shaderMaterial.js

@@ -144,7 +144,7 @@ var BABYLON;
                     this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
                 }
                 // Bones
-                if (mesh.useBones) {
+                if (mesh && mesh.useBones) {
                     this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                 }
                 for (var name in this._textures) {

+ 1 - 1
Babylon/Materials/babylon.shaderMaterial.ts

@@ -185,7 +185,7 @@
                 }
 
                 // Bones
-                if (mesh.useBones) {
+                if (mesh && mesh.useBones) {
                     this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                 }
 

+ 6 - 2
Babylon/Mesh/babylon.mesh.js

@@ -891,7 +891,7 @@ var BABYLON;
          */
         Mesh.prototype.simplify = function (settings, parallelProcessing, simplificationType, successCallback) {
             if (parallelProcessing === void 0) { parallelProcessing = true; }
-            if (simplificationType === void 0) { simplificationType = 0 /* QUADRATIC */; }
+            if (simplificationType === void 0) { simplificationType = BABYLON.SimplificationType.QUADRATIC; }
             this.getScene().simplificationQueue.addTask({
                 settings: settings,
                 parallelProcessing: parallelProcessing,
@@ -1271,10 +1271,12 @@ var BABYLON;
                 if (faceVertices.length === 0) {
                     continue;
                 }
+                // Add UVs and get back to world
+                var localRotationMatrix = BABYLON.Matrix.RotationYawPitchRoll(yaw, pitch, angle);
                 for (var vIndex = 0; vIndex < faceVertices.length; vIndex++) {
                     var vertex = faceVertices[vIndex];
                     vertexData.indices.push(currentVertexDataIndex);
-                    BABYLON.Vector3.TransformCoordinates(vertex.position, decalWorldMatrix).toArray(vertexData.positions, currentVertexDataIndex * 3);
+                    vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);
                     vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);
                     vertexData.uvs.push(0.5 + vertex.position.x / size.x);
                     vertexData.uvs.push(0.5 + vertex.position.y / size.y);
@@ -1284,6 +1286,8 @@ var BABYLON;
             // Return mesh
             var decal = new Mesh(name, sourceMesh.getScene());
             vertexData.applyToMesh(decal);
+            decal.position = position.clone();
+            decal.rotation = new BABYLON.Vector3(pitch, yaw, angle);
             return decal;
         };
         // Tools

+ 5 - 1
Babylon/Mesh/babylon.mesh.ts

@@ -1545,11 +1545,12 @@
                 }
                 
                 // Add UVs and get back to world
+                var localRotationMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, angle);
                 for (var vIndex = 0; vIndex < faceVertices.length; vIndex++) {
                     var vertex = faceVertices[vIndex];
 
                     vertexData.indices.push(currentVertexDataIndex);
-                    Vector3.TransformCoordinates(vertex.position, decalWorldMatrix).toArray(vertexData.positions, currentVertexDataIndex * 3);
+                    vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);
                     vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);
                     vertexData.uvs.push(0.5 + vertex.position.x / size.x);
                     vertexData.uvs.push(0.5 + vertex.position.y / size.y);
@@ -1562,6 +1563,9 @@
             var decal = new Mesh(name, sourceMesh.getScene());
             vertexData.applyToMesh(decal);
 
+            decal.position = position.clone();
+            decal.rotation = new Vector3(pitch, yaw, angle);
+
             return decal;
         }
 

+ 7 - 2
babylon.2.1-alpha.debug.js

@@ -12054,10 +12054,13 @@ var BABYLON;
                 if (faceVertices.length === 0) {
                     continue;
                 }
+                // Add UVs and get back to world
+                var localRotationMatrix = BABYLON.Matrix.RotationYawPitchRoll(yaw, pitch, angle);
                 for (var vIndex = 0; vIndex < faceVertices.length; vIndex++) {
                     var vertex = faceVertices[vIndex];
                     vertexData.indices.push(currentVertexDataIndex);
-                    BABYLON.Vector3.TransformCoordinates(vertex.position, decalWorldMatrix).toArray(vertexData.positions, currentVertexDataIndex * 3);
+                    //Vector3.TransformCoordinates(vertex.position, localRotationMatrix).toArray(vertexData.positions, currentVertexDataIndex * 3);
+                    vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);
                     vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);
                     vertexData.uvs.push(0.5 + vertex.position.x / size.x);
                     vertexData.uvs.push(0.5 + vertex.position.y / size.y);
@@ -12067,6 +12070,8 @@ var BABYLON;
             // Return mesh
             var decal = new Mesh(name, sourceMesh.getScene());
             vertexData.applyToMesh(decal);
+            decal.position = position.clone();
+            decal.rotation = new BABYLON.Vector3(pitch, yaw, angle);
             return decal;
         };
         // Tools
@@ -22014,7 +22019,7 @@ var BABYLON;
                     this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
                 }
                 // Bones
-                if (mesh.useBones) {
+                if (mesh && mesh.useBones) {
                     this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
                 }
                 for (var name in this._textures) {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 6 - 5
babylon.2.1-alpha.js