@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.3.4 → 3.3.6

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 (71) hide show
  1. package/package.json +19 -20
  2. package/src/RenderingEngine.ts +0 -1336
  3. package/src/index.ts +0 -81
  4. package/src/injectors/Tag3dGeometryCreationInjector.ts +0 -154
  5. package/src/injectors/TextureUnifierInjector.ts +0 -214
  6. package/src/interfaces/ILoader.ts +0 -3
  7. package/src/interfaces/IPostProcessingEffectDefinitions.ts +0 -402
  8. package/src/interfaces/IRenderingEngine.ts +0 -48
  9. package/src/loaders/EnvironmentMapLoader.ts +0 -357
  10. package/src/loaders/GeometryLoader.ts +0 -585
  11. package/src/loaders/HTMLElementAnchorLoader.ts +0 -107
  12. package/src/loaders/LightLoader.ts +0 -171
  13. package/src/loaders/MaterialLoader.ts +0 -1413
  14. package/src/managers/CameraManager.ts +0 -178
  15. package/src/managers/EnvironmentGeometryManager.ts +0 -224
  16. package/src/managers/PostProcessingManager.ts +0 -1181
  17. package/src/managers/RenderingManager.ts +0 -657
  18. package/src/managers/SceneTracingManager.ts +0 -127
  19. package/src/managers/SceneTreeManager.ts +0 -576
  20. package/src/managers/postprocessing/GodRaysManager.ts +0 -52
  21. package/src/managers/postprocessing/OutlineManager.ts +0 -58
  22. package/src/managers/postprocessing/SSAARenderPass.ts +0 -339
  23. package/src/managers/postprocessing/SelectiveBloomManager.ts +0 -58
  24. package/src/managers/postprocessing/ao/ao/AOEffect.ts +0 -180
  25. package/src/managers/postprocessing/ao/ao/AOPass.ts +0 -128
  26. package/src/managers/postprocessing/ao/ao/shader/ao_compose.glsl +0 -17
  27. package/src/managers/postprocessing/ao/ao/shader/ao_compose.ts +0 -19
  28. package/src/managers/postprocessing/ao/hbao/HBAOEffect.ts +0 -41
  29. package/src/managers/postprocessing/ao/hbao/shader/hbao.glsl +0 -96
  30. package/src/managers/postprocessing/ao/hbao/shader/hbao.ts +0 -98
  31. package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.glsl +0 -92
  32. package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.ts +0 -95
  33. package/src/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.ts +0 -259
  34. package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.glsl +0 -125
  35. package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.ts +0 -127
  36. package/src/managers/postprocessing/ao/ssao/SSAOEffect.ts +0 -106
  37. package/src/managers/postprocessing/ao/ssao/shader/ssao.glsl +0 -128
  38. package/src/managers/postprocessing/ao/ssao/shader/ssao.ts +0 -130
  39. package/src/managers/postprocessing/ao/utils/shader/basic.glsl +0 -6
  40. package/src/managers/postprocessing/ao/utils/shader/basic.ts +0 -8
  41. package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.glsl +0 -36
  42. package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.ts +0 -38
  43. package/src/managers/postprocessing/utils/CopyMaterial.ts +0 -130
  44. package/src/managers/postprocessing/utils/CopyShader.ts +0 -39
  45. package/src/managers/postprocessing/utils/FullScreenQuad.ts +0 -47
  46. package/src/managers/postprocessing/utils/NormalPass.ts +0 -222
  47. package/src/managers/postprocessing/utils/RenderPass.ts +0 -366
  48. package/src/materials/GemMaterial.ts +0 -268
  49. package/src/materials/MeshUnlitMaterialParameters.ts +0 -4
  50. package/src/materials/MultiPointsMaterial.ts +0 -646
  51. package/src/materials/SpecularGlossinessMaterial.ts +0 -182
  52. package/src/objects/SDBone.ts +0 -51
  53. package/src/objects/SDColor.ts +0 -54
  54. package/src/objects/SDData.ts +0 -44
  55. package/src/objects/SDObject.ts +0 -58
  56. package/src/shaders/PCSS.ts +0 -124
  57. package/src/shaders/gem.ts +0 -579
  58. package/src/shaders/gem_frag.glsl +0 -522
  59. package/src/shaders/gem_vert.glsl +0 -53
  60. package/src/shaders/multi_points.ts +0 -291
  61. package/src/shaders/multi_points_frag.glsl +0 -166
  62. package/src/shaders/multi_points_vert.glsl +0 -120
  63. package/src/styling/viewport-css.ts +0 -113
  64. package/src/styling/viewport.css +0 -111
  65. package/src/three/font.ts +0 -2
  66. package/src/three/geometries/TextGeometry.ts +0 -58
  67. package/src/three/loaders/FontLoader.ts +0 -205
  68. package/src/three/loaders/RGBELoader.ts +0 -496
  69. package/src/types/IThreejsData.ts +0 -16
  70. package/src/types/ThreejsData.ts +0 -43
  71. package/tsconfig.json +0 -20
