Explorar o código

Should parents be serialized as well

Now a flag can be used to serialize the parents of the selected mesh(es)
Raanan Weber %!s(int64=10) %!d(string=hai) anos
pai
achega
f7f88a9ab6
Modificáronse 2 ficheiros con 20 adicións e 2 borrados
  1. 9 1
      src/Tools/babylon.sceneSerializer.js
  2. 11 1
      src/Tools/babylon.sceneSerializer.ts

+ 9 - 1
src/Tools/babylon.sceneSerializer.js

@@ -739,9 +739,17 @@ var BABYLON;
             }
             return serializationObject;
         };
-        SceneSerializer.SerializeMesh = function (toSerialize /* Mesh || Mesh[] */) {
+        SceneSerializer.SerializeMesh = function (toSerialize /* Mesh || Mesh[] */, withParents) {
+            if (withParents === void 0) { withParents = false; }
             var serializationObject = {};
             toSerialize = (toSerialize instanceof Array) ? toSerialize : [toSerialize];
+            if (withParents) {
+                for (var i = 0; i < toSerialize.length; ++i) {
+                    if (toSerialize[i].parent) {
+                        toSerialize.push(toSerialize[i].parent);
+                    }
+                }
+            }
             toSerialize.forEach(function (mesh) {
                 finalizeSingleMesh(mesh, serializationObject);
             });

+ 11 - 1
src/Tools/babylon.sceneSerializer.ts

@@ -903,10 +903,20 @@
             return serializationObject;
         }
 
-        public static SerializeMesh(toSerialize: any /* Mesh || Mesh[] */): any {
+        public static SerializeMesh(toSerialize: any /* Mesh || Mesh[] */, withParents : boolean = false): any {
             var serializationObject: any = {};
 
             toSerialize = (toSerialize instanceof Array) ? toSerialize : [toSerialize];
+
+            if (withParents) {
+                //deliberate for loop! not for each, appended should be processed as well.
+                for (var i = 0; i < toSerialize.length; ++i) {
+                    if (toSerialize[i].parent) {
+                        toSerialize.push(toSerialize[i].parent);
+                    }
+                }
+            }
+
             toSerialize.forEach(function (mesh: Mesh) {
                 finalizeSingleMesh(mesh, serializationObject);
             });