@configura/babylon-view 1.4.0 → 1.6.0-alpha.0

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.
Files changed (125) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/animation/AnimatableObject.d.ts +8 -8
  4. package/dist/animation/AnimatableObject.js +3 -3
  5. package/dist/animation/animator/Animator.d.ts +33 -33
  6. package/dist/animation/animator/Animator.js +58 -58
  7. package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
  8. package/dist/animation/animator/AnimatorEasing.js +31 -31
  9. package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
  10. package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
  11. package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
  12. package/dist/animation/animator/AnimatorHighlight.js +32 -32
  13. package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
  14. package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
  15. package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
  16. package/dist/animation/animator/AnimatorQueue.js +57 -57
  17. package/dist/animation/animator/AnimatorScale.d.ts +8 -8
  18. package/dist/animation/animator/AnimatorScale.js +13 -13
  19. package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
  20. package/dist/animation/animator/AnimatorSpin.js +13 -13
  21. package/dist/animation/animator/EasingFunctions.d.ts +35 -35
  22. package/dist/animation/animator/EasingFunctions.js +137 -137
  23. package/dist/animation/coordinator/Coordinator.d.ts +28 -28
  24. package/dist/animation/coordinator/Coordinator.js +47 -47
  25. package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
  26. package/dist/animation/coordinator/CoordinatorDropAndSpin.js +133 -133
  27. package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
  28. package/dist/animation/coordinator/CoordinatorIdentity.js +12 -12
  29. package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
  30. package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
  31. package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
  32. package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
  33. package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
  34. package/dist/animation/coordinator/CoordinatorPulseBounce.js +40 -40
  35. package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
  36. package/dist/animation/coordinator/CoordinatorPulseHighlight.js +34 -34
  37. package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
  38. package/dist/animation/coordinator/CoordinatorPulseInflate.js +30 -30
  39. package/dist/camera/CameraCreator.d.ts +5 -5
  40. package/dist/camera/CameraCreator.js +4 -4
  41. package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +26 -26
  42. package/dist/camera/CfgArcRotateCameraPointersInput.js +264 -264
  43. package/dist/camera/CfgOrbitalCamera.d.ts +68 -68
  44. package/dist/camera/CfgOrbitalCamera.js +250 -250
  45. package/dist/camera/CfgOrbitalCameraControlProps.d.ts +6 -6
  46. package/dist/camera/CfgOrbitalCameraControlProps.js +3 -3
  47. package/dist/camera/GradingApplier.d.ts +3 -3
  48. package/dist/camera/GradingApplier.js +48 -48
  49. package/dist/engine/EngineCreator.d.ts +3 -3
  50. package/dist/engine/EngineCreator.js +10 -10
  51. package/dist/geometry/CfgGeometry.d.ts +29 -29
  52. package/dist/geometry/CfgGeometry.js +146 -146
  53. package/dist/geometry/CfgMesh.d.ts +10 -10
  54. package/dist/geometry/CfgMesh.js +38 -38
  55. package/dist/geometry/geoSplitter.d.ts +8 -8
  56. package/dist/geometry/geoSplitter.js +192 -192
  57. package/dist/geometry/stretch/CfgMorphTarget.d.ts +15 -15
  58. package/dist/geometry/stretch/CfgMorphTarget.js +65 -65
  59. package/dist/geometry/stretch/CfgStretchData.d.ts +116 -114
  60. package/dist/geometry/stretch/CfgStretchData.js +346 -340
  61. package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +16 -16
  62. package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -95
  63. package/dist/index.d.ts +13 -13
  64. package/dist/index.js +13 -13
  65. package/dist/light/CfgDirectionalLight.d.ts +8 -8
  66. package/dist/light/CfgDirectionalLight.js +18 -18
  67. package/dist/light/CfgHemisphericLight.d.ts +7 -7
  68. package/dist/light/CfgHemisphericLight.js +17 -17
  69. package/dist/light/CfgPointLight.d.ts +8 -8
  70. package/dist/light/CfgPointLight.js +18 -18
  71. package/dist/light/DefaultLightRig.d.ts +19 -19
  72. package/dist/light/DefaultLightRig.js +77 -77
  73. package/dist/light/LightRigCreator.d.ts +9 -9
  74. package/dist/light/LightRigCreator.js +3 -3
  75. package/dist/material/CfgMaterial.d.ts +68 -68
  76. package/dist/material/CfgMaterial.js +482 -482
  77. package/dist/material/DummyMaterialCreator.d.ts +4 -4
  78. package/dist/material/DummyMaterialCreator.js +15 -15
  79. package/dist/material/material.d.ts +18 -18
  80. package/dist/material/material.js +128 -128
  81. package/dist/material/texture.d.ts +14 -14
  82. package/dist/material/texture.js +306 -306
  83. package/dist/nodes/CfgContentRootNode.d.ts +19 -19
  84. package/dist/nodes/CfgContentRootNode.js +75 -75
  85. package/dist/nodes/CfgDeferredMeshNode.d.ts +55 -55
  86. package/dist/nodes/CfgDeferredMeshNode.js +377 -377
  87. package/dist/nodes/CfgProductNode.d.ts +126 -126
  88. package/dist/nodes/CfgProductNode.js +579 -578
  89. package/dist/nodes/CfgSymNode.d.ts +50 -50
  90. package/dist/nodes/CfgSymNode.js +249 -249
  91. package/dist/nodes/CfgSymRootNode.d.ts +45 -45
  92. package/dist/nodes/CfgSymRootNode.js +220 -220
  93. package/dist/nodes/CfgTransformNode.d.ts +33 -33
  94. package/dist/nodes/CfgTransformNode.js +83 -83
  95. package/dist/scene/SceneCreator.d.ts +6 -6
  96. package/dist/scene/SceneCreator.js +22 -22
  97. package/dist/utilities/CfgBoundingBox.d.ts +21 -21
  98. package/dist/utilities/CfgBoundingBox.js +81 -81
  99. package/dist/utilities/anchor/anchor.d.ts +55 -51
  100. package/dist/utilities/anchor/anchor.js +140 -136
  101. package/dist/utilities/anchor/anchorMap.d.ts +20 -20
  102. package/dist/utilities/anchor/anchorMap.js +111 -111
  103. package/dist/utilities/utilities3D.d.ts +70 -70
  104. package/dist/utilities/utilities3D.js +265 -265
  105. package/dist/utilities/utilitiesColor.d.ts +18 -18
  106. package/dist/utilities/utilitiesColor.js +48 -48
  107. package/dist/utilities/utilitiesImage.d.ts +6 -6
  108. package/dist/utilities/utilitiesImage.js +107 -107
  109. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +7 -7
  110. package/dist/utilities/utilitiesSymRootIdentifier.js +26 -26
  111. package/dist/view/BaseView.d.ts +78 -78
  112. package/dist/view/BaseView.js +297 -297
  113. package/dist/view/BaseViewConfiguration.d.ts +32 -32
  114. package/dist/view/BaseViewConfiguration.js +10 -8
  115. package/dist/view/RenderEnv.d.ts +43 -43
  116. package/dist/view/RenderEnv.js +7 -7
  117. package/dist/view/SingleProductDefaultCameraView.d.ts +33 -33
  118. package/dist/view/SingleProductDefaultCameraView.js +141 -141
  119. package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +46 -46
  120. package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
  121. package/dist/view/SingleProductView.d.ts +42 -42
  122. package/dist/view/SingleProductView.js +206 -206
  123. package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
  124. package/dist/view/SingleProductViewConfiguration.js +19 -19
  125. package/package.json +5 -5
