@combeenation/3d-viewer 4.0.0-beta1 → 4.0.0-beta2
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/README.md +1 -0
- package/dist/lib-cjs/api/classes/element.d.ts +12 -16
- package/dist/lib-cjs/api/classes/element.js +129 -194
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/event.d.ts +1 -15
- package/dist/lib-cjs/api/classes/event.js +1 -15
- package/dist/lib-cjs/api/classes/event.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +7 -101
- package/dist/lib-cjs/api/classes/parameter.js +21 -141
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.js +36 -11
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +2 -2
- package/dist/lib-cjs/api/classes/placementAnimation.js +0 -11
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +14 -48
- package/dist/lib-cjs/api/classes/variant.js +56 -320
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +1 -5
- package/dist/lib-cjs/api/classes/variantInstance.js +0 -10
- package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +3 -6
- package/dist/lib-cjs/api/classes/viewer.js +59 -133
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +1 -5
- package/dist/lib-cjs/api/internal/sceneSetup.js +71 -75
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +4 -54
- package/dist/lib-cjs/api/util/babylonHelper.js +8 -160
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +12 -62
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +8 -8
- package/dist/lib-cjs/api/util/resourceHelper.js +24 -63
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/index.d.ts +22 -24
- package/dist/lib-cjs/index.js +38 -42
- package/dist/lib-cjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/classes/element.ts +117 -146
- package/src/api/classes/{parameterizable.ts → elementParameterizable.ts} +1 -12
- package/src/api/classes/event.ts +1 -16
- package/src/api/classes/parameter.ts +22 -153
- package/src/api/classes/parameterObservable.ts +31 -9
- package/src/api/classes/placementAnimation.ts +0 -10
- package/src/api/classes/variant.ts +51 -187
- package/src/api/classes/variantInstance.ts +1 -8
- package/src/api/classes/viewer.ts +11 -68
- package/src/api/internal/sceneSetup.ts +109 -99
- package/src/api/util/babylonHelper.ts +10 -171
- package/src/api/util/globalTypes.ts +14 -71
- package/src/api/util/resourceHelper.ts +23 -31
- package/src/dev.ts +6 -2
- package/src/index.ts +23 -27
- package/src/pagesconfig.json +13 -8
- package/src/api/classes/variantParameterizable.ts +0 -73
- package/src/api/classes/viewerLight.ts +0 -330
- package/src/api/util/stringHelper.ts +0 -26
|
@@ -1,171 +1,180 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import { Engine } from '@babylonjs/core/Engines/engine';
|
|
3
|
-
import '@babylonjs/core/Helpers/sceneHelpers';
|
|
4
3
|
import '@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader';
|
|
5
|
-
import
|
|
4
|
+
import '@babylonjs/core/Helpers/sceneHelpers';
|
|
5
|
+
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
|
|
6
|
+
import { HDRCubeTexture } from '@babylonjs/core/Materials/Textures/hdrCubeTexture';
|
|
7
|
+
import { Texture } from '@babylonjs/core/Materials/Textures/texture';
|
|
8
|
+
import { Color3, Color4 } from '@babylonjs/core/Maths/math.color';
|
|
6
9
|
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
|
|
7
|
-
import { GroundMesh } from '@babylonjs/core/Meshes/groundMesh';
|
|
8
10
|
import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
|
|
9
11
|
import { DefaultRenderingPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline';
|
|
10
12
|
import { Scene } from '@babylonjs/core/scene';
|
|
11
|
-
import {
|
|
13
|
+
import type { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
|
|
14
|
+
import { Camera } from '@babylonjs/core/Cameras/camera';
|
|
15
|
+
import { Light } from '@babylonjs/core/Lights/light';
|
|
12
16
|
import { Parameter } from '../classes/parameter';
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
_resolve( _ground );
|
|
47
|
-
};
|
|
48
|
-
MeshBuilder.CreateGroundFromHeightMap(
|
|
49
|
-
name,
|
|
50
|
-
definition.url,
|
|
51
|
-
definition,
|
|
52
|
-
scene,
|
|
53
|
-
);
|
|
54
|
-
break;
|
|
55
|
-
default:
|
|
56
|
-
throw new Error( `Ground of type "${definition.type}" not implemented (yet).` );
|
|
57
|
-
}
|
|
58
|
-
} );
|
|
18
|
+
|
|
19
|
+
const defaultLightning = async function(scene: Scene) {
|
|
20
|
+
const defaultSetup: LightDefinition = {
|
|
21
|
+
type: 'hemispheric',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const defaultLight = await processLight(scene, 'default_light', defaultSetup) as HemisphericLight;
|
|
25
|
+
defaultLight.groundColor = Color3.Black();
|
|
26
|
+
defaultLight.diffuse = Color3.White();
|
|
27
|
+
|
|
28
|
+
return defaultLight;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const processLight = async function(scene: Scene, name: string, lightSetup: LightDefinition) {
|
|
33
|
+
|
|
34
|
+
let light: Light;
|
|
35
|
+
|
|
36
|
+
switch(lightSetup.type ) {
|
|
37
|
+
case 'hemispheric':
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const hemisphericLightModule = await import(/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight');
|
|
40
|
+
light = new hemisphericLightModule.HemisphericLight( name, Vector3.Up(), scene);
|
|
41
|
+
break;
|
|
42
|
+
case 'point':
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
const pointLightModule = await import(/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight');
|
|
45
|
+
light = new pointLightModule.PointLight( name, Vector3.Up(), scene);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return light;
|
|
59
50
|
};
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
return await processCamera( scene, 'default_camera', {
|
|
52
|
+
|
|
53
|
+
const defaultCamera = async function(scene: Scene) {
|
|
54
|
+
|
|
55
|
+
const cameraSetup: CameraDefinition = {
|
|
66
56
|
type: 'arc',
|
|
67
57
|
active: true,
|
|
68
|
-
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const defaultCamera = await processCamera(scene, 'default_camera', cameraSetup);
|
|
61
|
+
|
|
62
|
+
return defaultCamera;
|
|
69
63
|
};
|
|
70
64
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* @param name
|
|
74
|
-
* @param cameraSetup
|
|
75
|
-
*/
|
|
76
|
-
const processCamera = async function( scene: Scene, name: string, cameraSetup: CameraDefinition ): Promise<Camera> {
|
|
65
|
+
const processCamera = async function(scene: Scene, name: string, cameraSetup: CameraDefinition) {
|
|
66
|
+
|
|
77
67
|
let camera: Camera;
|
|
68
|
+
|
|
78
69
|
let target = Vector3.Zero();
|
|
79
|
-
if(
|
|
80
|
-
target = Parameter.parseVector(
|
|
70
|
+
if(cameraSetup.target) {
|
|
71
|
+
target = Parameter.parseVector(cameraSetup.target);
|
|
81
72
|
}
|
|
82
|
-
|
|
73
|
+
|
|
74
|
+
switch(cameraSetup.type ) {
|
|
83
75
|
case 'arc':
|
|
84
76
|
// @ts-ignore
|
|
85
77
|
const arcCameraModule = await import(/* webpackChunkName: "arc-rotate-camera" */ '@babylonjs/core/Cameras/arcRotateCamera');
|
|
86
|
-
camera = new arcCameraModule.ArcRotateCamera(
|
|
78
|
+
camera = new arcCameraModule.ArcRotateCamera(name, Math.PI / 4, Math.PI / 4, 2, target, scene );
|
|
87
79
|
camera.metadata = {
|
|
88
80
|
alpha: Math.PI / 4,
|
|
89
81
|
beta: Math.PI / 4,
|
|
90
82
|
radius: 2
|
|
91
83
|
};
|
|
92
84
|
break;
|
|
85
|
+
|
|
93
86
|
}
|
|
94
|
-
|
|
87
|
+
|
|
88
|
+
if(cameraSetup.active) {
|
|
95
89
|
camera.attachControl( scene.getEngine().getRenderingCanvas()!, true );
|
|
96
90
|
}
|
|
91
|
+
|
|
97
92
|
if( cameraSetup.fov ) {
|
|
98
93
|
camera.fov = cameraSetup.fov;
|
|
99
94
|
}
|
|
95
|
+
|
|
100
96
|
camera.storeState();
|
|
101
97
|
return camera;
|
|
102
98
|
};
|
|
103
99
|
|
|
104
|
-
|
|
105
|
-
* @param engine
|
|
106
|
-
* @param sceneJson
|
|
107
|
-
*/
|
|
108
|
-
const sceneSetup = async function(engine: Engine, sceneJson: SceneJson): Promise<Scene> {
|
|
100
|
+
const sceneSetup = async function(engine: Engine, sceneJson: SceneJson) {
|
|
109
101
|
const scene = new Scene( engine );
|
|
110
102
|
scene.clearColor = new Color4(0, 0, 0, 0);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if( !
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
103
|
+
|
|
104
|
+
let cameras: Camera[] = [];
|
|
105
|
+
//there is either no "cameras" or "cameras" is empty
|
|
106
|
+
if( ! sceneJson.scene.hasOwnProperty('cameras') || (sceneJson.scene.cameras && ! Object.keys(sceneJson.scene.cameras).length ) ) {
|
|
107
|
+
const camera = await defaultCamera(scene);
|
|
108
|
+
|
|
109
|
+
cameras.push(camera);
|
|
118
110
|
} else {
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
for(let camera in sceneJson.scene.cameras) {
|
|
112
|
+
cameras.push(await processCamera(scene, camera, sceneJson.scene.cameras[camera]));
|
|
113
|
+
}
|
|
121
114
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
//there is either no "lights" or "lights" is empty
|
|
118
|
+
if( ! sceneJson.scene.hasOwnProperty('lights') || (sceneJson.scene.lights && ! Object.keys(sceneJson.scene.lights).length ) ) {
|
|
119
|
+
// await defaultLightning(scene);
|
|
120
|
+
} else {
|
|
121
|
+
for(let light in sceneJson.scene.lights) {
|
|
122
|
+
await processLight(scene, light, sceneJson.scene.lights[light]);
|
|
127
123
|
}
|
|
128
124
|
}
|
|
125
|
+
|
|
126
|
+
|
|
129
127
|
// TODO: try to split this away from the default rendering pipeline to save module imports
|
|
130
128
|
// The "hdr" setting had negative effect on rendering in Safari. Everything looked a little "edgy". I'm not completely
|
|
131
129
|
// sure if disabling it comes with other negative side effects I don't see right now, so we should probably
|
|
132
130
|
// investigate this a little more in detail at some point.
|
|
133
131
|
const defaultPipeline = new DefaultRenderingPipeline( 'default-rendering-pipeline', false, scene );
|
|
132
|
+
|
|
134
133
|
/* DISABLED: causes problems with Internet Explorer
|
|
135
134
|
defaultPipeline.imageProcessingEnabled = true;
|
|
136
135
|
*/
|
|
136
|
+
|
|
137
137
|
if( sceneJson.scene.globals.aa ) {
|
|
138
138
|
defaultPipeline.fxaaEnabled = true; //implicitly does FxaaPostProcess()
|
|
139
139
|
}
|
|
140
|
+
|
|
140
141
|
// Set samples regardless of fxaa setting since we don't want to use fxaa but still increase the sample count
|
|
141
142
|
defaultPipeline.samples = 8;
|
|
143
|
+
|
|
142
144
|
if( sceneJson.scene.globals['camera-settings'] ) {
|
|
143
|
-
if( sceneJson.scene.globals['camera-settings']
|
|
145
|
+
if( sceneJson.scene.globals['camera-settings'].sharpen && sceneJson.scene.globals['camera-settings'].sharpen.enabled ) {
|
|
144
146
|
defaultPipeline.sharpenEnabled = true; //implicitly does SharpenPostProcess()
|
|
145
147
|
//defaultPipeline.sharpen.colorAmount = 1;
|
|
146
148
|
//defaultPipeline.sharpen.edgeAmount = 0;
|
|
147
149
|
}
|
|
148
|
-
|
|
150
|
+
|
|
151
|
+
if( sceneJson.scene.globals['camera-settings'].bloom && sceneJson.scene.globals['camera-settings'].bloom.enabled ) {
|
|
149
152
|
defaultPipeline.bloomEnabled = true;
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
|
|
154
|
+
if( sceneJson.scene.globals['camera-settings'].bloom.size ) {
|
|
155
|
+
defaultPipeline.bloomScale = sceneJson.scene.globals['camera-settings'].bloom.size;
|
|
152
156
|
}
|
|
153
|
-
|
|
154
|
-
|
|
157
|
+
|
|
158
|
+
if( sceneJson.scene.globals['camera-settings'].bloom.threshold ) {
|
|
159
|
+
defaultPipeline.bloomThreshold = sceneJson.scene.globals['camera-settings'].bloom.threshold;
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
|
|
163
|
+
if( sceneJson.scene.globals['camera-settings'].contrast ) {
|
|
164
|
+
scene.imageProcessingConfiguration.contrast = sceneJson.scene.globals['camera-settings'].contrast;
|
|
159
165
|
}
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
|
|
167
|
+
if( sceneJson.scene.globals['camera-settings'].exposure ) {
|
|
168
|
+
scene.imageProcessingConfiguration.exposure = sceneJson.scene.globals['camera-settings'].exposure;
|
|
162
169
|
}
|
|
163
|
-
|
|
170
|
+
|
|
171
|
+
if( sceneJson.scene.globals['camera-settings'].dof && sceneJson.scene.globals['camera-settings'].dof.enabled ) {
|
|
164
172
|
//@ts-ignore
|
|
165
173
|
const module = await import(/* webpackChunkName: "lens-rendering" */ './lensRendering');
|
|
166
|
-
new module.LensRenderingPipeline( 'lens-rendering', sceneJson.scene.globals['camera-settings']!.
|
|
174
|
+
new module.LensRenderingPipeline( 'lens-rendering', sceneJson.scene.globals['camera-settings'].dof!.settings, scene, 1.0, cameras );
|
|
167
175
|
}
|
|
168
176
|
}
|
|
177
|
+
|
|
169
178
|
// TODO: make this dynamic
|
|
170
179
|
/*
|
|
171
180
|
const texture = new HDRCubeTexture("/assets/small_cave_1k.hdr", scene, 256);
|
|
@@ -186,9 +195,10 @@ const sceneSetup = async function(engine: Engine, sceneJson: SceneJson): Promise
|
|
|
186
195
|
*/
|
|
187
196
|
|
|
188
197
|
// TODO: shadows don't work with HemishpericLight
|
|
198
|
+
|
|
189
199
|
return scene;
|
|
190
200
|
};
|
|
191
201
|
|
|
192
202
|
export {
|
|
193
203
|
sceneSetup
|
|
194
|
-
}
|
|
204
|
+
}
|
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
import { HighlightLayer } from '@babylonjs/core/Layers/highlightLayer';
|
|
2
|
-
import { Light } from '@babylonjs/core/Lights/light';
|
|
3
|
-
import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator';
|
|
4
2
|
import { Material } from '@babylonjs/core/Materials/material';
|
|
5
3
|
import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
|
|
6
4
|
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
|
|
7
|
-
import { Axis } from '@babylonjs/core/Maths/math.axis';
|
|
8
5
|
import { Color3 } from '@babylonjs/core/Maths/math.color';
|
|
9
|
-
import {
|
|
6
|
+
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
|
|
10
7
|
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
|
|
11
8
|
import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
|
|
12
9
|
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
13
10
|
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
14
11
|
import { Node } from '@babylonjs/core/node';
|
|
15
12
|
import { Scene } from '@babylonjs/core/scene';
|
|
16
|
-
import { cloneDeep,
|
|
13
|
+
import { cloneDeep, merge } from 'lodash-es';
|
|
17
14
|
import { DottedPath } from '../classes/dottedPath';
|
|
18
15
|
|
|
19
|
-
/**
|
|
20
|
-
* @param node
|
|
21
|
-
* @return Node
|
|
22
|
-
*/
|
|
23
|
-
const getRootNode = function( node: Node ): Node {
|
|
24
|
-
let _node = node;
|
|
25
|
-
while( _node.parent ) {
|
|
26
|
-
_node = _node.parent;
|
|
27
|
-
}
|
|
28
|
-
return _node;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
16
|
/**
|
|
32
17
|
* @param nodes
|
|
33
18
|
* @param predicate
|
|
@@ -54,17 +39,18 @@ const mapToDottedNodes = function <T>( nodes: Node[],
|
|
|
54
39
|
* @param node
|
|
55
40
|
* @return DottedPath
|
|
56
41
|
*/
|
|
57
|
-
const
|
|
42
|
+
const getDottedPathForTransformNode = function( node: TransformNode ): DottedPath {
|
|
58
43
|
const dottedPath = DottedPath.create( node.name );
|
|
59
44
|
let _parent = node;
|
|
60
45
|
while( _parent.parent ) {
|
|
61
|
-
_parent = _parent.parent;
|
|
46
|
+
_parent = _parent.parent as TransformNode;
|
|
62
47
|
dottedPath.unshiftPart( _parent.name );
|
|
63
48
|
}
|
|
64
49
|
return dottedPath;
|
|
65
50
|
};
|
|
66
51
|
|
|
67
52
|
/**
|
|
53
|
+
*
|
|
68
54
|
* @param node
|
|
69
55
|
* @param predicate
|
|
70
56
|
* @param deep
|
|
@@ -92,21 +78,6 @@ const cloneTransformNode = function( node: TransformNode,
|
|
|
92
78
|
return clone;
|
|
93
79
|
};
|
|
94
80
|
|
|
95
|
-
/**
|
|
96
|
-
* @param node
|
|
97
|
-
*/
|
|
98
|
-
const cloneNodeWithParents = function( node: Node | null ): Node | null {
|
|
99
|
-
let clone = null;
|
|
100
|
-
if( node instanceof TransformNode ) {
|
|
101
|
-
clone = node.clone( node.name, cloneNodeWithParents( node.parent ), true );
|
|
102
|
-
} else if( node instanceof Light ) {
|
|
103
|
-
clone = node.clone( node.name, cloneNodeWithParents( node.parent ) );
|
|
104
|
-
} else if( node ) {
|
|
105
|
-
throw new Error( `Cloning of "${node?.constructor.name}" is not implemented (yet).` );
|
|
106
|
-
}
|
|
107
|
-
return clone;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
81
|
/**
|
|
111
82
|
* @param node
|
|
112
83
|
* @param deep
|
|
@@ -135,11 +106,11 @@ const cloneTransformNodeMaterial = function( node: TransformNode,
|
|
|
135
106
|
* @param deep
|
|
136
107
|
* @param metadata
|
|
137
108
|
*/
|
|
138
|
-
const
|
|
109
|
+
const injectTransformNodeMetadata = function( node: TransformNode, metadata: {}, deep: boolean = true ) {
|
|
139
110
|
node.metadata = merge( {}, node.metadata, metadata );
|
|
140
|
-
if( deep
|
|
111
|
+
if( deep ) {
|
|
141
112
|
const children = node.getChildTransformNodes( true );
|
|
142
|
-
children.forEach( child =>
|
|
113
|
+
children.forEach( child => injectTransformNodeMetadata( child, metadata, deep ) );
|
|
143
114
|
}
|
|
144
115
|
};
|
|
145
116
|
|
|
@@ -194,79 +165,6 @@ const deactivateTransformNode = function( node: TransformNode, deep: boolean = t
|
|
|
194
165
|
}
|
|
195
166
|
};
|
|
196
167
|
|
|
197
|
-
/**
|
|
198
|
-
* @param node
|
|
199
|
-
*/
|
|
200
|
-
const enableNodeWithParents = function( node: Node ) {
|
|
201
|
-
node.setEnabled( true );
|
|
202
|
-
if ( node.parent ) {
|
|
203
|
-
enableNodeWithParents( node.parent );
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @param node
|
|
209
|
-
*/
|
|
210
|
-
const disableNodeWithParents = function( node: Node ) {
|
|
211
|
-
node.setEnabled( false );
|
|
212
|
-
if ( node.parent ) {
|
|
213
|
-
disableNodeWithParents( node.parent );
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Attention: this function mutates the position of a node. Keep in mind that there are dependencies to other
|
|
219
|
-
* functions moving nodes around.
|
|
220
|
-
* @param node
|
|
221
|
-
* @param rotation
|
|
222
|
-
*/
|
|
223
|
-
const rotateTransformNode = function( node: TransformNode, rotation: Vector3 ): TransformNode {
|
|
224
|
-
// remember absolute rotation and reset it before translating
|
|
225
|
-
if( !has( node.metadata, 'rotation.initial' ) ) {
|
|
226
|
-
injectNodeMetadata( node, { 'rotation.initial': node.rotationQuaternion?.asArray() }, false );
|
|
227
|
-
}
|
|
228
|
-
if( !has( node.metadata, 'rotation.position' ) || get( node.metadata, 'position.dirty' ) ) {
|
|
229
|
-
let rotationPosition = node.absolutePosition.clone();
|
|
230
|
-
if( has( node.metadata, 'rotation.offset' ) ) {
|
|
231
|
-
rotationPosition = rotationPosition.subtract( get( node.metadata, 'rotation.offset' ) as Vector3 );
|
|
232
|
-
}
|
|
233
|
-
injectNodeMetadata( node, { 'rotation.position': rotationPosition }, false );
|
|
234
|
-
injectNodeMetadata( node, { 'position.dirty': false }, false );
|
|
235
|
-
}
|
|
236
|
-
node.setAbsolutePosition( get( node.metadata, 'rotation.position' ) );
|
|
237
|
-
if( node.metadata.rotation ) {
|
|
238
|
-
node.rotationQuaternion = Quaternion.FromArray( get( node.metadata, 'rotation.initial' ) as [] );
|
|
239
|
-
}
|
|
240
|
-
node.rotateAround( Vector3.Zero(), Axis.X, rotation.x );
|
|
241
|
-
node.rotateAround( Vector3.Zero(), Axis.Y, rotation.y );
|
|
242
|
-
node.rotateAround( Vector3.Zero(), Axis.Z, rotation.z );
|
|
243
|
-
node.computeWorldMatrix( true );
|
|
244
|
-
injectNodeMetadata( node, {
|
|
245
|
-
'rotation.offset': node.absolutePosition.subtract( get( node.metadata, 'rotation.position' ) as Vector3 )
|
|
246
|
-
}, false );
|
|
247
|
-
return node;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Attention: this function mutates the position of a node. Keep in mind that there are dependencies to other
|
|
252
|
-
* functions moving nodes around.
|
|
253
|
-
* @param node
|
|
254
|
-
* @param distance
|
|
255
|
-
*/
|
|
256
|
-
const moveTransformNode = function( node: TransformNode, distance: Vector3 ): TransformNode {
|
|
257
|
-
// remember absolute position and reset it before translating
|
|
258
|
-
if( !has( node.metadata, 'position.initial' ) ) {
|
|
259
|
-
injectNodeMetadata( node, { 'position.initial': node.absolutePosition.clone() }, false );
|
|
260
|
-
}
|
|
261
|
-
let position = get( node.metadata, 'position.initial' ) as Vector3;
|
|
262
|
-
if( has( node.metadata, 'rotation.offset' ) ) {
|
|
263
|
-
position = position.add( get( node.metadata, 'rotation.offset' ) as Vector3 );
|
|
264
|
-
}
|
|
265
|
-
node.setAbsolutePosition( position.add( distance ) );
|
|
266
|
-
injectNodeMetadata( node, { 'position.dirty': true }, false );
|
|
267
|
-
return node;
|
|
268
|
-
};
|
|
269
|
-
|
|
270
168
|
/**
|
|
271
169
|
* @param node
|
|
272
170
|
* @param material
|
|
@@ -437,56 +335,6 @@ const removeFromHighlightLayer = function( layer: HighlightLayer, node: Transfor
|
|
|
437
335
|
}
|
|
438
336
|
};
|
|
439
337
|
|
|
440
|
-
/**
|
|
441
|
-
* @param node
|
|
442
|
-
* @param receiveShadows
|
|
443
|
-
* @param deep
|
|
444
|
-
*/
|
|
445
|
-
const setReceiveShadows = function( node: TransformNode, receiveShadows: boolean, deep: boolean = true ) {
|
|
446
|
-
if( node instanceof AbstractMesh ) {
|
|
447
|
-
node.receiveShadows = receiveShadows;
|
|
448
|
-
}
|
|
449
|
-
if( deep ) {
|
|
450
|
-
node.getChildTransformNodes( true ).forEach(
|
|
451
|
-
child => setReceiveShadows( child, receiveShadows, deep )
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* @param node
|
|
458
|
-
* @param generator
|
|
459
|
-
* @param deep
|
|
460
|
-
*/
|
|
461
|
-
const addToShadowGenerator = function( generator: ShadowGenerator, node: TransformNode, deep: boolean = true ) {
|
|
462
|
-
if( node instanceof AbstractMesh ) {
|
|
463
|
-
// We have to remove the node because there's no duplicate check in babylon
|
|
464
|
-
generator.removeShadowCaster( node, false );
|
|
465
|
-
generator.addShadowCaster( node, false );
|
|
466
|
-
}
|
|
467
|
-
if( deep ) {
|
|
468
|
-
node.getChildTransformNodes( true ).forEach(
|
|
469
|
-
child => addToShadowGenerator( generator, child, deep )
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* @param node
|
|
476
|
-
* @param generator
|
|
477
|
-
* @param deep
|
|
478
|
-
*/
|
|
479
|
-
const removeFromShadowGenerator = function( generator: ShadowGenerator, node: TransformNode, deep: boolean = true ) {
|
|
480
|
-
if( node instanceof AbstractMesh ) {
|
|
481
|
-
generator.removeShadowCaster( node, false );
|
|
482
|
-
}
|
|
483
|
-
if( deep ) {
|
|
484
|
-
node.getChildTransformNodes( true ).forEach(
|
|
485
|
-
child => removeFromShadowGenerator( generator, child, deep )
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
};
|
|
489
|
-
|
|
490
338
|
/**
|
|
491
339
|
* https://forum.babylonjs.com/t/get-mesh-bounding-box-position-and-size-in-2d-screen-coordinates/1058/3
|
|
492
340
|
* @param mesh
|
|
@@ -524,20 +372,14 @@ const getClientRectFromMesh = function( mesh: AbstractMesh, scene: Scene, canvas
|
|
|
524
372
|
};
|
|
525
373
|
|
|
526
374
|
export {
|
|
527
|
-
getRootNode,
|
|
528
375
|
mapToDottedNodes,
|
|
529
|
-
|
|
376
|
+
getDottedPathForTransformNode,
|
|
530
377
|
cloneTransformNode,
|
|
531
|
-
cloneNodeWithParents,
|
|
532
378
|
cloneTransformNodeMaterial,
|
|
533
|
-
|
|
379
|
+
injectTransformNodeMetadata,
|
|
534
380
|
assertTransformNode,
|
|
535
381
|
activateTransformNode,
|
|
536
382
|
deactivateTransformNode,
|
|
537
|
-
enableNodeWithParents,
|
|
538
|
-
disableNodeWithParents,
|
|
539
|
-
rotateTransformNode,
|
|
540
|
-
moveTransformNode,
|
|
541
383
|
setMaterial,
|
|
542
384
|
setSourceNodeMaterial,
|
|
543
385
|
setMaterialColor,
|
|
@@ -546,8 +388,5 @@ export {
|
|
|
546
388
|
setMaterialRoughness,
|
|
547
389
|
addToHighlightLayer,
|
|
548
390
|
removeFromHighlightLayer,
|
|
549
|
-
setReceiveShadows,
|
|
550
|
-
addToShadowGenerator,
|
|
551
|
-
removeFromShadowGenerator,
|
|
552
391
|
getClientRectFromMesh
|
|
553
392
|
};
|