@combeenation/3d-viewer 12.4.1 → 13.0.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.
- package/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +63 -63
- package/dist/lib-cjs/index.js +81 -114
- package/dist/lib-cjs/index.js.map +1 -1
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.d.ts +10 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js +124 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js.map +1 -0
- package/dist/lib-cjs/internal/cloningHelper.d.ts +19 -0
- package/dist/lib-cjs/internal/cloningHelper.js +165 -0
- package/dist/lib-cjs/internal/cloningHelper.js.map +1 -0
- package/dist/lib-cjs/internal/deviceHelper.d.ts +9 -0
- package/dist/lib-cjs/{api/util → internal}/deviceHelper.js +6 -10
- package/dist/lib-cjs/internal/deviceHelper.js.map +1 -0
- package/dist/lib-cjs/internal/geometryHelper.d.ts +21 -0
- package/dist/lib-cjs/{api/util → internal}/geometryHelper.js +57 -24
- package/dist/lib-cjs/internal/geometryHelper.js.map +1 -0
- package/dist/lib-cjs/internal/metadataHelper.d.ts +26 -0
- package/dist/lib-cjs/internal/metadataHelper.js +51 -0
- package/dist/lib-cjs/internal/metadataHelper.js.map +1 -0
- package/dist/lib-cjs/internal/paintableHelper.d.ts +40 -0
- package/dist/lib-cjs/internal/paintableHelper.js +287 -0
- package/dist/lib-cjs/internal/paintableHelper.js.map +1 -0
- package/dist/lib-cjs/internal/tagsHelper.d.ts +12 -0
- package/dist/lib-cjs/internal/tagsHelper.js +38 -0
- package/dist/lib-cjs/internal/tagsHelper.js.map +1 -0
- package/dist/lib-cjs/manager/cameraManager.d.ts +51 -0
- package/dist/lib-cjs/manager/cameraManager.js +154 -0
- package/dist/lib-cjs/manager/cameraManager.js.map +1 -0
- package/dist/lib-cjs/manager/debugManager.d.ts +60 -0
- package/dist/lib-cjs/manager/debugManager.js +218 -0
- package/dist/lib-cjs/manager/debugManager.js.map +1 -0
- package/dist/lib-cjs/manager/eventManager.d.ts +52 -0
- package/dist/lib-cjs/manager/eventManager.js +72 -0
- package/dist/lib-cjs/manager/eventManager.js.map +1 -0
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.d.ts +29 -34
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.js +99 -120
- package/dist/lib-cjs/manager/gltfExportManager.js.map +1 -0
- package/dist/lib-cjs/manager/materialManager.d.ts +35 -0
- package/dist/lib-cjs/manager/materialManager.js +126 -0
- package/dist/lib-cjs/manager/materialManager.js.map +1 -0
- package/dist/lib-cjs/manager/modelManager.d.ts +145 -0
- package/dist/lib-cjs/manager/modelManager.js +381 -0
- package/dist/lib-cjs/manager/modelManager.js.map +1 -0
- package/dist/lib-cjs/manager/parameterManager.d.ts +210 -0
- package/dist/lib-cjs/manager/parameterManager.js +515 -0
- package/dist/lib-cjs/manager/parameterManager.js.map +1 -0
- package/dist/lib-cjs/manager/sceneManager.d.ts +45 -0
- package/dist/lib-cjs/manager/sceneManager.js +65 -0
- package/dist/lib-cjs/manager/sceneManager.js.map +1 -0
- package/dist/lib-cjs/manager/screenshotManager.d.ts +36 -0
- package/dist/lib-cjs/manager/screenshotManager.js +40 -0
- package/dist/lib-cjs/manager/screenshotManager.js.map +1 -0
- package/dist/lib-cjs/manager/textureManager.d.ts +12 -0
- package/dist/lib-cjs/manager/textureManager.js +44 -0
- package/dist/lib-cjs/manager/textureManager.js.map +1 -0
- package/dist/lib-cjs/viewer.d.ts +117 -0
- package/dist/lib-cjs/viewer.js +222 -0
- package/dist/lib-cjs/viewer.js.map +1 -0
- package/dist/lib-cjs/{api/classes/viewerError.d.ts → viewerError.d.ts} +6 -1
- package/dist/lib-cjs/{api/classes/viewerError.js → viewerError.js} +6 -1
- package/dist/lib-cjs/viewerError.js.map +1 -0
- package/package.json +10 -11
- package/src/dev.ts +14 -37
- package/src/{types.d.ts → globalTypes.d.ts} +8 -18
- package/src/index.ts +79 -113
- package/src/internal/cbnCustomBabylonLoaderPlugin.ts +149 -0
- package/src/internal/cloningHelper.ts +225 -0
- package/src/internal/deviceHelper.ts +25 -0
- package/src/{api/util → internal}/geometryHelper.ts +63 -24
- package/src/internal/metadataHelper.ts +63 -0
- package/src/internal/paintableHelper.ts +310 -0
- package/src/internal/tagsHelper.ts +41 -0
- package/src/manager/cameraManager.ts +236 -0
- package/src/manager/debugManager.ts +245 -0
- package/src/manager/eventManager.ts +72 -0
- package/src/{api/manager → manager}/gltfExportManager.ts +132 -125
- package/src/manager/materialManager.ts +135 -0
- package/src/manager/modelManager.ts +456 -0
- package/src/manager/parameterManager.ts +652 -0
- package/src/manager/sceneManager.ts +101 -0
- package/src/manager/screenshotManager.ts +59 -0
- package/src/manager/textureManager.ts +32 -0
- package/src/viewer.ts +296 -0
- package/src/{api/classes/viewerError.ts → viewerError.ts} +6 -1
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +0 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +0 -3
- package/dist/lib-cjs/api/classes/animationInterface.js.map +0 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +0 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +0 -167
- package/dist/lib-cjs/api/classes/dottedPath.js.map +0 -1
- package/dist/lib-cjs/api/classes/element.d.ts +0 -153
- package/dist/lib-cjs/api/classes/element.js +0 -703
- package/dist/lib-cjs/api/classes/element.js.map +0 -1
- package/dist/lib-cjs/api/classes/event.d.ts +0 -401
- package/dist/lib-cjs/api/classes/event.js +0 -425
- package/dist/lib-cjs/api/classes/event.js.map +0 -1
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +0 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +0 -50
- package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +0 -1
- package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +0 -7
- package/dist/lib-cjs/api/classes/fuzzyMap.js +0 -22
- package/dist/lib-cjs/api/classes/fuzzyMap.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +0 -410
- package/dist/lib-cjs/api/classes/parameter.js +0 -643
- package/dist/lib-cjs/api/classes/parameter.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +0 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +0 -73
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +0 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +0 -103
- package/dist/lib-cjs/api/classes/parameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +0 -45
- package/dist/lib-cjs/api/classes/placementAnimation.js +0 -177
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +0 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +0 -261
- package/dist/lib-cjs/api/classes/variant.js +0 -873
- package/dist/lib-cjs/api/classes/variant.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +0 -53
- package/dist/lib-cjs/api/classes/variantInstance.js +0 -126
- package/dist/lib-cjs/api/classes/variantInstance.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +0 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +0 -87
- package/dist/lib-cjs/api/classes/variantParameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +0 -215
- package/dist/lib-cjs/api/classes/viewer.js +0 -709
- package/dist/lib-cjs/api/classes/viewer.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerError.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +0 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +0 -345
- package/dist/lib-cjs/api/classes/viewerLight.js.map +0 -1
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +0 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +0 -12
- package/dist/lib-cjs/api/internal/lensRendering.js.map +0 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +0 -13
- package/dist/lib-cjs/api/internal/sceneSetup.js +0 -228
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +0 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +0 -30
- package/dist/lib-cjs/api/manager/animationManager.js +0 -127
- package/dist/lib-cjs/api/manager/animationManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +0 -33
- package/dist/lib-cjs/api/manager/sceneManager.js +0 -129
- package/dist/lib-cjs/api/manager/sceneManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/tagManager.d.ts +0 -118
- package/dist/lib-cjs/api/manager/tagManager.js +0 -531
- package/dist/lib-cjs/api/manager/tagManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +0 -22
- package/dist/lib-cjs/api/manager/textureLoadManager.js +0 -108
- package/dist/lib-cjs/api/manager/textureLoadManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +0 -106
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +0 -291
- package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +0 -1
- package/dist/lib-cjs/api/store/specStorage.d.ts +0 -32
- package/dist/lib-cjs/api/store/specStorage.js +0 -66
- package/dist/lib-cjs/api/store/specStorage.js.map +0 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +0 -238
- package/dist/lib-cjs/api/util/babylonHelper.js +0 -826
- package/dist/lib-cjs/api/util/babylonHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/debugHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/debugHelper.js +0 -94
- package/dist/lib-cjs/api/util/debugHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/deviceHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/deviceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/geometryHelper.d.ts +0 -17
- package/dist/lib-cjs/api/util/geometryHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +0 -490
- package/dist/lib-cjs/api/util/globalTypes.js +0 -2
- package/dist/lib-cjs/api/util/globalTypes.js.map +0 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/resourceHelper.js +0 -215
- package/dist/lib-cjs/api/util/resourceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +0 -229
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +0 -13
- package/dist/lib-cjs/api/util/stringHelper.js +0 -33
- package/dist/lib-cjs/api/util/stringHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/structureHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/structureHelper.js +0 -58
- package/dist/lib-cjs/api/util/structureHelper.js.map +0 -1
- package/src/api/classes/animationInterface.ts +0 -10
- package/src/api/classes/dottedPath.ts +0 -181
- package/src/api/classes/element.ts +0 -766
- package/src/api/classes/event.ts +0 -457
- package/src/api/classes/eventBroadcaster.ts +0 -52
- package/src/api/classes/fuzzyMap.ts +0 -21
- package/src/api/classes/parameter.ts +0 -686
- package/src/api/classes/parameterObservable.ts +0 -73
- package/src/api/classes/parameterizable.ts +0 -87
- package/src/api/classes/placementAnimation.ts +0 -162
- package/src/api/classes/variant.ts +0 -965
- package/src/api/classes/variantInstance.ts +0 -123
- package/src/api/classes/variantParameterizable.ts +0 -83
- package/src/api/classes/viewer.ts +0 -751
- package/src/api/classes/viewerLight.ts +0 -335
- package/src/api/internal/debugViewer.ts +0 -90
- package/src/api/internal/lensRendering.ts +0 -9
- package/src/api/internal/sceneSetup.ts +0 -208
- package/src/api/manager/animationManager.ts +0 -143
- package/src/api/manager/sceneManager.ts +0 -134
- package/src/api/manager/tagManager.ts +0 -572
- package/src/api/manager/textureLoadManager.ts +0 -107
- package/src/api/manager/variantInstanceManager.ts +0 -306
- package/src/api/store/specStorage.ts +0 -68
- package/src/api/util/babylonHelper.ts +0 -915
- package/src/api/util/debugHelper.ts +0 -121
- package/src/api/util/deviceHelper.ts +0 -31
- package/src/api/util/globalTypes.ts +0 -566
- package/src/api/util/resourceHelper.ts +0 -201
- package/src/api/util/sceneLoaderHelper.ts +0 -247
- package/src/api/util/stringHelper.ts +0 -30
- package/src/api/util/structureHelper.ts +0 -62
|
@@ -1,766 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
activateTransformNode as activate,
|
|
3
|
-
addToHighlightLayer,
|
|
4
|
-
addToShadowGenerator,
|
|
5
|
-
assertMeshCapability,
|
|
6
|
-
assertTransformNode,
|
|
7
|
-
cloneTransformNode,
|
|
8
|
-
cloneTransformNodeMaterial,
|
|
9
|
-
deactivateTransformNode as deactivate,
|
|
10
|
-
drawPaintableOnMaterial,
|
|
11
|
-
getClientRectFromMesh,
|
|
12
|
-
injectMetadata,
|
|
13
|
-
mapToDottedNodes,
|
|
14
|
-
removeFromHighlightLayer,
|
|
15
|
-
removeFromShadowGenerator,
|
|
16
|
-
setMaterial,
|
|
17
|
-
setMaterialColor,
|
|
18
|
-
setMaterialMetallness,
|
|
19
|
-
setMaterialRoughness,
|
|
20
|
-
setReceiveShadows,
|
|
21
|
-
transformTransformNode,
|
|
22
|
-
} from '../util/babylonHelper';
|
|
23
|
-
import { createImageFromImgSrc, createImageFromSvg } from '../util/resourceHelper';
|
|
24
|
-
import { addMissingMaterialObserver } from '../util/sceneLoaderHelper';
|
|
25
|
-
import { VariantParameterizable } from './../classes/variantParameterizable';
|
|
26
|
-
import { DottedPath } from './dottedPath';
|
|
27
|
-
import { Event } from './event';
|
|
28
|
-
import { Parameter } from './parameter';
|
|
29
|
-
import { Variant } from './variant';
|
|
30
|
-
import { HighlightLayer } from '@babylonjs/core/Layers/highlightLayer';
|
|
31
|
-
import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator';
|
|
32
|
-
import { Light } from '@babylonjs/core/Lights/light';
|
|
33
|
-
import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
|
|
34
|
-
import { Material } from '@babylonjs/core/Materials/material';
|
|
35
|
-
import { Color3 } from '@babylonjs/core/Maths/math.color';
|
|
36
|
-
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
|
|
37
|
-
import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
|
|
38
|
-
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
39
|
-
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
40
|
-
import { Tags } from '@babylonjs/core/Misc/tags';
|
|
41
|
-
import { has, isArray, isNumber, merge, union } from 'lodash-es';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* An {@link Element} of a {@link Variant}. Acts as a container for diverse definitions. Lives only in the context of a
|
|
45
|
-
* {@link Variant}.
|
|
46
|
-
*
|
|
47
|
-
* When used in typings, refer to via its alias {@link VariantElement} to prevent name clashes with the web APIs
|
|
48
|
-
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) class
|
|
49
|
-
*/
|
|
50
|
-
export class Element extends VariantParameterizable {
|
|
51
|
-
public readonly nodes: TransformNode[] = [];
|
|
52
|
-
|
|
53
|
-
protected readonly _dottedNodes: Map<DottedPath, TransformNode> = new Map();
|
|
54
|
-
|
|
55
|
-
protected _highlightLayer?: HighlightLayer;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Constructor.
|
|
59
|
-
*/
|
|
60
|
-
protected constructor(public readonly variant: Variant, public readonly name: string) {
|
|
61
|
-
super(variant, name);
|
|
62
|
-
if (process.env.NODE_ENV === 'development') {
|
|
63
|
-
this.assertPathDefinitions();
|
|
64
|
-
}
|
|
65
|
-
const nodes = this.variant.inheritedNodes.map(node => {
|
|
66
|
-
const nodeNamingStrategy = {
|
|
67
|
-
handler: variant.viewer.nodeNamingStrategyHandler,
|
|
68
|
-
payload: {
|
|
69
|
-
variantInstance: variant.variantInstance!,
|
|
70
|
-
variant: variant,
|
|
71
|
-
variantParameterizable: this,
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
return cloneTransformNode(node, nodeNamingStrategy, this.filterNode.bind(this), true);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// when cloning an instanced mesh the source mesh is still referencing to the source of the original mesh
|
|
78
|
-
// this is wrong, as we want to reference the cloned source
|
|
79
|
-
// this can only be done after the cloning process of the whole tree is finished, as we can't be sure if all
|
|
80
|
-
// instanced meshes or all sources meshes are cloning prior
|
|
81
|
-
const reassignSourceMesh = (node: TransformNode) => {
|
|
82
|
-
if (node instanceof InstancedMesh) {
|
|
83
|
-
// find the cloned instance and source mesh
|
|
84
|
-
const clonedInstance = node as InstancedMesh;
|
|
85
|
-
const originalInstance = clonedInstance.metadata.cloneSource as InstancedMesh;
|
|
86
|
-
const originalSource = originalInstance.sourceMesh;
|
|
87
|
-
const clonedSource = originalSource.metadata.cloneTarget;
|
|
88
|
-
// it's not possible to just exchange the source mesh => readonly property
|
|
89
|
-
// we have to create a new clone with the correct source mesh
|
|
90
|
-
const exchangedInstance = clonedInstance.clone(clonedInstance.name, clonedInstance.parent, true, clonedSource);
|
|
91
|
-
|
|
92
|
-
// fix enabled and tags state after cloning
|
|
93
|
-
exchangedInstance.setEnabled(clonedInstance.isEnabled(false));
|
|
94
|
-
if (Tags.HasTags(clonedInstance)) {
|
|
95
|
-
Tags.AddTagsTo(exchangedInstance, Tags.GetTags(clonedInstance, true));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// re-reference the childs of the cloned instance as well
|
|
99
|
-
const childs = clonedInstance.getChildTransformNodes(true);
|
|
100
|
-
childs.forEach(child => (child.parent = exchangedInstance));
|
|
101
|
-
|
|
102
|
-
// old instance mesh is not needed anymore and can be disposed
|
|
103
|
-
clonedInstance.dispose();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// recurse into childs
|
|
107
|
-
const children = node.getChildTransformNodes(true);
|
|
108
|
-
children.forEach(reassignSourceMesh);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
nodes.forEach(node => {
|
|
112
|
-
if (node) {
|
|
113
|
-
reassignSourceMesh(node);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
this.nodes = nodes.filter(node => !!node) as TransformNode[];
|
|
118
|
-
this._dottedNodes = mapToDottedNodes<TransformNode>(this.nodes, node => node instanceof TransformNode);
|
|
119
|
-
variant.broadcastEvent(Event.ELEMENT_NODES_CLONED, this);
|
|
120
|
-
this.addMissingMaterialObservers();
|
|
121
|
-
this.addParameterObservers();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Creates an {@link Element} with given name.
|
|
126
|
-
*/
|
|
127
|
-
public static async create(variant: Variant, name: string): Promise<Element> {
|
|
128
|
-
const element = new Element(variant, name);
|
|
129
|
-
variant.broadcastEvent(Event.ELEMENT_CREATED, element);
|
|
130
|
-
return element;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* The {@link DottedPath} in the built tree of {@link Element}s.
|
|
135
|
-
* E.g. "_.top-1.sub-2.sub-sub-3.el-1"
|
|
136
|
-
*/
|
|
137
|
-
get dottedPath(): DottedPath {
|
|
138
|
-
return DottedPath.create(this.variant.dottedPath).addPart(this.name);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* The id representing a {@link DottedPath}.
|
|
143
|
-
*/
|
|
144
|
-
get id(): string {
|
|
145
|
-
const dottedPath = DottedPath.create(this.dottedPath);
|
|
146
|
-
dottedPath.shiftPart(); // remove root
|
|
147
|
-
return dottedPath.path;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* The {@link ElementDefinition} of the {@link Element}.
|
|
152
|
-
*/
|
|
153
|
-
get definition(): ElementDefinition {
|
|
154
|
-
const definition = this.variant.structureJson.elements![this.name];
|
|
155
|
-
if (isArray(definition)) {
|
|
156
|
-
return {
|
|
157
|
-
paths: {
|
|
158
|
-
include: definition,
|
|
159
|
-
},
|
|
160
|
-
} as ElementDefinition;
|
|
161
|
-
}
|
|
162
|
-
return definition as ElementDefinition;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* The {@link PathDefinitions} of the {@link Element}.
|
|
167
|
-
*/
|
|
168
|
-
get pathDefinitions(): PathDefinitions {
|
|
169
|
-
return this.definition.paths;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* The {@link TraceableDefinitions} of the {@link Element}.
|
|
174
|
-
*/
|
|
175
|
-
get traceableDefinitions(): TraceableDefinitions {
|
|
176
|
-
return this.definition.traceables || {};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* The {@link PaintableDefinition} of the {@link Element}.
|
|
181
|
-
*/
|
|
182
|
-
get paintableDefinitions(): PaintableDefinitions {
|
|
183
|
-
return this.definition.paintables || {};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* The inherited {@link ParameterBag}.
|
|
188
|
-
* Merges the {@link Variant}'s parameters and those from the {@link Element}.
|
|
189
|
-
*/
|
|
190
|
-
get inheritedParameters(): ParameterBag {
|
|
191
|
-
return merge({}, this.variant.inheritedParameters, this.parameters);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* The actual {@link TransformNode}s that make up this {@link Element}.
|
|
196
|
-
*/
|
|
197
|
-
get nodesFlat(): TransformNode[] {
|
|
198
|
-
return this.nodes.reduce(
|
|
199
|
-
(acc, cur) => [...acc, ...(cur.getChildren(n => n instanceof TransformNode, false) as TransformNode[])],
|
|
200
|
-
this.nodes
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* The actual {@link Mesh}es that make up this {@link Element}.
|
|
206
|
-
* Handy for e.g. creating a bounding box around an entire element.
|
|
207
|
-
*/
|
|
208
|
-
get meshesFlat(): Mesh[] {
|
|
209
|
-
return this.nodes.reduce(
|
|
210
|
-
(acc, cur) => [...acc, ...(cur.getChildren(n => n instanceof Mesh, false) as Mesh[])],
|
|
211
|
-
this.nodes.filter(n => n instanceof Mesh) as Mesh[]
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* The actual {@link AbstractMesh}es that make up this {@link Element}.
|
|
217
|
-
* I.e. (real) Meshes as well as InstancedMeshes.
|
|
218
|
-
*/
|
|
219
|
-
get abstractMeshesFlat(): AbstractMesh[] {
|
|
220
|
-
return this.nodes.reduce(
|
|
221
|
-
(acc, cur) => [...acc, ...(cur.getChildren(n => n instanceof AbstractMesh, false) as AbstractMesh[])],
|
|
222
|
-
this.nodes.filter(n => n instanceof AbstractMesh) as AbstractMesh[]
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* The meshes of this {@link Element}.
|
|
228
|
-
*/
|
|
229
|
-
get meshes(): Mesh[] {
|
|
230
|
-
return this.nodes.filter(node => node instanceof Mesh) as Mesh[];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* @protected
|
|
235
|
-
*/
|
|
236
|
-
set highlightLayer(layer: HighlightLayer | undefined) {
|
|
237
|
-
this._highlightLayer = layer;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
get highlightLayer(): HighlightLayer | undefined {
|
|
241
|
-
return this._highlightLayer;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Destroys this {@link Element} and dispose all nodes.
|
|
246
|
-
*/
|
|
247
|
-
public destroy(): Element {
|
|
248
|
-
this.nodes.forEach(node => {
|
|
249
|
-
node.dispose();
|
|
250
|
-
});
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Gets a node by its {@link DottedPath}.
|
|
256
|
-
*/
|
|
257
|
-
public getNode(dottedPath: DottedPathArgument): TransformNode {
|
|
258
|
-
const _dottedPath = DottedPath.create(dottedPath);
|
|
259
|
-
const keys = Array.from(this._dottedNodes.keys()).map(dp => dp.path);
|
|
260
|
-
const values = Array.from(this._dottedNodes.values());
|
|
261
|
-
const node = values[keys.indexOf(_dottedPath.path)];
|
|
262
|
-
if (!node) {
|
|
263
|
-
throw new Error(`Node with path "${_dottedPath.path}" does not exist for element "${this.id}".`);
|
|
264
|
-
}
|
|
265
|
-
return node;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Gets a mesh by its {@link DottedPath}.
|
|
270
|
-
*/
|
|
271
|
-
public async getMesh(dottedPath: DottedPathArgument): Promise<Mesh | null> {
|
|
272
|
-
const node = await this.getNode(dottedPath);
|
|
273
|
-
if (node instanceof Mesh) {
|
|
274
|
-
return node;
|
|
275
|
-
}
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Gets a {@link PaintableDefinition} by its name.
|
|
281
|
-
*/
|
|
282
|
-
public getPaintableDefinition(name: string): PaintableDefinition {
|
|
283
|
-
if (!this.paintableDefinitions || !this.paintableDefinitions[name]) {
|
|
284
|
-
throw new Error(`No paintable "${name}" defined for element "${this.id}".`);
|
|
285
|
-
}
|
|
286
|
-
return this.paintableDefinitions[name];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Gets a {@link TraceableDefinition} by its name.
|
|
291
|
-
*/
|
|
292
|
-
public getTraceableDefinition(name: string): TraceableDefinition {
|
|
293
|
-
if (!this.traceableDefinitions || !this.traceableDefinitions[name]) {
|
|
294
|
-
throw new Error(`No traceable "${name}" defined to add observer in element "${this.id}".`);
|
|
295
|
-
}
|
|
296
|
-
return this.traceableDefinitions[name];
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Gets the paintable Node by its name.
|
|
301
|
-
*/
|
|
302
|
-
public getPaintableNode(name: string): TransformNode {
|
|
303
|
-
return this.getNode(this.getPaintableDefinition(name).path);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Gets the traceable Node by its name.
|
|
308
|
-
*/
|
|
309
|
-
public getTraceableNode(name: string): TransformNode {
|
|
310
|
-
return this.getNode(this.getTraceableDefinition(name).path);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* @see {@link VariantParameterizable.commitParameters}
|
|
315
|
-
* @emit {@link Event.ELEMENT_PARAMETER_COMMITTED}
|
|
316
|
-
*/
|
|
317
|
-
public async commitParameters(parameters?: ParameterBag): Promise<VariantParameterizable> {
|
|
318
|
-
return super.commitParameters(parameters);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Adds an observer function for camera matrix changes.
|
|
323
|
-
* The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
|
|
324
|
-
*/
|
|
325
|
-
public addTraceableObserver(traceable: string, observer: CallableFunction, payload?: any): Element {
|
|
326
|
-
if (payload && !(payload instanceof HTMLElement)) {
|
|
327
|
-
throw new Error(`Payload for camera observer must be an instance of "HTMLElement" in element "${this.id}".`);
|
|
328
|
-
}
|
|
329
|
-
if (!this.traceableDefinitions || !this.traceableDefinitions[traceable]) {
|
|
330
|
-
throw new Error(`No traceable "${traceable}" defined to add observer in element "${this.id}".`);
|
|
331
|
-
}
|
|
332
|
-
const node = this.getTraceableNode(traceable);
|
|
333
|
-
if (!(node instanceof AbstractMesh)) {
|
|
334
|
-
throw new Error(`The path must be an instance of "AbstractMesh" for camera observer in element "${this.id}".`);
|
|
335
|
-
}
|
|
336
|
-
this.variant.viewer.sceneManager.activeCamera.onViewMatrixChangedObservable.add((eventData, eventState) => {
|
|
337
|
-
const position = getClientRectFromMesh(node, this.variant.viewer.scene, this.variant.viewer.canvas);
|
|
338
|
-
if (payload) {
|
|
339
|
-
payload.style.top = `${position.top}px`;
|
|
340
|
-
payload.style.left = `${position.left}px`;
|
|
341
|
-
}
|
|
342
|
-
observer(node, position);
|
|
343
|
-
});
|
|
344
|
-
return this;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Draws a `ImageBitmap` or `OffscreenCanvas` onto a `paintable` defined via {@link PaintableDefinition}.
|
|
349
|
-
*/
|
|
350
|
-
public drawPaintable(paintable: string, imageSource: HTMLImageElement): Element {
|
|
351
|
-
// node and material checks and preperation
|
|
352
|
-
const node = this.getPaintableNode(paintable);
|
|
353
|
-
if (!(node instanceof AbstractMesh)) {
|
|
354
|
-
throw new Error(
|
|
355
|
-
`The path must be an instance of "AbstractMesh" for paintable "${paintable}" ` + `in element "${this.id}".`
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (node.material && this.variant.viewer.cloneMaterialsOnMutation) {
|
|
360
|
-
if (node.material && !has(node.metadata, 'dirty.material')) {
|
|
361
|
-
cloneTransformNodeMaterial(node);
|
|
362
|
-
}
|
|
363
|
-
if (!has(node.metadata, 'dirty.material.texture')) {
|
|
364
|
-
// inject initial value and mark as dirty
|
|
365
|
-
injectMetadata(node, { dirty: { material: { texture: true } } });
|
|
366
|
-
}
|
|
367
|
-
} else if (!node.material) {
|
|
368
|
-
// paintables should also work if no material is assigned to the node per default
|
|
369
|
-
// in this case a certain fallback material with fitting default values is defined
|
|
370
|
-
const pbrMat = new PBRMaterial(`${this.id}.${paintable}.material`, this.variant.viewer.scene);
|
|
371
|
-
pbrMat.roughness = 1.0;
|
|
372
|
-
pbrMat.metallic = 1.0;
|
|
373
|
-
node.material = pbrMat;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// TODO: Not sure if this really should be overwritten every time the paintable is redrawn.
|
|
377
|
-
// Maybe the 3D artist had something in mind when setting a certain transparency mode, which would get overwritten
|
|
378
|
-
// in this case.
|
|
379
|
-
// Applying it as a default if no material is set is fine though (see roughness/metallic some lines above).
|
|
380
|
-
// Removing this line will most likely break existing configurators, so be cautios!
|
|
381
|
-
node.material.transparencyMode = Material.MATERIAL_ALPHATESTANDBLEND;
|
|
382
|
-
|
|
383
|
-
const paintableDefinition = this.getPaintableDefinition(paintable);
|
|
384
|
-
if (isNumber(paintableDefinition.textureOptions)) {
|
|
385
|
-
// convert into object to satisfy the interface of `drawPaintableOnMaterial`
|
|
386
|
-
paintableDefinition.textureOptions = {
|
|
387
|
-
width: paintableDefinition.textureOptions,
|
|
388
|
-
height: paintableDefinition.textureOptions,
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// convert texture size options into scale values, as the scaling is now done via uvScale properties
|
|
393
|
-
const paintableOptions: PaintableOptions = {};
|
|
394
|
-
if (paintableDefinition.textureOptions.width) {
|
|
395
|
-
paintableOptions.uScale = paintableDefinition.textureOptions.width / (imageSource.width as number);
|
|
396
|
-
}
|
|
397
|
-
if (paintableDefinition.textureOptions.height) {
|
|
398
|
-
paintableOptions.vScale = paintableDefinition.textureOptions.height / (imageSource.height as number);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// forward to generic "paintable" call
|
|
402
|
-
drawPaintableOnMaterial(node.material, imageSource, this.variant.viewer.scene, paintableOptions);
|
|
403
|
-
|
|
404
|
-
return this;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Draws a SVG string onto a `paintable` defined via {@link PaintableDefinition}.
|
|
409
|
-
*/
|
|
410
|
-
public async drawPaintableFromSvg(paintable: string, svgSource: string): Promise<Element> {
|
|
411
|
-
const image = await createImageFromSvg(svgSource);
|
|
412
|
-
return this.drawPaintable(paintable, image);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Draws an Image from source (URL/URI) onto a `paintable` defined via {@link PaintableDefinition}.
|
|
417
|
-
*/
|
|
418
|
-
public async drawPaintableFromImgSrc(paintable: string, imgSource: string): Promise<Element> {
|
|
419
|
-
const image = await createImageFromImgSrc(imgSource);
|
|
420
|
-
return this.drawPaintable(paintable, image);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Adds observers for loading missing materials where needed
|
|
425
|
-
*/
|
|
426
|
-
protected addMissingMaterialObservers() {
|
|
427
|
-
for (const abstractMesh of this.abstractMeshesFlat) {
|
|
428
|
-
addMissingMaterialObserver(abstractMesh);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
|
|
434
|
-
*/
|
|
435
|
-
protected addParameterObservers(): Element {
|
|
436
|
-
this._parameterObservers.set(Parameter.VISIBLE, [
|
|
437
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
438
|
-
let visible;
|
|
439
|
-
try {
|
|
440
|
-
visible = Parameter.parseBoolean(newValue);
|
|
441
|
-
} catch (e) {
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
if (visible === true) {
|
|
445
|
-
// Override visible state and materials if tag manager is in use to support texture lazy loading
|
|
446
|
-
if (element.variant.viewer.tagManager.parameters.size > 0) {
|
|
447
|
-
const hiddenNodeNames: string[] = [];
|
|
448
|
-
element.variant.viewer.tagManager.parameters.forEach((parameterBag, subject) => {
|
|
449
|
-
const nodes = element.variant.viewer.tagManager.getNodesBySubject(subject);
|
|
450
|
-
const visibleParamValue = parameterBag[Parameter.VISIBLE];
|
|
451
|
-
const isVisible = undefined === visibleParamValue || Parameter.parseBoolean(visibleParamValue);
|
|
452
|
-
if (!isVisible) {
|
|
453
|
-
hiddenNodeNames.push(...nodes.map(node => node.name));
|
|
454
|
-
}
|
|
455
|
-
// overwrite materials immediatly, so that original material of node doesn't get loaded, since it could
|
|
456
|
-
// be exchanged by the tag manager
|
|
457
|
-
if (parameterBag[Parameter.MATERIAL]) {
|
|
458
|
-
nodes.forEach(node => setMaterial(node, parameterBag[Parameter.MATERIAL], false));
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
// enable all nodes that are not explicitely hidden by the tag manager
|
|
462
|
-
element.nodesFlat.map(node => {
|
|
463
|
-
if (!hiddenNodeNames.includes(node.name)) {
|
|
464
|
-
node.setEnabled(true);
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
// The default behaviour.
|
|
470
|
-
element.nodes.forEach(node => {
|
|
471
|
-
injectMetadata(node, { visibility: node.isEnabled() });
|
|
472
|
-
activate(node);
|
|
473
|
-
});
|
|
474
|
-
} else if (visible === false) {
|
|
475
|
-
element.nodes.forEach(node => {
|
|
476
|
-
injectMetadata(node, { visibility: node.isEnabled() });
|
|
477
|
-
deactivate(node);
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
},
|
|
481
|
-
]);
|
|
482
|
-
this._parameterObservers.set(Parameter.SCALING, [
|
|
483
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
484
|
-
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
485
|
-
element.nodes.forEach(node =>
|
|
486
|
-
transformTransformNode(node, {
|
|
487
|
-
scaling: Parameter.parseVector(newValue),
|
|
488
|
-
position: Parameter.parseVector(
|
|
489
|
-
element.inheritedParameters[Parameter.POSITION] || Parameter.getDefaultValue(Parameter.POSITION)
|
|
490
|
-
),
|
|
491
|
-
rotation: Parameter.parseRotation(
|
|
492
|
-
element.inheritedParameters[Parameter.ROTATION] || Parameter.getDefaultValue(Parameter.ROTATION)
|
|
493
|
-
),
|
|
494
|
-
})
|
|
495
|
-
);
|
|
496
|
-
},
|
|
497
|
-
]);
|
|
498
|
-
this._parameterObservers.set(Parameter.POSITION, [
|
|
499
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
500
|
-
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
501
|
-
element.nodes.forEach(node =>
|
|
502
|
-
transformTransformNode(node, {
|
|
503
|
-
scaling: Parameter.parseVector(
|
|
504
|
-
element.inheritedParameters[Parameter.SCALING] || Parameter.getDefaultValue(Parameter.SCALING)
|
|
505
|
-
),
|
|
506
|
-
position: Parameter.parseVector(newValue),
|
|
507
|
-
rotation: Parameter.parseRotation(
|
|
508
|
-
element.inheritedParameters[Parameter.ROTATION] || Parameter.getDefaultValue(Parameter.ROTATION)
|
|
509
|
-
),
|
|
510
|
-
})
|
|
511
|
-
);
|
|
512
|
-
},
|
|
513
|
-
]);
|
|
514
|
-
this._parameterObservers.set(Parameter.ROTATION, [
|
|
515
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
516
|
-
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
517
|
-
element.nodes.forEach(node =>
|
|
518
|
-
transformTransformNode(node, {
|
|
519
|
-
scaling: Parameter.parseVector(
|
|
520
|
-
element.inheritedParameters[Parameter.SCALING] || Parameter.getDefaultValue(Parameter.SCALING)
|
|
521
|
-
),
|
|
522
|
-
position: Parameter.parseVector(
|
|
523
|
-
element.inheritedParameters[Parameter.POSITION] || Parameter.getDefaultValue(Parameter.POSITION)
|
|
524
|
-
),
|
|
525
|
-
rotation: Parameter.parseRotation(newValue),
|
|
526
|
-
})
|
|
527
|
-
);
|
|
528
|
-
},
|
|
529
|
-
]);
|
|
530
|
-
this._parameterObservers.set(Parameter.MATERIAL, [
|
|
531
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
532
|
-
const materialName = newValue.toString();
|
|
533
|
-
for (const node of element.nodes) {
|
|
534
|
-
assertTransformNode(node, node => assertMeshCapability(node, Parameter.MATERIAL));
|
|
535
|
-
setMaterial(node, materialName, true, element.variant);
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
]);
|
|
539
|
-
this._parameterObservers.set(Parameter.MATERIAL_COLOR, [
|
|
540
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
541
|
-
const color = Parameter.parseColor(newValue);
|
|
542
|
-
element.nodes.forEach(node => {
|
|
543
|
-
assertTransformNode(node, node => assertMeshCapability(node, Parameter.MATERIAL_COLOR));
|
|
544
|
-
if (this.variant.viewer.cloneMaterialsOnMutation) {
|
|
545
|
-
if (!has(node.metadata, 'dirty.material')) {
|
|
546
|
-
cloneTransformNodeMaterial(node);
|
|
547
|
-
}
|
|
548
|
-
if (!has(node.metadata, 'dirty.material.color')) {
|
|
549
|
-
// inject initial value and mark as dirty
|
|
550
|
-
injectMetadata(node, { dirty: { material: { color: oldValue } } });
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
setMaterialColor(node, color);
|
|
554
|
-
});
|
|
555
|
-
},
|
|
556
|
-
]);
|
|
557
|
-
this._parameterObservers.set(Parameter.MATERIAL_METALLNESS, [
|
|
558
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
559
|
-
const metallness = Parameter.parseNumber(newValue);
|
|
560
|
-
element.nodes.forEach(node => {
|
|
561
|
-
assertTransformNode(node, node => assertMeshCapability(node, Parameter.MATERIAL_METALLNESS));
|
|
562
|
-
if (this.variant.viewer.cloneMaterialsOnMutation) {
|
|
563
|
-
if (!has(node.metadata, 'dirty.material')) {
|
|
564
|
-
cloneTransformNodeMaterial(node);
|
|
565
|
-
}
|
|
566
|
-
if (!has(node.metadata, 'dirty.material.metallness')) {
|
|
567
|
-
// inject initial value and mark as dirty
|
|
568
|
-
injectMetadata(node, { dirty: { material: { metallness: oldValue } } });
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
setMaterialMetallness(node, metallness);
|
|
572
|
-
});
|
|
573
|
-
},
|
|
574
|
-
]);
|
|
575
|
-
this._parameterObservers.set(Parameter.MATERIAL_ROUGHNESS, [
|
|
576
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
577
|
-
const roughness = Parameter.parseNumber(newValue);
|
|
578
|
-
element.nodes.forEach(node => {
|
|
579
|
-
assertTransformNode(node, node => assertMeshCapability(node, Parameter.MATERIAL_ROUGHNESS));
|
|
580
|
-
if (this.variant.viewer.cloneMaterialsOnMutation) {
|
|
581
|
-
if (!has(node.metadata, 'dirty.material')) {
|
|
582
|
-
cloneTransformNodeMaterial(node);
|
|
583
|
-
}
|
|
584
|
-
if (!has(node.metadata, 'dirty.material.roughness')) {
|
|
585
|
-
// inject initial value and mark as dirty
|
|
586
|
-
injectMetadata(node, { dirty: { material: { roughness: oldValue } } });
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
setMaterialRoughness(node, roughness);
|
|
590
|
-
});
|
|
591
|
-
},
|
|
592
|
-
]);
|
|
593
|
-
this._parameterObservers.set(Parameter.HIGHLIGHT_COLOR, [
|
|
594
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
595
|
-
// trigger Parameter.HIGHLIGHTED observers
|
|
596
|
-
this._parameterObservers.get(Parameter.HIGHLIGHTED)?.forEach(observer => {
|
|
597
|
-
observer(element, !!element.highlighted, !!element.highlighted);
|
|
598
|
-
});
|
|
599
|
-
},
|
|
600
|
-
]);
|
|
601
|
-
this._parameterObservers.set(Parameter.HIGHLIGHT_ENABLED, [
|
|
602
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
603
|
-
let curr;
|
|
604
|
-
try {
|
|
605
|
-
curr = Parameter.parseBoolean(newValue);
|
|
606
|
-
} catch (e) {
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
609
|
-
switch (curr) {
|
|
610
|
-
case true:
|
|
611
|
-
if (element._highlightLayer) {
|
|
612
|
-
break;
|
|
613
|
-
}
|
|
614
|
-
element.highlightLayer = new HighlightLayer(
|
|
615
|
-
DottedPath.create(element.id).addPart('highlight').path,
|
|
616
|
-
element.variant.viewer.scene
|
|
617
|
-
);
|
|
618
|
-
break;
|
|
619
|
-
case false:
|
|
620
|
-
element.highlightLayer?.dispose();
|
|
621
|
-
break;
|
|
622
|
-
}
|
|
623
|
-
},
|
|
624
|
-
]);
|
|
625
|
-
this._parameterObservers.set(Parameter.HIGHLIGHTED, [
|
|
626
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
627
|
-
if (!element.inheritedParameters[Parameter.HIGHLIGHT_ENABLED]) {
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
// trigger Parameter.HIGHLIGHT_ENABLED observers to ensure HighlightLayer
|
|
631
|
-
this._parameterObservers.get(Parameter.HIGHLIGHT_ENABLED)?.forEach(observer => {
|
|
632
|
-
observer(element, this.parameters[Parameter.HIGHLIGHT_ENABLED], true);
|
|
633
|
-
});
|
|
634
|
-
let highlighted;
|
|
635
|
-
try {
|
|
636
|
-
highlighted = Parameter.parseBoolean(newValue);
|
|
637
|
-
} catch (e) {
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
// Add/Remove meshes to previously created highlight layers.
|
|
641
|
-
if (highlighted === true) {
|
|
642
|
-
element.nodes.forEach(node => {
|
|
643
|
-
assertTransformNode(node, node => assertMeshCapability(node, Parameter.HIGHLIGHTED));
|
|
644
|
-
let color = Color3.Green();
|
|
645
|
-
if (element.inheritedParameters[Parameter.HIGHLIGHT_COLOR]) {
|
|
646
|
-
color = Parameter.parseColor(element.inheritedParameters[Parameter.HIGHLIGHT_COLOR]);
|
|
647
|
-
}
|
|
648
|
-
if (typeof element._highlightLayer !== 'undefined') {
|
|
649
|
-
addToHighlightLayer(element._highlightLayer, color, node);
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
} else if (highlighted === false) {
|
|
653
|
-
element.nodes.forEach(node => {
|
|
654
|
-
if (typeof element._highlightLayer !== 'undefined') {
|
|
655
|
-
removeFromHighlightLayer(element._highlightLayer, node);
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
},
|
|
660
|
-
]);
|
|
661
|
-
this._parameterObservers.set(Parameter.CAST_SHADOW, [
|
|
662
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
663
|
-
let castShadow;
|
|
664
|
-
try {
|
|
665
|
-
castShadow = Parameter.parseBoolean(newValue);
|
|
666
|
-
} catch (e) {
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
let lightCsl = element.inheritedParameters[Parameter.CAST_SHADOW_FROM_LIGHTS];
|
|
670
|
-
if (!lightCsl) {
|
|
671
|
-
lightCsl = element.variant.inheritedViewerLights.map(l => l.name).join(',');
|
|
672
|
-
}
|
|
673
|
-
if (castShadow === true) {
|
|
674
|
-
await this.castShadowValueHandler(lightCsl, addToShadowGenerator);
|
|
675
|
-
}
|
|
676
|
-
if (castShadow === false) {
|
|
677
|
-
await this.castShadowValueHandler(lightCsl, removeFromShadowGenerator);
|
|
678
|
-
}
|
|
679
|
-
},
|
|
680
|
-
]);
|
|
681
|
-
this._parameterObservers.set(Parameter.CAST_SHADOW_FROM_LIGHTS, [
|
|
682
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
683
|
-
// TODO: Possible performance issue in combination with CAST_SHADOW, since both observers are initially called
|
|
684
|
-
// when CAST_SHADOW and CAST_SHADOW_FROM_LIGHTS are defined in the spec.
|
|
685
|
-
const lightCsl = element.variant.inheritedViewerLights.map(l => l.name).join(',');
|
|
686
|
-
// cleanup all shadow generators
|
|
687
|
-
await this.castShadowValueHandler(lightCsl, removeFromShadowGenerator);
|
|
688
|
-
if (element.castShadow === true) {
|
|
689
|
-
// if newValue is undefined or '' then set newValue to lightCsl (use all lights)
|
|
690
|
-
if (!newValue) {
|
|
691
|
-
newValue = lightCsl;
|
|
692
|
-
}
|
|
693
|
-
await this.castShadowValueHandler(newValue, addToShadowGenerator);
|
|
694
|
-
}
|
|
695
|
-
},
|
|
696
|
-
]);
|
|
697
|
-
this._parameterObservers.set(Parameter.RECEIVE_SHADOWS, [
|
|
698
|
-
async (element: Element, oldValue: Undefinable<ParameterValue>, newValue: ParameterValue) => {
|
|
699
|
-
element.nodes.forEach(node => setReceiveShadows(node, Parameter.parseBoolean(newValue)));
|
|
700
|
-
},
|
|
701
|
-
]);
|
|
702
|
-
return this;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Filter for nodes that are not defined or excluded in the `pathDefinitions`.
|
|
707
|
-
*/
|
|
708
|
-
protected filterNode(node: TransformNode): boolean {
|
|
709
|
-
let includeTokens: string[] = [];
|
|
710
|
-
this.pathDefinitions.include.forEach(dottedPath => {
|
|
711
|
-
includeTokens = union(includeTokens, DottedPath.create(dottedPath).leafTokens);
|
|
712
|
-
});
|
|
713
|
-
const shallKeep = (dp: DottedPath) => {
|
|
714
|
-
const isDirectlyIncluded = !!includeTokens.find(_dp => _dp === dp.path);
|
|
715
|
-
const isSubOfIncluded = !!this.pathDefinitions.include.find(_dp => {
|
|
716
|
-
return dp.path.startsWith(`${_dp}${DottedPath.DELIMITER}`);
|
|
717
|
-
});
|
|
718
|
-
return isDirectlyIncluded || isSubOfIncluded;
|
|
719
|
-
};
|
|
720
|
-
const shallExclude = (dp: DottedPath) => {
|
|
721
|
-
if (!this.pathDefinitions.exclude) {
|
|
722
|
-
return false;
|
|
723
|
-
}
|
|
724
|
-
return !!this.pathDefinitions.exclude.find(_dp => dp.path === _dp);
|
|
725
|
-
};
|
|
726
|
-
return shallKeep(node.metadata.dottedPath) && !shallExclude(node.metadata.dottedPath);
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Asserts whether all {@link pathDefinitions} link to a valid `Node` path.
|
|
731
|
-
* @protected
|
|
732
|
-
*/
|
|
733
|
-
protected assertPathDefinitions() {
|
|
734
|
-
const dottedNodes = this.variant.inheritedDottedNodes;
|
|
735
|
-
if (dottedNodes.size === 0) {
|
|
736
|
-
throw new Error(`There are no mapped nodes for element "${this.id}".`);
|
|
737
|
-
}
|
|
738
|
-
const include = this.pathDefinitions.include.map(path => DottedPath.create(path).path);
|
|
739
|
-
const exclude = this.pathDefinitions.exclude?.map(path => DottedPath.create(path).path);
|
|
740
|
-
const keys = Array.from(dottedNodes.keys()).map(dottedPath => dottedPath.path);
|
|
741
|
-
union<string>(include, exclude).forEach(path => {
|
|
742
|
-
if (keys.indexOf(path) === -1) {
|
|
743
|
-
throw new Error(`Node with path "${path}" does not exist for element "${this.id}".`);
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* Handles callback for given light parameter.
|
|
750
|
-
*/
|
|
751
|
-
private async castShadowValueHandler(lightCsl: ParameterValue, mutator: CallableFunction) {
|
|
752
|
-
const lights: Light[] = [];
|
|
753
|
-
for (const lightName of Parameter.parseCommaSeparatedList(lightCsl)) {
|
|
754
|
-
const viewerLight = await this.variant.getViewerLight(lightName);
|
|
755
|
-
if (viewerLight) {
|
|
756
|
-
lights.push(viewerLight.light);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
const shadowGenerators = lights.map(light => light?.getShadowGenerator() as ShadowGenerator).filter(Boolean);
|
|
760
|
-
shadowGenerators.forEach(generator => {
|
|
761
|
-
this.nodes.forEach(node => {
|
|
762
|
-
mutator(generator, node);
|
|
763
|
-
});
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
}
|