@combeenation/3d-viewer 6.5.0 → 7.0.0-beta1
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.
- package/dist/lib-cjs/api/classes/element.d.ts +4 -0
- package/dist/lib-cjs/api/classes/element.js +59 -58
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/event.d.ts +55 -1
- package/dist/lib-cjs/api/classes/event.js +55 -1
- package/dist/lib-cjs/api/classes/event.js.map +1 -1
- package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +7 -0
- package/dist/lib-cjs/api/classes/fuzzyMap.js +22 -0
- package/dist/lib-cjs/api/classes/fuzzyMap.js.map +1 -0
- package/dist/lib-cjs/api/classes/parameter.d.ts +12 -0
- package/dist/lib-cjs/api/classes/parameter.js +86 -33
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.js +2 -27
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +23 -4
- package/dist/lib-cjs/api/classes/variant.js +45 -20
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +11 -2
- package/dist/lib-cjs/api/classes/variantInstance.js +22 -2
- package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +13 -1
- package/dist/lib-cjs/api/classes/viewer.js +57 -7
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +3 -3
- package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/tagManager.d.ts +108 -0
- package/dist/lib-cjs/api/manager/tagManager.js +420 -0
- package/dist/lib-cjs/api/manager/tagManager.js.map +1 -0
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +8 -3
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +27 -8
- package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
- package/dist/lib-cjs/api/store/specStorage.d.ts +8 -0
- package/dist/lib-cjs/api/store/specStorage.js +15 -0
- package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +36 -7
- package/dist/lib-cjs/api/util/babylonHelper.js +92 -15
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +38 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +1 -0
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +20 -2
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +2 -1
- package/dist/lib-cjs/index.js +3 -1
- package/dist/lib-cjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/classes/element.ts +96 -82
- package/src/api/classes/event.ts +68 -1
- package/src/api/classes/fuzzyMap.ts +21 -0
- package/src/api/classes/parameter.ts +91 -34
- package/src/api/classes/parameterObservable.ts +2 -29
- package/src/api/classes/variant.ts +82 -33
- package/src/api/classes/variantInstance.ts +27 -1
- package/src/api/classes/viewer.ts +63 -12
- package/src/api/classes/viewerLight.ts +10 -10
- package/src/api/manager/animationManager.ts +2 -2
- package/src/api/manager/sceneManager.ts +5 -1
- package/src/api/manager/tagManager.ts +451 -0
- package/src/api/manager/variantInstanceManager.ts +35 -8
- package/src/api/store/specStorage.ts +17 -0
- package/src/api/util/babylonHelper.ts +99 -21
- package/src/api/util/globalTypes.ts +56 -1
- package/src/api/util/sceneLoaderHelper.ts +21 -2
- package/src/dev.ts +3 -1
- package/src/index.ts +2 -0
- package/src/types.d.ts +7 -0
|
@@ -3,6 +3,7 @@ import { sceneSetup } from '../internal/sceneSetup';
|
|
|
3
3
|
import { AnimationManager } from '../manager/animationManager';
|
|
4
4
|
import { GltfExportManager } from '../manager/gltfExportManager';
|
|
5
5
|
import { SceneManager } from '../manager/sceneManager';
|
|
6
|
+
import { TagManager } from '../manager/tagManager';
|
|
6
7
|
import { VariantInstanceManager } from '../manager/variantInstanceManager';
|
|
7
8
|
import { SpecStorage } from '../store/specStorage';
|
|
8
9
|
import { backgroundDomeName, envHelperMetadataName } from '../util/babylonHelper';
|
|
@@ -14,7 +15,6 @@ import { AnimationInterface } from './animationInterface';
|
|
|
14
15
|
import { Event } from './event';
|
|
15
16
|
import { EventBroadcaster } from './eventBroadcaster';
|
|
16
17
|
import { Parameter } from './parameter';
|
|
17
|
-
import { Variant } from './variant';
|
|
18
18
|
import { VariantInstance } from './variantInstance';
|
|
19
19
|
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
|
|
20
20
|
import { PickingInfo } from '@babylonjs/core/Collisions/pickingInfo';
|
|
@@ -52,18 +52,22 @@ export class Viewer extends EventBroadcaster {
|
|
|
52
52
|
|
|
53
53
|
protected _sceneManager: SceneManager | null = null;
|
|
54
54
|
|
|
55
|
+
protected _tagManager: TagManager | null = null;
|
|
56
|
+
|
|
55
57
|
protected _gltfExportManager: GltfExportManager | null = null;
|
|
56
58
|
|
|
57
59
|
protected _variantInstances: VariantInstanceManager | null = null;
|
|
58
60
|
|
|
59
|
-
// default value is `
|
|
61
|
+
// default value is `false` ATM for compatibility reasons
|
|
60
62
|
// in the future material cloning should be the edge case
|
|
61
|
-
protected _cloneMaterialsOnMutation: boolean =
|
|
63
|
+
protected _cloneMaterialsOnMutation: boolean = false;
|
|
62
64
|
|
|
63
65
|
protected _isRenderLoopPaused: boolean = false;
|
|
64
66
|
|
|
65
67
|
protected _inspectorLoaded: boolean = false;
|
|
66
68
|
|
|
69
|
+
protected _nodeNamingStrategyHandler: NodeNamingStrategyHandler | null = null;
|
|
70
|
+
|
|
67
71
|
static version = buildInfo.version;
|
|
68
72
|
|
|
69
73
|
// these are constants for calculating the camera settings, depending on the bounding box size of the meshes to zoom
|
|
@@ -132,6 +136,24 @@ export class Viewer extends EventBroadcaster {
|
|
|
132
136
|
*/
|
|
133
137
|
public constructor(public readonly canvas: HTMLCanvasElement, protected structureJson: string | StructureJson) {
|
|
134
138
|
super();
|
|
139
|
+
this._tagManager = new TagManager(this);
|
|
140
|
+
this._nodeNamingStrategyHandler = (node, payload) => {
|
|
141
|
+
const suffix: string[] = [];
|
|
142
|
+
if (payload.variant.elements.length > 0) {
|
|
143
|
+
const nodeElements = payload.variant.elements.filter(
|
|
144
|
+
e => e.nodesFlat.filter(n => n.metadata?.cloneSource?.id === node.id).length > 0
|
|
145
|
+
);
|
|
146
|
+
if (nodeElements.length > 0) {
|
|
147
|
+
suffix.push(payload.variantParameterizable.name);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const variantInstances = this.variantInstances.allWithVariantName(payload.variant.name);
|
|
151
|
+
if (variantInstances.length > 0) {
|
|
152
|
+
suffix.push(payload.variantInstance.name);
|
|
153
|
+
}
|
|
154
|
+
const originalName = node.metadata?.originalName || node.name;
|
|
155
|
+
return [originalName, ...suffix.filter(s => !!s)].join('.');
|
|
156
|
+
};
|
|
135
157
|
}
|
|
136
158
|
|
|
137
159
|
/**
|
|
@@ -201,6 +223,13 @@ export class Viewer extends EventBroadcaster {
|
|
|
201
223
|
return this._animationManager;
|
|
202
224
|
}
|
|
203
225
|
|
|
226
|
+
get tagManager(): TagManager {
|
|
227
|
+
if (!this._tagManager) {
|
|
228
|
+
throw new Error(`There is no tagManager instance.`);
|
|
229
|
+
}
|
|
230
|
+
return this._tagManager;
|
|
231
|
+
}
|
|
232
|
+
|
|
204
233
|
/**
|
|
205
234
|
* Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
|
|
206
235
|
*/
|
|
@@ -208,6 +237,26 @@ export class Viewer extends EventBroadcaster {
|
|
|
208
237
|
return this._cloneMaterialsOnMutation;
|
|
209
238
|
}
|
|
210
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Gets the strategy handler for naming cloned nodes.
|
|
242
|
+
*/
|
|
243
|
+
get nodeNamingStrategyHandler(): NodeNamingStrategyHandler {
|
|
244
|
+
if (!this._nodeNamingStrategyHandler) {
|
|
245
|
+
throw new Error(`The NodeNamingStrategyHandler has not been registered yet.`);
|
|
246
|
+
}
|
|
247
|
+
return this._nodeNamingStrategyHandler;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Sets the strategy handler for naming cloned nodes.
|
|
252
|
+
*/
|
|
253
|
+
set nodeNamingStrategyHandler(value: NodeNamingStrategyHandler) {
|
|
254
|
+
if (!value || typeof value !== 'function') {
|
|
255
|
+
throw new Error(`The NodeNamingStrategyHandler is not a callable function.`);
|
|
256
|
+
}
|
|
257
|
+
this._nodeNamingStrategyHandler = value;
|
|
258
|
+
}
|
|
259
|
+
|
|
211
260
|
/**
|
|
212
261
|
* Starts the application. This will
|
|
213
262
|
* * load the given "index" JSON file
|
|
@@ -220,9 +269,8 @@ export class Viewer extends EventBroadcaster {
|
|
|
220
269
|
* @emits {@link Event.BOOTSTRAP_START}
|
|
221
270
|
* @emits {@link Event.BOOTSTRAP_END}
|
|
222
271
|
*/
|
|
223
|
-
public async bootstrap(): Promise<Viewer> {
|
|
272
|
+
public async bootstrap(tagManagerParameterValues?: TagManagerParameterValue[]): Promise<Viewer> {
|
|
224
273
|
this.broadcastEvent(Event.BOOTSTRAP_START, this);
|
|
225
|
-
|
|
226
274
|
let indexJson;
|
|
227
275
|
if (isString(this.structureJson)) {
|
|
228
276
|
indexJson = await loadJson<StructureJson>(this.structureJson);
|
|
@@ -234,19 +282,16 @@ export class Viewer extends EventBroadcaster {
|
|
|
234
282
|
}
|
|
235
283
|
// fill spec store
|
|
236
284
|
SpecStorage.createFromSpec(indexJson);
|
|
237
|
-
|
|
285
|
+
// init custom loader plugin
|
|
238
286
|
this.initCbnBabylonLoaderPlugin();
|
|
239
|
-
|
|
240
287
|
// load scene
|
|
241
288
|
if (isString(indexJson.scene)) {
|
|
242
289
|
const sceneJson = await loadJson<SceneJson>(indexJson.scene);
|
|
243
290
|
indexJson.scene = sceneJson;
|
|
244
291
|
}
|
|
245
292
|
this._scene = await this.initScene();
|
|
246
|
-
|
|
247
293
|
// create instance manager
|
|
248
|
-
|
|
249
|
-
this._variantInstances = await VariantInstanceManager.create(rootVariant);
|
|
294
|
+
this._variantInstances = await VariantInstanceManager.create(this);
|
|
250
295
|
// create optional default instances
|
|
251
296
|
if (indexJson.setup) {
|
|
252
297
|
if (isString(indexJson.setup)) {
|
|
@@ -255,13 +300,17 @@ export class Viewer extends EventBroadcaster {
|
|
|
255
300
|
}
|
|
256
301
|
await this.createVariantInstances();
|
|
257
302
|
}
|
|
303
|
+
this.broadcastEvent(Event.VARIANT_INSTANCES_READY, this);
|
|
258
304
|
// create gltf export manager
|
|
259
305
|
this._gltfExportManager = await GltfExportManager.create(this);
|
|
260
306
|
// resize handler
|
|
261
307
|
window.addEventListener('resize', debounce(this.resize.bind(this), 100));
|
|
262
308
|
// wait until scene is completely ready
|
|
263
309
|
await this.scene.whenReadyAsync();
|
|
264
|
-
|
|
310
|
+
// set tag manager values
|
|
311
|
+
if (tagManagerParameterValues) {
|
|
312
|
+
await this.tagManager.setParameterValues(tagManagerParameterValues);
|
|
313
|
+
}
|
|
265
314
|
// event broadcasting
|
|
266
315
|
this.broadcastEvent(Event.BOOTSTRAP_END, this);
|
|
267
316
|
// render loop
|
|
@@ -495,7 +544,7 @@ export class Viewer extends EventBroadcaster {
|
|
|
495
544
|
activeCamera.pinchPrecision = Viewer._autofocusConstants.pinchPrecision / radius;
|
|
496
545
|
}
|
|
497
546
|
|
|
498
|
-
const radiusFactor = settings?.radiusFactor ?? 1;
|
|
547
|
+
const radiusFactor = settings?.radiusFactor ?? 1.5;
|
|
499
548
|
const alpha = (settings?.alpha ?? -90) * (Math.PI / 180);
|
|
500
549
|
const beta = (settings?.beta ?? 90) * (Math.PI / 180);
|
|
501
550
|
|
|
@@ -648,6 +697,8 @@ export class Viewer extends EventBroadcaster {
|
|
|
648
697
|
if (sceneJson.cloneMaterialsOnMutation !== undefined) {
|
|
649
698
|
this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
|
|
650
699
|
}
|
|
700
|
+
// register observers for tag manager
|
|
701
|
+
this.tagManager.registerNewTransformNodeObservers(scene);
|
|
651
702
|
this.broadcastEvent(Event.SCENE_PROCESSING_END, scene);
|
|
652
703
|
return scene;
|
|
653
704
|
}
|
|
@@ -106,7 +106,7 @@ export class ViewerLight extends VariantParameterizable {
|
|
|
106
106
|
*/
|
|
107
107
|
protected addParameterObservers(): ViewerLight {
|
|
108
108
|
this._parameterObservers.set(Parameter.VISIBLE, [
|
|
109
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
109
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
110
110
|
let visible;
|
|
111
111
|
try {
|
|
112
112
|
visible = Parameter.parseBoolean(newValue);
|
|
@@ -121,12 +121,12 @@ export class ViewerLight extends VariantParameterizable {
|
|
|
121
121
|
},
|
|
122
122
|
]);
|
|
123
123
|
this._parameterObservers.set(Parameter.INTENSITY, [
|
|
124
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
124
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
125
125
|
set(light.light, 'intensity', Parameter.parseNumber(newValue));
|
|
126
126
|
},
|
|
127
127
|
]);
|
|
128
128
|
this._parameterObservers.set(Parameter.SCALING, [
|
|
129
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
129
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
130
130
|
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
131
131
|
const rootNode = getRootNode(light.light);
|
|
132
132
|
if (rootNode instanceof TransformNode) {
|
|
@@ -139,7 +139,7 @@ export class ViewerLight extends VariantParameterizable {
|
|
|
139
139
|
},
|
|
140
140
|
]);
|
|
141
141
|
this._parameterObservers.set(Parameter.POSITION, [
|
|
142
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
142
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
143
143
|
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
144
144
|
const rootNode = getRootNode(light.light);
|
|
145
145
|
if (rootNode instanceof TransformNode) {
|
|
@@ -152,7 +152,7 @@ export class ViewerLight extends VariantParameterizable {
|
|
|
152
152
|
},
|
|
153
153
|
]);
|
|
154
154
|
this._parameterObservers.set(Parameter.ROTATION, [
|
|
155
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
155
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
156
156
|
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
157
157
|
const rootNode = getRootNode(light.light);
|
|
158
158
|
if (rootNode instanceof TransformNode) {
|
|
@@ -165,7 +165,7 @@ export class ViewerLight extends VariantParameterizable {
|
|
|
165
165
|
},
|
|
166
166
|
]);
|
|
167
167
|
this._parameterObservers.set(Parameter.DIRECTION, [
|
|
168
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
168
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
169
169
|
if (
|
|
170
170
|
(light.light instanceof ShadowLight && !(light.light instanceof PointLight)) ||
|
|
171
171
|
light.light instanceof HemisphericLight
|
|
@@ -175,26 +175,26 @@ export class ViewerLight extends VariantParameterizable {
|
|
|
175
175
|
},
|
|
176
176
|
]);
|
|
177
177
|
this._parameterObservers.set(Parameter.ANGLE, [
|
|
178
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
178
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
179
179
|
if (light.light.getClassName() === 'SpotLight') {
|
|
180
180
|
set(light.light, 'angle', Parameter.parseNumber(newValue));
|
|
181
181
|
}
|
|
182
182
|
},
|
|
183
183
|
]);
|
|
184
184
|
this._parameterObservers.set(Parameter.EXPONENT, [
|
|
185
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
185
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
186
186
|
if (light.light.getClassName() === 'SpotLight') {
|
|
187
187
|
set(light.light, 'exponent', Parameter.parseNumber(newValue));
|
|
188
188
|
}
|
|
189
189
|
},
|
|
190
190
|
]);
|
|
191
191
|
this._parameterObservers.set(Parameter.DIFFUSE, [
|
|
192
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
192
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
193
193
|
set(light.light, 'diffuse', Parameter.parseColor(newValue));
|
|
194
194
|
},
|
|
195
195
|
]);
|
|
196
196
|
this._parameterObservers.set(Parameter.SPECULAR, [
|
|
197
|
-
async (light: ViewerLight, oldValue: ParameterValue
|
|
197
|
+
async (light: ViewerLight, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
198
198
|
set(light.light, 'specular', Parameter.parseColor(newValue));
|
|
199
199
|
},
|
|
200
200
|
]);
|
|
@@ -2,7 +2,7 @@ import { AnimationInterface } from '../classes/animationInterface';
|
|
|
2
2
|
import { PlacementAnimation } from '../classes/placementAnimation';
|
|
3
3
|
import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
|
|
4
4
|
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
|
|
5
|
-
import { Scene as BabylonScene
|
|
5
|
+
import { Scene as BabylonScene } from '@babylonjs/core/scene';
|
|
6
6
|
import { Nullable } from '@babylonjs/core/types';
|
|
7
7
|
//import { CustomEase } from 'gsap/CustomEase';
|
|
8
8
|
//import { ExpoScaleEase, RoughEase, SlowMo } from 'gsap/EasePack';
|
|
@@ -16,7 +16,7 @@ export class AnimationManager {
|
|
|
16
16
|
/**
|
|
17
17
|
* Constructor.
|
|
18
18
|
*/
|
|
19
|
-
protected constructor(protected scene:
|
|
19
|
+
protected constructor(protected scene: BabylonScene) {}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Creates an {@link AnimationManager} based on given BabylonJS scene.
|
|
@@ -93,7 +93,11 @@ export class SceneManager extends ParameterObservable {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
protected addParameterObservers(): SceneManager {
|
|
96
|
-
const handleEnvParamChange = (
|
|
96
|
+
const handleEnvParamChange = (
|
|
97
|
+
manager: SceneManager,
|
|
98
|
+
oldValue: Undefinable<ParameterValue>,
|
|
99
|
+
newValue: ParameterValue
|
|
100
|
+
) => {
|
|
97
101
|
const params = {
|
|
98
102
|
color: manager.parameters[Parameter.ENVIRONMENT_COLOR],
|
|
99
103
|
intensity: manager.parameters[Parameter.ENVIRONMENT_INTENSITY],
|