@inweb/viewer-three 27.2.3 → 27.3.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/viewer-three.js +103 -43
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +2 -2
- package/dist/viewer-three.module.js +103 -43
- package/dist/viewer-three.module.js.map +1 -1
- package/package.json +5 -5
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicGltfLoader.js +89 -0
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.ts +44 -33
- package/src/Viewer/models/ModelImpl.ts +13 -10
package/dist/viewer-three.js
CHANGED
|
@@ -38048,19 +38048,19 @@ void main() {
|
|
|
38048
38048
|
return this;
|
|
38049
38049
|
}
|
|
38050
38050
|
explode(scale = 0, coeff = 4) {
|
|
38051
|
-
const
|
|
38052
|
-
const
|
|
38051
|
+
const centersCache = new Map();
|
|
38052
|
+
const calcObjectCenter = (object, target) => {
|
|
38053
38053
|
const extents = new Box3().setFromObject(object);
|
|
38054
38054
|
const handle = object.userData.handle;
|
|
38055
38055
|
if (!handle)
|
|
38056
38056
|
return extents.getCenter(target);
|
|
38057
|
-
const center =
|
|
38057
|
+
const center = centersCache.get(handle);
|
|
38058
38058
|
if (center)
|
|
38059
38059
|
return target.copy(center);
|
|
38060
38060
|
const objects = this.getObjectsByHandles(handle);
|
|
38061
38061
|
objects.forEach((x) => extents.expandByObject(x));
|
|
38062
38062
|
extents.getCenter(target);
|
|
38063
|
-
|
|
38063
|
+
centersCache.set(handle, target.clone());
|
|
38064
38064
|
return target;
|
|
38065
38065
|
};
|
|
38066
38066
|
function calcExplodeDepth(object, depth) {
|
|
@@ -38071,13 +38071,14 @@ void main() {
|
|
|
38071
38071
|
result = objectDepth;
|
|
38072
38072
|
});
|
|
38073
38073
|
object.userData.originalPosition = object.position.clone();
|
|
38074
|
-
object.userData.originalCenter =
|
|
38074
|
+
object.userData.originalCenter = calcObjectCenter(object, new Vector3());
|
|
38075
38075
|
return result;
|
|
38076
38076
|
}
|
|
38077
38077
|
const explodeScale = scale / 100;
|
|
38078
38078
|
const explodeRoot = this.scene;
|
|
38079
|
-
if (!explodeRoot.userData.explodeDepth)
|
|
38079
|
+
if (!explodeRoot.userData.explodeDepth) {
|
|
38080
38080
|
explodeRoot.userData.explodeDepth = calcExplodeDepth(explodeRoot, 1);
|
|
38081
|
+
}
|
|
38081
38082
|
const maxDepth = explodeRoot.userData.explodeDepth;
|
|
38082
38083
|
const scaledExplodeDepth = explodeScale * maxDepth + 1;
|
|
38083
38084
|
const explodeDepth = 0 | scaledExplodeDepth;
|
|
@@ -38094,8 +38095,8 @@ void main() {
|
|
|
38094
38095
|
objectScale *= currentSegmentFraction;
|
|
38095
38096
|
const parentCenter = object.parent.userData.originalCenter;
|
|
38096
38097
|
const objectCenter = object.userData.originalCenter;
|
|
38097
|
-
const
|
|
38098
|
-
object.position.add(
|
|
38098
|
+
const localOffset = objectCenter.clone().sub(parentCenter).multiplyScalar(objectScale);
|
|
38099
|
+
object.position.add(localOffset);
|
|
38099
38100
|
}
|
|
38100
38101
|
object.children.forEach((x) => explodeObject(x, depth + 1));
|
|
38101
38102
|
}
|
|
@@ -38187,67 +38188,73 @@ void main() {
|
|
|
38187
38188
|
return this;
|
|
38188
38189
|
}
|
|
38189
38190
|
explode(scale = 0, coeff = 4) {
|
|
38190
|
-
const
|
|
38191
|
+
const centersCache = new Map();
|
|
38191
38192
|
const calcObjectCenter = (object, target) => {
|
|
38192
38193
|
const extents = new Box3().setFromObject(object);
|
|
38193
38194
|
const handle = object.userData.handle;
|
|
38194
38195
|
if (!handle)
|
|
38195
38196
|
return extents.getCenter(target);
|
|
38196
|
-
const center =
|
|
38197
|
+
const center = centersCache.get(handle);
|
|
38197
38198
|
if (center)
|
|
38198
38199
|
return target.copy(center);
|
|
38199
38200
|
const objects = this.getObjectsByHandles(handle);
|
|
38200
38201
|
objects.forEach((x) => extents.expandByObject(x));
|
|
38201
38202
|
extents.getCenter(target);
|
|
38202
|
-
|
|
38203
|
+
centersCache.set(handle, target.clone());
|
|
38203
38204
|
return target;
|
|
38204
38205
|
};
|
|
38205
|
-
|
|
38206
|
-
|
|
38207
|
-
|
|
38208
|
-
|
|
38209
|
-
|
|
38210
|
-
|
|
38211
|
-
if (result < objectDepth)
|
|
38212
|
-
result = objectDepth;
|
|
38213
|
-
});
|
|
38206
|
+
const calcObjectDepth = (object) => {
|
|
38207
|
+
if (object.userData.depth !== undefined)
|
|
38208
|
+
return object.userData.depth;
|
|
38209
|
+
const parent = object.parent;
|
|
38210
|
+
const depth = parent && object !== explodeRoot ? calcObjectDepth(parent) + 1 : 0;
|
|
38211
|
+
object.userData.depth = depth;
|
|
38214
38212
|
object.userData.originalPosition = object.position.clone();
|
|
38215
38213
|
object.userData.originalCenter = calcObjectCenter(object, new Vector3());
|
|
38216
|
-
return
|
|
38217
|
-
}
|
|
38214
|
+
return depth;
|
|
38215
|
+
};
|
|
38218
38216
|
const explodeScale = scale / 100;
|
|
38219
38217
|
const explodeRoot = this.scene.children[0];
|
|
38220
|
-
if (!explodeRoot.userData.explodeDepth)
|
|
38221
|
-
|
|
38218
|
+
if (!explodeRoot.userData.explodeDepth) {
|
|
38219
|
+
let maxDepth = 0;
|
|
38220
|
+
this.gltfLoader.originalObjects.forEach((object) => {
|
|
38221
|
+
const depth = calcObjectDepth(object);
|
|
38222
|
+
if (depth > maxDepth)
|
|
38223
|
+
maxDepth = depth;
|
|
38224
|
+
});
|
|
38225
|
+
explodeRoot.userData.explodeDepth = maxDepth;
|
|
38226
|
+
}
|
|
38222
38227
|
const maxDepth = explodeRoot.userData.explodeDepth;
|
|
38223
38228
|
const scaledExplodeDepth = explodeScale * maxDepth + 1;
|
|
38224
38229
|
const explodeDepth = 0 | scaledExplodeDepth;
|
|
38225
38230
|
const currentSegmentFraction = scaledExplodeDepth - explodeDepth;
|
|
38226
|
-
const
|
|
38227
|
-
|
|
38228
|
-
if (object
|
|
38229
|
-
return;
|
|
38230
|
-
|
|
38231
|
-
|
|
38232
|
-
|
|
38233
|
-
|
|
38231
|
+
const offsetCache = new Map();
|
|
38232
|
+
const calcObjectOffset = (object, target) => {
|
|
38233
|
+
if (offsetCache.has(object))
|
|
38234
|
+
return target.copy(offsetCache.get(object));
|
|
38235
|
+
const parent = object.parent;
|
|
38236
|
+
if (parent && object !== explodeRoot)
|
|
38237
|
+
calcObjectOffset(parent, target);
|
|
38238
|
+
const depth = object.userData.depth;
|
|
38239
|
+
if (depth > 0 && depth <= explodeDepth) {
|
|
38234
38240
|
let objectScale = explodeScale * coeff;
|
|
38235
38241
|
if (depth === explodeDepth)
|
|
38236
38242
|
objectScale *= currentSegmentFraction;
|
|
38237
|
-
const parentCenter =
|
|
38243
|
+
const parentCenter = parent.userData.originalCenter;
|
|
38238
38244
|
const objectCenter = object.userData.originalCenter;
|
|
38239
|
-
const
|
|
38240
|
-
|
|
38241
|
-
const matrix = new Matrix4().makeTranslation(objectOffset.x, objectOffset.y, objectOffset.z);
|
|
38242
|
-
transformMap.set(object, matrix);
|
|
38245
|
+
const localOffset = objectCenter.clone().sub(parentCenter).multiplyScalar(objectScale);
|
|
38246
|
+
target.add(localOffset);
|
|
38243
38247
|
}
|
|
38244
|
-
object.
|
|
38245
|
-
|
|
38246
|
-
|
|
38247
|
-
|
|
38248
|
-
|
|
38249
|
-
|
|
38248
|
+
offsetCache.set(object, target.clone());
|
|
38249
|
+
return target;
|
|
38250
|
+
};
|
|
38251
|
+
const transformMap = new Map();
|
|
38252
|
+
this.gltfLoader.originalObjects.forEach((object) => {
|
|
38253
|
+
const globalOffset = calcObjectOffset(object, new Vector3());
|
|
38254
|
+
transformMap.set(object, new Matrix4().makeTranslation(globalOffset));
|
|
38255
|
+
});
|
|
38250
38256
|
this.gltfLoader.applyObjectTransforms(transformMap);
|
|
38257
|
+
this.scene.updateMatrixWorld();
|
|
38251
38258
|
return this;
|
|
38252
38259
|
}
|
|
38253
38260
|
}
|
|
@@ -38973,6 +38980,8 @@ void main() {
|
|
|
38973
38980
|
this.oldOptimizeObjects = new Set();
|
|
38974
38981
|
this.objectTransforms = new Map();
|
|
38975
38982
|
this.transformedGeometries = new Map();
|
|
38983
|
+
this.syncTransformsToOriginalObjects = true;
|
|
38984
|
+
this._originalObjectMatrices = new Map();
|
|
38976
38985
|
this.activeChunkLoads = 0;
|
|
38977
38986
|
this.chunkQueue = [];
|
|
38978
38987
|
this.objectIdToIndex = new Map();
|
|
@@ -40127,6 +40136,7 @@ void main() {
|
|
|
40127
40136
|
this.isolatedObjects = [];
|
|
40128
40137
|
this.objectTransforms.clear();
|
|
40129
40138
|
this.transformedGeometries.clear();
|
|
40139
|
+
this._originalObjectMatrices.clear();
|
|
40130
40140
|
this.totalLoadedObjects = 0;
|
|
40131
40141
|
this.currentMemoryUsage = 0;
|
|
40132
40142
|
this.pendingMemoryUsage = 0;
|
|
@@ -40972,6 +40982,47 @@ void main() {
|
|
|
40972
40982
|
this.updateMaterialUniforms();
|
|
40973
40983
|
}
|
|
40974
40984
|
}
|
|
40985
|
+
if (this.syncTransformsToOriginalObjects) {
|
|
40986
|
+
this._syncOriginalObjectTransforms(objectTransformMap);
|
|
40987
|
+
}
|
|
40988
|
+
}
|
|
40989
|
+
_syncOriginalObjectTransforms(objectTransformMap) {
|
|
40990
|
+
for (const [obj, savedPos] of this._originalObjectMatrices) {
|
|
40991
|
+
obj.position.copy(savedPos);
|
|
40992
|
+
if (obj.userData.highlight) {
|
|
40993
|
+
obj.userData.highlight.position.copy(savedPos);
|
|
40994
|
+
}
|
|
40995
|
+
}
|
|
40996
|
+
this._originalObjectMatrices.clear();
|
|
40997
|
+
const _offset = new Vector3();
|
|
40998
|
+
const _parentInverse = new Matrix4();
|
|
40999
|
+
if (objectTransformMap instanceof Map) {
|
|
41000
|
+
for (const [object, matrix] of objectTransformMap.entries()) {
|
|
41001
|
+
if (!object.userData?.handle) continue;
|
|
41002
|
+
if (!this._originalObjectMatrices.has(object)) {
|
|
41003
|
+
this._originalObjectMatrices.set(object, object.position.clone());
|
|
41004
|
+
}
|
|
41005
|
+
_offset.setFromMatrixPosition(matrix);
|
|
41006
|
+
if (object.userData.structureId) {
|
|
41007
|
+
const rootGroup = this.structureRoots.get(object.userData.structureId);
|
|
41008
|
+
if (rootGroup && object.parent && object.parent !== rootGroup) {
|
|
41009
|
+
const origin = new Vector3(0, 0, 0);
|
|
41010
|
+
origin.applyMatrix4(rootGroup.matrixWorld);
|
|
41011
|
+
_offset.applyMatrix4(rootGroup.matrixWorld);
|
|
41012
|
+
_offset.sub(origin);
|
|
41013
|
+
const parentOrigin = new Vector3(0, 0, 0);
|
|
41014
|
+
_parentInverse.copy(object.parent.matrixWorld).invert();
|
|
41015
|
+
parentOrigin.applyMatrix4(_parentInverse);
|
|
41016
|
+
_offset.applyMatrix4(_parentInverse);
|
|
41017
|
+
_offset.sub(parentOrigin);
|
|
41018
|
+
}
|
|
41019
|
+
}
|
|
41020
|
+
object.position.add(_offset);
|
|
41021
|
+
if (object.userData.highlight) {
|
|
41022
|
+
object.userData.highlight.position.copy(object.position);
|
|
41023
|
+
}
|
|
41024
|
+
}
|
|
41025
|
+
}
|
|
40975
41026
|
}
|
|
40976
41027
|
createExplodeTransforms(objects = null, explodeCenter = null, explodeFactor = 1.5) {
|
|
40977
41028
|
const transformMap = new Map();
|
|
@@ -41055,6 +41106,15 @@ void main() {
|
|
|
41055
41106
|
clearTransforms() {
|
|
41056
41107
|
this.objectTransforms.clear();
|
|
41057
41108
|
this._resetTransformData(true);
|
|
41109
|
+
if (this.syncTransformsToOriginalObjects) {
|
|
41110
|
+
for (const [obj, savedPos] of this._originalObjectMatrices) {
|
|
41111
|
+
obj.position.copy(savedPos);
|
|
41112
|
+
if (obj.userData.highlight) {
|
|
41113
|
+
obj.userData.highlight.position.copy(savedPos);
|
|
41114
|
+
}
|
|
41115
|
+
}
|
|
41116
|
+
this._originalObjectMatrices.clear();
|
|
41117
|
+
}
|
|
41058
41118
|
}
|
|
41059
41119
|
clearHandleTransforms() {
|
|
41060
41120
|
this.clearTransforms();
|