@antv/g 1.0.0-alpha.32 → 1.0.0-alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -407,11 +407,16 @@ function () {
407
407
  sortable.dirty = true;
408
408
  }
409
409
 
410
+ this.updateGraphDepth(child);
410
411
  var transform = entity.getComponent(_components.Transform);
411
412
 
412
413
  if (transform) {
413
414
  this.dirtifyWorld(child, transform);
414
415
  }
416
+
417
+ if (transform.frozen) {
418
+ this.unfreezeParentToRoot(child);
419
+ }
415
420
  };
416
421
 
417
422
  DefaultSceneGraphService.prototype.detach = function (child) {
@@ -579,6 +584,10 @@ function () {
579
584
  };
580
585
 
581
586
  DefaultSceneGraphService.prototype.dirtifyWorld = function (element, transform) {
587
+ if (!transform.dirtyFlag) {
588
+ this.unfreezeParentToRoot(element);
589
+ }
590
+
582
591
  this.dirtifyWorldInternal(element, transform);
583
592
  };
584
593
 
@@ -602,10 +611,6 @@ function () {
602
611
  transform = element.entity.getComponent(_components.Transform);
603
612
  }
604
613
 
605
- if (!transform) {
606
- return _glMatrix.mat4.create();
607
- }
608
-
609
614
  if (!transform.localDirtyFlag && !transform.dirtyFlag) {
610
615
  return transform.worldTransform;
611
616
  }
@@ -614,7 +619,7 @@ function () {
614
619
  this.getWorldTransform(element.parentNode);
615
620
  }
616
621
 
617
- this.updateTransform(element, transform);
622
+ this.sync(element, transform);
618
623
  return transform.worldTransform;
619
624
  };
620
625
 
@@ -811,13 +816,14 @@ function () {
811
816
 
812
817
  if (!transform.dirtyFlag) {
813
818
  transform.dirtyFlag = true;
819
+ transform.frozen = false;
814
820
  element.childNodes.forEach(function (child) {
815
821
  var childTransform = child.entity.getComponent(_components.Transform);
816
822
 
817
823
  if (!childTransform.dirtyFlag) {
818
824
  _this.dirtifyWorldInternal(child, childTransform);
819
825
  }
820
- }); // emit on leaf node
826
+ }); // FIXME: emit on leaf node
821
827
 
822
828
  if (element.childNodes.length === 0) {
823
829
  dirtifyRenderable(element);
@@ -825,9 +831,31 @@ function () {
825
831
  }
826
832
  };
827
833
 
828
- DefaultSceneGraphService.prototype.updateTransform = function (element, transform) {
834
+ DefaultSceneGraphService.prototype.syncHierarchy = function (element) {
835
+ var transform = element.entity.getComponent(_components.Transform);
836
+
837
+ if (transform.frozen) {
838
+ return;
839
+ }
840
+
841
+ transform.frozen = true;
842
+
843
+ if (transform.localDirtyFlag || transform.dirtyFlag) {
844
+ this.sync(element, transform);
845
+ }
846
+
847
+ var children = element.childNodes;
848
+
849
+ for (var i = 0; i < children.length; i++) {
850
+ this.syncHierarchy(children[i]);
851
+ }
852
+ };
853
+
854
+ DefaultSceneGraphService.prototype.sync = function (element, transform) {
829
855
  if (transform.localDirtyFlag) {
830
- this.getLocalTransform(element);
856
+ _glMatrix.mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, transform.localScale, transform.origin);
857
+
858
+ transform.localDirtyFlag = false;
831
859
  }
832
860
 
833
861
  if (transform.dirtyFlag) {
@@ -841,8 +869,36 @@ function () {
841
869
  // @see https://github.com/playcanvas/engine/issues/1077#issuecomment-359765557
842
870
  _glMatrix.mat4.multiply(transform.worldTransform, parentTransform.worldTransform, transform.localTransform);
843
871
  }
872
+ }
873
+ };
874
+
875
+ DefaultSceneGraphService.prototype.updateGraphDepth = function (element) {
876
+ var transform = element.entity.getComponent(_components.Transform);
877
+
878
+ if (element.parentNode) {
879
+ transform.graphDepth = element.parentNode.entity.getComponent(_components.Transform).graphDepth + 1;
880
+ } else {
881
+ transform.graphDepth = 0;
882
+ }
883
+
884
+ var children = element.childNodes;
885
+
886
+ for (var i = 0; i < children.length; i++) {
887
+ this.updateGraphDepth(children[i]);
888
+ }
889
+ };
890
+
891
+ DefaultSceneGraphService.prototype.unfreezeParentToRoot = function (child) {
892
+ var p = child.parentNode;
893
+
894
+ while (p) {
895
+ var transform = p.entity.getComponent(_components.Transform);
896
+
897
+ if (transform) {
898
+ transform.frozen = false;
899
+ }
844
900
 
845
- transform.dirtyFlag = false;
901
+ p = p.parentNode;
846
902
  }
847
903
  };
848
904
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "1.0.0-alpha.32",
3
+ "version": "1.0.0-alpha.33",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.esm.js",
@@ -52,5 +52,5 @@
52
52
  "scripts": {
53
53
  "umd": "webpack"
54
54
  },
55
- "gitHead": "4da9ca442ec295aeec5b2fa19ffe4304160efbb5"
55
+ "gitHead": "5fd0248267f142dd756e106b908a6793b828454b"
56
56
  }