浏览代码

Merge pull request #543 from RaananW/math-fix

Quaternion Init fix at toMesh and FromMesh
Raanan Weber 10 年之前
父节点
当前提交
3d6d16c1e1
共有 2 个文件被更改,包括 27 次插入14 次删除
  1. 11 7
      Babylon/Mesh/babylon.csg.js
  2. 16 7
      Babylon/Mesh/babylon.csg.ts

+ 11 - 7
Babylon/Mesh/babylon.csg.js

@@ -259,13 +259,16 @@ var BABYLON;
         // Convert BABYLON.Mesh to BABYLON.CSG
         CSG.FromMesh = function (mesh) {
             var vertex, normal, uv, position, polygon, polygons = [], vertices;
+            var matrix, meshPosition, meshRotation, meshRotationQuaternion, meshScaling;
             if (mesh instanceof BABYLON.Mesh) {
                 mesh.computeWorldMatrix(true);
-                var matrix = mesh.getWorldMatrix();
-                var meshPosition = mesh.position.clone();
-                var meshRotation = mesh.rotation.clone();
-                var meshRotationQuaternion = mesh.rotationQuaternion.clone();
-                var meshScaling = mesh.scaling.clone();
+                matrix = mesh.getWorldMatrix();
+                meshPosition = mesh.position.clone();
+                meshRotation = mesh.rotation.clone();
+                if (mesh.rotationQuaternion) {
+                    meshRotationQuaternion = mesh.rotationQuaternion.clone();
+                }
+                meshScaling = mesh.scaling.clone();
             }
             else {
                 throw 'BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh';
@@ -492,7 +495,9 @@ var BABYLON;
             mesh.material = material;
             mesh.position.copyFrom(this.position);
             mesh.rotation.copyFrom(this.rotation);
-            mesh.rotationQuaternion.copyFrom(this.rotationQuaternion);
+            if (this.rotationQuaternion) {
+                mesh.rotationQuaternion = this.rotationQuaternion.clone();
+            }
             mesh.scaling.copyFrom(this.scaling);
             mesh.computeWorldMatrix(true);
             return mesh;
@@ -501,4 +506,3 @@ var BABYLON;
     })();
     BABYLON.CSG = CSG;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.csg.js.map

+ 16 - 7
Babylon/Mesh/babylon.csg.ts

@@ -285,14 +285,21 @@
                 polygon,
                 polygons = [],
                 vertices;
-
+			var matrix, 
+				meshPosition,
+				meshRotation,
+				meshRotationQuaternion,
+				meshScaling;
+				
             if (mesh instanceof BABYLON.Mesh) {
                 mesh.computeWorldMatrix(true);
-                var matrix = mesh.getWorldMatrix();
-                var meshPosition = mesh.position.clone();
-                var meshRotation = mesh.rotation.clone();
-                var meshRotationQuaternion = mesh.rotationQuaternion.clone();
-                var meshScaling = mesh.scaling.clone();
+                matrix = mesh.getWorldMatrix();
+                meshPosition = mesh.position.clone();
+                meshRotation = mesh.rotation.clone();
+				if(mesh.rotationQuaternion) {
+					meshRotationQuaternion = mesh.rotationQuaternion.clone();
+				}
+                meshScaling = mesh.scaling.clone();
             } else {
                 throw 'BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh';
             }
@@ -589,7 +596,9 @@
 
             mesh.position.copyFrom(this.position);
             mesh.rotation.copyFrom(this.rotation);
-            mesh.rotationQuaternion.copyFrom(this.rotationQuaternion);
+			if(this.rotationQuaternion) {
+				mesh.rotationQuaternion = this.rotationQuaternion.clone();
+			}
             mesh.scaling.copyFrom(this.scaling);
             mesh.computeWorldMatrix(true);