Переглянути джерело

Merge pull request #1559 from abow/master

added bone.getLocalPositionFromAbsolute
David Catuhe 8 роки тому
батько
коміт
f312376333
2 змінених файлів з 29 додано та 1 видалено
  1. 1 1
      dist/preview release/what's new.md
  2. 28 0
      src/Bones/babylon.bone.ts

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

@@ -19,7 +19,7 @@
 - Added Ray.intersectsMesh, Ray.show, Ray.hide ([abow](https://github.com/abow))
 - Added AbstractMesh.setPivotPoint, AbstractMesh.getPivotPoint, AbstractMesh.getAbsolutePivotPoint ([abow](https://github.com/abow))
 - Added Debug.AxesViewer and Debug.BoneAxesViewer ([abow](https://github.com/abow))
-- Added Bone.getAbsolutePositionFromLocal ([abow](https://github.com/abow))
+- Added Bone.getAbsolutePositionFromLocal and getLocalPositionFromAbsolute ([abow](https://github.com/abow))
 - Added Bone.setRotation, Bone.getRotation, Bone.setRotationQuaternion, Bone.getRotationQuaternion ([abow](https://github.com/abow))
 - Added Bone.getAbsolutePosition and Bone.getAbsolutePositionToRef ([abow](https://github.com/abow))
 - Added Bone.translate, Bone.setPosition, Bone.setAbsolutePosition ([abow](https://github.com/abow))

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

@@ -753,5 +753,33 @@
 
         }
 
+        public getLocalPositionFromAbsolute(position:Vector3, mesh?:AbstractMesh): Vector3{
+
+            var result = Vector3.Zero();
+
+            this.getLocalPositionFromAbsoluteToRef(position, mesh, result);
+
+            return result;
+
+        }
+
+        public getLocalPositionFromAbsoluteToRef(position:Vector3, mesh:AbstractMesh, result:Vector3): void{
+
+            this._skeleton.computeAbsoluteTransforms();
+
+            var tmat = Tmp.Matrix[0];
+
+            tmat.copyFrom(this.getAbsoluteTransform());
+            
+            if (mesh) {
+                tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+            }
+
+            tmat.invert();
+
+            Vector3.TransformCoordinatesToRef(position, tmat, result);
+
+        }
+
     }
 }