浏览代码

Fix instantiateHierarchy

David Catuhe 6 年之前
父节点
当前提交
d1796be9f8
共有 1 个文件被更改,包括 11 次插入9 次删除
  1. 11 9
      src/Meshes/mesh.ts

+ 11 - 9
src/Meshes/mesh.ts

@@ -497,15 +497,17 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
 
     // Methods
     public instantiateHierarchy(newParent: Nullable<TransformNode> = null): Nullable<TransformNode> {
-        let instance = this.createInstance("instance of " + (this.name || this.id));
-
-        instance.parent = newParent || this.parent;
-        instance.position = this.position.clone();
-        instance.scaling = this.scaling.clone();
-        if (this.rotationQuaternion)  {
-            instance.rotationQuaternion = this.rotationQuaternion.clone();
-        } else {
-            instance.rotation = this.rotation.clone();
+        let instance = this.getTotalVertices() > 0 ? this.createInstance("instance of " + (this.name || this.id)) :  this.clone("Clone of " +  (this.name || this.id), newParent || this.parent, true);
+
+        if (instance) {
+            instance.parent = newParent || this.parent;
+            instance.position = this.position.clone();
+            instance.scaling = this.scaling.clone();
+            if (this.rotationQuaternion)  {
+                instance.rotationQuaternion = this.rotationQuaternion.clone();
+            } else {
+                instance.rotation = this.rotation.clone();
+            }
         }
 
         for (var child of this.getChildTransformNodes(true)) {