فهرست منبع

Add Missing Link Transform Node To File Loader

MackeyK24 6 سال پیش
والد
کامیت
9cbe29f15e
4فایلهای تغییر یافته به همراه50 افزوده شده و 0 حذف شده
  1. 1 0
      dist/preview release/what's new.md
  2. 3 0
      src/Bones/bone.ts
  3. 8 0
      src/Bones/skeleton.ts
  4. 38 0
      src/Loading/Plugins/babylonFileLoader.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -272,6 +272,7 @@
 ### Loaders
 
 - Added missing `loadedAnimationGroups` to `MeshAssetTask` ([bghgary](https://github.com/bghgary))
+- Added missing `linkTransformNode` to `BabylonFileLoader` ([MackeyK24](https://github.com/mackeyk24))
 
 ## Breaking changes
 

+ 3 - 0
src/Bones/bone.ts

@@ -60,6 +60,9 @@ export class Bone extends Node {
     public _linkedTransformNode: Nullable<TransformNode> = null;
 
     /** @hidden */
+    public _waitingTransformNodeId: Nullable<string> = null;
+
+    /** @hidden */
     get _matrix(): Matrix {
         this._compose();
         return this._localMatrix;

+ 8 - 0
src/Bones/skeleton.ts

@@ -63,6 +63,9 @@ export class Skeleton implements IAnimatable {
     /** @hidden */
     public _numBonesWithLinkedTransformNode = 0;
 
+    /** @hidden */
+    public _hasWaitingData: Nullable<boolean> = null;
+
     /**
      * Specifies if the skeleton should be serialized
      */
@@ -691,6 +694,11 @@ export class Skeleton implements IAnimatable {
             if (parsedBone.animation) {
                 bone.animations.push(Animation.Parse(parsedBone.animation));
             }
+
+            if (parsedBone.linkedTransformNodeId !== undefined && parsedBone.linkedTransformNodeId !== null) {
+                skeleton._hasWaitingData = true;
+                bone._waitingTransformNodeId = parsedBone.linkedTransformNodeId;
+            }
         }
 
         // placed after bones, so createAnimationRange can cascade down

+ 38 - 0
src/Loading/Plugins/babylonFileLoader.ts

@@ -345,6 +345,25 @@ var loadAssetContainer = (scene: Scene, data: string, rootUrl: string, onError?:
             }
         }
 
+        // link skeleton transform nodes
+        for (index = 0, cache = scene.skeletons.length; index < cache; index++) {
+            var skeleton = scene.skeletons[index];
+            if (skeleton._hasWaitingData) {
+                if (skeleton.bones != null) {
+                    skeleton.bones.forEach((bone) => {
+                        if (bone._waitingTransformNodeId) {
+                            var linkTransformNode = scene.getLastEntryByID(bone._waitingTransformNodeId) as TransformNode;
+                            if (linkTransformNode) {
+                                bone.linkTransformNode(linkTransformNode);
+                            }
+                            bone._waitingTransformNodeId = null;
+                        }
+                    });
+                }
+                skeleton._hasWaitingData = null;
+            }
+        }
+
         // freeze world matrix application
         for (index = 0, cache = scene.meshes.length; index < cache; index++) {
             var currentMesh = scene.meshes[index];
@@ -569,6 +588,25 @@ SceneLoader.RegisterPlugin({
                     }
                 }
 
+                // link skeleton transform nodes
+                for (index = 0, cache = scene.skeletons.length; index < cache; index++) {
+                    var skeleton = scene.skeletons[index];
+                    if (skeleton._hasWaitingData) {
+                        if (skeleton.bones != null) {
+                            skeleton.bones.forEach((bone) => {
+                                if (bone._waitingTransformNodeId) {
+                                    var linkTransformNode = scene.getLastEntryByID(bone._waitingTransformNodeId) as TransformNode;
+                                    if (linkTransformNode) {
+                                        bone.linkTransformNode(linkTransformNode);
+                                    }
+                                    bone._waitingTransformNodeId = null;
+                                }
+                            });
+                        }
+                        skeleton._hasWaitingData = null;
+                    }
+                }
+
                 // freeze and compute world matrix application
                 for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     currentMesh = scene.meshes[index];