Browse Source

Avoiding exceptions at FromMesh

In FromMesh there is another position where, if there is no quaternion,
an exception will be thrown.
I also code-hoisted the variables, to make the code a bit more readable
Raanan Weber 10 năm trước cách đây
mục cha
commit
483c784751
2 tập tin đã thay đổi với 21 bổ sung11 xóa
  1. 8 5
      Babylon/Mesh/babylon.csg.js
  2. 13 6
      Babylon/Mesh/babylon.csg.ts

+ 8 - 5
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';

+ 13 - 6
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';
             }