Prechádzať zdrojové kódy

added trackNodeOffset to C2D Group2D

Adam Bowman 8 rokov pred
rodič
commit
48572575ea

+ 15 - 0
canvas2D/src/Engine/babylon.canvas2d.ts

@@ -1295,6 +1295,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;
 
             // Compute the screen position of each group that track a given scene node
             for (let group of this._trackedGroups) {
@@ -1305,6 +1307,19 @@
                 let node = group.trackedNode;
                 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;
+                    worldMtx.setTranslation(tmpVec3);
+                }
+
                 let proj = Vector3.Project(Canvas2D._v, worldMtx, Canvas2D._m, v);
 
                 // Set the visibility state accordingly, if the position is outside the frustum (well on the Z planes only...) set the group to hidden

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

@@ -83,6 +83,7 @@
             scaleY                  ?: number,
             dontInheritParentScale  ?: boolean,
             trackNode               ?: Node,
+            trackNodeOffset         ?: Vector3,
             opacity                 ?: number,
             zOrder                  ?: number, 
             origin                  ?: Vector2,
@@ -124,6 +125,7 @@
             let size = (!settings.size && !settings.width && !settings.height) ? null : (settings.size || (new Size(settings.width || 0, settings.height || 0)));
 
             this._trackedNode = (settings.trackNode == null) ? null : settings.trackNode;
+            this._trackedNodeOffset = (settings.trackNodeOffset == null) ? null : settings.trackNodeOffset;
             if (this._trackedNode && this.owner) {
                 this.owner._registerTrackedNode(this);
             }
@@ -345,6 +347,21 @@
             }
         }
 
+        /**
+         * Get/set the offset of the tracked node in the tracked node's local space.
+         */
+        public get trackedNodeOffset(): Vector3 {
+            return this._trackedNodeOffset;
+        }
+
+        public set trackedNodeOffset(val: Vector3) {
+            if (!this._trackedNodeOffset) {
+                this._trackedNodeOffset = val.clone();
+            } else {
+                this._trackedNodeOffset.copyFrom(val);
+            }
+        }
+
         protected levelIntersect(intersectInfo: IntersectInfo2D): boolean {
             // If we've made it so far it means the boundingInfo intersection test succeed, the Group2D is shaped the same, so we always return true
             return true;
@@ -1033,6 +1050,7 @@
         }
 
         private _trackedNode: Node;
+        private _trackedNodeOffset: Vector3;
         protected _isRenderableGroup: boolean;
         protected _isCachedGroup: boolean;
         private _cacheGroupDirty: boolean;