Browse Source

new mesh.attachToBone feature

David Catuhe 10 years ago
parent
commit
b01036be97

File diff suppressed because it is too large
+ 18 - 17
dist/preview release - alpha/babylon.2.2.js


+ 19 - 1
dist/preview release - alpha/babylon.2.2.max.js

@@ -8002,7 +8002,16 @@ var BABYLON;
             // Parent
             if (this.parent && this.parent.getWorldMatrix && this.billboardMode === AbstractMesh.BILLBOARDMODE_NONE) {
                 this._markSyncedWithParent();
-                this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+                if (this._meshToBoneReferal) {
+                    if (!this._localMeshReferalTransform) {
+                        this._localMeshReferalTransform = BABYLON.Matrix.Zero();
+                    }
+                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._localMeshReferalTransform);
+                    this._localMeshReferalTransform.multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), this._worldMatrix);
+                }
+                else {
+                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+                }
             }
             else {
                 this._worldMatrix.copyFrom(this._localWorld);
@@ -8060,6 +8069,14 @@ var BABYLON;
             var pitch = Math.atan2(dv.y, len);
             this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw + yawCor, pitch + pitchCor, rollCor);
         };
+        AbstractMesh.prototype.attachToBone = function (bone, affectedMesh) {
+            this._meshToBoneReferal = affectedMesh;
+            this.parent = bone;
+        };
+        AbstractMesh.prototype.detachFromBone = function () {
+            this._meshToBoneReferal = null;
+            this.parent = null;
+        };
         AbstractMesh.prototype.isInFrustum = function (frustumPlanes) {
             return this._boundingInfo.isInFrustum(frustumPlanes);
         };
@@ -21813,6 +21830,7 @@ var BABYLON;
             }
         };
         Bone.prototype.markAsDirty = function () {
+            this._currentRenderId++;
             this._skeleton._markAsDirty();
         };
         return Bone;

File diff suppressed because it is too large
+ 20 - 19
dist/preview release - alpha/babylon.2.2.noworker.js


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

@@ -1,9 +1,9 @@
 - 2.2.0:
   - **Major updates**
+    - Meshes can now be attached to bones. See [documentation here](http://babylondoc.azurewebsites.net/page.php?p=22421) and [sample here](http://www.babylonjs-playground.com/#11BH6Z#18) [deltakosh](https://github.com/deltakosh)
     - HDR Rendering pipeline. See [demo here]() [julien-moreau](https://github.com/julien-moreau)
   - **Updates**
     - Vertex color and diffuse color can now be mixed [deltakosh](https://github.com/deltakosh)
-    - Meshes can now be attached to bones [deltakosh](https://github.com/deltakosh)
     - Depth-of-field improvements [PR](https://github.com/BabylonJS/Babylon.js/pull/567) [jahow](https://github.com/jahow)
     - Engine now initialize WebGL with preserveDrawingBuffer = false by default [deltakosh](https://github.com/deltakosh)
     - withEpsilon with a user defined epsilon [PR](https://github.com/BabylonJS/Babylon.js/pull/573) [RaananW](https://github.com/RaananW)

+ 1 - 0
src/Bones/babylon.bone.js

@@ -73,6 +73,7 @@ var BABYLON;
             }
         };
         Bone.prototype.markAsDirty = function () {
+            this._currentRenderId++;
             this._skeleton._markAsDirty();
         };
         return Bone;

+ 1 - 0
src/Bones/babylon.bone.ts

@@ -85,6 +85,7 @@
         }
 
         public markAsDirty(): void {
+            this._currentRenderId++;
             this._skeleton._markAsDirty();
         }
     }

+ 18 - 1
src/Mesh/babylon.abstractMesh.js

@@ -444,7 +444,16 @@ var BABYLON;
             // Parent
             if (this.parent && this.parent.getWorldMatrix && this.billboardMode === AbstractMesh.BILLBOARDMODE_NONE) {
                 this._markSyncedWithParent();
-                this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+                if (this._meshToBoneReferal) {
+                    if (!this._localMeshReferalTransform) {
+                        this._localMeshReferalTransform = BABYLON.Matrix.Zero();
+                    }
+                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._localMeshReferalTransform);
+                    this._localMeshReferalTransform.multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), this._worldMatrix);
+                }
+                else {
+                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+                }
             }
             else {
                 this._worldMatrix.copyFrom(this._localWorld);
@@ -502,6 +511,14 @@ var BABYLON;
             var pitch = Math.atan2(dv.y, len);
             this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw + yawCor, pitch + pitchCor, rollCor);
         };
+        AbstractMesh.prototype.attachToBone = function (bone, affectedMesh) {
+            this._meshToBoneReferal = affectedMesh;
+            this.parent = bone;
+        };
+        AbstractMesh.prototype.detachFromBone = function () {
+            this._meshToBoneReferal = null;
+            this.parent = null;
+        };
         AbstractMesh.prototype.isInFrustum = function (frustumPlanes) {
             return this._boundingInfo.isInFrustum(frustumPlanes);
         };

+ 25 - 1
src/Mesh/babylon.abstractMesh.ts

@@ -81,6 +81,9 @@
         private _diffPositionForCollisions = new Vector3(0, 0, 0);
         private _newPositionForCollisions = new Vector3(0, 0, 0);
 
+        // Attach to bone
+        private _meshToBoneReferal: AbstractMesh;
+
         // Cache
         private _localScaling = Matrix.Zero();
         private _localRotation = Matrix.Zero();
@@ -88,6 +91,7 @@
         private _localBillboard = Matrix.Zero();
         private _localPivotScaling = Matrix.Zero();
         private _localPivotScalingRotation = Matrix.Zero();
+        private _localMeshReferalTransform: Matrix;
         private _localWorld = Matrix.Zero();
         public _worldMatrix = Matrix.Zero();
         private _rotateYByPI = Matrix.RotationY(Math.PI);
@@ -491,7 +495,17 @@
             // Parent
             if (this.parent && this.parent.getWorldMatrix && this.billboardMode === AbstractMesh.BILLBOARDMODE_NONE) {
                 this._markSyncedWithParent();
-                this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+
+                if (this._meshToBoneReferal) {
+                    if (!this._localMeshReferalTransform) {
+                        this._localMeshReferalTransform = Matrix.Zero();
+                    }
+
+                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._localMeshReferalTransform);
+                    this._localMeshReferalTransform.multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), this._worldMatrix);
+                } else {
+                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+                }
             } else {
                 this._worldMatrix.copyFrom(this._localWorld);
             }
@@ -565,6 +579,16 @@
             this.rotationQuaternion = Quaternion.RotationYawPitchRoll(yaw + yawCor, pitch + pitchCor, rollCor);
         }
 
+        public attachToBone(bone: Bone, affectedMesh: AbstractMesh): void {
+            this._meshToBoneReferal = affectedMesh;
+            this.parent = bone;
+        }
+
+        public detachFromBone(): void {
+            this._meshToBoneReferal = null;
+            this.parent = null;
+        }
+
         public isInFrustum(frustumPlanes: Plane[]): boolean {
             return this._boundingInfo.isInFrustum(frustumPlanes);
         }