Browse Source

Fixed issue with skeleton cloning

David Catuhe 9 năm trước cách đây
mục cha
commit
e36c7f1ece

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 21 - 30
dist/preview release/babylon.core.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 779 - 778
dist/preview release/babylon.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 29 - 40
dist/preview release/babylon.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 7920 - 7903
dist/preview release/babylon.max.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 27 - 37
dist/preview release/babylon.noworker.js


+ 9 - 0
src/Animations/babylon.animation.js

@@ -6,6 +6,9 @@ var BABYLON;
             this.from = from;
             this.to = to;
         }
+        AnimationRange.prototype.clone = function () {
+            return new AnimationRange(this.name, this.from, this.to);
+        };
         return AnimationRange;
     })();
     BABYLON.AnimationRange = AnimationRange;
@@ -234,6 +237,12 @@ var BABYLON;
             if (this._keys) {
                 clone.setKeys(this._keys);
             }
+            if (this._ranges) {
+                clone._ranges = {};
+                for (var name in this._ranges) {
+                    clone._ranges[name] = this._ranges[name].clone();
+                }
+            }
             return clone;
         };
         Animation.prototype.setKeys = function (values) {

+ 11 - 0
src/Animations/babylon.animation.ts

@@ -2,6 +2,10 @@
     export class AnimationRange {
         constructor(public name: string, public from: number, public to: number) {
         }
+
+        public clone(): AnimationRange {
+            return new AnimationRange(this.name, this.from, this.to);
+        }
     }
 
     /**
@@ -281,6 +285,13 @@
                 clone.setKeys(this._keys);
             }
 
+            if (this._ranges) {
+                clone._ranges = {};
+                for (var name in this._ranges) {
+                    clone._ranges[name] = this._ranges[name].clone();
+                }
+            }
+
             return clone;
         }
 

+ 8 - 0
src/Bones/babylon.skeleton.js

@@ -181,6 +181,7 @@ var BABYLON;
         };
         Skeleton.prototype.clone = function (name, id) {
             var result = new Skeleton(name, id || name, this._scene);
+            result.needInitialSkinMatrix = this.needInitialSkinMatrix;
             for (var index = 0; index < this.bones.length; index++) {
                 var source = this.bones[index];
                 var parentBone = null;
@@ -191,6 +192,13 @@ var BABYLON;
                 var bone = new BABYLON.Bone(source.name, result, parentBone, source.getBaseMatrix().clone(), source.getRestPose().clone());
                 BABYLON.Tools.DeepCopy(source.animations, bone.animations);
             }
+            if (this._ranges) {
+                result._ranges = {};
+                for (var rangeName in this._ranges) {
+                    result._ranges[rangeName] = this._ranges[rangeName].clone();
+                }
+            }
+            result.prepare();
             return result;
         };
         Skeleton.prototype.dispose = function () {

+ 11 - 0
src/Bones/babylon.skeleton.ts

@@ -218,6 +218,8 @@
         public clone(name: string, id: string): Skeleton {
             var result = new Skeleton(name, id || name, this._scene);
 
+            result.needInitialSkinMatrix = this.needInitialSkinMatrix;
+
             for (var index = 0; index < this.bones.length; index++) {
                 var source = this.bones[index];
                 var parentBone = null;
@@ -231,6 +233,15 @@
                 Tools.DeepCopy(source.animations, bone.animations);
             }
 
+            if (this._ranges) {
+                result._ranges = {};
+                for (var rangeName in this._ranges) {
+                    result._ranges[rangeName] = this._ranges[rangeName].clone();
+                }
+            }
+
+            result.prepare();
+
             return result;
         }
 

+ 2 - 1
src/Materials/Textures/babylon.hdrcubetexture.ts

@@ -16,7 +16,7 @@ module BABYLON {
             "down",
             "back"
         ];
-        
+
         private _useInGammaSpace = false;
         private _generateHarmonics = true;
         private _noMipmap: boolean;
@@ -230,3 +230,4 @@ module BABYLON {
         }
     }
 } 
+

+ 1 - 1
src/Tools/HDR/babylon.tools.cubemaptosphericalpolynomial.ts

@@ -138,4 +138,4 @@ module BABYLON.Internals {
             return SphericalPolynomial.getSphericalPolynomialFromHarmonics(sphericalHarmonics);
         }
     }
-} 
+} 

+ 25 - 26
src/Tools/HDR/babylon.tools.hdr.ts

@@ -36,10 +36,9 @@ module BABYLON.Internals {
             return mantissa * Math.pow(2, exponent);
         }
 
-        private static Rgbe2float(float32array: Float32Array, 
+        private static Rgbe2float(float32array: Float32Array,
             red: number, green: number, blue: number, exponent: number,
-            index: number)
-        {
+            index: number) {
             if (exponent > 0) {   /*nonzero pixel*/
                 exponent = this.Ldexp(1.0, exponent - (128 + 8));
 
@@ -58,7 +57,7 @@ module BABYLON.Internals {
             var line = "";
             var character = "";
 
-            for(var i = startIndex; i < uint8array.length - startIndex; i++) {
+            for (var i = startIndex; i < uint8array.length - startIndex; i++) {
                 character = String.fromCharCode(uint8array[i]);
 
                 if (character == "\n") {
@@ -79,10 +78,10 @@ module BABYLON.Internals {
          * @param uint8array The binary file stored in  native array.
          * @return The header information.
          */
-        public static RGBE_ReadHeader(uint8array: Uint8Array) : HDRInfo {
+        public static RGBE_ReadHeader(uint8array: Uint8Array): HDRInfo {
             var height: number = 0;
             var width: number = 0;
-            
+
             var line = this.readStringLine(uint8array, 0);
             if (line[0] != '#' || line[1] != '?') {
                 throw "Bad HDR Format.";
@@ -90,7 +89,7 @@ module BABYLON.Internals {
 
             var endOfHeader = false;
             var findFormat = false;
-            var lineIndex:number = 0;
+            var lineIndex: number = 0;
 
             do {
                 lineIndex += (line.length + 1);
@@ -105,24 +104,24 @@ module BABYLON.Internals {
             } while (!endOfHeader);
 
             if (!findFormat) {
-                throw "HDR Bad header format, unsupported FORMAT"; 
+                throw "HDR Bad header format, unsupported FORMAT";
             }
 
             lineIndex += (line.length + 1);
             line = this.readStringLine(uint8array, lineIndex);
-            
+
             var sizeRegexp = /^\-Y (.*) \+X (.*)$/g;
             var match = sizeRegexp.exec(line);
 
             // TODO. Support +Y and -X if needed.
             if (match.length < 3) {
-                throw "HDR Bad header format, no size"; 
+                throw "HDR Bad header format, no size";
             }
             width = parseInt(match[2]);
             height = parseInt(match[1]);
 
             if (width < 8 || width > 0x7fff) {
-                throw "HDR Bad header format, unsupported size"; 
+                throw "HDR Bad header format, unsupported size";
             }
 
             lineIndex += (line.length + 1);
@@ -145,7 +144,7 @@ module BABYLON.Internals {
          * @param size The expected size of the extracted cubemap.
          * @return The Cube Map information.
          */
-        public static GetCubeMapTextureData(buffer: ArrayBuffer, size: number) : CubeMapInfo {
+        public static GetCubeMapTextureData(buffer: ArrayBuffer, size: number): CubeMapInfo {
             var uint8array = new Uint8Array(buffer);
             var hdrInfo = this.RGBE_ReadHeader(uint8array);
             var data = this.RGBE_ReadPixels_RLE(uint8array, hdrInfo);
@@ -166,12 +165,12 @@ module BABYLON.Internals {
          * @param hdrInfo The header information of the file.
          * @return The pixels data in RGB right to left up to down order.
          */
-        public static RGBE_ReadPixels(uint8array:Uint8Array, hdrInfo:HDRInfo): Float32Array {
+        public static RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {
             // Keep for multi format supports.
             return this.RGBE_ReadPixels_RLE(uint8array, hdrInfo);
         }
-        
-        private static RGBE_ReadPixels_RLE(uint8array:Uint8Array, hdrInfo:HDRInfo): Float32Array {
+
+        private static RGBE_ReadPixels_RLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {
             var num_scanlines = hdrInfo.height;
             var scanline_width = hdrInfo.width;
 
@@ -183,32 +182,32 @@ module BABYLON.Internals {
             var scanLineArray = new Uint8Array(scanLineArrayBuffer);
 
             // 3 channels of 4 bytes per pixel in float.
-            var resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3); 
+            var resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);
             var resultArray = new Float32Array(resultBuffer);
 
             // read in each successive scanline
-            while(num_scanlines > 0) {
+            while (num_scanlines > 0) {
                 a = uint8array[dataIndex++];
                 b = uint8array[dataIndex++];
                 c = uint8array[dataIndex++];
                 d = uint8array[dataIndex++];
 
                 if (a != 2 || b != 2 || (c & 0x80)) {
-                  // this file is not run length encoded
-                  throw "HDR Bad header format, not RLE"; 
+                    // this file is not run length encoded
+                    throw "HDR Bad header format, not RLE";
                 }
 
-                if (((c<<8) | d) != scanline_width) {
-                  throw "HDR Bad header format, wrong scan line width"; 
+                if (((c << 8) | d) != scanline_width) {
+                    throw "HDR Bad header format, wrong scan line width";
                 }
 
                 index = 0;
 
                 // read each of the four channels for the scanline into the buffer
-                for(i = 0; i < 4; i++) {
+                for (i = 0; i < 4; i++) {
                     endIndex = (i + 1) * scanline_width;
 
-                    while(index < endIndex) {
+                    while (index < endIndex) {
                         a = uint8array[dataIndex++];
                         b = uint8array[dataIndex++];
 
@@ -219,7 +218,7 @@ module BABYLON.Internals {
                                 throw "HDR Bad Format, bad scanline data (run)";
                             }
 
-                            while(count-- > 0) {
+                            while (count-- > 0) {
                                 scanLineArray[index++] = b;
                             }
                         }
@@ -241,7 +240,7 @@ module BABYLON.Internals {
                 }
 
                 // now convert data from buffer into floats
-                for(i = 0; i < scanline_width; i++) {
+                for (i = 0; i < scanline_width; i++) {
                     a = scanLineArray[i];
                     b = scanLineArray[i + scanline_width];
                     c = scanLineArray[i + 2 * scanline_width];
@@ -258,4 +257,4 @@ module BABYLON.Internals {
             return resultArray;
         }
     }
-} 
+} 

+ 1 - 0
src/Tools/HDR/babylon.tools.panoramaToCubemap.ts

@@ -194,3 +194,4 @@ module BABYLON.Internals {
         }
     }
 } 
+

+ 1 - 0
src/Tools/HDR/babylon.tools.pmremgenerator.ts

@@ -1225,3 +1225,4 @@ namespace BABYLON.Internals {
         }
     }
 }
+