@@ -1,576 +0,0 @@
1
- import * as THREE from 'three';
2
- import { AbstractCamera } from '@shapediver/viewer.rendering-engine.camera-engine';
3
- import { AbstractLight, DirectionalLight } from '@shapediver/viewer.rendering-engine.light-engine';
4
- import {
5
- AbstractMaterialData,
6
- AnimationData,
7
- BoneData,
8
- GeometryData,
9
- HTMLElementAnchorData,
10
- IMaterialAbstractData,
11
- ISDTFOverview,
12
- MaterialStandardData,
13
- SDTFItemData,
14
- SDTFOverviewData
15
- } from '@shapediver/viewer.shared.types';
16
- import { Box, IBox } from '@shapediver/viewer.shared.math';
17
- import { IManager, RENDERER_TYPE } from '@shapediver/viewer.rendering-engine.rendering-engine';
18
- import {
19
- ITree,
20
- ITreeNode,
21
- ITreeNodeData,
22
- Tree
23
- } from '@shapediver/viewer.shared.node-tree';
24
- import { mat4, vec3 } from 'gl-matrix';
25
- import { RenderingEngine } from '../RenderingEngine';
26
- import { SD_DATA_TYPE, SDData } from '../objects/SDData';
27
- import { SDBone } from '../objects/SDBone';
28
- import { SDObject } from '../objects/SDObject';
29
- import { ThreejsData } from '../types/ThreejsData';
30
- /* eslint-disable @typescript-eslint/no-empty-function */
31
- import {
32
- EventEngine,
33
- EVENTTYPE,
34
- InputValidator,
35
- StateEngine,
36
- } from '@shapediver/viewer.shared.services';
37
-
38
- // #region Type aliases (1)
39
-
40
- type UpdateFilter = {
41
- transformationOnly: boolean
42
- }
43
-
44
- // #endregion Type aliases (1)
45
-
46
- // #region Classes (1)
47
-
48
- export class SceneTreeManager implements IManager {
49
- // #region Properties (12)
50
-
51
- private readonly _eventEngine: EventEngine = EventEngine.instance;
52
- private readonly _inputValidator: InputValidator = InputValidator.instance;
53
- private readonly _scene: THREE.Scene = new THREE.Scene();
54
- private readonly _stateEngine: StateEngine = StateEngine.instance;
55
- private readonly _tree: ITree = Tree.instance;
56
-
57
- private _boundingBox: IBox = new Box();
58
- private _boundingBoxSensitiveData: {
59
- data: AbstractLight,
60
- dataChild: SDData
61
- }[] = [];
62
- private _currentSDTFOverview!: ISDTFOverview;
63
- private _hiddenCamera: THREE.PerspectiveCamera = new THREE.PerspectiveCamera();
64
- private _lastRendererType: RENDERER_TYPE = RENDERER_TYPE.STANDARD;
65
- private _lastRootVersion: string = '';
66
- private _mainNode!: SDObject;
67
-
68
- // #endregion Properties (12)
69
-
70
- // #region Constructors (1)
71
-
72
- constructor(private readonly _renderingEngine: RenderingEngine) {
73
- this._scene.background = new THREE.Color('#ffffff');
74
- }
75
-
76
- // #endregion Constructors (1)
77
-
78
- // #region Public Getters And Setters (4)
79
-
80
- public get boundingBox(): IBox {
81
- return this._boundingBox;
82
- }
83
-
84
- public get lastRendererType(): RENDERER_TYPE {
85
- return this._lastRendererType;
86
- }
87
-
88
- public get lastRootVersion(): string {
89
- return this._lastRootVersion;
90
- }
91
-
92
- public get scene() {
93
- return this._scene;
94
- }
95
-
96
- // #endregion Public Getters And Setters (4)
97
-
98
- // #region Public Methods (6)
99
-
100
- public init(): void { }
101
-
102
- public isEmpty() {
103
- return ((this._boundingBox.min[0] === 0 && this._boundingBox.min[1] === 0 && this._boundingBox.min[2] === 0 &&
104
- this._boundingBox.max[0] === 0 && this._boundingBox.max[1] === 0 && this._boundingBox.max[2] === 0) || this._boundingBox.isEmpty());
105
- }
106
-
107
- /**
108
- * Convert the data of the scene graph node into the format of the implementation.
109
- *
110
- * @param data the data element
111
- * @param obj the corresponding type node
112
- */
113
- public updateData(node: ITreeNode, obj: SDObject, data: ITreeNodeData, filter: UpdateFilter, isVisibleInHierarchy: boolean, skeleton?: THREE.Skeleton): void {
114
- let dataChild = <SDData>obj.children.find(oc => (<SDData>oc).SDid === data.id && (<SDData>oc).SDversion === data.version);
115
- let newChild = false;
116
-
117
- if (!dataChild) {
118
- newChild = true;
119
- dataChild = new SDData(data.id, data.version);
120
- obj.add(dataChild);
121
- }
122
-
123
- if (this._renderingEngine.type === RENDERER_TYPE.ATTRIBUTES) {
124
- this.injectAttributeData(node, data);
125
- } else {
126
- const sdtfTransform = node.getTransformation('sdtf');
127
- if (sdtfTransform) node.removeTransformation(sdtfTransform);
128
-
129
- if (data instanceof GeometryData)
130
- data.attributeMaterial = null;
131
- }
132
-
133
- switch (true) {
134
- case data instanceof GeometryData:
135
- {
136
- dataChild.SDtype = SD_DATA_TYPE.GEOMETRY;
137
-
138
- if (filter.transformationOnly === false)
139
- this._renderingEngine.geometryLoader.load(<GeometryData>data, dataChild, newChild, skeleton).clone();
140
-
141
- let bb: IBox = new Box();
142
- if (skeleton) {
143
- bb = (<GeometryData>data).primitive.computeBoundingBox(node.worldMatrix);
144
- } else {
145
- const clone = dataChild.clone();
146
- clone.applyTransformation(node.worldMatrix);
147
- const threeBox = new THREE.Box3().setFromObject(clone, true);
148
- bb = new Box(vec3.fromValues(threeBox.min.x, threeBox.min.y, threeBox.min.z), vec3.fromValues(threeBox.max.x, threeBox.max.y, threeBox.max.z));
149
- }
150
-
151
- // adjust the general BB
152
- node.boundingBox.union(bb);
153
-
154
- // create the specific BB if it doesn't exist yet
155
- if (!node.boundingBoxViewport[this._renderingEngine.id])
156
- node.boundingBoxViewport[this._renderingEngine.id] = new Box();
157
-
158
- // adjust the specific BB
159
- node.boundingBoxViewport[this._renderingEngine.id].union(bb);
160
- }
161
- break;
162
- case data instanceof ThreejsData:
163
- {
164
- dataChild.SDtype = SD_DATA_TYPE.THREEJS;
165
- dataChild.add(<SDData>(<ThreejsData>data).obj);
166
-
167
- const bbThree = new THREE.Box3().setFromObject((<ThreejsData>data).obj);
168
-
169
- // adjust the general BB
170
- node.boundingBox.union(new Box(vec3.fromValues(...bbThree.min.toArray()), vec3.fromValues(...bbThree.max.toArray())));
171
-
172
- // create the specific BB if it doesn't exist yet
173
- if (!node.boundingBoxViewport[this._renderingEngine.id])
174
- node.boundingBoxViewport[this._renderingEngine.id] = new Box();
175
-
176
- // adjust the specific BB
177
- node.boundingBoxViewport[this._renderingEngine.id].union(new Box(vec3.fromValues(...bbThree.min.toArray()), vec3.fromValues(...bbThree.max.toArray())));
178
- }
179
- break;
180
- case data instanceof AbstractMaterialData:
181
- dataChild.SDtype = SD_DATA_TYPE.MATERIAL;
182
- break;
183
- case data instanceof AbstractLight:
184
- dataChild.SDtype = SD_DATA_TYPE.LIGHT;
185
- if (filter.transformationOnly === false) this._renderingEngine.lightLoader.load(<AbstractLight>data, dataChild);
186
- if (data instanceof DirectionalLight && (<DirectionalLight>data).useNodeData === false)
187
- this._boundingBoxSensitiveData.push({ data: <AbstractLight>data, dataChild });
188
- break;
189
- case data instanceof AbstractCamera:
190
- dataChild.SDtype = SD_DATA_TYPE.CAMERA;
191
- if (filter.transformationOnly === false) this._renderingEngine.cameraManager.load(<AbstractCamera>data, dataChild);
192
- break;
193
- case data instanceof HTMLElementAnchorData:
194
- dataChild.SDtype = SD_DATA_TYPE.HTML_ELEMENT_ANCHOR;
195
- if (filter.transformationOnly === false) this._renderingEngine.htmlElementAnchorLoader.load(node, <HTMLElementAnchorData>data, isVisibleInHierarchy);
196
- break;
197
- case data instanceof AnimationData:
198
- dataChild.SDtype = SD_DATA_TYPE.ANIMATION;
199
- break;
200
- default:
201
- // if there is no valid conversion here, call the convertData of the implementation
202
- break;
203
- }
204
- }
205
-
206
- public updateMorphWeights(node: ITreeNode = this._tree.root, obj: SDObject = this._mainNode) {
207
- if (!node || !obj) return;
208
-
209
- for (let i = 0, len = node.data.length; i < len; i++) {
210
- if (node.data[i] instanceof GeometryData) {
211
- const data: GeometryData = <GeometryData>node.data[i];
212
- const dataChild = <SDData>obj.children.find(oc => (<SDData>oc).SDid === data.id && (<SDData>oc).SDversion === data.version);
213
- if (dataChild)
214
- dataChild.traverse(o => {
215
- if (o instanceof THREE.Points ||
216
- o instanceof THREE.LineSegments ||
217
- o instanceof THREE.LineLoop ||
218
- o instanceof THREE.Line ||
219
- o instanceof THREE.Mesh)
220
- o.morphTargetInfluences = data.morphWeights;
221
- });
222
- }
223
- }
224
-
225
- for (let i = 0, len = node.children.length; i < len; i++) {
226
- const nodeChild = node.children[i];
227
- if (!nodeChild) continue;
228
- const objChild = <SDObject>obj.children.find(oc => (<SDObject>oc).SDid === nodeChild.id);
229
- if (objChild) this.updateMorphWeights(nodeChild, objChild);
230
- }
231
- }
232
-
233
- /**
234
- * Update the current node via the scene graph node.
235
- * Convert the data if needed.
236
- *
237
- * @param node the scene graph node
238
- * @param obj the current type object
239
- */
240
- public updateNode(node: ITreeNode = this._tree.root, obj: THREE.Object3D = this._mainNode, filter: UpdateFilter = { transformationOnly: false }, visibleInHierarchy: boolean = true, skeleton?: THREE.Skeleton) {
241
- const convertedObject = <SDObject>obj;
242
-
243
- // reset the general bounding box of the current node
244
- // it will be recomputed in the following steps
245
- node.boundingBox.reset();
246
-
247
- // create the specific BB if it doesn't exist yet
248
- if (!node.boundingBoxViewport[this._renderingEngine.id])
249
- node.boundingBoxViewport[this._renderingEngine.id] = new Box();
250
-
251
- // reset the specific bounding box of the current node
252
- // it will be recomputed in the following steps
253
- node.boundingBoxViewport[this._renderingEngine.id].reset();
254
-
255
- if (filter.transformationOnly === false) {
256
- // remove all data items that do not exist anymore
257
- const dataIds = node.data.map(d => d.id);
258
- const dataToRemove = convertedObject.children.filter(oc => {
259
- if (oc instanceof SDData) {
260
- if (dataIds.includes(oc.SDid)) {
261
- const data = node.data.find(d => d.id === oc.SDid);
262
- if (data && data.version !== oc.SDversion) {
263
- // version is different
264
- return true;
265
- } else {
266
- return false;
267
- }
268
- } else {
269
- // id not included anymore
270
- return true;
271
- }
272
- } else {
273
- return false;
274
- }
275
- });
276
-
277
- dataToRemove.forEach(dTR => {
278
- this.removeData(<SDData>dTR);
279
- convertedObject.remove(dTR);
280
- });
281
-
282
- // remove all child nodes in the transformed object that do not exist anymore
283
- // the filter goes also through the data items as they were already added
284
- const nodeIds = node.children.filter(d => !d.excludeViewports.includes(this._renderingEngine.id)).map(d => d.id);
285
- const childrenToRemove = convertedObject.children.filter(oc => {
286
- if (oc instanceof SDObject && !(oc instanceof SDData)) {
287
- if (nodeIds.includes(oc.SDid)) {
288
- const child = node.children.find(d => d.id === oc.SDid);
289
- if (child && child.version !== oc.SDversion) {
290
- // version is different
291
- return true;
292
- } else {
293
- return false;
294
- }
295
- } else {
296
- // id not included anymore
297
- return true;
298
- }
299
- } else {
300
- return false;
301
- }
302
- });
303
- childrenToRemove.forEach(cTR => {
304
- cTR.traverse(o => {
305
- if (o instanceof SDData)
306
- this.removeData(o);
307
- });
308
- convertedObject.remove(cTR);
309
- });
310
- }
311
-
312
- // create the skeleton if the node is marked as the skin node (root node of the skeleton)
313
- if (node.skinNode === true) {
314
- const bones: THREE.Bone[] = [];
315
- for (let i = 0; i < node.bones.length; i++)
316
- bones.push(this.getBone(node.bones[i]));
317
-
318
- const boneInverses: THREE.Matrix4[] = [];
319
- for (let i = 0; i < node.boneInverses.length; i++)
320
- boneInverses.push(new THREE.Matrix4().fromArray(node.boneInverses[i]));
321
-
322
- skeleton = new THREE.Skeleton(bones, boneInverses);
323
- }
324
-
325
- const isVisible = node.visible && !node.excludeViewports.includes(this._renderingEngine.id) && !(node.restrictViewports.length > 0 && !node.restrictViewports.includes(this._renderingEngine.id));
326
- const isVisibleInHierarchy = visibleInHierarchy && isVisible;
327
-
328
- // convert all data items of the current node
329
- // old versions will be replaced by new ones
330
- for (let i = 0, len = node.data.length; i < len; i++)
331
- this.updateData(node, convertedObject, node.data[i], filter, isVisibleInHierarchy, skeleton);
332
-
333
- // add new children and update the ones that have a different version
334
- for (let i = 0, len = node.children.length; i < len; i++) {
335
- const nodeChild = node.children[i];
336
- const objChild = <SDObject>convertedObject.children.find(oc => (<SDObject>oc).SDid === nodeChild.id);
337
-
338
- if (!objChild) {
339
- const newChild = node.data.find(d => d instanceof BoneData) ? new SDBone(nodeChild.id, nodeChild.version) : new SDObject(nodeChild.id, nodeChild.version);
340
- const oldChild = nodeChild.convertedObject[this._renderingEngine.id] as THREE.Object3D;
341
- nodeChild.convertedObject[this._renderingEngine.id] = newChild;
342
- if (nodeChild.updateCallbackConvertedObject)
343
- nodeChild.updateCallbackConvertedObject(newChild, oldChild, this._renderingEngine.id);
344
- convertedObject.add(newChild);
345
- this.updateNode(nodeChild, newChild, filter, isVisibleInHierarchy, skeleton);
346
- } else if (objChild.SDversion !== nodeChild.version) {
347
- // if the version is different, update the child
348
- this.updateNode(nodeChild, objChild, filter, isVisibleInHierarchy, skeleton);
349
- objChild.SDversion = nodeChild.version;
350
- } else {
351
- this.updateNode(nodeChild, objChild, filter, isVisibleInHierarchy, skeleton);
352
- }
353
-
354
- // adjust the general BB
355
- if (!nodeChild.boundingBox.isEmpty())
356
- node.boundingBox.union(nodeChild.boundingBox);
357
-
358
- // adjust the specific BB
359
- if (nodeChild.boundingBoxViewport[this._renderingEngine.id] && !nodeChild.boundingBoxViewport[this._renderingEngine.id].isEmpty()) {
360
- // only do this if the node is
361
- // 1. visible
362
- // 2. no included in the "excludeViewports"
363
- // 3. if there are "restrictViewports", it needs to be in them
364
- if (isVisible)
365
- node.boundingBoxViewport[this._renderingEngine.id].union(nodeChild.boundingBoxViewport[this._renderingEngine.id]);
366
- }
367
- }
368
-
369
- convertedObject.visible = node.visible && !node.excludeViewports.includes(this._renderingEngine.id) && !(node.restrictViewports.length > 0 && !node.restrictViewports.includes(this._renderingEngine.id));
370
- convertedObject.applyTransformation(node.nodeMatrix);
371
- }
372
-
373
- public updateSceneTree(root: ITreeNode): void {
374
- if (this._tree.root.version === this._lastRootVersion) return;
375
- this._lastRootVersion = this._tree.root.version;
376
- this._lastRendererType = this._renderingEngine.type;
377
-
378
- if (this._renderingEngine.closed) return;
379
- const oldBB = this._boundingBox.clone();
380
- this._boundingBox = new Box();
381
- this._renderingEngine.lightLoader.shadowMapCount = 0;
382
-
383
- if (!this._mainNode) {
384
- this._mainNode = new SDObject(root.id, root.version);
385
- const oldObj = root.convertedObject[this._renderingEngine.id] as THREE.Object3D;
386
- root.convertedObject[this._renderingEngine.id] = this._mainNode;
387
- if (root.updateCallbackConvertedObject)
388
- root.updateCallbackConvertedObject!(this._mainNode, oldObj, this._renderingEngine.id);
389
- this._scene.add(this._mainNode);
390
- }
391
-
392
- this._boundingBoxSensitiveData = [];
393
-
394
- this._currentSDTFOverview = this.createSDTFOverview();
395
- this.updateNode(root, this._mainNode);
396
- this._boundingBox = root.boundingBoxViewport[this._renderingEngine.id].clone();
397
-
398
- for (let i = 0; i < this._boundingBoxSensitiveData.length; i++)
399
- this._renderingEngine.lightLoader.adjustToBoundingBox(this._boundingBoxSensitiveData[i].data, this._boundingBoxSensitiveData[i].dataChild, this._boundingBox);
400
-
401
- if (!(this._boundingBox.min[0] === oldBB.min[0] && this._boundingBox.min[1] === oldBB.min[1] && this._boundingBox.min[2] === oldBB.min[2] &&
402
- this._boundingBox.max[0] === oldBB.max[0] && this._boundingBox.max[1] === oldBB.max[1] && this._boundingBox.max[2] === oldBB.max[2])) {
403
- if (!this._stateEngine.viewportEngines[this._renderingEngine.id]?.boundingBoxCreated.resolved && !this._boundingBox.isEmpty())
404
- this._stateEngine.viewportEngines[this._renderingEngine.id]?.boundingBoxCreated.resolve(true);
405
-
406
- this._eventEngine.emitEvent(EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, {
407
- viewportId: this._renderingEngine.id, boundingBox: {
408
- min: vec3.clone(this._boundingBox.min),
409
- max: vec3.clone(this._boundingBox.max),
410
- }
411
- });
412
- }
413
-
414
- if (this._boundingBox.isEmpty()) {
415
- // check if all outputs that should be loaded at the start of a session are loaded
416
- // if the bounding box is empty then, emit the event
417
- if (Object.values(this._stateEngine.sessionEngines).every(s => s && s.initialOutputsLoaded.resolved === true)) {
418
- this._eventEngine.emitEvent(EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_EMPTY, {
419
- viewportId: this._renderingEngine.id
420
- });
421
- }
422
- }
423
-
424
- this._renderingEngine.renderingManager.evaluateTextureUnitCount(this._renderingEngine.lightLoader.shadowMapCount + this._renderingEngine.materialLoader.maxMapCount);
425
-
426
- /**
427
- *
428
- * Three.js texture upload and compiling
429
- * This step is needed as three.js would compile the shaders and initialize the texture on the first render call instead.
430
- *
431
- */
432
-
433
- // we initialize all texture and then clear the cache
434
- const threeJsTextureCache = this._renderingEngine.materialLoader.threeJsTextureCache;
435
- for (const key in threeJsTextureCache) {
436
- if (threeJsTextureCache[key].usage === 0) {
437
- threeJsTextureCache[key].texture.dispose();
438
- delete threeJsTextureCache[key];
439
- } else if (threeJsTextureCache[key].initialized === false) {
440
- this._renderingEngine.renderer.initTexture(threeJsTextureCache[key].texture);
441
- threeJsTextureCache[key].initialized = true;
442
- }
443
- }
444
-
445
- // we compile the shaders
446
- this._renderingEngine.renderer.compile(this._renderingEngine.scene, this._hiddenCamera);
447
- }
448
-
449
- // #endregion Public Methods (6)
450
-
451
- // #region Private Methods (5)
452
-
453
- private collectSDTFItemData(node: ITreeNode): SDTFItemData | undefined {
454
- for (let i = 0, len = node.data.length; i < len; i++)
455
- if (node.data[i] instanceof SDTFItemData)
456
- return <SDTFItemData>node.data[i];
457
-
458
- if (!node.parent) return;
459
- return this.collectSDTFItemData(node.parent);
460
- }
461
-
462
- private createSDTFOverview(node: ITreeNode = this._tree.root): ISDTFOverview {
463
- const out: SDTFOverviewData = new SDTFOverviewData({});
464
- for (let i = 0, len = node.data.length; i < len; i++)
465
- if (node.data[i] instanceof SDTFOverviewData)
466
- out.merge(<SDTFOverviewData>node.data[i]);
467
-
468
- for (let i = 0, len = node.children.length; i < len; i++)
469
- out.merge(new SDTFOverviewData(this.createSDTFOverview(node.children[i])));
470
-
471
- return out.overview;
472
- }
473
-
474
- private getBone(node: ITreeNode): SDBone {
475
- let bone: SDBone;
476
- this._mainNode.traverse((o) => {
477
- if ((<SDObject>o).SDid === node.id)
478
- bone = (<SDBone>o);
479
- });
480
- return bone!;
481
- }
482
-
483
- private injectAttributeData(node: ITreeNode, data: ITreeNodeData) {
484
- const itemData = this.collectSDTFItemData(node);
485
- const visData: {
486
- material: IMaterialAbstractData,
487
- matrix: mat4
488
- } = {
489
- material: new MaterialStandardData({ color: this._renderingEngine.defaultMaterialColor, opacity: 1 }),
490
- matrix: mat4.create()
491
- };
492
-
493
- if (this._renderingEngine.visualizeAttributes) {
494
- const userVisData = this._renderingEngine.visualizeAttributes(this._currentSDTFOverview, itemData);
495
- this._inputValidator.validateAndError('Viewer.visualizeAttributes', userVisData, 'object', true);
496
- this._inputValidator.validateAndError('Viewer.visualizeAttributes', userVisData.matrix, 'mat4', true);
497
- visData.material = userVisData.material;
498
- visData.matrix = userVisData.matrix;
499
- }
500
-
501
- node.addTransformation({
502
- id: 'sdtf',
503
- matrix: visData.matrix
504
- });
505
-
506
- if (data instanceof GeometryData)
507
- data.attributeMaterial = visData.material;
508
- }
509
-
510
- private removeData(dataObject: SDData) {
511
- if (dataObject.userData.removed === true) return;
512
- dataObject.userData.removed = true;
513
-
514
- switch (true) {
515
- case dataObject.SDtype === SD_DATA_TYPE.GEOMETRY:
516
- dataObject.traverse((o) => {
517
- if (dataObject.id !== o.id && o.userData.removed === true) return;
518
- o.userData.removed = true;
519
-
520
- if (o instanceof THREE.Mesh || o instanceof THREE.Line || o instanceof THREE.Points || o instanceof THREE.LineSegments || o instanceof THREE.LineLoop) {
521
- this.scene.remove(o);
522
- this._renderingEngine.geometryLoader.removeFromGeometryCache(o.geometry.userData.SDid + '_' + o.geometry.userData.SDversion);
523
- this._renderingEngine.geometryLoader.removeFromPrimitiveCache(o.geometry.userData.primitiveSDid + '_' + o.geometry.userData.primitiveSDversion);
524
- this._renderingEngine.materialLoader.removeFromMaterialCache(o.material.userData.SDid + '_' + o.material.userData.SDversion);
525
-
526
- const texturesToRemove: THREE.Texture[] = [];
527
- for (const t in o.material) {
528
- if (o.material[t] instanceof THREE.Texture) {
529
- o.material[t].name = t;
530
- if (t !== 'envMap') {
531
- if (!texturesToRemove.includes(o.material[t]))
532
- texturesToRemove.push(o.material[t]);
533
- }
534
- }
535
- }
536
-
537
- for (const texture of texturesToRemove) {
538
- if (texture.userData.cacheKey) {
539
- this._renderingEngine.materialLoader.threeJsTextureCache[texture.userData.cacheKey].usage--;
540
- } else {
541
- if (texture.name === 'sphericalNormalMap') {
542
- this._renderingEngine.geometryLoader.removeFromGemSphericalMapsCache(o.geometry.userData.primitiveSDid + '_' + o.geometry.userData.primitiveSDversion);
543
- texture.dispose();
544
- } else {
545
- texture.dispose();
546
- }
547
- }
548
- }
549
- }
550
- });
551
- break;
552
- case dataObject.SDtype === SD_DATA_TYPE.THREEJS:
553
- break;
554
- case dataObject.SDtype === SD_DATA_TYPE.MATERIAL:
555
- break;
556
- case dataObject.SDtype === SD_DATA_TYPE.LIGHT:
557
- dataObject.traverse((o) => {
558
- if (o instanceof THREE.Light)
559
- o.dispose();
560
- });
561
- break;
562
- case dataObject.SDtype === SD_DATA_TYPE.HTML_ELEMENT_ANCHOR:
563
- this._renderingEngine.htmlElementAnchorLoader.removeData(dataObject.SDid, dataObject.SDversion);
564
- break;
565
- case dataObject.SDtype === SD_DATA_TYPE.ANIMATION:
566
- break;
567
- default:
568
- // if there is no valid conversion here, call the convertData of the implementation
569
- break;
570
- }
571
- }
572
-
573
- // #endregion Private Methods (5)
574
- }
575
-
576
- // #endregion Classes (1)
@@ -1,52 +0,0 @@
1
- import * as THREE from 'three';
2
- import { GodRaysEffect } from 'postprocessing';
3
- import { ITreeNode } from '@shapediver/viewer.shared.node-tree';
4
- import { RenderingEngine } from '../../RenderingEngine';
5
-
6
- export class GodRaysManager {
7
- // #region Properties (2)
8
-
9
- private _godRaysEffect!: GodRaysEffect;
10
- private _lightSource: THREE.Mesh | THREE.Points | null = null;
11
-
12
- // #endregion Properties (2)
13
-
14
- // #region Constructors (1)
15
-
16
- constructor(private readonly _renderingEngine: RenderingEngine) { }
17
-
18
- // #endregion Constructors (1)
19
-
20
- // #region Public Methods (3)
21
-
22
- public removeLightSource(): void {
23
- this._godRaysEffect.lightSource = new THREE.Mesh();
24
- }
25
-
26
- public setEffect(godRaysEffect: GodRaysEffect) {
27
- this._godRaysEffect = godRaysEffect;
28
- this._godRaysEffect.lightSource = this._lightSource;
29
- }
30
-
31
- public setLightSource(node: ITreeNode): void {
32
- this._lightSource = null;
33
- (node.convertedObject[this._renderingEngine.id] as THREE.Object3D).traverse(o => {
34
- if (o instanceof THREE.Mesh || o instanceof THREE.Points)
35
- this._lightSource = o;
36
- });
37
-
38
- if (this._lightSource) {
39
- if (Array.isArray((<THREE.Mesh | THREE.Points>this._lightSource).material)) {
40
- (<THREE.Material[]>(<THREE.Mesh | THREE.Points>this._lightSource).material).forEach(m => m.transparent = true);
41
- (<THREE.Material[]>(<THREE.Mesh | THREE.Points>this._lightSource).material).forEach(m => m.depthWrite = false);
42
- } else {
43
- (<THREE.Material>(<THREE.Mesh | THREE.Points>this._lightSource).material).transparent = true;
44
- (<THREE.Material>(<THREE.Mesh | THREE.Points>this._lightSource).material).depthWrite = false;
45
- }
46
- }
47
-
48
- this._godRaysEffect.lightSource = this._lightSource;
49
- }
50
-
51
- // #endregion Public Methods (3)
52
- }
@@ -1,58 +0,0 @@
1
- import * as THREE from 'three';
2
- import { ITreeNode } from '@shapediver/viewer.shared.node-tree';
3
- import { OutlineEffect } from 'postprocessing';
4
- import { RenderingEngine } from '../../RenderingEngine';
5
-
6
- export class OutlineManager {
7
- // #region Properties (2)
8
-
9
- private _outlineEffect!: OutlineEffect;
10
- private _outlineNodes: ITreeNode[] = [];
11
-
12
- // #endregion Properties (2)
13
-
14
- // #region Constructors (1)
15
-
16
- constructor(private readonly _renderingEngine: RenderingEngine) { }
17
-
18
- // #endregion Constructors (1)
19
-
20
- // #region Public Methods (5)
21
-
22
- public addSelection(node: ITreeNode): void {
23
- this._outlineNodes.push(node);
24
- this.updateOutlineEffectObjects();
25
- }
26
-
27
- public clearSelection(): void {
28
- this._outlineNodes = [];
29
- this.updateOutlineEffectObjects();
30
- }
31
-
32
- public removeSelection(node: ITreeNode): boolean {
33
- const index = this._outlineNodes.indexOf(node);
34
- if (index !== -1)
35
- this._outlineNodes.splice(index, 1);
36
-
37
- this.updateOutlineEffectObjects();
38
- return index !== -1;
39
- }
40
-
41
- public setEffect(outlineEffect: OutlineEffect) {
42
- this._outlineEffect = outlineEffect;
43
- this.updateOutlineEffectObjects();
44
- }
45
-
46
- public updateOutlineEffectObjects() {
47
- this._outlineEffect.selection.clear();
48
-
49
- for (let i = 0; i < this._outlineNodes.length; i++) {
50
- (this._outlineNodes[i].convertedObject[this._renderingEngine.id] as THREE.Object3D).traverse(o => {
51
- if (o instanceof THREE.Mesh)
52
- this._outlineEffect.selection.add(o);
53
- });
54
- }
55
- }
56
-
57
- // #endregion Public Methods (5)
58
- }