@combeenation/3d-viewer 0.0.1
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/LICENSE +13 -0
- package/README.md +111 -0
- package/dist/types/api/classes/animationInterface.d.ts +8 -0
- package/dist/types/api/classes/dottedPath.d.ts +79 -0
- package/dist/types/api/classes/element.d.ts +153 -0
- package/dist/types/api/classes/event.d.ts +396 -0
- package/dist/types/api/classes/eventBroadcaster.d.ts +26 -0
- package/dist/types/api/classes/fuzzyMap.d.ts +7 -0
- package/dist/types/api/classes/parameter.d.ts +351 -0
- package/dist/types/api/classes/parameterObservable.d.ts +36 -0
- package/dist/types/api/classes/parameterizable.d.ts +15 -0
- package/dist/types/api/classes/placementAnimation.d.ts +45 -0
- package/dist/types/api/classes/variant.d.ts +253 -0
- package/dist/types/api/classes/variantInstance.d.ts +53 -0
- package/dist/types/api/classes/variantParameterizable.d.ts +17 -0
- package/dist/types/api/classes/viewer.d.ts +200 -0
- package/dist/types/api/classes/viewerLight.d.ts +66 -0
- package/dist/types/api/internal/lensRendering.d.ts +8 -0
- package/dist/types/api/internal/sceneSetup.d.ts +13 -0
- package/dist/types/api/manager/animationManager.d.ts +30 -0
- package/dist/types/api/manager/gltfExportManager.d.ts +78 -0
- package/dist/types/api/manager/sceneManager.d.ts +33 -0
- package/dist/types/api/manager/tagManager.d.ts +108 -0
- package/dist/types/api/manager/textureLoadManager.d.ts +22 -0
- package/dist/types/api/manager/variantInstanceManager.d.ts +103 -0
- package/dist/types/api/store/specStorage.d.ts +32 -0
- package/dist/types/api/util/babylonHelper.d.ts +235 -0
- package/dist/types/api/util/globalTypes.d.ts +436 -0
- package/dist/types/api/util/resourceHelper.d.ts +58 -0
- package/dist/types/api/util/sceneLoaderHelper.d.ts +44 -0
- package/dist/types/api/util/stringHelper.d.ts +13 -0
- package/dist/types/api/util/structureHelper.d.ts +9 -0
- package/dist/types/declaration.tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +27 -0
- package/package.json +87 -0
- package/src/api/classes/animationInterface.ts +10 -0
- package/src/api/classes/dottedPath.ts +181 -0
- package/src/api/classes/element.ts +731 -0
- package/src/api/classes/event.ts +452 -0
- package/src/api/classes/eventBroadcaster.ts +52 -0
- package/src/api/classes/fuzzyMap.ts +21 -0
- package/src/api/classes/parameter.ts +554 -0
- package/src/api/classes/parameterObservable.ts +73 -0
- package/src/api/classes/parameterizable.ts +87 -0
- package/src/api/classes/placementAnimation.ts +162 -0
- package/src/api/classes/variant.ts +933 -0
- package/src/api/classes/variantInstance.ts +123 -0
- package/src/api/classes/variantParameterizable.ts +85 -0
- package/src/api/classes/viewer.ts +742 -0
- package/src/api/classes/viewerLight.ts +339 -0
- package/src/api/internal/debugViewer.ts +90 -0
- package/src/api/internal/lensRendering.ts +9 -0
- package/src/api/internal/sceneSetup.ts +205 -0
- package/src/api/manager/animationManager.ts +143 -0
- package/src/api/manager/gltfExportManager.ts +236 -0
- package/src/api/manager/sceneManager.ts +136 -0
- package/src/api/manager/tagManager.ts +451 -0
- package/src/api/manager/textureLoadManager.ts +95 -0
- package/src/api/manager/variantInstanceManager.ts +298 -0
- package/src/api/store/specStorage.ts +68 -0
- package/src/api/util/babylonHelper.ts +822 -0
- package/src/api/util/globalTypes.ts +503 -0
- package/src/api/util/resourceHelper.ts +191 -0
- package/src/api/util/sceneLoaderHelper.ts +170 -0
- package/src/api/util/stringHelper.ts +30 -0
- package/src/api/util/structureHelper.ts +49 -0
- package/src/buildinfo.json +3 -0
- package/src/dev.ts +62 -0
- package/src/index.ts +79 -0
- package/src/types.d.ts +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2020 Combeenation GmbH
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# 3D viewer
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
- Create a label called `JS_3dViewerLbl` which we'll use to render the 3d viewer into:
|
|
6
|
+
|
|
7
|
+
- Set its value to `<canvas></canvas>`
|
|
8
|
+
- Add CSS class `ViewerLbl`
|
|
9
|
+
- Add the following CSS styles to your configurator:
|
|
10
|
+
|
|
11
|
+
```css
|
|
12
|
+
.ViewerLbl .cfgrctrl-innerlabel {
|
|
13
|
+
height: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.ViewerLbl canvas {
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- Install viewer dependencies: `npm i @combeenation/3d-viewer`
|
|
23
|
+
- Create specification (example, bare minimum):
|
|
24
|
+
```js
|
|
25
|
+
/**
|
|
26
|
+
* @return {StructureJson}
|
|
27
|
+
*/
|
|
28
|
+
export function createSpec() {
|
|
29
|
+
return {
|
|
30
|
+
scene: {
|
|
31
|
+
engine: {
|
|
32
|
+
antialiasing: true,
|
|
33
|
+
options: {
|
|
34
|
+
preserveDrawingBuffer: true,
|
|
35
|
+
stencil: true,
|
|
36
|
+
// `xrCompatible` is required to fix WebXR issue in Safari 15 as mentioned in the Babylon.js forum:
|
|
37
|
+
// https://forum.babylonjs.com/t/safari-15-0-breaks-every-babylonjs-application/23973
|
|
38
|
+
xrCompatible: false,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
scene: {
|
|
42
|
+
globals: {},
|
|
43
|
+
cameras: {},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
setup: {
|
|
47
|
+
instances: [
|
|
48
|
+
{
|
|
49
|
+
name: 'DirtBikeInstance',
|
|
50
|
+
variant: 'DirtBike',
|
|
51
|
+
lazy: false,
|
|
52
|
+
parameters: {
|
|
53
|
+
visible: true,
|
|
54
|
+
scaling: '( 1, 1, 1 )',
|
|
55
|
+
position: '( 0, 0, 0 )',
|
|
56
|
+
rotation: '( 0, 0, 0 )',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
variants: {
|
|
62
|
+
DirtBike: {
|
|
63
|
+
glTF: 'https://combeepublic.blob.core.windows.net/resources/the-3d-file.glb',
|
|
64
|
+
elements: {
|
|
65
|
+
Main: ['__root__'],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
- Bootstrap viewer (example code):
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
import { Viewer } from '@combeenation/3d-viewer';
|
|
76
|
+
import { CtrlUtils } from '@combeenation/custom-js-utils';
|
|
77
|
+
import { createSpec } from 'path/to/spec-file';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Bootstraps the viewer using the JSON spec, registers all needed events etc.
|
|
81
|
+
*/
|
|
82
|
+
export async function bootstrapViewer() {
|
|
83
|
+
Cbn.utils.Log.add(`Bootstrapping viewer v${Viewer.version}`, Cbn.utils.Log.Type.Misc)();
|
|
84
|
+
|
|
85
|
+
const $canvas = $(CtrlUtils.getLabel('JS_3dViewerLbl').el.dom).find('canvas');
|
|
86
|
+
const canvas = /** @type {HTMLCanvasElement} */ ($canvas.get(0));
|
|
87
|
+
const viewer = new Viewer(canvas, createSpec());
|
|
88
|
+
await viewer.bootstrap([]);
|
|
89
|
+
|
|
90
|
+
// The resize listener doesn't seem to work on the canvas itself, therefore we're installing it on its parent
|
|
91
|
+
Cbn.utils.ResizeEvents.addResizeListener(canvas.parentElement, () => viewer.resize());
|
|
92
|
+
|
|
93
|
+
return viewer;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- Call `bootstrapViewer` e.g. somewhere in `onCfgrReady` in your main file:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
CfgrUtils.onCfgrReady(async () => {
|
|
101
|
+
// ...
|
|
102
|
+
|
|
103
|
+
const viewer = await bootstrapViewer();
|
|
104
|
+
|
|
105
|
+
// ...
|
|
106
|
+
|
|
107
|
+
// Make some functions accessible in the global window object (e.g. for debugging in the console etc.)
|
|
108
|
+
// Can be extended as needed.
|
|
109
|
+
window.CfgrJS = { /* ... */ viewer /* ... */ };
|
|
110
|
+
});
|
|
111
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare class DottedPath {
|
|
2
|
+
static DELIMITER: string;
|
|
3
|
+
static SAFE_CHAR: string;
|
|
4
|
+
parts: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Magic factory function that creates a DottedPath based on the argument type.
|
|
7
|
+
*/
|
|
8
|
+
static create(dottedPath?: DottedPathArgument): DottedPath;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a DottedPath from a string.
|
|
11
|
+
* Allows patterns with unsafe characters wrapped in apostrophes or quotes.
|
|
12
|
+
* E.g. "part1.part2.'part.3'.part_4"
|
|
13
|
+
*/
|
|
14
|
+
static createFromPath(path: string): DottedPath;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a DottedPath from a string list.
|
|
17
|
+
*/
|
|
18
|
+
static createFromParts(parts: string[]): DottedPath;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an empty DottedPath.
|
|
21
|
+
*/
|
|
22
|
+
static createEmpty(): DottedPath;
|
|
23
|
+
/**
|
|
24
|
+
* Sanitizes given part: replaces all characters like {@link DottedPath.DELIMITER}
|
|
25
|
+
* with a "safe" character like {@link DottedPath.SAFE_CHAR}.
|
|
26
|
+
* (i) Does not trim whitespace.
|
|
27
|
+
*/
|
|
28
|
+
static sanitizePart(part: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Constructor
|
|
31
|
+
*/
|
|
32
|
+
private constructor();
|
|
33
|
+
/**
|
|
34
|
+
* The path.
|
|
35
|
+
* (i) Does not return an empty dot for no path.
|
|
36
|
+
*/
|
|
37
|
+
get path(): string;
|
|
38
|
+
/**
|
|
39
|
+
* The first part.
|
|
40
|
+
*/
|
|
41
|
+
get firstPart(): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* The last part.
|
|
44
|
+
*/
|
|
45
|
+
get lastPart(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the tokens to each leaf of the DottedPath tree.
|
|
48
|
+
* E.g. "part1.part2.part_3" will return an array like
|
|
49
|
+
* ["part1", "part1.part2", "part1.part2.part_3"]
|
|
50
|
+
*/
|
|
51
|
+
get leafTokens(): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Removes the first part and returns it.
|
|
54
|
+
*/
|
|
55
|
+
shiftPart(): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Adds part to the beginning of parts list.
|
|
58
|
+
*/
|
|
59
|
+
unshiftPart(part: string, duplicateCheck?: boolean): DottedPath;
|
|
60
|
+
/**
|
|
61
|
+
* Adds part to the end of parts list.
|
|
62
|
+
* (i) Does not add a part if the last char already is the delimiter or if an empty string was passed.
|
|
63
|
+
*/
|
|
64
|
+
addPart(part: string, duplicateCheck?: boolean): DottedPath;
|
|
65
|
+
/**
|
|
66
|
+
* Adds multiple parts to the end of parts list.
|
|
67
|
+
*/
|
|
68
|
+
addParts(parts: string[], duplicateCheck?: boolean): DottedPath;
|
|
69
|
+
/**
|
|
70
|
+
* Removes the last part and returns it.
|
|
71
|
+
*/
|
|
72
|
+
popPart(): string | undefined;
|
|
73
|
+
toString(): string;
|
|
74
|
+
valueOf(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Clones the DottedPath.
|
|
77
|
+
*/
|
|
78
|
+
clone(): DottedPath;
|
|
79
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { VariantParameterizable } from './../classes/variantParameterizable';
|
|
2
|
+
import { DottedPath } from './dottedPath';
|
|
3
|
+
import { Variant } from './variant';
|
|
4
|
+
import { HighlightLayer } from '@babylonjs/core/Layers/highlightLayer';
|
|
5
|
+
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
|
|
6
|
+
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
7
|
+
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
8
|
+
/**
|
|
9
|
+
* An {@link Element} of a {@link Variant}. Acts as a container for diverse definitions. Lives only in the context of a
|
|
10
|
+
* {@link Variant}.
|
|
11
|
+
*
|
|
12
|
+
* When used in typings, refer to via its alias {@link VariantElement} to prevent name clashes with the web APIs
|
|
13
|
+
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) class
|
|
14
|
+
*/
|
|
15
|
+
export declare class Element extends VariantParameterizable {
|
|
16
|
+
readonly variant: Variant;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly nodes: TransformNode[];
|
|
19
|
+
protected readonly _dottedNodes: Map<DottedPath, TransformNode>;
|
|
20
|
+
protected _highlightLayer?: HighlightLayer;
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*/
|
|
24
|
+
protected constructor(variant: Variant, name: string);
|
|
25
|
+
/**
|
|
26
|
+
* Creates an {@link Element} with given name.
|
|
27
|
+
*/
|
|
28
|
+
static create(variant: Variant, name: string): Promise<Element>;
|
|
29
|
+
/**
|
|
30
|
+
* The {@link DottedPath} in the built tree of {@link Element}s.
|
|
31
|
+
* E.g. "_.top-1.sub-2.sub-sub-3.el-1"
|
|
32
|
+
*/
|
|
33
|
+
get dottedPath(): DottedPath;
|
|
34
|
+
/**
|
|
35
|
+
* The id representing a {@link DottedPath}.
|
|
36
|
+
*/
|
|
37
|
+
get id(): string;
|
|
38
|
+
/**
|
|
39
|
+
* The {@link ElementDefinition} of the {@link Element}.
|
|
40
|
+
*/
|
|
41
|
+
get definition(): ElementDefinition;
|
|
42
|
+
/**
|
|
43
|
+
* The {@link PathDefinitions} of the {@link Element}.
|
|
44
|
+
*/
|
|
45
|
+
get pathDefinitions(): PathDefinitions;
|
|
46
|
+
/**
|
|
47
|
+
* The {@link TraceableDefinitions} of the {@link Element}.
|
|
48
|
+
*/
|
|
49
|
+
get traceableDefinitions(): TraceableDefinitions;
|
|
50
|
+
/**
|
|
51
|
+
* The {@link PaintableDefinition} of the {@link Element}.
|
|
52
|
+
*/
|
|
53
|
+
get paintableDefinitions(): PaintableDefinitions;
|
|
54
|
+
/**
|
|
55
|
+
* The inherited {@link ParameterBag}.
|
|
56
|
+
* Merges the {@link Variant}'s parameters and those from the {@link Element}.
|
|
57
|
+
*/
|
|
58
|
+
get inheritedParameters(): ParameterBag;
|
|
59
|
+
/**
|
|
60
|
+
* The actual {@link TransformNode}s that make up this {@link Element}.
|
|
61
|
+
*/
|
|
62
|
+
get nodesFlat(): TransformNode[];
|
|
63
|
+
/**
|
|
64
|
+
* The actual {@link Mesh}es that make up this {@link Element}.
|
|
65
|
+
* Handy for e.g. creating a bounding box around an entire element.
|
|
66
|
+
*/
|
|
67
|
+
get meshesFlat(): Mesh[];
|
|
68
|
+
/**
|
|
69
|
+
* The actual {@link AbstractMesh}es that make up this {@link Element}.
|
|
70
|
+
* I.e. (real) Meshes as well as InstancedMeshes.
|
|
71
|
+
*/
|
|
72
|
+
get abstractMeshesFlat(): AbstractMesh[];
|
|
73
|
+
/**
|
|
74
|
+
* The meshes of this {@link Element}.
|
|
75
|
+
*/
|
|
76
|
+
get meshes(): Mesh[];
|
|
77
|
+
/**
|
|
78
|
+
* @protected
|
|
79
|
+
*/
|
|
80
|
+
set highlightLayer(layer: HighlightLayer | undefined);
|
|
81
|
+
get highlightLayer(): HighlightLayer | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Destroys this {@link Element} and dispose all nodes.
|
|
84
|
+
*/
|
|
85
|
+
destroy(): Element;
|
|
86
|
+
/**
|
|
87
|
+
* Gets a node by its {@link DottedPath}.
|
|
88
|
+
*/
|
|
89
|
+
getNode(dottedPath: DottedPathArgument): TransformNode;
|
|
90
|
+
/**
|
|
91
|
+
* Gets a mesh by its {@link DottedPath}.
|
|
92
|
+
*/
|
|
93
|
+
getMesh(dottedPath: DottedPathArgument): Promise<Mesh | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Gets a {@link PaintableDefinition} by its name.
|
|
96
|
+
*/
|
|
97
|
+
getPaintableDefinition(name: string): PaintableDefinition;
|
|
98
|
+
/**
|
|
99
|
+
* Gets a {@link TraceableDefinition} by its name.
|
|
100
|
+
*/
|
|
101
|
+
getTraceableDefinition(name: string): TraceableDefinition;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the paintable Node by its name.
|
|
104
|
+
*/
|
|
105
|
+
getPaintableNode(name: string): TransformNode;
|
|
106
|
+
/**
|
|
107
|
+
* Gets the traceable Node by its name.
|
|
108
|
+
*/
|
|
109
|
+
getTraceableNode(name: string): TransformNode;
|
|
110
|
+
/**
|
|
111
|
+
* @see {@link VariantParameterizable.commitParameters}
|
|
112
|
+
* @emit {@link Event.ELEMENT_PARAMETER_COMMITTED}
|
|
113
|
+
*/
|
|
114
|
+
commitParameters(parameters?: ParameterBag): Promise<VariantParameterizable>;
|
|
115
|
+
/**
|
|
116
|
+
* Adds an observer function for camera matrix changes.
|
|
117
|
+
* The `observer` gets 2 parameters: the `AbstractMesh` and a `ClientRect` object.
|
|
118
|
+
*/
|
|
119
|
+
addTraceableObserver(traceable: string, observer: CallableFunction, payload?: any): Element;
|
|
120
|
+
/**
|
|
121
|
+
* Draws a `ImageBitmap` or `OffscreenCanvas` onto a `paintable` defined via {@link PaintableDefinition}.
|
|
122
|
+
*/
|
|
123
|
+
drawPaintable(paintable: string, imageSource: CanvasImageSource): Element;
|
|
124
|
+
/**
|
|
125
|
+
* Draws a SVG string onto a `paintable` defined via {@link PaintableDefinition}.
|
|
126
|
+
*/
|
|
127
|
+
drawPaintableFromSvg(paintable: string, svgSource: string): Promise<Element>;
|
|
128
|
+
/**
|
|
129
|
+
* Draws an Image from source (URL/URI) onto a `paintable` defined via {@link PaintableDefinition}.
|
|
130
|
+
*/
|
|
131
|
+
drawPaintableFromImgSrc(paintable: string, imgSource: string): Promise<Element>;
|
|
132
|
+
/**
|
|
133
|
+
* Adds observers for loading missing materials where needed
|
|
134
|
+
*/
|
|
135
|
+
protected addMissingMaterialObservers(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
|
|
138
|
+
*/
|
|
139
|
+
protected addParameterObservers(): Element;
|
|
140
|
+
/**
|
|
141
|
+
* Filter for nodes that are not defined or excluded in the `pathDefinitions`.
|
|
142
|
+
*/
|
|
143
|
+
protected filterNode(node: TransformNode): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Asserts whether all {@link pathDefinitions} link to a valid `Node` path.
|
|
146
|
+
* @protected
|
|
147
|
+
*/
|
|
148
|
+
protected assertPathDefinitions(): void;
|
|
149
|
+
/**
|
|
150
|
+
* Handles callback for given light parameter.
|
|
151
|
+
*/
|
|
152
|
+
private castShadowValueHandler;
|
|
153
|
+
}
|