@combeenation/3d-viewer 4.0.0-beta5 → 4.1.0-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib-cjs/api/classes/element.js +31 -28
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameter.js +2 -2
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.js +8 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.js +16 -9
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.js +21 -18
- package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +35 -0
- package/dist/lib-cjs/api/manager/gltfExportManager.js +108 -0
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -0
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +4 -13
- package/dist/lib-cjs/api/util/babylonHelper.js +27 -47
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +5 -0
- package/package.json +1 -1
- package/src/api/classes/element.ts +27 -23
- package/src/api/classes/parameter.ts +2 -2
- package/src/api/classes/variantParameterizable.ts +8 -1
- package/src/api/classes/viewer.ts +16 -7
- package/src/api/classes/viewerLight.ts +19 -15
- package/src/api/util/babylonHelper.ts +29 -48
- package/src/api/util/globalTypes.ts +6 -0
- package/src/dev.ts +2 -2
|
@@ -13,6 +13,7 @@ import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
|
13
13
|
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
14
14
|
import { Node } from '@babylonjs/core/node';
|
|
15
15
|
import { Scene } from '@babylonjs/core/scene';
|
|
16
|
+
import { Nullable } from '@babylonjs/core/types';
|
|
16
17
|
import { cloneDeep, get, has, merge } from 'lodash-es';
|
|
17
18
|
import { DottedPath } from '../classes/dottedPath';
|
|
18
19
|
|
|
@@ -98,9 +99,9 @@ const cloneTransformNode = function( node: TransformNode,
|
|
|
98
99
|
const cloneNodeWithParents = function( node: Node | null ): Node | null {
|
|
99
100
|
let clone = null;
|
|
100
101
|
if( node instanceof TransformNode ) {
|
|
101
|
-
clone = node.clone( node.name, cloneNodeWithParents( node.parent )
|
|
102
|
+
clone = node.clone( node.name, cloneNodeWithParents( node.parent ) as Nullable<Node>, true );
|
|
102
103
|
} else if( node instanceof Light ) {
|
|
103
|
-
clone = node.clone( node.name, cloneNodeWithParents( node.parent ) );
|
|
104
|
+
clone = node.clone( node.name, cloneNodeWithParents( node.parent ) as Nullable<Node> );
|
|
104
105
|
} else if( node ) {
|
|
105
106
|
throw new Error( `Cloning of "${node?.constructor.name}" is not implemented (yet).` );
|
|
106
107
|
}
|
|
@@ -215,56 +216,37 @@ const disableNodeWithParents = function( node: Node ) {
|
|
|
215
216
|
};
|
|
216
217
|
|
|
217
218
|
/**
|
|
218
|
-
*
|
|
219
|
-
* functions moving nodes around.
|
|
219
|
+
* Applies a {@link TransformationDefinition} consecutively to ensure dependencies in positioning etc.
|
|
220
220
|
* @param node
|
|
221
|
-
* @param
|
|
221
|
+
* @param transformation
|
|
222
222
|
*/
|
|
223
|
-
const
|
|
224
|
-
//
|
|
225
|
-
if( !has( node.metadata, '
|
|
226
|
-
injectNodeMetadata( node, { '
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|
223
|
+
const transformTransformNode = function( node: TransformNode, transformation: TransformationDefinition ) {
|
|
224
|
+
// scaling
|
|
225
|
+
if( !has( node.metadata, 'scaling.initial' ) ) {
|
|
226
|
+
injectNodeMetadata( node, { 'scaling.initial': node.scaling }, false );
|
|
227
|
+
}
|
|
228
|
+
const initialScaling = get( node.metadata, 'scaling.initial' ) as Vector3;
|
|
229
|
+
node.scaling = initialScaling.multiply( transformation.scaling );
|
|
230
|
+
// position
|
|
258
231
|
if( !has( node.metadata, 'position.initial' ) ) {
|
|
259
232
|
injectNodeMetadata( node, { 'position.initial': node.absolutePosition.clone() }, false );
|
|
260
233
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
234
|
+
const initialPosition = get( node.metadata, 'position.initial' ) as Vector3;
|
|
235
|
+
node.setAbsolutePosition( initialPosition.add( transformation.position ).multiply( transformation.scaling ) );
|
|
236
|
+
// rotation
|
|
237
|
+
if( !has( node.metadata, 'rotation.initial' ) ) {
|
|
238
|
+
let rotationQuaternion = node.rotationQuaternion;
|
|
239
|
+
if( !rotationQuaternion ) {
|
|
240
|
+
rotationQuaternion = Quaternion.RotationYawPitchRoll( node.rotation.x, node.rotation.y, node.rotation.z );
|
|
241
|
+
}
|
|
242
|
+
injectNodeMetadata( node, { 'rotation.initial': rotationQuaternion.asArray() }, false );
|
|
264
243
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
244
|
+
const initialRotationQuaternion = Quaternion.FromArray( get( node.metadata, 'rotation.initial' ) as [] );
|
|
245
|
+
node.rotationQuaternion = initialRotationQuaternion;
|
|
246
|
+
node.rotateAround( Vector3.Zero(), Axis.X, transformation.rotation.x );
|
|
247
|
+
node.rotateAround( Vector3.Zero(), Axis.Y, transformation.rotation.y );
|
|
248
|
+
node.rotateAround( Vector3.Zero(), Axis.Z, transformation.rotation.z );
|
|
249
|
+
node.computeWorldMatrix( true );
|
|
268
250
|
};
|
|
269
251
|
|
|
270
252
|
/**
|
|
@@ -536,8 +518,7 @@ export {
|
|
|
536
518
|
deactivateTransformNode,
|
|
537
519
|
enableNodeWithParents,
|
|
538
520
|
disableNodeWithParents,
|
|
539
|
-
|
|
540
|
-
moveTransformNode,
|
|
521
|
+
transformTransformNode,
|
|
541
522
|
setMaterial,
|
|
542
523
|
setSourceNodeMaterial,
|
|
543
524
|
setMaterialColor,
|
|
@@ -79,6 +79,12 @@ type ElementDefinition = {
|
|
|
79
79
|
paintables?: PaintableDefinitions
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
type TransformationDefinition = {
|
|
83
|
+
scaling: Vector3,
|
|
84
|
+
position: Vector3,
|
|
85
|
+
rotation: Vector3
|
|
86
|
+
};
|
|
87
|
+
|
|
82
88
|
type StructureJson = {
|
|
83
89
|
/**
|
|
84
90
|
* `scene` describes the visualisation of the Babylon `scene` such as the incidence of light and camera position. If a
|
package/src/dev.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { set } from 'lodash-es';
|
|
|
4
4
|
|
|
5
5
|
import { Emitter, Viewer } from '.';
|
|
6
6
|
|
|
7
|
-
import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/
|
|
7
|
+
import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/index';
|
|
8
8
|
|
|
9
9
|
const loadingElement = document.getElementById( 'loading' ) as HTMLDivElement;
|
|
10
10
|
|
|
@@ -22,7 +22,7 @@ document.addEventListener('DOMContentLoaded', main );
|
|
|
22
22
|
async function main() {
|
|
23
23
|
const viewer = await bootstrapViewer();
|
|
24
24
|
// "Export" for console testing...
|
|
25
|
-
set( window, '
|
|
25
|
+
set( window, 'viewer', viewer);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async function bootstrapViewer() {
|