@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,826 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.drawPaintableOnMaterial = exports.reportDuplicateNodeNames = exports.duplicateNodeNames = exports.intersectingNodeNames = exports.mapTags = exports.envHelperMetadataName = exports.backgroundDomeName = exports.changeEnvironment = exports.getClientRectFromMesh = exports.removeFromShadowGenerator = exports.addToShadowGenerator = exports.setReceiveShadows = exports.removeFromHighlightLayer = exports.addToHighlightLayer = exports.setMaterialRoughness = exports.setMaterialMetallness = exports.setMaterialTexture = exports.setMaterialColor = exports.setSourceNodeMaterial = exports.setMaterial = exports.transformTransformNode = exports.disableNodeWithParents = exports.enableNodeWithParents = exports.deactivateTransformNode = exports.activateTransformNode = exports.assertMeshCapability = exports.assertTransformNode = exports.injectMetadata = exports.applyMaterial = exports.getOrCreateMaterial = exports.cloneTransformNodeMaterial = exports.cloneNodeWithParents = exports.cloneTransformNode = exports.getDottedPathForNode = exports.mapToDottedNodes = exports.isLoadableTexture = exports.getRootNode = void 0;
|
|
13
|
-
const dottedPath_1 = require("../classes/dottedPath");
|
|
14
|
-
const event_1 = require("../classes/event");
|
|
15
|
-
const sceneSetup_1 = require("../internal/sceneSetup");
|
|
16
|
-
const sceneLoaderHelper_1 = require("./sceneLoaderHelper");
|
|
17
|
-
const photoDome_1 = require("@babylonjs/core/Helpers/photoDome");
|
|
18
|
-
const light_1 = require("@babylonjs/core/Lights/light");
|
|
19
|
-
const baseTexture_1 = require("@babylonjs/core/Materials/Textures/baseTexture");
|
|
20
|
-
const cubeTexture_1 = require("@babylonjs/core/Materials/Textures/cubeTexture");
|
|
21
|
-
const dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
|
|
22
|
-
const texture_1 = require("@babylonjs/core/Materials/Textures/texture");
|
|
23
|
-
const math_axis_1 = require("@babylonjs/core/Maths/math.axis");
|
|
24
|
-
const math_color_1 = require("@babylonjs/core/Maths/math.color");
|
|
25
|
-
const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
|
|
26
|
-
const abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
|
|
27
|
-
const instancedMesh_1 = require("@babylonjs/core/Meshes/instancedMesh");
|
|
28
|
-
const transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
|
|
29
|
-
const tags_1 = require("@babylonjs/core/Misc/tags");
|
|
30
|
-
const tools_1 = require("@babylonjs/core/Misc/tools");
|
|
31
|
-
const lodash_es_1 = require("lodash-es");
|
|
32
|
-
const backgroundDomeName = 'BackgroundDome_ViewerGenerated';
|
|
33
|
-
exports.backgroundDomeName = backgroundDomeName;
|
|
34
|
-
const envHelperMetadataName = 'viewerEnvHelper';
|
|
35
|
-
exports.envHelperMetadataName = envHelperMetadataName;
|
|
36
|
-
const materialWaitingToBeSetMetadataName = 'materialWaitingToBeSet';
|
|
37
|
-
// Holds pending `createMaterialFromCbnAssets` promises for dedicated material ids
|
|
38
|
-
// In this case we can make sure that a single material is not requested multiple times if used in various nodes
|
|
39
|
-
const getMaterialPromises = new Map();
|
|
40
|
-
/**
|
|
41
|
-
* @param node
|
|
42
|
-
* @return Node
|
|
43
|
-
*/
|
|
44
|
-
const getRootNode = function (node) {
|
|
45
|
-
let _node = node;
|
|
46
|
-
while (_node.parent) {
|
|
47
|
-
_node = _node.parent;
|
|
48
|
-
}
|
|
49
|
-
return _node;
|
|
50
|
-
};
|
|
51
|
-
exports.getRootNode = getRootNode;
|
|
52
|
-
/**
|
|
53
|
-
* @param nodes
|
|
54
|
-
* @param predicate
|
|
55
|
-
* @return Map<DottedPath, T>
|
|
56
|
-
*/
|
|
57
|
-
const mapToDottedNodes = function (nodes, predicate) {
|
|
58
|
-
const map = new Map();
|
|
59
|
-
const addNodes = function (_node) {
|
|
60
|
-
if (predicate && predicate(_node)) {
|
|
61
|
-
map.set(_node.metadata.dottedPath, _node);
|
|
62
|
-
}
|
|
63
|
-
_node.getChildren().forEach(child => {
|
|
64
|
-
addNodes(child);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
nodes.forEach(node => {
|
|
68
|
-
addNodes(node);
|
|
69
|
-
});
|
|
70
|
-
return map;
|
|
71
|
-
};
|
|
72
|
-
exports.mapToDottedNodes = mapToDottedNodes;
|
|
73
|
-
/**
|
|
74
|
-
* @param node
|
|
75
|
-
* @return DottedPath
|
|
76
|
-
*/
|
|
77
|
-
const getDottedPathForNode = function (node) {
|
|
78
|
-
const dottedPath = dottedPath_1.DottedPath.create(node.name);
|
|
79
|
-
let _parent = node;
|
|
80
|
-
while (_parent.parent) {
|
|
81
|
-
_parent = _parent.parent;
|
|
82
|
-
dottedPath.unshiftPart(_parent.name);
|
|
83
|
-
}
|
|
84
|
-
return dottedPath;
|
|
85
|
-
};
|
|
86
|
-
exports.getDottedPathForNode = getDottedPathForNode;
|
|
87
|
-
/**
|
|
88
|
-
* @param node
|
|
89
|
-
* @param nodeNamingStrategy
|
|
90
|
-
* @param predicate
|
|
91
|
-
* @param deep
|
|
92
|
-
* @return TransformNode | null
|
|
93
|
-
*/
|
|
94
|
-
const cloneTransformNode = function (node, nodeNamingStrategy, predicate, deep = true) {
|
|
95
|
-
if (predicate && !predicate(node)) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
const newName = nodeNamingStrategy.handler(node, nodeNamingStrategy.payload);
|
|
99
|
-
const clone = node.clone(newName, node.parent, true);
|
|
100
|
-
if (clone) {
|
|
101
|
-
clone.id = newName;
|
|
102
|
-
injectMetadata(clone, { cloneSource: node }, false);
|
|
103
|
-
injectMetadata(node, { cloneTarget: clone }, false);
|
|
104
|
-
// if the cloned node is of type InstancedMesh, due to a bug(?),
|
|
105
|
-
// the InstancedMesh.isEnabled state may have changed after cloning.
|
|
106
|
-
// in that case, set the clone's enabled state to the original's state
|
|
107
|
-
if (node instanceof instancedMesh_1.InstancedMesh) {
|
|
108
|
-
clone.setEnabled(node.isEnabled(false));
|
|
109
|
-
// tags are not cloned for instanced meshes by default
|
|
110
|
-
if (tags_1.Tags.HasTags(node)) {
|
|
111
|
-
tags_1.Tags.AddTagsTo(clone, tags_1.Tags.GetTags(node, true));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (deep) {
|
|
116
|
-
const children = node.getChildTransformNodes(true);
|
|
117
|
-
children.forEach(child => {
|
|
118
|
-
const clonedChild = cloneTransformNode(child, nodeNamingStrategy, predicate, deep);
|
|
119
|
-
if (clonedChild) {
|
|
120
|
-
clonedChild.parent = clone;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return clone;
|
|
125
|
-
};
|
|
126
|
-
exports.cloneTransformNode = cloneTransformNode;
|
|
127
|
-
/**
|
|
128
|
-
* @param node
|
|
129
|
-
*/
|
|
130
|
-
const cloneNodeWithParents = function (node) {
|
|
131
|
-
let clone = null;
|
|
132
|
-
if (node instanceof transformNode_1.TransformNode) {
|
|
133
|
-
clone = node.clone(node.name, cloneNodeWithParents(node.parent), true);
|
|
134
|
-
}
|
|
135
|
-
else if (node instanceof light_1.Light) {
|
|
136
|
-
clone = node.clone(node.name, cloneNodeWithParents(node.parent));
|
|
137
|
-
}
|
|
138
|
-
else if (node) {
|
|
139
|
-
throw new Error(`Cloning of "${node === null || node === void 0 ? void 0 : node.constructor.name}" is not implemented (yet).`);
|
|
140
|
-
}
|
|
141
|
-
return clone;
|
|
142
|
-
};
|
|
143
|
-
exports.cloneNodeWithParents = cloneNodeWithParents;
|
|
144
|
-
/**
|
|
145
|
-
* @param node
|
|
146
|
-
* @param deep
|
|
147
|
-
* @param prefix
|
|
148
|
-
* @return TransformNode
|
|
149
|
-
*/
|
|
150
|
-
const cloneTransformNodeMaterial = function (node, prefix = '', deep = true) {
|
|
151
|
-
if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
|
|
152
|
-
const newMatName = dottedPath_1.DottedPath.create(prefix).addParts([node.material.name, 'clone', node.uniqueId.toString()]);
|
|
153
|
-
node.material = node.material.clone(newMatName.path);
|
|
154
|
-
}
|
|
155
|
-
if (deep) {
|
|
156
|
-
const children = node.getChildTransformNodes(true);
|
|
157
|
-
children.forEach(child => cloneTransformNodeMaterial(child, prefix, deep));
|
|
158
|
-
}
|
|
159
|
-
return node;
|
|
160
|
-
};
|
|
161
|
-
exports.cloneTransformNodeMaterial = cloneTransformNodeMaterial;
|
|
162
|
-
/**
|
|
163
|
-
* @param object
|
|
164
|
-
* @param deep
|
|
165
|
-
* @param metadata
|
|
166
|
-
*/
|
|
167
|
-
const injectMetadata = function (object, metadata, deep = true) {
|
|
168
|
-
object.metadata = (0, lodash_es_1.merge)({}, object.metadata, metadata);
|
|
169
|
-
if (deep && object instanceof transformNode_1.TransformNode) {
|
|
170
|
-
const children = object.getChildTransformNodes(true);
|
|
171
|
-
children.forEach(child => injectMetadata(child, metadata, deep));
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
exports.injectMetadata = injectMetadata;
|
|
175
|
-
/**
|
|
176
|
-
* @param node
|
|
177
|
-
* @param assertCallable
|
|
178
|
-
* @param callableParameters
|
|
179
|
-
* @param deep
|
|
180
|
-
*/
|
|
181
|
-
const assertTransformNode = function (node, assertCallable, callableParameters = [], deep = true) {
|
|
182
|
-
assertCallable(node, ...callableParameters);
|
|
183
|
-
if (deep) {
|
|
184
|
-
const children = node.getChildTransformNodes(true);
|
|
185
|
-
children.forEach(child => assertTransformNode(child, assertCallable, callableParameters, deep));
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
exports.assertTransformNode = assertTransformNode;
|
|
189
|
-
/**
|
|
190
|
-
* @param node
|
|
191
|
-
* @param parameter
|
|
192
|
-
*/
|
|
193
|
-
const assertMeshCapability = function (node, parameter) {
|
|
194
|
-
if (!(node instanceof abstractMesh_1.AbstractMesh)) {
|
|
195
|
-
const cls = node.getClassName();
|
|
196
|
-
throw new Error(`Changing parameter "${parameter}" of a(n) ${cls} is not supported. Tried to change node "${node.id}".`);
|
|
197
|
-
}
|
|
198
|
-
if (node instanceof instancedMesh_1.InstancedMesh) {
|
|
199
|
-
throw new Error(`Changing parameter "${parameter}" of an InstancedMesh is not supported. Tried to change node "${node.id}".`);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
exports.assertMeshCapability = assertMeshCapability;
|
|
203
|
-
/**
|
|
204
|
-
* @param node
|
|
205
|
-
* @param deep
|
|
206
|
-
*/
|
|
207
|
-
const activateTransformNode = function (node, deep = true) {
|
|
208
|
-
node.setEnabled(true);
|
|
209
|
-
/*
|
|
210
|
-
if( node instanceof AbstractMesh ) {
|
|
211
|
-
node.visibility = 1;
|
|
212
|
-
node.isPickable = true;
|
|
213
|
-
}
|
|
214
|
-
*/
|
|
215
|
-
if (deep) {
|
|
216
|
-
node.getChildTransformNodes(true).forEach(child => activateTransformNode(child, deep));
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
exports.activateTransformNode = activateTransformNode;
|
|
220
|
-
/**
|
|
221
|
-
* @param node
|
|
222
|
-
* @param deep
|
|
223
|
-
*/
|
|
224
|
-
const deactivateTransformNode = function (node, deep = true) {
|
|
225
|
-
node.setEnabled(false);
|
|
226
|
-
/*
|
|
227
|
-
if( node instanceof AbstractMesh ) {
|
|
228
|
-
node.visibility = 0;
|
|
229
|
-
node.isPickable = false;
|
|
230
|
-
}
|
|
231
|
-
*/
|
|
232
|
-
if (deep) {
|
|
233
|
-
node.getChildTransformNodes(true).forEach(child => deactivateTransformNode(child, deep));
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
exports.deactivateTransformNode = deactivateTransformNode;
|
|
237
|
-
/**
|
|
238
|
-
* @param node
|
|
239
|
-
*/
|
|
240
|
-
const enableNodeWithParents = function (node) {
|
|
241
|
-
node.setEnabled(true);
|
|
242
|
-
if (node.parent) {
|
|
243
|
-
enableNodeWithParents(node.parent);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
exports.enableNodeWithParents = enableNodeWithParents;
|
|
247
|
-
/**
|
|
248
|
-
* @param node
|
|
249
|
-
*/
|
|
250
|
-
const disableNodeWithParents = function (node) {
|
|
251
|
-
node.setEnabled(false);
|
|
252
|
-
if (node.parent) {
|
|
253
|
-
disableNodeWithParents(node.parent);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
exports.disableNodeWithParents = disableNodeWithParents;
|
|
257
|
-
/**
|
|
258
|
-
* Applies a {@link TransformationDefinition} consecutively to ensure dependencies in positioning etc.
|
|
259
|
-
* @param node
|
|
260
|
-
* @param transformation
|
|
261
|
-
*/
|
|
262
|
-
const transformTransformNode = function (node, transformation) {
|
|
263
|
-
// scaling
|
|
264
|
-
if (!(0, lodash_es_1.has)(node.metadata, 'scaling.initial')) {
|
|
265
|
-
injectMetadata(node, { 'scaling.initial': node.scaling }, false);
|
|
266
|
-
}
|
|
267
|
-
const initialScaling = (0, lodash_es_1.get)(node.metadata, 'scaling.initial');
|
|
268
|
-
node.scaling = initialScaling.multiply(transformation.scaling);
|
|
269
|
-
// position
|
|
270
|
-
if (!(0, lodash_es_1.has)(node.metadata, 'position.initial')) {
|
|
271
|
-
injectMetadata(node, { 'position.initial': node.absolutePosition.clone() }, false);
|
|
272
|
-
}
|
|
273
|
-
const initialPosition = (0, lodash_es_1.get)(node.metadata, 'position.initial');
|
|
274
|
-
node.setAbsolutePosition(initialPosition.add(transformation.position).multiply(transformation.scaling));
|
|
275
|
-
// rotation
|
|
276
|
-
if (!(0, lodash_es_1.has)(node.metadata, 'rotation.initial')) {
|
|
277
|
-
let rotationQuaternion = node.rotationQuaternion;
|
|
278
|
-
if (!rotationQuaternion) {
|
|
279
|
-
rotationQuaternion = math_vector_1.Quaternion.RotationYawPitchRoll(node.rotation.x, node.rotation.y, node.rotation.z);
|
|
280
|
-
}
|
|
281
|
-
injectMetadata(node, { 'rotation.initial': rotationQuaternion.asArray() }, false);
|
|
282
|
-
}
|
|
283
|
-
const initialRotationQuaternion = math_vector_1.Quaternion.FromArray((0, lodash_es_1.get)(node.metadata, 'rotation.initial'));
|
|
284
|
-
node.rotationQuaternion = initialRotationQuaternion;
|
|
285
|
-
node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.X, transformation.rotation.x);
|
|
286
|
-
node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.Y, transformation.rotation.y);
|
|
287
|
-
node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.Z, transformation.rotation.z);
|
|
288
|
-
node.computeWorldMatrix(true);
|
|
289
|
-
};
|
|
290
|
-
exports.transformTransformNode = transformTransformNode;
|
|
291
|
-
/**
|
|
292
|
-
* Apply changes of environment (background texture, etc.) consecutively in order to avoid dependency related issues.
|
|
293
|
-
* @param scene
|
|
294
|
-
* @param envDef
|
|
295
|
-
*/
|
|
296
|
-
const changeEnvironment = function (scene, envDef) {
|
|
297
|
-
var _a;
|
|
298
|
-
// issue warning if both background texture and usedefault are set
|
|
299
|
-
if (envDef.environmentUseDefault && envDef.environmentBackground) {
|
|
300
|
-
console.warn(`!!! Warning !!! Spec parameter 'environment.usedefault' is being overruled by 'environment.background'.`);
|
|
301
|
-
}
|
|
302
|
-
const useDefaultEnv = envDef.environmentUseDefault && !envDef.environmentBackground;
|
|
303
|
-
// 1) set ENVIRONMENT_COLOR
|
|
304
|
-
const clearColorBefore = scene.clearColor.toString();
|
|
305
|
-
scene.clearColor = envDef.environmentColor
|
|
306
|
-
? math_color_1.Color4.FromColor3(envDef.environmentColor)
|
|
307
|
-
: useDefaultEnv
|
|
308
|
-
? sceneSetup_1.defaultEnvHelperColor
|
|
309
|
-
: sceneSetup_1.defaultSceneClearColor;
|
|
310
|
-
const clearColorChanged = clearColorBefore !== scene.clearColor.toString();
|
|
311
|
-
// 2) dispose existing & set new ENVIRONMENT (==texture)
|
|
312
|
-
const curEnvTexture = scene.environmentTexture;
|
|
313
|
-
const envTextureChanged = envDef.environment !== (curEnvTexture === null || curEnvTexture === void 0 ? void 0 : curEnvTexture.url);
|
|
314
|
-
if (curEnvTexture && (!envDef.environment || envTextureChanged)) {
|
|
315
|
-
curEnvTexture.dispose();
|
|
316
|
-
}
|
|
317
|
-
const rotation = envDef.environmentRotation !== undefined ? tools_1.Tools.ToRadians(envDef.environmentRotation) : 0;
|
|
318
|
-
if (envDef.environment && envTextureChanged) {
|
|
319
|
-
const envTexture = cubeTexture_1.CubeTexture.CreateFromPrefilteredData(envDef.environment, scene);
|
|
320
|
-
envTexture.rotationY = rotation;
|
|
321
|
-
scene.environmentTexture = envTexture;
|
|
322
|
-
}
|
|
323
|
-
else if (curEnvTexture && curEnvTexture.rotationY !== rotation) {
|
|
324
|
-
curEnvTexture.rotationY = rotation;
|
|
325
|
-
}
|
|
326
|
-
// 3) dispose existing & set new ENVIRONMENT_BACKGROUND
|
|
327
|
-
const curDome = scene.getNodeByName(backgroundDomeName);
|
|
328
|
-
const backgroundUrlChanged = envDef.environmentBackground !== (curDome === null || curDome === void 0 ? void 0 : curDome.texture.url);
|
|
329
|
-
if (curDome && (!envDef.environmentBackground || backgroundUrlChanged)) {
|
|
330
|
-
curDome.dispose();
|
|
331
|
-
}
|
|
332
|
-
const rotationPhotoDome = -1 * rotation;
|
|
333
|
-
if (envDef.environmentBackground && backgroundUrlChanged) {
|
|
334
|
-
const textureUrl = envDef.environmentBackground;
|
|
335
|
-
const dome = new photoDome_1.PhotoDome(backgroundDomeName, textureUrl, { resolution: 32, size: 450 }, scene);
|
|
336
|
-
// Rotate submesh to get them in line with environment texture
|
|
337
|
-
dome.getChildMeshes(true)[0].rotation.y = tools_1.Tools.ToRadians(90);
|
|
338
|
-
dome.rotation.y = rotationPhotoDome;
|
|
339
|
-
}
|
|
340
|
-
else if (curDome && curDome.rotation.y !== rotationPhotoDome) {
|
|
341
|
-
curDome.rotation.y = rotationPhotoDome;
|
|
342
|
-
}
|
|
343
|
-
// 4) dispose existing & set new ENVIRONMENT_USEDEFAULT (only if no background is set)
|
|
344
|
-
const curEnvHelper = (_a = scene.metadata) === null || _a === void 0 ? void 0 : _a[envHelperMetadataName];
|
|
345
|
-
if (curEnvHelper && !useDefaultEnv) {
|
|
346
|
-
curEnvHelper.dispose();
|
|
347
|
-
delete scene.metadata[envHelperMetadataName];
|
|
348
|
-
}
|
|
349
|
-
const envHelperMainColor = math_color_1.Color3.FromArray(scene.clearColor.asArray());
|
|
350
|
-
if (useDefaultEnv && !curEnvHelper) {
|
|
351
|
-
const envHelper = scene.createDefaultEnvironment({ sizeAuto: true });
|
|
352
|
-
envHelper === null || envHelper === void 0 ? void 0 : envHelper.setMainColor(envHelperMainColor);
|
|
353
|
-
if (envHelper) {
|
|
354
|
-
scene.metadata = (0, lodash_es_1.merge)({}, scene.metadata, { [envHelperMetadataName]: envHelper });
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
else if (curEnvHelper && useDefaultEnv && clearColorChanged) {
|
|
358
|
-
curEnvHelper.setMainColor(envHelperMainColor);
|
|
359
|
-
}
|
|
360
|
-
// 5) set ENVIRONMENT_INTENSITY
|
|
361
|
-
if (envDef.environmentIntensity !== undefined) {
|
|
362
|
-
scene.environmentIntensity = envDef.environmentIntensity;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
exports.changeEnvironment = changeEnvironment;
|
|
366
|
-
/**
|
|
367
|
-
* Sets a material by a given material id as material property on the given node.
|
|
368
|
-
*
|
|
369
|
-
* If the material is not already available in the scene, the viewer tries to create a material based on a Combeenation
|
|
370
|
-
* [material asset](https://docs.combeenation.com/docs/howto-create-and-use-babylon-and-material-asset).
|
|
371
|
-
* This of course only works if the viewer is used inside a Combeenation configurator.
|
|
372
|
-
*
|
|
373
|
-
* Furthermore this function also defers the material creation if the node is not visible yet to improve network &
|
|
374
|
-
* viewer bootstrap performance as textures are automatically being lazy loaded only when they are actually visible in
|
|
375
|
-
* the scene.
|
|
376
|
-
*
|
|
377
|
-
* Finally the material will not be applied before all its textures have been loaded. In this way "flickering" effects
|
|
378
|
-
* will be avoided, since the material would be incomplete without its loaded textures.
|
|
379
|
-
*/
|
|
380
|
-
const setMaterial = function (node, materialId, deep = true, variant) {
|
|
381
|
-
if (node instanceof abstractMesh_1.AbstractMesh) {
|
|
382
|
-
const materialExists = node.getScene().getMaterialById(materialId);
|
|
383
|
-
const hasMissingMaterial = (0, lodash_es_1.has)(node.metadata, sceneLoaderHelper_1.missingMaterialMetadataName);
|
|
384
|
-
const deferMaterialCreation = !materialExists && !node.isEnabled();
|
|
385
|
-
if (deferMaterialCreation) {
|
|
386
|
-
// do not set the material
|
|
387
|
-
injectMetadata(node, { [sceneLoaderHelper_1.missingMaterialMetadataName]: materialId }, false);
|
|
388
|
-
// if it already had the missing material flag before, there already exists an observer...
|
|
389
|
-
if (!hasMissingMaterial) {
|
|
390
|
-
(0, sceneLoaderHelper_1.addMissingMaterialObserver)(node);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
// create material and apply it when textures have been loaded
|
|
395
|
-
getOrCreateMaterial(node.getScene(), materialId, variant).then(material => {
|
|
396
|
-
applyMaterial(material, node).then(() => event_1.emitter.emit(event_1.Event.MESH_MATERIAL_APPLIED, node, material));
|
|
397
|
-
if (hasMissingMaterial) {
|
|
398
|
-
delete node.metadata[sceneLoaderHelper_1.missingMaterialMetadataName];
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
// recursively set materials on children (if desired)
|
|
404
|
-
if (deep) {
|
|
405
|
-
for (const child of node.getChildTransformNodes(true)) {
|
|
406
|
-
setMaterial(child, materialId, deep, variant);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
exports.setMaterial = setMaterial;
|
|
411
|
-
/**
|
|
412
|
-
* Removes material from promise map once it has been added to the scene, because we can be sure that the material will
|
|
413
|
-
* be taken from the scene directly, the next time it is requested
|
|
414
|
-
*/
|
|
415
|
-
const onNewMaterialAddedCb = (material) => {
|
|
416
|
-
if (getMaterialPromises.has(material.id)) {
|
|
417
|
-
getMaterialPromises.delete(material.id);
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
/**
|
|
421
|
-
* Responsible for adding the `onNewMaterialAddedCb` only once
|
|
422
|
-
*/
|
|
423
|
-
const registerOnNewMaterialAddedCbOnce = (scene) => {
|
|
424
|
-
const observerAlreadyAssigned = scene.onNewMaterialAddedObservable.observers.find(observer => observer.callback === onNewMaterialAddedCb);
|
|
425
|
-
if (!observerAlreadyAssigned) {
|
|
426
|
-
scene.onNewMaterialAddedObservable.add(onNewMaterialAddedCb);
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
/**
|
|
430
|
-
* Gets the Material either from the given {@link Variant}, the given scene or tries to create it from an Combeenation
|
|
431
|
-
* material asset when inside a Combeenation configurator.
|
|
432
|
-
*/
|
|
433
|
-
const getOrCreateMaterial = function (scene, materialId, variant) {
|
|
434
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
-
registerOnNewMaterialAddedCbOnce(scene);
|
|
436
|
-
let chosenMaterial;
|
|
437
|
-
chosenMaterial = variant === null || variant === void 0 ? void 0 : variant.inheritedMaterials.find(mat => mat.id === materialId);
|
|
438
|
-
chosenMaterial = chosenMaterial || scene.materials.find(mat => mat.id === materialId);
|
|
439
|
-
if (!chosenMaterial) {
|
|
440
|
-
// material not available yet, request it from Combeenation assets
|
|
441
|
-
if (getMaterialPromises.has(materialId)) {
|
|
442
|
-
// request is already pending, just wait for the result
|
|
443
|
-
chosenMaterial = yield getMaterialPromises.get(materialId);
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
// request not pending, call the dedicated function
|
|
447
|
-
const getMaterialProm = (0, sceneLoaderHelper_1.createMaterialFromCbnAssets)(materialId, scene);
|
|
448
|
-
// store the promise in a global map, so that subsequent requests can reference it
|
|
449
|
-
getMaterialPromises.set(materialId, getMaterialProm);
|
|
450
|
-
chosenMaterial = yield getMaterialProm;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
if (chosenMaterial) {
|
|
454
|
-
return chosenMaterial;
|
|
455
|
-
}
|
|
456
|
-
// reject when material was not found
|
|
457
|
-
let rejectMessage = `Material with id "${materialId}" does not exist on scene.`;
|
|
458
|
-
if (variant) {
|
|
459
|
-
rejectMessage = `Material with id "${materialId}" does not exist for variant "${variant.id}".`;
|
|
460
|
-
}
|
|
461
|
-
throw new Error(rejectMessage);
|
|
462
|
-
});
|
|
463
|
-
};
|
|
464
|
-
exports.getOrCreateMaterial = getOrCreateMaterial;
|
|
465
|
-
/**
|
|
466
|
-
* Waits until the materials textures are loaded and shaders are compiled.
|
|
467
|
-
* Then sets the material on the node if there is no newer "set material" request
|
|
468
|
-
*/
|
|
469
|
-
const applyMaterial = function (material, node) {
|
|
470
|
-
var _a;
|
|
471
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
472
|
-
// set current material id as last valid id, in this case all previously set materials on the node will be invalidated
|
|
473
|
-
injectMetadata(node, { [materialWaitingToBeSetMetadataName]: material.id }, false);
|
|
474
|
-
const promTexturesReady = new Promise(resolve => baseTexture_1.BaseTexture.WhenAllReady(material.getActiveTextures(), resolve));
|
|
475
|
-
// this promise should only take some time on the first call of the corresponding shader (eg: PBRMaterial shader)
|
|
476
|
-
// on each other call of the same material/shader type there should be not be a waiting time, or at maximum one frame
|
|
477
|
-
// https://forum.babylonjs.com/t/mesh-flickering-when-setting-material-initially/37312
|
|
478
|
-
const promMaterialCompiled = material.forceCompilationAsync(node);
|
|
479
|
-
// material needs to fulfill 2 criterias before it's ready to use
|
|
480
|
-
// - textures need to be "ready" => downloaded
|
|
481
|
-
// - dedicated shader needs to be compiled
|
|
482
|
-
// if this would not be the case you can see some "flickering" when setting the material
|
|
483
|
-
yield Promise.all([promTexturesReady, promMaterialCompiled]);
|
|
484
|
-
// textures ready, now check if the material is still up-to-date
|
|
485
|
-
if (material.id === ((_a = node.metadata) === null || _a === void 0 ? void 0 : _a[materialWaitingToBeSetMetadataName])) {
|
|
486
|
-
node.material = material;
|
|
487
|
-
delete node.metadata[materialWaitingToBeSetMetadataName];
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
};
|
|
491
|
-
exports.applyMaterial = applyMaterial;
|
|
492
|
-
/**
|
|
493
|
-
* !!! Warning !!!
|
|
494
|
-
* This function is not public API. Whilst it can help solving certain problems, it only works reliably in well defined
|
|
495
|
-
* situations and can cause unwanted side effects under some conditions. Use carefully at your own risk!
|
|
496
|
-
*
|
|
497
|
-
* See https://combeenation.myjetbrains.com/youtrack/issue/CB-5906 for further details regarding this warning.
|
|
498
|
-
*
|
|
499
|
-
* Set material of an instanced meshes source mesh.
|
|
500
|
-
* Changes the material of all instanced meshes which have the same source mesh.
|
|
501
|
-
*
|
|
502
|
-
* @param node
|
|
503
|
-
* @param material
|
|
504
|
-
* @param deep
|
|
505
|
-
*
|
|
506
|
-
* @ignore
|
|
507
|
-
*/
|
|
508
|
-
const setSourceNodeMaterial = function (node, material, deep = true) {
|
|
509
|
-
const warn = ` You're using "setSourceNodeMaterial" which is not public API.
|
|
510
|
-
Whilst it can help solving certain problems, it only works reliably in well defined situations and can cause unwanted side effects under some conditions.
|
|
511
|
-
Use carefully at your own risk!`;
|
|
512
|
-
console.warn(`!!! Warning !!!\n${warn}`);
|
|
513
|
-
if (node instanceof instancedMesh_1.InstancedMesh) {
|
|
514
|
-
node.sourceMesh.material = material;
|
|
515
|
-
}
|
|
516
|
-
if (deep) {
|
|
517
|
-
node.getChildTransformNodes(true).forEach(child => setSourceNodeMaterial(child, material, deep));
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
exports.setSourceNodeMaterial = setSourceNodeMaterial;
|
|
521
|
-
/**
|
|
522
|
-
* @param node
|
|
523
|
-
* @param color
|
|
524
|
-
* @param deep
|
|
525
|
-
*/
|
|
526
|
-
const setMaterialColor = function (node, color, deep = true) {
|
|
527
|
-
if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
|
|
528
|
-
const materialCls = node.material.getClassName();
|
|
529
|
-
switch (materialCls) {
|
|
530
|
-
case 'PBRMaterial':
|
|
531
|
-
node.material.albedoColor = color.toLinearSpace();
|
|
532
|
-
break;
|
|
533
|
-
case 'StandardMaterial':
|
|
534
|
-
node.material.diffuseColor = color;
|
|
535
|
-
break;
|
|
536
|
-
default:
|
|
537
|
-
throw new Error(`Setting color for material of instance "${materialCls}" not implemented (yet).`);
|
|
538
|
-
}
|
|
539
|
-
setMaterial(node, node.material.id, false);
|
|
540
|
-
}
|
|
541
|
-
if (deep) {
|
|
542
|
-
node.getChildTransformNodes(true).forEach(child => setMaterialColor(child, color, deep));
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
exports.setMaterialColor = setMaterialColor;
|
|
546
|
-
/**
|
|
547
|
-
* @param node
|
|
548
|
-
* @param texture
|
|
549
|
-
* @param deep
|
|
550
|
-
*/
|
|
551
|
-
const setMaterialTexture = function (node, texture, deep = true) {
|
|
552
|
-
if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
|
|
553
|
-
const materialCls = node.material.getClassName();
|
|
554
|
-
switch (materialCls) {
|
|
555
|
-
case 'PBRMaterial':
|
|
556
|
-
node.material.albedoTexture = texture;
|
|
557
|
-
break;
|
|
558
|
-
case 'StandardMaterial':
|
|
559
|
-
node.material.diffuseTexture = texture;
|
|
560
|
-
break;
|
|
561
|
-
default:
|
|
562
|
-
throw new Error(`Setting texture for material of instance "${materialCls}" not implemented (yet).`);
|
|
563
|
-
}
|
|
564
|
-
setMaterial(node, node.material.id, false);
|
|
565
|
-
}
|
|
566
|
-
if (deep) {
|
|
567
|
-
node.getChildTransformNodes(true).forEach(child => setMaterialTexture(child, texture, deep));
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
exports.setMaterialTexture = setMaterialTexture;
|
|
571
|
-
/**
|
|
572
|
-
* @param node
|
|
573
|
-
* @param metallness
|
|
574
|
-
* @param deep
|
|
575
|
-
*/
|
|
576
|
-
const setMaterialMetallness = function (node, metallness, deep = true) {
|
|
577
|
-
if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
|
|
578
|
-
const materialCls = node.material.getClassName();
|
|
579
|
-
switch (materialCls) {
|
|
580
|
-
case 'PBRMaterial':
|
|
581
|
-
node.material.metallic = metallness;
|
|
582
|
-
break;
|
|
583
|
-
default:
|
|
584
|
-
throw new Error(`Setting metallness for material of instance "${materialCls}" not implemented (yet).`);
|
|
585
|
-
}
|
|
586
|
-
setMaterial(node, node.material.id, false);
|
|
587
|
-
}
|
|
588
|
-
if (deep) {
|
|
589
|
-
node.getChildTransformNodes(true).forEach(child => setMaterialMetallness(child, metallness, deep));
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
exports.setMaterialMetallness = setMaterialMetallness;
|
|
593
|
-
/**
|
|
594
|
-
* @param node
|
|
595
|
-
* @param roughness
|
|
596
|
-
* @param deep
|
|
597
|
-
*/
|
|
598
|
-
const setMaterialRoughness = function (node, roughness, deep = true) {
|
|
599
|
-
if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
|
|
600
|
-
const materialCls = node.material.getClassName();
|
|
601
|
-
switch (materialCls) {
|
|
602
|
-
case 'PBRMaterial':
|
|
603
|
-
node.material.roughness = roughness;
|
|
604
|
-
break;
|
|
605
|
-
case 'StandardMaterial':
|
|
606
|
-
node.material.roughness = roughness;
|
|
607
|
-
break;
|
|
608
|
-
default:
|
|
609
|
-
throw new Error(`Setting roughness for material of instance "${materialCls}" not implemented (yet).`);
|
|
610
|
-
}
|
|
611
|
-
setMaterial(node, node.material.id, false);
|
|
612
|
-
}
|
|
613
|
-
if (deep) {
|
|
614
|
-
node.getChildTransformNodes(true).forEach(child => setMaterialRoughness(child, roughness, deep));
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
exports.setMaterialRoughness = setMaterialRoughness;
|
|
618
|
-
/**
|
|
619
|
-
* @param node
|
|
620
|
-
* @param layer
|
|
621
|
-
* @param color
|
|
622
|
-
* @param deep
|
|
623
|
-
*/
|
|
624
|
-
const addToHighlightLayer = function (layer, color, node, deep = true) {
|
|
625
|
-
if (node instanceof abstractMesh_1.AbstractMesh) {
|
|
626
|
-
layer.addMesh(node, color);
|
|
627
|
-
}
|
|
628
|
-
if (deep) {
|
|
629
|
-
node.getChildTransformNodes(true).forEach(child => addToHighlightLayer(layer, color, child, deep));
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
exports.addToHighlightLayer = addToHighlightLayer;
|
|
633
|
-
/**
|
|
634
|
-
* @param node
|
|
635
|
-
* @param layer
|
|
636
|
-
* @param deep
|
|
637
|
-
*/
|
|
638
|
-
const removeFromHighlightLayer = function (layer, node, deep = true) {
|
|
639
|
-
if (node instanceof abstractMesh_1.AbstractMesh) {
|
|
640
|
-
layer.removeMesh(node);
|
|
641
|
-
}
|
|
642
|
-
if (deep) {
|
|
643
|
-
node.getChildTransformNodes(true).forEach(child => removeFromHighlightLayer(layer, child, deep));
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
exports.removeFromHighlightLayer = removeFromHighlightLayer;
|
|
647
|
-
/**
|
|
648
|
-
* @param node
|
|
649
|
-
* @param receiveShadows
|
|
650
|
-
* @param deep
|
|
651
|
-
*/
|
|
652
|
-
const setReceiveShadows = function (node, receiveShadows, deep = true) {
|
|
653
|
-
if (node instanceof abstractMesh_1.AbstractMesh) {
|
|
654
|
-
node.receiveShadows = receiveShadows;
|
|
655
|
-
}
|
|
656
|
-
if (deep) {
|
|
657
|
-
node.getChildTransformNodes(true).forEach(child => setReceiveShadows(child, receiveShadows, deep));
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
exports.setReceiveShadows = setReceiveShadows;
|
|
661
|
-
/**
|
|
662
|
-
* @param node
|
|
663
|
-
* @param generator
|
|
664
|
-
* @param deep
|
|
665
|
-
*/
|
|
666
|
-
const addToShadowGenerator = function (generator, node, deep = true) {
|
|
667
|
-
if (node instanceof abstractMesh_1.AbstractMesh) {
|
|
668
|
-
// We have to remove the node because there's no duplicate check in babylon
|
|
669
|
-
generator.removeShadowCaster(node, false);
|
|
670
|
-
generator.addShadowCaster(node, false);
|
|
671
|
-
}
|
|
672
|
-
if (deep) {
|
|
673
|
-
node.getChildTransformNodes(true).forEach(child => addToShadowGenerator(generator, child, deep));
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
exports.addToShadowGenerator = addToShadowGenerator;
|
|
677
|
-
/**
|
|
678
|
-
* @param node
|
|
679
|
-
* @param generator
|
|
680
|
-
* @param deep
|
|
681
|
-
*/
|
|
682
|
-
const removeFromShadowGenerator = function (generator, node, deep = true) {
|
|
683
|
-
if (node instanceof abstractMesh_1.AbstractMesh) {
|
|
684
|
-
generator.removeShadowCaster(node, false);
|
|
685
|
-
}
|
|
686
|
-
if (deep) {
|
|
687
|
-
node.getChildTransformNodes(true).forEach(child => removeFromShadowGenerator(generator, child, deep));
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
exports.removeFromShadowGenerator = removeFromShadowGenerator;
|
|
691
|
-
/**
|
|
692
|
-
* https://forum.babylonjs.com/t/get-mesh-bounding-box-position-and-size-in-2d-screen-coordinates/1058/3
|
|
693
|
-
* @param mesh
|
|
694
|
-
* @param scene
|
|
695
|
-
* @param canvas
|
|
696
|
-
*/
|
|
697
|
-
const getClientRectFromMesh = function (mesh, scene, canvas) {
|
|
698
|
-
// get bounding box of the mesh
|
|
699
|
-
const meshVectors = mesh.getBoundingInfo().boundingBox.vectors;
|
|
700
|
-
// get the matrix and viewport needed to project the vectors onto the screen
|
|
701
|
-
const worldMatrix = mesh.getWorldMatrix();
|
|
702
|
-
const transformMatrix = scene.getTransformMatrix();
|
|
703
|
-
const viewport = scene.activeCamera.viewport;
|
|
704
|
-
// loop though all the vectors and project them against the current camera viewport to get a set of coordinates
|
|
705
|
-
const coordinates = meshVectors.map(vector => {
|
|
706
|
-
const projection = math_vector_1.Vector3.Project(vector, worldMatrix, transformMatrix, viewport);
|
|
707
|
-
projection.x = projection.x * canvas.clientWidth;
|
|
708
|
-
projection.y = projection.y * canvas.clientHeight;
|
|
709
|
-
return projection;
|
|
710
|
-
});
|
|
711
|
-
// get the min and max for all the coordinates so we can calculate the largest possible screen size
|
|
712
|
-
const maxX = Math.max(...coordinates.map(o => o.x));
|
|
713
|
-
const minX = Math.min(...coordinates.map(o => o.x));
|
|
714
|
-
const maxY = Math.max(...coordinates.map(o => o.y));
|
|
715
|
-
const minY = Math.min(...coordinates.map(o => o.y));
|
|
716
|
-
// return a ClientRect from this
|
|
717
|
-
return {
|
|
718
|
-
width: maxX - minX,
|
|
719
|
-
height: maxY - minY,
|
|
720
|
-
left: minX,
|
|
721
|
-
top: minY,
|
|
722
|
-
right: maxX,
|
|
723
|
-
bottom: maxY,
|
|
724
|
-
};
|
|
725
|
-
};
|
|
726
|
-
exports.getClientRectFromMesh = getClientRectFromMesh;
|
|
727
|
-
/**
|
|
728
|
-
* This type guard checks whether the given `BaseTextures` is any of its subtypes which comes with an url and
|
|
729
|
-
* `onLoadObservable`.
|
|
730
|
-
*
|
|
731
|
-
* !!! Timing of when this function is called is important !!!
|
|
732
|
-
* See the following for more details: https://forum.babylonjs.com/t/basetexture-whenallready-returns-too-early/34501/6
|
|
733
|
-
*/
|
|
734
|
-
const isLoadableTexture = function (texture) {
|
|
735
|
-
const castedTexture = texture;
|
|
736
|
-
return !!castedTexture.url && !!castedTexture.onLoadObservable;
|
|
737
|
-
};
|
|
738
|
-
exports.isLoadableTexture = isLoadableTexture;
|
|
739
|
-
/**
|
|
740
|
-
* @param objects
|
|
741
|
-
* @param tagMapping
|
|
742
|
-
*/
|
|
743
|
-
const mapTags = function (objects, tagMapping) {
|
|
744
|
-
var _a;
|
|
745
|
-
let affectedTags = [];
|
|
746
|
-
for (const object of objects) {
|
|
747
|
-
const oldTags = Object.keys((_a = tags_1.Tags.GetTags(object, false)) !== null && _a !== void 0 ? _a : {});
|
|
748
|
-
const mappedTags = oldTags.map(t => tagMapping[t] || t);
|
|
749
|
-
tags_1.Tags.RemoveTagsFrom(object, oldTags.join(' '));
|
|
750
|
-
tags_1.Tags.AddTagsTo(object, mappedTags.join(' '));
|
|
751
|
-
affectedTags = [...affectedTags, ...mappedTags];
|
|
752
|
-
}
|
|
753
|
-
return (0, lodash_es_1.uniq)(affectedTags);
|
|
754
|
-
};
|
|
755
|
-
exports.mapTags = mapTags;
|
|
756
|
-
/**
|
|
757
|
-
* Gets an array of ids for nodeIds that exist in both TransformNode arrays.
|
|
758
|
-
* @param nodes1
|
|
759
|
-
* @param nodes2
|
|
760
|
-
* @param predicate
|
|
761
|
-
*/
|
|
762
|
-
const intersectingNodeNames = function (nodes1, nodes2, predicate) {
|
|
763
|
-
const nodeNames1 = nodes1.filter(n => !predicate || predicate(n)).map(n => n.name);
|
|
764
|
-
const nodesNames2 = nodes2.filter(n => !predicate || predicate(n)).map(n => n.name);
|
|
765
|
-
return nodeNames1.filter(n1 => nodesNames2.includes(n1));
|
|
766
|
-
};
|
|
767
|
-
exports.intersectingNodeNames = intersectingNodeNames;
|
|
768
|
-
/**
|
|
769
|
-
* Gets an array of ids for duplicate nodeIds in given node array.
|
|
770
|
-
* @param nodes
|
|
771
|
-
* @param predicate
|
|
772
|
-
*/
|
|
773
|
-
const duplicateNodeNames = function (nodes, predicate) {
|
|
774
|
-
const nodeNames = nodes.filter(n => !predicate || predicate(n)).map(n => n.name);
|
|
775
|
-
return nodeNames.filter((v, i, self) => self.indexOf(v) !== i);
|
|
776
|
-
};
|
|
777
|
-
exports.duplicateNodeNames = duplicateNodeNames;
|
|
778
|
-
/**
|
|
779
|
-
* Reports duplicate nodeIds.
|
|
780
|
-
* @param nodeNames
|
|
781
|
-
*/
|
|
782
|
-
const reportDuplicateNodeNames = function (nodeNames) {
|
|
783
|
-
var _a;
|
|
784
|
-
if (nodeNames.length > 0) {
|
|
785
|
-
const warn = `There are duplicate nodeNames: ${nodeNames.join(', ')}`;
|
|
786
|
-
console.warn(`!!! Warning !!!\n${warn}`);
|
|
787
|
-
(_a = window.Cbn) === null || _a === void 0 ? void 0 : _a.Assets.reportDuplicateNodeName(nodeNames);
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
exports.reportDuplicateNodeNames = reportDuplicateNodeNames;
|
|
791
|
-
const drawPaintableOnMaterial = function (material, imageSource, scene, options) {
|
|
792
|
-
var _a, _b, _c, _d;
|
|
793
|
-
// always take width and height from image source, scaling is done with uvScale properties
|
|
794
|
-
const widthAndHeight = {
|
|
795
|
-
width: imageSource.width,
|
|
796
|
-
height: imageSource.height,
|
|
797
|
-
};
|
|
798
|
-
const texture = new dynamicTexture_1.DynamicTexture(`${material.id}.paintable_texture`, widthAndHeight, scene);
|
|
799
|
-
// draw image on texture
|
|
800
|
-
const ctx = texture.getContext();
|
|
801
|
-
ctx.drawImage(imageSource, 0, 0);
|
|
802
|
-
texture.update();
|
|
803
|
-
// apply settings from paintable options to tweak position and scaling of image on the texture
|
|
804
|
-
texture.uScale = (_a = options === null || options === void 0 ? void 0 : options.uScale) !== null && _a !== void 0 ? _a : texture.uScale;
|
|
805
|
-
texture.vScale = (_b = options === null || options === void 0 ? void 0 : options.vScale) !== null && _b !== void 0 ? _b : texture.vScale;
|
|
806
|
-
texture.uOffset = (_c = options === null || options === void 0 ? void 0 : options.uOffset) !== null && _c !== void 0 ? _c : texture.uOffset;
|
|
807
|
-
texture.vOffset = (_d = options === null || options === void 0 ? void 0 : options.vOffset) !== null && _d !== void 0 ? _d : texture.vOffset;
|
|
808
|
-
// wrap mode is preferred, as it will always show the texture, no matter which position offset is currently chosen
|
|
809
|
-
// clamp mode requires more knowledge (and patience) when adjusting the uv scale and offset values
|
|
810
|
-
texture.wrapU = texture_1.Texture.WRAP_ADDRESSMODE;
|
|
811
|
-
texture.wrapV = texture_1.Texture.WRAP_ADDRESSMODE;
|
|
812
|
-
// apply the paintable texture on the dedicated material type
|
|
813
|
-
const materialCls = material.getClassName();
|
|
814
|
-
switch (materialCls) {
|
|
815
|
-
case 'PBRMaterial':
|
|
816
|
-
material.albedoTexture = texture;
|
|
817
|
-
break;
|
|
818
|
-
case 'StandardMaterial':
|
|
819
|
-
material.diffuseTexture = texture;
|
|
820
|
-
break;
|
|
821
|
-
default:
|
|
822
|
-
throw new Error(`Setting paintable texture for material of instance "${materialCls}" not implemented (yet).`);
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
exports.drawPaintableOnMaterial = drawPaintableOnMaterial;
|
|
826
|
-
//# sourceMappingURL=babylonHelper.js.map
|