Selaa lähdekoodia

Merge pull request #1749 from abow/trackNodeOrigin

stopped allocation of Vector3 and Matrix when trackingNodes in screen space
Loïc Baumann 8 vuotta sitten
vanhempi
commit
7a5f9852cd

+ 4 - 8
canvas2D/src/Engine/babylon.canvas2d.ts

@@ -1286,6 +1286,8 @@
         private static tS = Vector3.Zero();
         private static tT = Vector3.Zero();
         private static tR = Quaternion.Identity();
+        private static _tmpMtx = Matrix.Identity();
+        private static _tmpVec3 = Vector3.Zero();
 
         private _updateTrackedNodes() {
             // Get the used camera
@@ -1295,8 +1297,8 @@
             cam.getViewMatrix().multiplyToRef(cam.getProjectionMatrix(), Canvas2D._m);
             let rh = this.engine.getRenderHeight();
             let v = cam.viewport.toGlobal(this.engine.getRenderWidth(), rh);
-            let tmpVec3:Vector3;
-            let tmpMtx:Matrix;
+            let tmpVec3 = Canvas2D._tmpVec3;
+            let tmpMtx = Canvas2D._tmpMtx;
 
             // Compute the screen position of each group that track a given scene node
             for (let group of this._trackedGroups) {
@@ -1308,12 +1310,6 @@
                 let worldMtx = node.getWorldMatrix();
 
                 if(group.trackedNodeOffset){
-                    if(!tmpVec3){
-                        tmpVec3 = Vector3.Zero();
-                    }
-                    if(!tmpMtx){
-                        tmpMtx = Matrix.Identity();
-                    }
                     Vector3.TransformCoordinatesToRef(group.trackedNodeOffset, worldMtx, tmpVec3);
                     tmpMtx.copyFrom(worldMtx);
                     worldMtx = tmpMtx;

+ 2 - 0
canvas2D/src/Engine/babylon.group2d.ts

@@ -43,6 +43,8 @@
          * - rotation: the initial rotation (in radian) of the primitive. default is 0
          * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
          * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
+         * - trackNode: if you want the ScreenSpaceCanvas to track the position of a given Scene Node, use this setting to specify the Node to track
+         * - trackNodeOffset: if you use trackNode you may want to specify a 3D Offset to apply to shift the Canvas
          * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
          * - zOrder: override the zOrder with the specified value
          * - origin: define the normalized origin point location, default [0.5;0.5]