@@ -1,43 +1,43 @@
1
- import { Camera } from "@babylonjs/core/Cameras/camera.js";
2
- import { ApplicationArea, CfgProduct } from "@configura/web-api";
3
- import { EventListener } from "@configura/web-utilities";
4
- import { CoordinatorWithMeta } from "../animation/coordinator/Coordinator.js";
5
- import { CameraCreator } from "../camera/CameraCreator.js";
6
- import { EngineCreator } from "../engine/EngineCreator.js";
7
- import { LightRigCreator } from "../light/LightRigCreator.js";
8
- import { DummyMaterialCreator } from "../material/DummyMaterialCreator.js";
9
- import { CfgProductNode } from "../nodes/CfgProductNode.js";
10
- import { SceneCreator } from "../scene/SceneCreator.js";
11
- import { BaseView } from "./BaseView.js";
12
- import { SingleProductViewConfiguration, SingleProductViewEventMap } from "./SingleProductViewConfiguration.js";
13
- export declare type LoadingOrApplicationAreas = ApplicationArea[] | "loading";
14
- export declare type SingleProductViewConstructorOptions<C extends Camera> = {
15
- canvas: HTMLCanvasElement;
16
- cameraCreator: CameraCreator<C>;
17
- engineCreator?: EngineCreator;
18
- lightRigCreator?: LightRigCreator;
19
- sceneCreator?: SceneCreator;
20
- dummyMaterialCreator?: DummyMaterialCreator;
21
- };
22
- export declare class SingleProductView<C extends Camera = Camera, T extends SingleProductViewEventMap = SingleProductViewEventMap> extends BaseView<C, T> {
23
- private _currentProductNode;
24
- private _scheduledForRemoval;
25
- private _viewPhaseObservable;
26
- private _currentPhase;
27
- private _animationCoordinatorCreator;
28
- private _animationCoordinator;
29
- constructor(options: SingleProductViewConstructorOptions<C>);
30
- destroy(): void;
31
- private scheduleForRemoval;
32
- setConfiguration(configuration: SingleProductViewConfiguration): void;
33
- get currentProductNode(): CfgProductNode | undefined;
34
- addEventListener<K extends keyof T>(event: K, listener: EventListener<T, K>): void;
35
- removeEventListener<K extends keyof T>(event: K, listener: EventListener<T, K>): void;
36
- protected getNeededFrameRender(time: number): boolean;
37
- protected renderFrame(time: number): void;
38
- private notifyPhaseChange;
39
- clearProduct: () => void;
40
- flushScheduledForRemove(animationCoordinator?: CoordinatorWithMeta): Promise<void>;
41
- loadProduct: (applicationAreas: LoadingOrApplicationAreas, product: CfgProduct) => (() => void);
42
- }
1
+ import { Camera } from "@babylonjs/core/Cameras/camera.js";
2
+ import { ApplicationArea, CfgProduct } from "@configura/web-api";
3
+ import { EventListener } from "@configura/web-utilities";
4
+ import { CoordinatorWithMeta } from "../animation/coordinator/Coordinator.js";
5
+ import { CameraCreator } from "../camera/CameraCreator.js";
6
+ import { EngineCreator } from "../engine/EngineCreator.js";
7
+ import { LightRigCreator } from "../light/LightRigCreator.js";
8
+ import { DummyMaterialCreator } from "../material/DummyMaterialCreator.js";
9
+ import { CfgProductNode } from "../nodes/CfgProductNode.js";
10
+ import { SceneCreator } from "../scene/SceneCreator.js";
11
+ import { BaseView } from "./BaseView.js";
12
+ import { SingleProductViewConfiguration, SingleProductViewEventMap } from "./SingleProductViewConfiguration.js";
13
+ export declare type LoadingOrApplicationAreas = ApplicationArea[] | "loading";
14
+ export declare type SingleProductViewConstructorOptions<C extends Camera> = {
15
+ canvas: HTMLCanvasElement;
16
+ cameraCreator: CameraCreator<C>;
17
+ engineCreator?: EngineCreator;
18
+ lightRigCreator?: LightRigCreator;
19
+ sceneCreator?: SceneCreator;
20
+ dummyMaterialCreator?: DummyMaterialCreator;
21
+ };
22
+ export declare class SingleProductView<C extends Camera = Camera, T extends SingleProductViewEventMap = SingleProductViewEventMap> extends BaseView<C, T> {
23
+ private _currentProductNode;
24
+ private _scheduledForRemoval;
25
+ private _viewPhaseObservable;
26
+ private _currentPhase;
27
+ private _animationCoordinatorCreator;
28
+ private _animationCoordinator;
29
+ constructor(options: SingleProductViewConstructorOptions<C>);
30
+ destroy(): void;
31
+ private scheduleForRemoval;
32
+ setConfiguration(configuration: SingleProductViewConfiguration): void;
33
+ get currentProductNode(): CfgProductNode | undefined;
34
+ addEventListener<K extends keyof T>(event: K, listener: EventListener<T, K>): void;
35
+ removeEventListener<K extends keyof T>(event: K, listener: EventListener<T, K>): void;
36
+ protected getNeededFrameRender(time: number): boolean;
37
+ protected renderFrame(time: number): void;
38
+ private notifyPhaseChange;
39
+ clearProduct: () => void;
40
+ flushScheduledForRemove(animationCoordinator?: CoordinatorWithMeta): Promise<void>;
41
+ loadProduct: (applicationAreas: LoadingOrApplicationAreas, product: CfgProduct) => (() => void);
42
+ }
43
43
  //# sourceMappingURL=SingleProductView.d.ts.map
