@inweb/viewer-three 27.9.1 → 27.11.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/extensions/loaders/GLTFCloudLoader.js +4 -2
- package/dist/extensions/loaders/GLTFCloudLoader.js.map +1 -1
- package/dist/extensions/loaders/GLTFCloudLoader.min.js +1 -1
- package/dist/extensions/loaders/GLTFCloudLoader.module.js +4 -2
- package/dist/extensions/loaders/GLTFCloudLoader.module.js.map +1 -1
- package/dist/extensions/loaders/GLTFFileLoader.js +2 -0
- package/dist/extensions/loaders/GLTFFileLoader.js.map +1 -1
- package/dist/extensions/loaders/GLTFFileLoader.min.js +1 -1
- package/dist/extensions/loaders/GLTFFileLoader.module.js +2 -0
- package/dist/extensions/loaders/GLTFFileLoader.module.js.map +1 -1
- package/dist/extensions/loaders/IFCXLoader.js +6 -2
- package/dist/extensions/loaders/IFCXLoader.js.map +1 -1
- package/dist/extensions/loaders/IFCXLoader.min.js +1 -1
- package/dist/extensions/loaders/IFCXLoader.module.js +6 -2
- package/dist/extensions/loaders/IFCXLoader.module.js.map +1 -1
- package/dist/extensions/loaders/PotreeLoader.js +2 -0
- package/dist/extensions/loaders/PotreeLoader.js.map +1 -1
- package/dist/extensions/loaders/PotreeLoader.min.js +1 -1
- package/dist/extensions/loaders/PotreeLoader.module.js +2 -0
- package/dist/extensions/loaders/PotreeLoader.module.js.map +1 -1
- package/dist/viewer-three.js +880 -258
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +4 -4
- package/dist/viewer-three.module.js +765 -258
- package/dist/viewer-three.module.js.map +1 -1
- package/extensions/loaders/GLTFCloudLoader.ts +5 -3
- package/extensions/loaders/GLTFFileLoader.ts +2 -0
- package/extensions/loaders/IFCX/IFCXCloudLoader.ts +5 -3
- package/extensions/loaders/IFCX/IFCXFileLoader.ts +2 -0
- package/extensions/loaders/Potree/PotreeFileLoader.ts +2 -0
- package/lib/Viewer/Viewer.d.ts +28 -10
- package/lib/Viewer/commands/Deselect.d.ts +2 -0
- package/lib/Viewer/commands/Explode.d.ts +1 -1
- package/lib/Viewer/commands/GetHidden.d.ts +2 -0
- package/lib/Viewer/commands/GetIsolated.d.ts +2 -0
- package/lib/Viewer/commands/GetSelected.d.ts +1 -1
- package/lib/Viewer/commands/Hide.d.ts +2 -0
- package/lib/Viewer/commands/HideAll.d.ts +2 -0
- package/lib/Viewer/commands/Isolate.d.ts +2 -0
- package/lib/Viewer/commands/Select.d.ts +2 -0
- package/lib/Viewer/commands/SetSelected.d.ts +1 -1
- package/lib/Viewer/commands/SetSelected2.d.ts +1 -1
- package/lib/Viewer/commands/Show.d.ts +2 -0
- package/lib/Viewer/commands/ToHandles.d.ts +2 -0
- package/lib/Viewer/commands/ToHandles2.d.ts +2 -0
- package/lib/Viewer/commands/ToggleSelection.d.ts +2 -0
- package/lib/Viewer/commands/Zoom.d.ts +3 -0
- package/lib/Viewer/commands/ZoomExtents.d.ts +2 -0
- package/lib/Viewer/commands/ZoomTo.d.ts +1 -2
- package/lib/Viewer/components/HighlighterComponent.d.ts +4 -3
- package/lib/Viewer/components/SelectionComponent.d.ts +1 -9
- package/lib/Viewer/components/index.d.ts +1 -1
- package/lib/Viewer/draggers/index.d.ts +2 -2
- package/lib/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.d.ts +10 -8
- package/lib/Viewer/loaders/GLTFCloudDynamicLoader.d.ts +5 -1
- package/lib/Viewer/loaders/GLTFFileDynamicLoader.d.ts +5 -1
- package/lib/Viewer/loaders/index.d.ts +5 -1
- package/lib/Viewer/models/Highlighter.types.d.ts +5 -0
- package/lib/Viewer/models/ModelImpl.d.ts +15 -11
- package/lib/Viewer/models/ModelImpl.types.d.ts +22 -0
- package/lib/index.d.ts +1 -1
- package/package.json +5 -5
- package/src/Viewer/Viewer.ts +132 -27
- package/src/Viewer/commands/ClearSelected.ts +3 -6
- package/src/Viewer/commands/Deselect.ts +35 -0
- package/src/Viewer/commands/Explode.ts +4 -3
- package/src/Viewer/commands/GetHidden.ts +30 -0
- package/src/Viewer/commands/GetIsolated.ts +30 -0
- package/src/Viewer/commands/GetSelected.ts +4 -4
- package/src/Viewer/commands/GetSelected2.ts +4 -7
- package/src/Viewer/commands/Hide.ts +35 -0
- package/src/Viewer/commands/HideAll.ts +32 -0
- package/src/Viewer/commands/HideSelected.ts +1 -11
- package/src/Viewer/commands/Isolate.ts +41 -0
- package/src/Viewer/commands/IsolateSelected.ts +1 -4
- package/src/Viewer/commands/ResetView.ts +1 -1
- package/src/Viewer/commands/Select.ts +36 -0
- package/src/Viewer/commands/SelectModel.ts +4 -8
- package/src/Viewer/commands/SetDefaultViewPosition.ts +2 -2
- package/src/Viewer/commands/SetSelected.ts +8 -11
- package/src/Viewer/commands/SetSelected2.ts +5 -16
- package/src/Viewer/commands/Show.ts +34 -0
- package/src/Viewer/commands/ShowAll.ts +2 -2
- package/src/Viewer/commands/{ZoomToObjects.ts → ToHandles.ts} +7 -10
- package/src/Viewer/commands/ToHandles2.ts +43 -0
- package/src/Viewer/commands/ToggleSelection.ts +40 -0
- package/src/Viewer/commands/Zoom.ts +66 -0
- package/src/Viewer/commands/{ZoomToExtents.ts → ZoomExtents.ts} +3 -3
- package/src/Viewer/commands/ZoomTo.ts +12 -38
- package/src/Viewer/commands/ZoomToSelected.ts +1 -7
- package/src/Viewer/commands/index.ts +24 -5
- package/src/Viewer/components/HighlighterComponent.ts +14 -12
- package/src/Viewer/components/SelectionComponent.ts +13 -77
- package/src/Viewer/components/index.ts +1 -1
- package/src/Viewer/draggers/OrbitDragger.ts +2 -2
- package/src/Viewer/draggers/index.ts +2 -2
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicGltfLoader.js +429 -2
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.ts +26 -35
- package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +33 -3
- package/src/Viewer/loaders/GLTFFileDynamicLoader.ts +32 -2
- package/src/Viewer/loaders/index.ts +5 -1
- package/src/Viewer/models/Highlighter.types.ts +30 -0
- package/src/Viewer/models/ModelImpl.ts +69 -58
- package/src/Viewer/models/{IModelImpl.ts → ModelImpl.types.ts} +8 -17
- package/src/index.ts +1 -1
- package/lib/Viewer/commands/ZoomToExtents.d.ts +0 -2
- package/lib/Viewer/commands/ZoomToObjects.d.ts +0 -2
- package/lib/Viewer/models/IModelImpl.d.ts +0 -26
|
@@ -25,7 +25,9 @@ import {
|
|
|
25
25
|
DataTexture,
|
|
26
26
|
RGBAFormat,
|
|
27
27
|
FloatType,
|
|
28
|
+
UnsignedByteType,
|
|
28
29
|
NearestFilter,
|
|
30
|
+
Vector4,
|
|
29
31
|
} from "three";
|
|
30
32
|
import { GL_CONSTANTS } from "./GltfStructure.js";
|
|
31
33
|
import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js";
|
|
@@ -34,6 +36,13 @@ const DRACO_EXTENSION_NAME = "KHR_draco_mesh_compression";
|
|
|
34
36
|
|
|
35
37
|
const STRUCTURE_ID_SEPARATOR = ":";
|
|
36
38
|
|
|
39
|
+
// Highlight styles are stored in a uniform vec4 array (4 vec4 per style):
|
|
40
|
+
// [fillColor.rgb, fillMix] [lineColor.rgb, lineMix]
|
|
41
|
+
// [emissiveIntensity, overlayOpacity, facesOverlay, fillOpacity] [edgesOverlay, 0, 0, 0]
|
|
42
|
+
const MAX_HIGHLIGHT_STYLES = 8;
|
|
43
|
+
const HIGHLIGHT_STYLE_VEC4_COUNT = 4;
|
|
44
|
+
const HIGHLIGHT_OVERLAY_RENDER_ORDER = 999;
|
|
45
|
+
|
|
37
46
|
//#AI-GENERATED using Gemini 2.5 Pro, Claude-4-sonnet
|
|
38
47
|
//#Reviewed and adapted by dborysov@opendesign.com
|
|
39
48
|
|
|
@@ -141,6 +150,28 @@ export class DynamicGltfLoader {
|
|
|
141
150
|
this.identityTransformData = null;
|
|
142
151
|
this.visibilityMaterials = new Set(); // Keep track of materials to update uniforms
|
|
143
152
|
|
|
153
|
+
// Per-object state textures (1 RGBA8 texel per objectId), shared by all visibility materials
|
|
154
|
+
// colorOverrideTexture: rgb = color, a = 255 when override is active
|
|
155
|
+
// highlightTexture: r = styleIndex + 1, 0 = not highlighted
|
|
156
|
+
this.colorOverrides = new Map(); // handle -> Color
|
|
157
|
+
this.highlightedHandles = new Map(); // handle -> styleIndex
|
|
158
|
+
this.highlightStyles = []; // styleIndex -> style settings
|
|
159
|
+
this.highlightStyleNames = new Map(); // style name -> styleIndex
|
|
160
|
+
this.highlightOverlays = new Map(); // mergedObject -> overlay object
|
|
161
|
+
this.highlightOverlayMaterials = null;
|
|
162
|
+
this.objectStateTextureSize = 1;
|
|
163
|
+
this.colorOverrideData = new Uint8Array(4);
|
|
164
|
+
this.highlightData = new Uint8Array(4);
|
|
165
|
+
this.objectStateUniforms = {
|
|
166
|
+
colorOverrideTexture: { value: this.createObjectStateTexture(this.colorOverrideData, 1) },
|
|
167
|
+
highlightTexture: { value: this.createObjectStateTexture(this.highlightData, 1) },
|
|
168
|
+
objectStateTextureSize: { value: 1 },
|
|
169
|
+
highlightStyles: {
|
|
170
|
+
value: Array.from({ length: MAX_HIGHLIGHT_STYLES * HIGHLIGHT_STYLE_VEC4_COUNT }, () => new Vector4()),
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
this.setHighlightStyle("default", {});
|
|
174
|
+
|
|
144
175
|
// KHR_draco_mesh_compression support — DRACOLoader is injected from
|
|
145
176
|
// the outside via setDracoLoader() so this module doesn't carry a hard
|
|
146
177
|
// dependency on three/examples/jsm/loaders/DRACOLoader.js (which has no
|
|
@@ -478,6 +509,31 @@ export class DynamicGltfLoader {
|
|
|
478
509
|
});
|
|
479
510
|
}
|
|
480
511
|
|
|
512
|
+
createObjectStateTexture(data, size) {
|
|
513
|
+
const texture = new DataTexture(data, size, size, RGBAFormat, UnsignedByteType);
|
|
514
|
+
texture.minFilter = NearestFilter;
|
|
515
|
+
texture.magFilter = NearestFilter;
|
|
516
|
+
texture.generateMipmaps = false;
|
|
517
|
+
texture.needsUpdate = true;
|
|
518
|
+
return texture;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
initObjectStateTextures() {
|
|
522
|
+
const size = Math.max(1, Math.ceil(Math.sqrt(this.maxObjectId + 1)));
|
|
523
|
+
|
|
524
|
+
this.objectStateUniforms.colorOverrideTexture.value.dispose();
|
|
525
|
+
this.objectStateUniforms.highlightTexture.value.dispose();
|
|
526
|
+
|
|
527
|
+
this.objectStateTextureSize = size;
|
|
528
|
+
this.colorOverrideData = new Uint8Array(size * size * 4);
|
|
529
|
+
this.highlightData = new Uint8Array(size * size * 4);
|
|
530
|
+
|
|
531
|
+
// Uniform objects are shared by all visibility materials, so updating .value is enough
|
|
532
|
+
this.objectStateUniforms.colorOverrideTexture.value = this.createObjectStateTexture(this.colorOverrideData, size);
|
|
533
|
+
this.objectStateUniforms.highlightTexture.value = this.createObjectStateTexture(this.highlightData, size);
|
|
534
|
+
this.objectStateUniforms.objectStateTextureSize.value = size;
|
|
535
|
+
}
|
|
536
|
+
|
|
481
537
|
// Fast reset to Identity matrices without creating Matrix4 objects
|
|
482
538
|
_resetTransformData(updateTexture = true) {
|
|
483
539
|
if (!this.transformData || !this.identityTransformData) return;
|
|
@@ -1291,6 +1347,18 @@ export class DynamicGltfLoader {
|
|
|
1291
1347
|
handle = this.getFullHandle(structure.id, meshDef.extras.handle);
|
|
1292
1348
|
}
|
|
1293
1349
|
|
|
1350
|
+
// Files without handles: an edges node follows the face node it belongs to,
|
|
1351
|
+
// so it shares that node's handle (needed for per-object highlight/hide/transform)
|
|
1352
|
+
if (!handle) {
|
|
1353
|
+
handle =
|
|
1354
|
+
isEdge && structure._lastFaceHandle
|
|
1355
|
+
? structure._lastFaceHandle
|
|
1356
|
+
: this.getFullHandle(structure.id, structure._nextObjectId++);
|
|
1357
|
+
}
|
|
1358
|
+
if (!isEdge) {
|
|
1359
|
+
structure._lastFaceHandle = handle;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1294
1362
|
this.nodes.set(uniqueNodeId, {
|
|
1295
1363
|
position: nodeGroup ? nodeGroup.position.clone() : new Vector3().setFromMatrixPosition(nodeMatrix),
|
|
1296
1364
|
nodeIndex: nodeId,
|
|
@@ -1302,7 +1370,7 @@ export class DynamicGltfLoader {
|
|
|
1302
1370
|
structure,
|
|
1303
1371
|
extras: nodeDef.extras,
|
|
1304
1372
|
geometryExtents,
|
|
1305
|
-
handle
|
|
1373
|
+
handle,
|
|
1306
1374
|
});
|
|
1307
1375
|
}
|
|
1308
1376
|
|
|
@@ -1583,7 +1651,7 @@ export class DynamicGltfLoader {
|
|
|
1583
1651
|
}
|
|
1584
1652
|
}
|
|
1585
1653
|
|
|
1586
|
-
createVisibilityMaterial(material) {
|
|
1654
|
+
createVisibilityMaterial(material, options = {}) {
|
|
1587
1655
|
this.visibilityMaterials.add(material);
|
|
1588
1656
|
|
|
1589
1657
|
const uniforms = {
|
|
@@ -1592,9 +1660,24 @@ export class DynamicGltfLoader {
|
|
|
1592
1660
|
};
|
|
1593
1661
|
material.userData.visibilityUniforms = uniforms;
|
|
1594
1662
|
|
|
1663
|
+
const stateUniforms = this.objectStateUniforms;
|
|
1664
|
+
material.defines = material.defines || {};
|
|
1665
|
+
// All edges share one material named "edges" — they get edges color / overlap,
|
|
1666
|
+
// everything else (meshes, lines, points) uses faces settings
|
|
1667
|
+
if (material.name === "edges" || options.edges) {
|
|
1668
|
+
material.defines.HL_IS_EDGE = "";
|
|
1669
|
+
}
|
|
1670
|
+
if (options.overlay) {
|
|
1671
|
+
material.defines.HL_OVERLAY = "";
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1595
1674
|
material.onBeforeCompile = (shader) => {
|
|
1596
1675
|
shader.uniforms.transformTexture = uniforms.transformTexture;
|
|
1597
1676
|
shader.uniforms.transformTextureSize = uniforms.transformTextureSize;
|
|
1677
|
+
shader.uniforms.colorOverrideTexture = stateUniforms.colorOverrideTexture;
|
|
1678
|
+
shader.uniforms.highlightTexture = stateUniforms.highlightTexture;
|
|
1679
|
+
shader.uniforms.objectStateTextureSize = stateUniforms.objectStateTextureSize;
|
|
1680
|
+
shader.uniforms.highlightStyles = stateUniforms.highlightStyles;
|
|
1598
1681
|
|
|
1599
1682
|
// 1. Common Definitions
|
|
1600
1683
|
shader.vertexShader = shader.vertexShader.replace(
|
|
@@ -1622,6 +1705,18 @@ export class DynamicGltfLoader {
|
|
|
1622
1705
|
|
|
1623
1706
|
return mat4(row0, row1, row2, row3);
|
|
1624
1707
|
}
|
|
1708
|
+
|
|
1709
|
+
uniform highp sampler2D colorOverrideTexture;
|
|
1710
|
+
uniform highp sampler2D highlightTexture;
|
|
1711
|
+
uniform float objectStateTextureSize;
|
|
1712
|
+
varying vec4 vColorOverride;
|
|
1713
|
+
varying float vHighlightStyle;
|
|
1714
|
+
|
|
1715
|
+
ivec2 getObjectStateCoord(float instanceId) {
|
|
1716
|
+
int size = int(objectStateTextureSize);
|
|
1717
|
+
int index = int(instanceId);
|
|
1718
|
+
return ivec2(index % size, index / size);
|
|
1719
|
+
}
|
|
1625
1720
|
`
|
|
1626
1721
|
);
|
|
1627
1722
|
|
|
@@ -1632,6 +1727,9 @@ export class DynamicGltfLoader {
|
|
|
1632
1727
|
void main() {
|
|
1633
1728
|
mat4 batchingMatrix = getTransformMatrix(objectId);
|
|
1634
1729
|
vVisibility = visibility;
|
|
1730
|
+
ivec2 objectStateCoord = getObjectStateCoord(objectId);
|
|
1731
|
+
vColorOverride = texelFetch(colorOverrideTexture, objectStateCoord, 0);
|
|
1732
|
+
vHighlightStyle = floor(texelFetch(highlightTexture, objectStateCoord, 0).r * 255.0 + 0.5) - 1.0;
|
|
1635
1733
|
`
|
|
1636
1734
|
);
|
|
1637
1735
|
|
|
@@ -1680,6 +1778,27 @@ export class DynamicGltfLoader {
|
|
|
1680
1778
|
`
|
|
1681
1779
|
#include <common>
|
|
1682
1780
|
varying float vVisibility;
|
|
1781
|
+
varying vec4 vColorOverride;
|
|
1782
|
+
varying float vHighlightStyle;
|
|
1783
|
+
uniform vec4 highlightStyles[${MAX_HIGHLIGHT_STYLES * HIGHLIGHT_STYLE_VEC4_COUNT}];
|
|
1784
|
+
|
|
1785
|
+
// Edges color for the "edges" material, faces color for everything else
|
|
1786
|
+
vec4 getHighlightColor(int base) {
|
|
1787
|
+
#ifdef HL_IS_EDGE
|
|
1788
|
+
return highlightStyles[base + 1];
|
|
1789
|
+
#else
|
|
1790
|
+
return highlightStyles[base];
|
|
1791
|
+
#endif
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
// Edges overlap flag for the "edges" material, faces overlap for everything else
|
|
1795
|
+
float getHighlightOverlay(int base) {
|
|
1796
|
+
#ifdef HL_IS_EDGE
|
|
1797
|
+
return highlightStyles[base + 3].x;
|
|
1798
|
+
#else
|
|
1799
|
+
return highlightStyles[base + 2].z;
|
|
1800
|
+
#endif
|
|
1801
|
+
}
|
|
1683
1802
|
`
|
|
1684
1803
|
)
|
|
1685
1804
|
.replace(
|
|
@@ -1687,6 +1806,47 @@ export class DynamicGltfLoader {
|
|
|
1687
1806
|
`
|
|
1688
1807
|
void main() {
|
|
1689
1808
|
if (vVisibility < 0.5) discard;
|
|
1809
|
+
#ifdef HL_OVERLAY
|
|
1810
|
+
if (vHighlightStyle < 0.0 || getHighlightOverlay(int(vHighlightStyle) * ${HIGHLIGHT_STYLE_VEC4_COUNT}) < 0.5) discard;
|
|
1811
|
+
#endif
|
|
1812
|
+
`
|
|
1813
|
+
)
|
|
1814
|
+
// 6. Color override & highlight color (after material/vertex/map colors are applied)
|
|
1815
|
+
.replace(
|
|
1816
|
+
"#include <color_fragment>",
|
|
1817
|
+
`
|
|
1818
|
+
#include <color_fragment>
|
|
1819
|
+
if (vColorOverride.a > 0.5) diffuseColor.rgb = vColorOverride.rgb;
|
|
1820
|
+
#ifdef HL_OVERLAY
|
|
1821
|
+
{
|
|
1822
|
+
int hlBase = int(vHighlightStyle) * ${HIGHLIGHT_STYLE_VEC4_COUNT};
|
|
1823
|
+
// Blend factor becomes overlay alpha: blends highlight with what is underneath
|
|
1824
|
+
vec4 hlColor = getHighlightColor(hlBase);
|
|
1825
|
+
diffuseColor = vec4(hlColor.rgb, highlightStyles[hlBase + 2].y * hlColor.a);
|
|
1826
|
+
}
|
|
1827
|
+
#else
|
|
1828
|
+
if (vHighlightStyle >= 0.0) {
|
|
1829
|
+
int hlBase = int(vHighlightStyle) * ${HIGHLIGHT_STYLE_VEC4_COUNT};
|
|
1830
|
+
vec4 hlColor = getHighlightColor(hlBase);
|
|
1831
|
+
// With overlap the overlay pass does the blending, keep the original color here
|
|
1832
|
+
float hlMix = getHighlightOverlay(hlBase) > 0.5 ? 0.0 : hlColor.a;
|
|
1833
|
+
diffuseColor.rgb = mix(diffuseColor.rgb, hlColor.rgb, hlMix);
|
|
1834
|
+
// Keep highlighted objects readable even when the material is dimmed (e.g. X-ray)
|
|
1835
|
+
if (highlightStyles[hlBase + 2].w >= 0.0) diffuseColor.a = highlightStyles[hlBase + 2].w;
|
|
1836
|
+
}
|
|
1837
|
+
#endif
|
|
1838
|
+
`
|
|
1839
|
+
)
|
|
1840
|
+
// 7. Emissive glow for highlighted objects
|
|
1841
|
+
.replace(
|
|
1842
|
+
"#include <opaque_fragment>",
|
|
1843
|
+
`
|
|
1844
|
+
if (vHighlightStyle >= 0.0) {
|
|
1845
|
+
int hlBase = int(vHighlightStyle) * ${HIGHLIGHT_STYLE_VEC4_COUNT};
|
|
1846
|
+
vec4 hlColor = getHighlightColor(hlBase);
|
|
1847
|
+
outgoingLight += hlColor.rgb * hlColor.a * highlightStyles[hlBase + 2].x;
|
|
1848
|
+
}
|
|
1849
|
+
#include <opaque_fragment>
|
|
1690
1850
|
`
|
|
1691
1851
|
);
|
|
1692
1852
|
|
|
@@ -1757,6 +1917,8 @@ export class DynamicGltfLoader {
|
|
|
1757
1917
|
});
|
|
1758
1918
|
this.structureRoots.clear();
|
|
1759
1919
|
|
|
1920
|
+
this._disposeHighlightOverlays();
|
|
1921
|
+
|
|
1760
1922
|
this.mergedMesh.forEach((mesh) => {
|
|
1761
1923
|
if (mesh.geometry) mesh.geometry.dispose();
|
|
1762
1924
|
if (mesh.material) {
|
|
@@ -1825,6 +1987,10 @@ export class DynamicGltfLoader {
|
|
|
1825
1987
|
this.meshToNodeMap = null;
|
|
1826
1988
|
this.visibilityMaterials.clear();
|
|
1827
1989
|
|
|
1990
|
+
this.colorOverrides.clear();
|
|
1991
|
+
this.highlightedHandles.clear();
|
|
1992
|
+
this.initObjectStateTextures();
|
|
1993
|
+
|
|
1828
1994
|
// NOTE: do *not* drop this._dracoLoader here. The DRACOLoader is owned
|
|
1829
1995
|
// by the caller (injected via setDracoLoader) and should survive across
|
|
1830
1996
|
// clear()/reload cycles — the loader keeps its worker pool warm and is
|
|
@@ -2023,6 +2189,7 @@ export class DynamicGltfLoader {
|
|
|
2023
2189
|
if (totalObjectsToMerge > 0) {
|
|
2024
2190
|
this.maxObjectId = totalObjectsToMerge;
|
|
2025
2191
|
this.initTransformTexture();
|
|
2192
|
+
this.initObjectStateTextures();
|
|
2026
2193
|
this.initializeObjectVisibility();
|
|
2027
2194
|
|
|
2028
2195
|
// Reset counter so IDs are assigned from 0 during merge
|
|
@@ -2087,6 +2254,9 @@ export class DynamicGltfLoader {
|
|
|
2087
2254
|
});
|
|
2088
2255
|
|
|
2089
2256
|
// Texture and visibility initialized at start of optimization
|
|
2257
|
+
// Re-apply color overrides / highlight set before optimization finished
|
|
2258
|
+
this.syncColorOverrides();
|
|
2259
|
+
this.syncHighlightedObjects();
|
|
2090
2260
|
console.log(`Optimization complete. Total objects: ${this.maxObjectId}`);
|
|
2091
2261
|
|
|
2092
2262
|
this.dispatchEvent("optimizationprogress", {
|
|
@@ -2787,6 +2957,263 @@ export class DynamicGltfLoader {
|
|
|
2787
2957
|
this.syncHiddenObjects();
|
|
2788
2958
|
}
|
|
2789
2959
|
|
|
2960
|
+
setColorByHandle(handle, color) {
|
|
2961
|
+
if (color === null || color === undefined) {
|
|
2962
|
+
this.colorOverrides.delete(handle);
|
|
2963
|
+
} else {
|
|
2964
|
+
this.colorOverrides.set(handle, new Color(color));
|
|
2965
|
+
}
|
|
2966
|
+
this.syncColorOverrides();
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
setColorByHandles(handles, color) {
|
|
2970
|
+
const overrideColor = new Color(color);
|
|
2971
|
+
handles.forEach((handle) => {
|
|
2972
|
+
this.colorOverrides.set(handle, overrideColor);
|
|
2973
|
+
});
|
|
2974
|
+
this.syncColorOverrides();
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
clearColorByHandles(handles) {
|
|
2978
|
+
handles.forEach((handle) => {
|
|
2979
|
+
this.colorOverrides.delete(handle);
|
|
2980
|
+
});
|
|
2981
|
+
this.syncColorOverrides();
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
// colors: Map or iterable of [handle, color] — per-handle colors with a single texture sync
|
|
2985
|
+
setColorsByHandles(colors) {
|
|
2986
|
+
for (const [handle, color] of colors) {
|
|
2987
|
+
if (color === null || color === undefined) {
|
|
2988
|
+
this.colorOverrides.delete(handle);
|
|
2989
|
+
} else {
|
|
2990
|
+
this.colorOverrides.set(handle, new Color(color));
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
this.syncColorOverrides();
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
clearAllColorOverrides() {
|
|
2997
|
+
this.colorOverrides.clear();
|
|
2998
|
+
this.syncColorOverrides();
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
getOptimizedHandles() {
|
|
3002
|
+
return Array.from(this.handleToOptimizedObjects.keys());
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
syncColorOverrides() {
|
|
3006
|
+
const data = this.colorOverrideData;
|
|
3007
|
+
const texelCount = data.length / 4;
|
|
3008
|
+
data.fill(0);
|
|
3009
|
+
|
|
3010
|
+
this.colorOverrides.forEach((color, handle) => {
|
|
3011
|
+
const index = this.objectIdToIndex.get(handle);
|
|
3012
|
+
if (index === undefined || index >= texelCount) return;
|
|
3013
|
+
const offset = index * 4;
|
|
3014
|
+
data[offset] = Math.round(MathUtils.clamp(color.r, 0, 1) * 255);
|
|
3015
|
+
data[offset + 1] = Math.round(MathUtils.clamp(color.g, 0, 1) * 255);
|
|
3016
|
+
data[offset + 2] = Math.round(MathUtils.clamp(color.b, 0, 1) * 255);
|
|
3017
|
+
data[offset + 3] = 255;
|
|
3018
|
+
});
|
|
3019
|
+
|
|
3020
|
+
this.objectStateUniforms.colorOverrideTexture.value.needsUpdate = true;
|
|
3021
|
+
}
|
|
3022
|
+
|
|
3023
|
+
// fillColor/lineColor: highlight color for faces (meshes, lines, points) / edges ("edges" material)
|
|
3024
|
+
// fillMix/lineMix: 0..1 blend with the original color (1 = replace)
|
|
3025
|
+
// fillOpacity: opacity of highlighted geometry in the main pass (-1 = keep material opacity)
|
|
3026
|
+
// emissiveIntensity: adds highlight color on top of lighting
|
|
3027
|
+
// facesOverlay/edgesOverlay (or overlay for both): draw highlighted faces / "edges" material geometry
|
|
3028
|
+
// again on top of everything (depthTest off) with overlayOpacity
|
|
3029
|
+
setHighlightStyle(name, settings = {}) {
|
|
3030
|
+
let index = this.highlightStyleNames.get(name);
|
|
3031
|
+
if (index === undefined) {
|
|
3032
|
+
if (this.highlightStyles.length >= MAX_HIGHLIGHT_STYLES) {
|
|
3033
|
+
console.warn(`DynamicLoader: Max highlight styles (${MAX_HIGHLIGHT_STYLES}) reached, "${name}" ignored`);
|
|
3034
|
+
return;
|
|
3035
|
+
}
|
|
3036
|
+
index = this.highlightStyles.length;
|
|
3037
|
+
this.highlightStyleNames.set(name, index);
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
const style = {
|
|
3041
|
+
fillColor: new Color(settings.fillColor ?? 0x4aa9fa),
|
|
3042
|
+
fillMix: settings.fillMix ?? 1,
|
|
3043
|
+
fillOpacity: settings.fillOpacity ?? -1,
|
|
3044
|
+
lineColor: new Color(settings.lineColor ?? settings.fillColor ?? 0x4aa9fa),
|
|
3045
|
+
lineMix: settings.lineMix ?? 1,
|
|
3046
|
+
emissiveIntensity: settings.emissiveIntensity ?? 0,
|
|
3047
|
+
facesOverlay: settings.facesOverlay ?? settings.overlay ?? true,
|
|
3048
|
+
edgesOverlay: settings.edgesOverlay ?? settings.overlay ?? true,
|
|
3049
|
+
overlayOpacity: settings.overlayOpacity ?? 1,
|
|
3050
|
+
};
|
|
3051
|
+
this.highlightStyles[index] = style;
|
|
3052
|
+
|
|
3053
|
+
const vectors = this.objectStateUniforms.highlightStyles.value;
|
|
3054
|
+
const base = index * HIGHLIGHT_STYLE_VEC4_COUNT;
|
|
3055
|
+
vectors[base].set(style.fillColor.r, style.fillColor.g, style.fillColor.b, style.fillMix);
|
|
3056
|
+
vectors[base + 1].set(style.lineColor.r, style.lineColor.g, style.lineColor.b, style.lineMix);
|
|
3057
|
+
vectors[base + 2].set(style.emissiveIntensity, style.overlayOpacity, style.facesOverlay ? 1 : 0, style.fillOpacity);
|
|
3058
|
+
vectors[base + 3].set(style.edgesOverlay ? 1 : 0, 0, 0, 0);
|
|
3059
|
+
|
|
3060
|
+
// Overlay visibility depends on style.facesOverlay/edgesOverlay
|
|
3061
|
+
if (this.highlightedHandles.size !== 0) {
|
|
3062
|
+
this.syncHighlightedObjects();
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
// Viewer-level highlight settings:
|
|
3067
|
+
// facesColor/edgesColor: highlight color of faces (meshes, lines, points) / edges ("edges" material)
|
|
3068
|
+
// edgesVisibility: false keeps edges in their own color
|
|
3069
|
+
// colorBlend: 0..1 blend between original and highlight color (1 = highlight color only)
|
|
3070
|
+
// facesOverlap/edgesOverlap: draw highlighted faces / edges on top of other geometry
|
|
3071
|
+
setHighlightSettings(settings = {}, styleName = "default") {
|
|
3072
|
+
const index = this.highlightStyleNames.get(styleName);
|
|
3073
|
+
const current = index !== undefined ? this.highlightStyles[index] : {};
|
|
3074
|
+
const merged = {
|
|
3075
|
+
facesColor: current.fillColor,
|
|
3076
|
+
edgesColor: current.lineColor,
|
|
3077
|
+
edgesVisibility: true,
|
|
3078
|
+
edgesOverlap: true,
|
|
3079
|
+
facesOverlap: true,
|
|
3080
|
+
colorBlend: 1,
|
|
3081
|
+
...current.viewerSettings,
|
|
3082
|
+
...settings,
|
|
3083
|
+
};
|
|
3084
|
+
|
|
3085
|
+
this.setHighlightStyle(styleName, {
|
|
3086
|
+
...current,
|
|
3087
|
+
fillColor: merged.facesColor,
|
|
3088
|
+
lineColor: merged.edgesColor,
|
|
3089
|
+
fillMix: merged.colorBlend,
|
|
3090
|
+
lineMix: merged.edgesVisibility ? merged.colorBlend : 0,
|
|
3091
|
+
facesOverlay: merged.facesOverlap,
|
|
3092
|
+
edgesOverlay: merged.edgesVisibility && merged.edgesOverlap,
|
|
3093
|
+
});
|
|
3094
|
+
|
|
3095
|
+
const style = this.highlightStyles[this.highlightStyleNames.get(styleName)];
|
|
3096
|
+
if (style) style.viewerSettings = merged;
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
highlightObjects(handles, styleName = "default") {
|
|
3100
|
+
const styleIndex = this.highlightStyleNames.get(styleName);
|
|
3101
|
+
if (styleIndex === undefined) {
|
|
3102
|
+
console.warn(`DynamicLoader: Unknown highlight style "${styleName}"`);
|
|
3103
|
+
return;
|
|
3104
|
+
}
|
|
3105
|
+
handles.forEach((handle) => {
|
|
3106
|
+
this.highlightedHandles.set(handle, styleIndex);
|
|
3107
|
+
});
|
|
3108
|
+
this.syncHighlightedObjects();
|
|
3109
|
+
}
|
|
3110
|
+
|
|
3111
|
+
unhighlightObjects(handles) {
|
|
3112
|
+
handles.forEach((handle) => {
|
|
3113
|
+
this.highlightedHandles.delete(handle);
|
|
3114
|
+
});
|
|
3115
|
+
this.syncHighlightedObjects();
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
unhighlightAllObjects() {
|
|
3119
|
+
this.highlightedHandles.clear();
|
|
3120
|
+
this.syncHighlightedObjects();
|
|
3121
|
+
}
|
|
3122
|
+
|
|
3123
|
+
isHandleHighlighted(handle) {
|
|
3124
|
+
return this.highlightedHandles.has(handle);
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
isHandleOptimized(handle) {
|
|
3128
|
+
return this.handleToOptimizedObjects.has(handle);
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
syncHighlightedObjects() {
|
|
3132
|
+
const data = this.highlightData;
|
|
3133
|
+
const texelCount = data.length / 4;
|
|
3134
|
+
data.fill(0);
|
|
3135
|
+
|
|
3136
|
+
const overlayTargets = new Set();
|
|
3137
|
+
this.highlightedHandles.forEach((styleIndex, handle) => {
|
|
3138
|
+
const index = this.objectIdToIndex.get(handle);
|
|
3139
|
+
if (index === undefined || index >= texelCount) return;
|
|
3140
|
+
data[index * 4] = styleIndex + 1;
|
|
3141
|
+
|
|
3142
|
+
const style = this.highlightStyles[styleIndex];
|
|
3143
|
+
if (style.facesOverlay || style.edgesOverlay) {
|
|
3144
|
+
const mergedObjects = this.handleToOptimizedObjects.get(handle);
|
|
3145
|
+
if (!mergedObjects) return;
|
|
3146
|
+
mergedObjects.forEach((object) => {
|
|
3147
|
+
if (object.userData.isEdge ? style.edgesOverlay : style.facesOverlay) overlayTargets.add(object);
|
|
3148
|
+
});
|
|
3149
|
+
}
|
|
3150
|
+
});
|
|
3151
|
+
|
|
3152
|
+
this.objectStateUniforms.highlightTexture.value.needsUpdate = true;
|
|
3153
|
+
|
|
3154
|
+
// Overlay pass only for merged objects that contain highlighted handles
|
|
3155
|
+
this.highlightOverlays.forEach((overlay, mergedObject) => {
|
|
3156
|
+
overlay.visible = overlayTargets.has(mergedObject);
|
|
3157
|
+
});
|
|
3158
|
+
overlayTargets.forEach((mergedObject) => {
|
|
3159
|
+
if (!this.highlightOverlays.has(mergedObject)) {
|
|
3160
|
+
this._createHighlightOverlay(mergedObject);
|
|
3161
|
+
}
|
|
3162
|
+
});
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
_getHighlightOverlayMaterial(mergedObject) {
|
|
3166
|
+
if (!this.highlightOverlayMaterials) {
|
|
3167
|
+
const common = { transparent: true, depthTest: false, depthWrite: false };
|
|
3168
|
+
this.highlightOverlayMaterials = {
|
|
3169
|
+
mesh: this.createVisibilityMaterial(new MeshPhongMaterial({ ...common, specular: 0x222222, shininess: 0 }), {
|
|
3170
|
+
overlay: true,
|
|
3171
|
+
}),
|
|
3172
|
+
line: this.createVisibilityMaterial(new LineBasicMaterial({ ...common }), { overlay: true }),
|
|
3173
|
+
edges: this.createVisibilityMaterial(new LineBasicMaterial({ ...common }), { overlay: true, edges: true }),
|
|
3174
|
+
points: this.createVisibilityMaterial(new PointsMaterial({ ...common, size: 0.05, sizeAttenuation: false }), {
|
|
3175
|
+
overlay: true,
|
|
3176
|
+
}),
|
|
3177
|
+
};
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
if (mergedObject.isPoints) return this.highlightOverlayMaterials.points;
|
|
3181
|
+
if (mergedObject.isLine) {
|
|
3182
|
+
return mergedObject.userData.isEdge ? this.highlightOverlayMaterials.edges : this.highlightOverlayMaterials.line;
|
|
3183
|
+
}
|
|
3184
|
+
return this.highlightOverlayMaterials.mesh;
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
_createHighlightOverlay(mergedObject) {
|
|
3188
|
+
// Shares geometry with the merged object, so transforms/visibility attributes apply as-is
|
|
3189
|
+
const overlay = new mergedObject.constructor(
|
|
3190
|
+
mergedObject.geometry,
|
|
3191
|
+
this._getHighlightOverlayMaterial(mergedObject)
|
|
3192
|
+
);
|
|
3193
|
+
overlay.frustumCulled = false;
|
|
3194
|
+
overlay.renderOrder = HIGHLIGHT_OVERLAY_RENDER_ORDER;
|
|
3195
|
+
overlay.raycast = () => {};
|
|
3196
|
+
overlay.userData.isHighlightOverlay = true;
|
|
3197
|
+
mergedObject.add(overlay);
|
|
3198
|
+
this.highlightOverlays.set(mergedObject, overlay);
|
|
3199
|
+
return overlay;
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
_disposeHighlightOverlays() {
|
|
3203
|
+
this.highlightOverlays.forEach((overlay) => {
|
|
3204
|
+
if (overlay.parent) overlay.parent.remove(overlay);
|
|
3205
|
+
});
|
|
3206
|
+
this.highlightOverlays.clear();
|
|
3207
|
+
|
|
3208
|
+
if (this.highlightOverlayMaterials) {
|
|
3209
|
+
Object.values(this.highlightOverlayMaterials).forEach((material) => {
|
|
3210
|
+
this.visibilityMaterials.delete(material);
|
|
3211
|
+
material.dispose();
|
|
3212
|
+
});
|
|
3213
|
+
this.highlightOverlayMaterials = null;
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
|
|
2790
3217
|
_updateVisibilityAttribute(mergedObject) {
|
|
2791
3218
|
if (
|
|
2792
3219
|
mergedObject.geometry &&
|
|
@@ -32,6 +32,10 @@ import { DynamicGltfLoader } from "./DynamicGltfLoader.js";
|
|
|
32
32
|
export class DynamicModelImpl extends ModelImpl {
|
|
33
33
|
public gltfLoader: DynamicGltfLoader;
|
|
34
34
|
|
|
35
|
+
override initialize() {
|
|
36
|
+
// do not call super !!!
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
override getInfo(): IInfo {
|
|
36
40
|
const stats = this.gltfLoader.getStats();
|
|
37
41
|
|
|
@@ -73,62 +77,47 @@ export class DynamicModelImpl extends ModelImpl {
|
|
|
73
77
|
return this.gltfLoader.getOriginalObjectForSelect();
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
override getObjectsByHandles(handles: string
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const handlesSet = new Set(handles);
|
|
80
|
-
|
|
81
|
-
const objects: Object3D[] = [];
|
|
82
|
-
handlesSet.forEach((handle) => {
|
|
83
|
-
objects.push(this.gltfLoader.getObjectsByHandle(handle));
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return objects.flat();
|
|
80
|
+
override getObjectsByHandles(handles: string[]): Object3D[] {
|
|
81
|
+
return handles.flatMap((handle) => this.gltfLoader.getObjectsByHandle(handle));
|
|
87
82
|
}
|
|
88
83
|
|
|
89
|
-
override
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const handleSet = new Set<string>();
|
|
93
|
-
objects
|
|
94
|
-
.filter((object) => this.gltfLoader.originalObjects.has(object))
|
|
95
|
-
.forEach((object) => {
|
|
96
|
-
handleSet.add(object.userData.handle);
|
|
97
|
-
});
|
|
84
|
+
override getHandles(): string[] {
|
|
85
|
+
return Array.from(this.gltfLoader.handleToObjects.keys());
|
|
86
|
+
}
|
|
98
87
|
|
|
99
|
-
|
|
88
|
+
override getHandlesByObjects(objects: Object3D[]): string[] {
|
|
89
|
+
return this.gltfLoader.getHandlesByObjects(objects);
|
|
100
90
|
}
|
|
101
91
|
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
// IModel
|
|
93
|
+
|
|
94
|
+
override hide(handles: string[]): this {
|
|
104
95
|
this.gltfLoader.hideObjects(handles);
|
|
105
96
|
return this;
|
|
106
97
|
}
|
|
107
98
|
|
|
108
|
-
override
|
|
109
|
-
const handles = this.getHandlesByObjects(objects);
|
|
99
|
+
override isolate(handles: string[]): this {
|
|
110
100
|
this.gltfLoader.isolateObjects(new Set(handles));
|
|
111
101
|
return this;
|
|
112
102
|
}
|
|
113
103
|
|
|
114
|
-
override
|
|
115
|
-
const handles = this.getHandlesByObjects(objects);
|
|
104
|
+
override show(handles: string[]): this {
|
|
116
105
|
this.gltfLoader.showObjects(handles);
|
|
117
106
|
return this;
|
|
118
107
|
}
|
|
119
108
|
|
|
120
|
-
override
|
|
109
|
+
override showAll(): this {
|
|
121
110
|
this.gltfLoader.showAllHiddenObjects();
|
|
122
111
|
return this;
|
|
123
112
|
}
|
|
124
113
|
|
|
125
|
-
override
|
|
126
|
-
this.gltfLoader.
|
|
114
|
+
override highlight(handles: string[]): this {
|
|
115
|
+
this.gltfLoader.highlightObjects(handles);
|
|
127
116
|
return this;
|
|
128
117
|
}
|
|
129
118
|
|
|
130
|
-
override
|
|
131
|
-
this.gltfLoader.
|
|
119
|
+
override unhighlight(handles: string[]): this {
|
|
120
|
+
this.gltfLoader.unhighlightObjects(handles);
|
|
132
121
|
return this;
|
|
133
122
|
}
|
|
134
123
|
|
|
@@ -141,14 +130,16 @@ export class DynamicModelImpl extends ModelImpl {
|
|
|
141
130
|
const handle = object.userData.handle;
|
|
142
131
|
if (!handle) return extents.getCenter(target);
|
|
143
132
|
|
|
144
|
-
const
|
|
133
|
+
const fullHandle = handle; // <- DynamicGltfLoader uses composite handles by default
|
|
134
|
+
|
|
135
|
+
const center = centersCache.get(fullHandle);
|
|
145
136
|
if (center) return target.copy(center);
|
|
146
137
|
|
|
147
|
-
const objects = this.getObjectsByHandles(
|
|
138
|
+
const objects = this.getObjectsByHandles([fullHandle]);
|
|
148
139
|
objects.forEach((x: Object3D) => extents.expandByObject(x));
|
|
149
140
|
extents.getCenter(target);
|
|
150
141
|
|
|
151
|
-
centersCache.set(
|
|
142
|
+
centersCache.set(fullHandle, target.clone());
|
|
152
143
|
|
|
153
144
|
return target;
|
|
154
145
|
};
|