Skip to content

Commit 9caa65a

Browse files
authored
Sync optimisation update (playcanvas#1583)
* Frozen property added to optimise SyncHierarchy * Core review feedback - comment added. * A fix for _frozen flag issue reported on GH
1 parent 155c59d commit 9caa65a

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/scene/graph-node.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Object.assign(pc, function () {
3535
this._dirtyLocal = false;
3636
this._aabbVer = 0;
3737

38+
// _frozen flag marks the node to ignore hierarchy sync etirely (including children nodes)
39+
// engine code automatically freezes and unfreezes objects whenever required
40+
// segrigating dynamic and stationary nodes into subhierarchies allows to reduce sync time significantly
3841
this._frozen = false;
3942

4043
this.worldTransform = new pc.Mat4();
@@ -1141,6 +1144,9 @@ Object.assign(pc, function () {
11411144

11421145
// The child (plus subhierarchy) will need world transforms to be recalculated
11431146
node._dirtifyWorld();
1147+
// node might be already marked as dirty, in that case the whole chain stays frozen, so let's enforce unfreeze
1148+
if (this._frozen)
1149+
node._unfreezeParentToRoot();
11441150

11451151
// alert an entity that it has been inserted
11461152
if (node.fire) node.fire('insert', this);

tests/scene/test_graphnode.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,5 +368,17 @@ describe('pc.GraphNode', function () {
368368

369369
});
370370

371+
it('GraphNode: frozen flag after reparent and sync for world-dirty node', function () {
372+
var p = new pc.GraphNode('parent');
373+
p.syncHierarchy();
374+
375+
var c = new pc.GraphNode('child');
376+
c._dirtifyWorld();
377+
378+
p.addChild(c);
379+
p.syncHierarchy();
380+
381+
equal(c._frozen, true);
382+
});
371383

372384
});

0 commit comments

Comments
 (0)