@@ -1,206 +1,206 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { CfgMtrlApplication, CfgMtrlApplicationSource, } from "@configura/web-api";
11
- import { getWaitFramesPromise, Observable } from "@configura/web-utilities";
12
- import { CoordinatorIdentity } from "../animation/coordinator/CoordinatorIdentity.js";
13
- import { CfgProductNode } from "../nodes/CfgProductNode.js";
14
- import { BaseView } from "./BaseView.js";
15
- import { SingleProductViewPhase, } from "./SingleProductViewConfiguration.js";
16
- export class SingleProductView extends BaseView {
17
- constructor(options) {
18
- super(options);
19
- this._scheduledForRemoval = [];
20
- this._viewPhaseObservable = new Observable();
21
- this._currentPhase = SingleProductViewPhase.Idle;
22
- this.notifyPhaseChange = (phase) => {
23
- this._viewPhaseObservable.notifyAll({
24
- previous: this._currentPhase,
25
- current: phase,
26
- });
27
- this._currentPhase = phase;
28
- };
29
- this.clearProduct = () => {
30
- let currentProductNode = this._currentProductNode;
31
- if (currentProductNode !== undefined) {
32
- this.notifyPhaseChange(SingleProductViewPhase.RemovePreviousProduct);
33
- this.scheduleForRemoval(currentProductNode);
34
- this._currentProductNode = undefined;
35
- }
36
- };
37
- this.loadProduct = (applicationAreas, product) => {
38
- this.notifyPhaseChange(SingleProductViewPhase.LoadProductCalled);
39
- const abortController = new AbortController();
40
- const abortSignal = abortController.signal;
41
- const loadingToken = this._loadingObservable.startChildLoading();
42
- const stopLoading = () => {
43
- this._loadingObservable.stopChildLoading(loadingToken);
44
- };
45
- (() => __awaiter(this, void 0, void 0, function* () {
46
- let isNewProduct = false;
47
- let currentProductNode = this._currentProductNode;
48
- if (currentProductNode === undefined ||
49
- !currentProductNode.product.isBackedBySame(product)) {
50
- this.clearProduct();
51
- this.notifyPhaseChange(SingleProductViewPhase.MakeNewProduct);
52
- currentProductNode = CfgProductNode.make(this._renderEnvironment, product);
53
- this.notifyPhaseChange(SingleProductViewPhase.AddNewProduct);
54
- this._currentProductNode = currentProductNode;
55
- this._contentRoot.add(currentProductNode);
56
- isNewProduct = true;
57
- }
58
- const animationCoordinator = {
59
- coordinator: this._animationCoordinator,
60
- isNewProduct,
61
- };
62
- try {
63
- this.notifyPhaseChange(SingleProductViewPhase.SetModelsAndLoadGeo);
64
- currentProductNode.refreshStretch();
65
- yield currentProductNode.loadGeo(animationCoordinator);
66
- if (isNewProduct) {
67
- // New products needs resizing before rendering the first time
68
- this.notifyPhaseChange(SingleProductViewPhase.HandleSizing);
69
- this.handleSizing(true);
70
- }
71
- if (abortSignal.aborted) {
72
- this.notifyPhaseChange(SingleProductViewPhase.Aborted);
73
- return;
74
- }
75
- if (applicationAreas !== "loading") {
76
- this.notifyPhaseChange(SingleProductViewPhase.SetApplicationAreas);
77
- currentProductNode.setApplicationAreas(applicationAreas.map((a) => CfgMtrlApplication.fromMtrlLikeApplication(CfgMtrlApplicationSource.ApplicationArea, a)));
78
- }
79
- const loadMaterialsPromise = currentProductNode.loadMaterials(animationCoordinator);
80
- const doRenderTemporaryMaterials = yield Promise.race([
81
- (() => __awaiter(this, void 0, void 0, function* () {
82
- yield loadMaterialsPromise;
83
- return false;
84
- }))(),
85
- (() => __awaiter(this, void 0, void 0, function* () {
86
- yield getWaitFramesPromise(10);
87
- return true;
88
- }))(),
89
- ]);
90
- this.notifyPhaseChange(SingleProductViewPhase.ApplyGeo);
91
- yield currentProductNode.applyGeo(animationCoordinator);
92
- this.flushScheduledForRemove(animationCoordinator);
93
- if (abortSignal.aborted) {
94
- this.notifyPhaseChange(SingleProductViewPhase.Aborted);
95
- return;
96
- }
97
- if (!isNewProduct) {
98
- // At this stage, any change in geometry has been applied
99
- this.notifyPhaseChange(SingleProductViewPhase.HandleSizing);
100
- this.handleSizing(false);
101
- }
102
- if (doRenderTemporaryMaterials) {
103
- this.scheduleRerender();
104
- }
105
- if (abortSignal.aborted) {
106
- this.notifyPhaseChange(SingleProductViewPhase.Aborted);
107
- return;
108
- }
109
- this.notifyPhaseChange(SingleProductViewPhase.LoadMaterials);
110
- yield loadMaterialsPromise;
111
- if (abortSignal.aborted) {
112
- this.notifyPhaseChange(SingleProductViewPhase.Aborted);
113
- return;
114
- }
115
- this.notifyPhaseChange(SingleProductViewPhase.ApplyMaterials);
116
- this.pauseRendering();
117
- yield currentProductNode.applyMaterials();
118
- this.resumeRendering();
119
- this.notifyPhaseChange(SingleProductViewPhase.AppliedMaterials);
120
- this.scheduleRerender();
121
- stopLoading();
122
- this.notifyPhaseChange(SingleProductViewPhase.Idle);
123
- }
124
- catch (e) {
125
- this.notifyPhaseChange(SingleProductViewPhase.Error);
126
- this.notifyError(e);
127
- stopLoading();
128
- // Might result in double-unlock of semaphore, this is OK.
129
- this.resumeRendering();
130
- }
131
- }))();
132
- return () => {
133
- abortController.abort();
134
- stopLoading();
135
- };
136
- };
137
- this._animationCoordinator = new CoordinatorIdentity(this, this._viewPhaseObservable);
138
- }
139
- destroy() {
140
- this._animationCoordinator.destroy();
141
- super.destroy();
142
- }
143
- scheduleForRemoval(productNode) {
144
- productNode.destroy();
145
- this._scheduledForRemoval.push(productNode);
146
- }
147
- setConfiguration(configuration) {
148
- const animationCoordinatorCreator = configuration.experimentalAnimationCoordinator;
149
- if (animationCoordinatorCreator !== undefined &&
150
- this._animationCoordinatorCreator !== animationCoordinatorCreator) {
151
- this._animationCoordinatorCreator = animationCoordinatorCreator;
152
- this._animationCoordinator.destroy();
153
- this._animationCoordinator = animationCoordinatorCreator(this, this._viewPhaseObservable);
154
- }
155
- super.setConfiguration(configuration);
156
- }
157
- get currentProductNode() {
158
- return this._currentProductNode;
159
- }
160
- addEventListener(event, listener) {
161
- switch (event) {
162
- case "viewPhase":
163
- this._viewPhaseObservable.listen(listener);
164
- break;
165
- default:
166
- super.addEventListener(event, listener);
167
- }
168
- }
169
- removeEventListener(event, listener) {
170
- switch (event) {
171
- case "viewPhase":
172
- this._viewPhaseObservable.stopListen(listener);
173
- break;
174
- default:
175
- super.removeEventListener(event, listener);
176
- }
177
- }
178
- getNeededFrameRender(time) {
179
- return (super.getNeededFrameRender(time) ||
180
- this._animationCoordinator.willTick(time, this._engine.getDeltaTime()));
181
- }
182
- renderFrame(time) {
183
- this._animationCoordinator.tick(time, this._engine.getDeltaTime());
184
- super.renderFrame(time);
185
- }
186
- flushScheduledForRemove(animationCoordinator) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- if (this._scheduledForRemoval.length === 0) {
189
- return;
190
- }
191
- const promises = [];
192
- while (true) {
193
- const productNode = this._scheduledForRemoval.shift();
194
- if (productNode === undefined) {
195
- break;
196
- }
197
- promises.push((() => __awaiter(this, void 0, void 0, function* () {
198
- yield productNode.flushScheduledForRemove(animationCoordinator);
199
- this._contentRoot.remove(true, productNode);
200
- }))());
201
- }
202
- yield Promise.all(promises);
203
- this.notifyPhaseChange(SingleProductViewPhase.RemovedProduct);
204
- });
205
- }
206
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { CfgMtrlApplication, CfgMtrlApplicationSource, } from "@configura/web-api";
11
+ import { getWaitFramesPromise, Observable } from "@configura/web-utilities";
12
+ import { CoordinatorIdentity } from "../animation/coordinator/CoordinatorIdentity.js";
13
+ import { CfgProductNode } from "../nodes/CfgProductNode.js";
14
+ import { BaseView } from "./BaseView.js";
15
+ import { SingleProductViewPhase, } from "./SingleProductViewConfiguration.js";
16
+ export class SingleProductView extends BaseView {
17
+ constructor(options) {
18
+ super(options);
19
+ this._scheduledForRemoval = [];
20
+ this._viewPhaseObservable = new Observable();
21
+ this._currentPhase = SingleProductViewPhase.Idle;
22
+ this.notifyPhaseChange = (phase) => {
23
+ this._viewPhaseObservable.notifyAll({
24
+ previous: this._currentPhase,
25
+ current: phase,
26
+ });
27
+ this._currentPhase = phase;
28
+ };
29
+ this.clearProduct = () => {
30
+ let currentProductNode = this._currentProductNode;
31
+ if (currentProductNode !== undefined) {
32
+ this.notifyPhaseChange(SingleProductViewPhase.RemovePreviousProduct);
33
+ this.scheduleForRemoval(currentProductNode);
34
+ this._currentProductNode = undefined;
35
+ }
36
+ };
37
+ this.loadProduct = (applicationAreas, product) => {
38
+ this.notifyPhaseChange(SingleProductViewPhase.LoadProductCalled);
39
+ const abortController = new AbortController();
40
+ const abortSignal = abortController.signal;
41
+ const loadingToken = this._loadingObservable.startChildLoading();
42
+ const stopLoading = () => {
43
+ this._loadingObservable.stopChildLoading(loadingToken);
44
+ };
45
+ (() => __awaiter(this, void 0, void 0, function* () {
46
+ let isNewProduct = false;
47
+ let currentProductNode = this._currentProductNode;
48
+ if (currentProductNode === undefined ||
49
+ !currentProductNode.product.isBackedBySame(product)) {
50
+ this.clearProduct();
51
+ this.notifyPhaseChange(SingleProductViewPhase.MakeNewProduct);
52
+ currentProductNode = CfgProductNode.make(this._renderEnvironment, product);
53
+ this.notifyPhaseChange(SingleProductViewPhase.AddNewProduct);
54
+ this._currentProductNode = currentProductNode;
55
+ this._contentRoot.add(currentProductNode);
56
+ isNewProduct = true;
57
+ }
58
+ const animationCoordinator = {
59
+ coordinator: this._animationCoordinator,
60
+ isNewProduct,
61
+ };
62
+ try {
63
+ this.notifyPhaseChange(SingleProductViewPhase.SetModelsAndLoadGeo);
64
+ currentProductNode.refreshStretch();
65
+ yield currentProductNode.loadGeo(animationCoordinator);
66
+ if (isNewProduct) {
67
+ // New products needs resizing before rendering the first time
68
+ this.notifyPhaseChange(SingleProductViewPhase.HandleSizing);
69
+ this.handleSizing(true);
70
+ }
71
+ if (abortSignal.aborted) {
72
+ this.notifyPhaseChange(SingleProductViewPhase.Aborted);
73
+ return;
74
+ }
75
+ if (applicationAreas !== "loading") {
76
+ this.notifyPhaseChange(SingleProductViewPhase.SetApplicationAreas);
77
+ currentProductNode.setApplicationAreas(applicationAreas.map((a) => CfgMtrlApplication.fromMtrlLikeApplication(CfgMtrlApplicationSource.ApplicationArea, a)));
78
+ }
79
+ const loadMaterialsPromise = currentProductNode.loadMaterials(animationCoordinator);
80
+ const doRenderTemporaryMaterials = yield Promise.race([
81
+ (() => __awaiter(this, void 0, void 0, function* () {
82
+ yield loadMaterialsPromise;
83
+ return false;
84
+ }))(),
85
+ (() => __awaiter(this, void 0, void 0, function* () {
86
+ yield getWaitFramesPromise(10);
87
+ return true;
88
+ }))(),
89
+ ]);
90
+ this.notifyPhaseChange(SingleProductViewPhase.ApplyGeo);
91
+ yield currentProductNode.applyGeo(animationCoordinator);
92
+ this.flushScheduledForRemove(animationCoordinator);
93
+ if (abortSignal.aborted) {
94
+ this.notifyPhaseChange(SingleProductViewPhase.Aborted);
95
+ return;
96
+ }
97
+ if (!isNewProduct) {
98
+ // At this stage, any change in geometry has been applied
99
+ this.notifyPhaseChange(SingleProductViewPhase.HandleSizing);
100
+ this.handleSizing(false);
101
+ }
102
+ if (doRenderTemporaryMaterials) {
103
+ this.scheduleRerender();
104
+ }
105
+ if (abortSignal.aborted) {
106
+ this.notifyPhaseChange(SingleProductViewPhase.Aborted);
107
+ return;
108
+ }
109
+ this.notifyPhaseChange(SingleProductViewPhase.LoadMaterials);
110
+ yield loadMaterialsPromise;
111
+ if (abortSignal.aborted) {
112
+ this.notifyPhaseChange(SingleProductViewPhase.Aborted);
113
+ return;
114
+ }
115
+ this.notifyPhaseChange(SingleProductViewPhase.ApplyMaterials);
116
+ this.pauseRendering();
117
+ yield currentProductNode.applyMaterials();
118
+ this.resumeRendering();
119
+ this.notifyPhaseChange(SingleProductViewPhase.AppliedMaterials);
120
+ this.scheduleRerender();
121
+ stopLoading();
122
+ this.notifyPhaseChange(SingleProductViewPhase.Idle);
123
+ }
124
+ catch (e) {
125
+ this.notifyPhaseChange(SingleProductViewPhase.Error);
126
+ this.notifyError(e);
127
+ stopLoading();
128
+ // Might result in double-unlock of semaphore, this is OK.
129
+ this.resumeRendering();
130
+ }
131
+ }))();
132
+ return () => {
133
+ abortController.abort();
134
+ stopLoading();
135
+ };
136
+ };
137
+ this._animationCoordinator = new CoordinatorIdentity(this, this._viewPhaseObservable);
138
+ }
139
+ destroy() {
140
+ this._animationCoordinator.destroy();
141
+ super.destroy();
142
+ }
143
+ scheduleForRemoval(productNode) {
144
+ productNode.destroy();
145
+ this._scheduledForRemoval.push(productNode);
146
+ }
147
+ setConfiguration(configuration) {
148
+ const animationCoordinatorCreator = configuration.experimentalAnimationCoordinator;
149
+ if (animationCoordinatorCreator !== undefined &&
150
+ this._animationCoordinatorCreator !== animationCoordinatorCreator) {
151
+ this._animationCoordinatorCreator = animationCoordinatorCreator;
152
+ this._animationCoordinator.destroy();
153
+ this._animationCoordinator = animationCoordinatorCreator(this, this._viewPhaseObservable);
154
+ }
155
+ super.setConfiguration(configuration);
156
+ }
157
+ get currentProductNode() {
158
+ return this._currentProductNode;
159
+ }
160
+ addEventListener(event, listener) {
161
+ switch (event) {
162
+ case "viewPhase":
163
+ this._viewPhaseObservable.listen(listener);
164
+ break;
165
+ default:
166
+ super.addEventListener(event, listener);
167
+ }
168
+ }
169
+ removeEventListener(event, listener) {
170
+ switch (event) {
171
+ case "viewPhase":
172
+ this._viewPhaseObservable.stopListen(listener);
173
+ break;
174
+ default:
175
+ super.removeEventListener(event, listener);
176
+ }
177
+ }
178
+ getNeededFrameRender(time) {
179
+ return (super.getNeededFrameRender(time) ||
180
+ this._animationCoordinator.willTick(time, this._engine.getDeltaTime()));
181
+ }
182
+ renderFrame(time) {
183
+ this._animationCoordinator.tick(time, this._engine.getDeltaTime());
184
+ super.renderFrame(time);
185
+ }
186
+ flushScheduledForRemove(animationCoordinator) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ if (this._scheduledForRemoval.length === 0) {
189
+ return;
190
+ }
191
+ const promises = [];
192
+ while (true) {
193
+ const productNode = this._scheduledForRemoval.shift();
194
+ if (productNode === undefined) {
195
+ break;
196
+ }
197
+ promises.push((() => __awaiter(this, void 0, void 0, function* () {
198
+ yield productNode.flushScheduledForRemove(animationCoordinator);
199
+ this._contentRoot.remove(true, productNode);
200
+ }))());
201
+ }
202
+ yield Promise.all(promises);
203
+ this.notifyPhaseChange(SingleProductViewPhase.RemovedProduct);
204
+ });
205
+ }
206
+ }
@@ -1,33 +1,33 @@
1
- import { EventListener } from "@configura/web-utilities";
2
- import { CoordinatorCreator } from "../animation/coordinator/Coordinator.js";
3
- import { BaseViewConfiguration, BaseViewEventMap } from "./BaseViewConfiguration.js";
4
- export interface SingleProductViewConfiguration extends BaseViewConfiguration {
5
- experimentalAnimationCoordinator?: CoordinatorCreator;
6
- }
7
- export interface SingleProductViewEventMap extends BaseViewEventMap {
8
- viewPhase: SingleProductViewPhaseEvent;
9
- }
10
- export declare type SingleProductViewEventListener<K extends keyof SingleProductViewEventMap> = EventListener<SingleProductViewEventMap, K>;
11
- export declare type SingleProductViewPhaseEvent = {
12
- previous: SingleProductViewPhase;
13
- current: SingleProductViewPhase;
14
- };
15
- export declare enum SingleProductViewPhase {
16
- Idle = "Idle",
17
- LoadProductCalled = "LoadProductCalled",
18
- RemovePreviousProduct = "RemovePreviousProduct",
19
- RemovedProduct = "RemovedProduct",
20
- MakeNewProduct = "MakeNewProduct",
21
- AddNewProduct = "AddNewProduct",
22
- SetApplicationAreas = "SetApplicationAreas",
23
- SetModelsAndLoadGeo = "SetModelsAndLoadGeo",
24
- GeoLoaded = "GeoLoaded",
25
- ApplyGeo = "ApplyGeo",
26
- HandleSizing = "HandleSizing",
27
- LoadMaterials = "LoadMaterials",
28
- ApplyMaterials = "ApplyMaterials",
29
- AppliedMaterials = "AppliedMaterials",
30
- Aborted = "Aborted",
31
- Error = "Error"
32
- }
1
+ import { EventListener } from "@configura/web-utilities";
2
+ import { CoordinatorCreator } from "../animation/coordinator/Coordinator.js";
3
+ import { BaseViewConfiguration, BaseViewEventMap } from "./BaseViewConfiguration.js";
4
+ export interface SingleProductViewConfiguration extends BaseViewConfiguration {
5
+ experimentalAnimationCoordinator?: CoordinatorCreator;
6
+ }
7
+ export interface SingleProductViewEventMap extends BaseViewEventMap {
8
+ viewPhase: SingleProductViewPhaseEvent;
9
+ }
10
+ export declare type SingleProductViewEventListener<K extends keyof SingleProductViewEventMap> = EventListener<SingleProductViewEventMap, K>;
11
+ export declare type SingleProductViewPhaseEvent = {
12
+ previous: SingleProductViewPhase;
13
+ current: SingleProductViewPhase;
14
+ };
15
+ export declare enum SingleProductViewPhase {
16
+ Idle = "Idle",
17
+ LoadProductCalled = "LoadProductCalled",
18
+ RemovePreviousProduct = "RemovePreviousProduct",
19
+ RemovedProduct = "RemovedProduct",
20
+ MakeNewProduct = "MakeNewProduct",
21
+ AddNewProduct = "AddNewProduct",
22
+ SetApplicationAreas = "SetApplicationAreas",
23
+ SetModelsAndLoadGeo = "SetModelsAndLoadGeo",
24
+ GeoLoaded = "GeoLoaded",
25
+ ApplyGeo = "ApplyGeo",
26
+ HandleSizing = "HandleSizing",
27
+ LoadMaterials = "LoadMaterials",
28
+ ApplyMaterials = "ApplyMaterials",
29
+ AppliedMaterials = "AppliedMaterials",
30
+ Aborted = "Aborted",
31
+ Error = "Error"
32
+ }
33
33
  //# sourceMappingURL=SingleProductViewConfiguration.d.ts.map
