@antv/g 1.0.0-alpha.30 → 1.0.0-alpha.35

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.
@@ -60,12 +60,15 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
60
60
  register({
61
61
  token: _aabb.GeometryUpdaterFactory,
62
62
  useFactory: function useFactory(context) {
63
+ var cache = {};
63
64
  return function (tagName) {
64
- if (context.container.isBoundNamed(_aabb.GeometryAABBUpdater, tagName)) {
65
- return context.container.getNamed(_aabb.GeometryAABBUpdater, tagName);
65
+ if (!cache[tagName]) {
66
+ if (context.container.isBoundNamed(_aabb.GeometryAABBUpdater, tagName)) {
67
+ cache[tagName] = context.container.getNamed(_aabb.GeometryAABBUpdater, tagName);
68
+ }
66
69
  }
67
70
 
68
- return null;
71
+ return cache[tagName];
69
72
  };
70
73
  }
71
74
  }); // bind style property handlers
@@ -73,36 +76,45 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
73
76
  register({
74
77
  token: _propertyHandlers.StylePropertyParserFactory,
75
78
  useFactory: function useFactory(context) {
79
+ var cache = {};
76
80
  return function (propertyName) {
77
- if (context.container.isBoundNamed(_propertyHandlers.StylePropertyParser, propertyName)) {
78
- return context.container.getNamed(_propertyHandlers.StylePropertyParser, propertyName);
81
+ if (!cache[propertyName]) {
82
+ if (context.container.isBoundNamed(_propertyHandlers.StylePropertyParser, propertyName)) {
83
+ cache[propertyName] = context.container.getNamed(_propertyHandlers.StylePropertyParser, propertyName);
84
+ }
79
85
  }
80
86
 
81
- return null;
87
+ return cache[propertyName];
82
88
  };
83
89
  }
84
90
  });
85
91
  register({
86
92
  token: _propertyHandlers.StylePropertyUpdaterFactory,
87
93
  useFactory: function useFactory(context) {
94
+ var cache = {};
88
95
  return function (propertyName) {
89
- if (context.container.isBoundNamed(_propertyHandlers.StylePropertyUpdater, propertyName)) {
90
- return context.container.getAllNamed(_propertyHandlers.StylePropertyUpdater, propertyName);
96
+ if (!cache[propertyName]) {
97
+ if (context.container.isBoundNamed(_propertyHandlers.StylePropertyUpdater, propertyName)) {
98
+ cache[propertyName] = context.container.getAllNamed(_propertyHandlers.StylePropertyUpdater, propertyName);
99
+ }
91
100
  }
92
101
 
93
- return null;
102
+ return cache[propertyName];
94
103
  };
95
104
  }
96
105
  });
97
106
  register({
98
107
  token: _propertyHandlers.StylePropertyMergerFactory,
99
108
  useFactory: function useFactory(context) {
109
+ var cache = {};
100
110
  return function (propertyName) {
101
- if (context.container.isBoundNamed(_propertyHandlers.StylePropertyMerger, propertyName)) {
102
- return context.container.getNamed(_propertyHandlers.StylePropertyMerger, propertyName);
111
+ if (!cache[propertyName]) {
112
+ if (context.container.isBoundNamed(_propertyHandlers.StylePropertyMerger, propertyName)) {
113
+ cache[propertyName] = context.container.getNamed(_propertyHandlers.StylePropertyMerger, propertyName);
114
+ }
103
115
  }
104
116
 
105
- return null;
117
+ return cache[propertyName];
106
118
  };
107
119
  }
108
120
  });
@@ -644,11 +644,10 @@ function (_super) {
644
644
  }
645
645
 
646
646
  for (var i = 0; i < PROPAGATION_LIMIT && target !== this.rootTarget; i++) {
647
- if (_Node.Node.isNode(target) && !target.parentNode) {
648
- throw new Error('Cannot find propagation path to disconnected target');
649
- }
650
-
651
- if (_Node.Node.isNode(target)) {
647
+ // if (Node.isNode(target) && !target.parentNode) {
648
+ // throw new Error('Cannot find propagation path to disconnected target');
649
+ // }
650
+ if (_Node.Node.isNode(target) && target.parentNode) {
652
651
  // [target, parent, parent, root]
653
652
  propagationPath.push(target.parentNode);
654
653
  target = target.parentNode;
@@ -22,26 +22,27 @@ export interface PickingResult {
22
22
  export declare class RenderingService {
23
23
  private renderingPluginProvider;
24
24
  private renderingContext;
25
+ private sceneGraphService;
25
26
  private inited;
26
27
  hooks: {
27
- init: AsyncSeriesHook<[], import("tapable").UnsetAdditionalOptions>;
28
- prepare: SyncWaterfallHook<[DisplayObject<any, any>], import("tapable").UnsetAdditionalOptions>;
28
+ init: AsyncSeriesHook<any, any, any>;
29
+ prepare: SyncWaterfallHook<DisplayObject<any, any>, any, any>;
29
30
  /**
30
31
  * called at beginning of each frame, won't get called if nothing to re-render
31
32
  */
32
- beginFrame: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
33
- beforeRender: SyncHook<[DisplayObject<any, any>], void, import("tapable").UnsetAdditionalOptions>;
34
- render: SyncHook<[DisplayObject<any, any>], void, import("tapable").UnsetAdditionalOptions>;
35
- afterRender: SyncHook<[DisplayObject<any, any>], void, import("tapable").UnsetAdditionalOptions>;
36
- endFrame: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
37
- destroy: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
38
- pick: AsyncSeriesWaterfallHook<[PickingResult], PickingResult>;
39
- pointerDown: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
40
- pointerUp: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
41
- pointerMove: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
42
- pointerOut: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
43
- pointerOver: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
44
- pointerWheel: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
33
+ beginFrame: SyncHook<any, any, any>;
34
+ beforeRender: SyncHook<DisplayObject<any, any>, any, any>;
35
+ render: SyncHook<DisplayObject<any, any>, any, any>;
36
+ afterRender: SyncHook<DisplayObject<any, any>, any, any>;
37
+ endFrame: SyncHook<any, any, any>;
38
+ destroy: SyncHook<any, any, any>;
39
+ pick: AsyncSeriesWaterfallHook<PickingResult, PickingResult, any>;
40
+ pointerDown: SyncHook<InteractivePointerEvent, any, any>;
41
+ pointerUp: SyncHook<InteractivePointerEvent, any, any>;
42
+ pointerMove: SyncHook<InteractivePointerEvent, any, any>;
43
+ pointerOut: SyncHook<InteractivePointerEvent, any, any>;
44
+ pointerOver: SyncHook<InteractivePointerEvent, any, any>;
45
+ pointerWheel: SyncHook<InteractivePointerEvent, any, any>;
45
46
  };
46
47
  init(): Promise<void>;
47
48
  render(): void;
@@ -43,11 +43,11 @@ function () {
43
43
  /**
44
44
  * called at beginning of each frame, won't get called if nothing to re-render
45
45
  */
46
- beginFrame: new _tapable.SyncHook([]),
46
+ beginFrame: new _tapable.SyncHook(),
47
47
  beforeRender: new _tapable.SyncHook(['objectToRender']),
48
48
  render: new _tapable.SyncHook(['objectToRender']),
49
49
  afterRender: new _tapable.SyncHook(['objectToRender']),
50
- endFrame: new _tapable.SyncHook([]),
50
+ endFrame: new _tapable.SyncHook(),
51
51
  destroy: new _tapable.SyncHook(),
52
52
  pick: new _tapable.AsyncSeriesWaterfallHook(['result']),
53
53
  pointerDown: new _tapable.SyncHook(['event']),
@@ -89,6 +89,8 @@ function () {
89
89
  };
90
90
 
91
91
  RenderingService.prototype.render = function () {
92
+ this.sceneGraphService.syncHierarchy(this.renderingContext.root);
93
+
92
94
  if (this.renderingContext.renderReasons.size && this.inited) {
93
95
  this.renderDisplayObject(this.renderingContext.root);
94
96
 
@@ -152,6 +154,7 @@ function () {
152
154
 
153
155
  (0, _tslib.__decorate)([(0, _manaSyringe.contrib)(RenderingPluginContribution), (0, _tslib.__metadata)("design:type", Object)], RenderingService.prototype, "renderingPluginProvider", void 0);
154
156
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_RenderingContext.RenderingContext), (0, _tslib.__metadata)("design:type", Object)], RenderingService.prototype, "renderingContext", void 0);
157
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_SceneGraphService.SceneGraphService), (0, _tslib.__metadata)("design:type", Object)], RenderingService.prototype, "sceneGraphService", void 0);
155
158
  RenderingService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], RenderingService);
156
159
  return RenderingService;
157
160
  }();
@@ -37,6 +37,7 @@ export interface SceneGraphService {
37
37
  getLocalBounds(element: INode, render?: boolean): AABB | null;
38
38
  getGeometryBounds(element: INode, render?: boolean): AABB | null;
39
39
  getBoundingClientRect(element: INode): Rectangle;
40
+ syncHierarchy(element: INode): void;
40
41
  }
41
42
  /**
42
43
  * update transform in scene graph
@@ -142,5 +143,8 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
142
143
  getLocalBounds(element: INode): AABB | null;
143
144
  getBoundingClientRect(element: INode): Rectangle;
144
145
  private dirtifyWorldInternal;
145
- private updateTransform;
146
+ syncHierarchy(element: INode): void;
147
+ private sync;
148
+ private updateGraphDepth;
149
+ private unfreezeParentToRoot;
146
150
  }
@@ -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.30",
3
+ "version": "1.0.0-alpha.35",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.esm.js",
@@ -39,18 +39,17 @@
39
39
  "homepage": "https://github.com/antvis/g#readme",
40
40
  "dependencies": {
41
41
  "@antv/g-ecs": "^1.0.0-alpha.14",
42
- "@antv/g-math": "^1.0.0-alpha.9",
42
+ "@antv/g-math": "^1.0.0-alpha.10",
43
43
  "@antv/path-util": "^2.0.14",
44
44
  "@antv/util": "^2.0.13",
45
- "@babel/runtime": "^7.16.0",
46
45
  "d3-color": "^1.4.0",
47
46
  "eventemitter3": "^4.0.0",
48
47
  "gl-matrix": "^3.1.0",
49
48
  "mana-syringe": "^0.2.2",
50
- "tapable": "2.2.1"
49
+ "tapable": "1.1.3"
51
50
  },
52
51
  "scripts": {
53
52
  "umd": "webpack"
54
53
  },
55
- "gitHead": "a5bedb7fc7482122f6d56b85d9c5654d16677203"
54
+ "gitHead": "73333422afc377066250bd705a8d0746007b91e3"
56
55
  }