@@ -1,19 +1,19 @@
1
- export var SingleProductViewPhase;
2
- (function (SingleProductViewPhase) {
3
- SingleProductViewPhase["Idle"] = "Idle";
4
- SingleProductViewPhase["LoadProductCalled"] = "LoadProductCalled";
5
- SingleProductViewPhase["RemovePreviousProduct"] = "RemovePreviousProduct";
6
- SingleProductViewPhase["RemovedProduct"] = "RemovedProduct";
7
- SingleProductViewPhase["MakeNewProduct"] = "MakeNewProduct";
8
- SingleProductViewPhase["AddNewProduct"] = "AddNewProduct";
9
- SingleProductViewPhase["SetApplicationAreas"] = "SetApplicationAreas";
10
- SingleProductViewPhase["SetModelsAndLoadGeo"] = "SetModelsAndLoadGeo";
11
- SingleProductViewPhase["GeoLoaded"] = "GeoLoaded";
12
- SingleProductViewPhase["ApplyGeo"] = "ApplyGeo";
13
- SingleProductViewPhase["HandleSizing"] = "HandleSizing";
14
- SingleProductViewPhase["LoadMaterials"] = "LoadMaterials";
15
- SingleProductViewPhase["ApplyMaterials"] = "ApplyMaterials";
16
- SingleProductViewPhase["AppliedMaterials"] = "AppliedMaterials";
17
- SingleProductViewPhase["Aborted"] = "Aborted";
18
- SingleProductViewPhase["Error"] = "Error";
19
- })(SingleProductViewPhase || (SingleProductViewPhase = {}));
1
+ export var SingleProductViewPhase;
2
+ (function (SingleProductViewPhase) {
3
+ SingleProductViewPhase["Idle"] = "Idle";
4
+ SingleProductViewPhase["LoadProductCalled"] = "LoadProductCalled";
5
+ SingleProductViewPhase["RemovePreviousProduct"] = "RemovePreviousProduct";
6
+ SingleProductViewPhase["RemovedProduct"] = "RemovedProduct";
7
+ SingleProductViewPhase["MakeNewProduct"] = "MakeNewProduct";
8
+ SingleProductViewPhase["AddNewProduct"] = "AddNewProduct";
9
+ SingleProductViewPhase["SetApplicationAreas"] = "SetApplicationAreas";
10
+ SingleProductViewPhase["SetModelsAndLoadGeo"] = "SetModelsAndLoadGeo";
11
+ SingleProductViewPhase["GeoLoaded"] = "GeoLoaded";
12
+ SingleProductViewPhase["ApplyGeo"] = "ApplyGeo";
13
+ SingleProductViewPhase["HandleSizing"] = "HandleSizing";
14
+ SingleProductViewPhase["LoadMaterials"] = "LoadMaterials";
15
+ SingleProductViewPhase["ApplyMaterials"] = "ApplyMaterials";
16
+ SingleProductViewPhase["AppliedMaterials"] = "AppliedMaterials";
17
+ SingleProductViewPhase["Aborted"] = "Aborted";
18
+ SingleProductViewPhase["Error"] = "Error";
19
+ })(SingleProductViewPhase || (SingleProductViewPhase = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configura/babylon-view",
3
- "version": "1.4.0",
3
+ "version": "1.6.0-alpha.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,16 +16,16 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babylonjs/core": "4.2.0",
19
- "@configura/web-core": "^1.4.0",
20
- "@configura/web-utilities": "^1.4.0"
19
+ "@configura/web-core": "^1.6.0-alpha.0",
20
+ "@configura/web-utilities": "^1.6.0-alpha.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@configura/web-api": "^1.4.0",
23
+ "@configura/web-api": "^1.6.0-alpha.0",
24
24
  "del-cli": "^3.0.0",
25
25
  "typescript": "4.2"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "17dac8cfe54d809165a54f8a0792fdd23fef57f9"
30
+ "gitHead": "f099cebca376c87c4743a8e9b1c4f1ceaee0c888"
31
31
  }