@inweb/viewer-three 25.12.1 → 25.12.2

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.
@@ -1,7 +1,9 @@
1
- import { Vector2, Raycaster, MeshBasicMaterial, Box3, Vector3, Sphere, LoadingManager, LoaderUtils, EventDispatcher, MOUSE, TOUCH, Quaternion, Spherical, Controls, Clock, Line, BufferGeometry, Float32BufferAttribute, LineBasicMaterial, Mesh, DoubleSide, Plane, Object3D, Matrix4, Vector4, AmbientLight, DirectionalLight, Color, PMREMGenerator, OrthographicCamera, CylinderGeometry, Sprite, CanvasTexture, SRGBColorSpace, SpriteMaterial, Scene, PerspectiveCamera, WebGLRenderer, LinearToneMapping } from "three";
1
+ import { Vector2, Raycaster, MeshBasicMaterial, Box3, Vector3, Sphere, LoadingManager, LoaderUtils, Group, Matrix4, Scene, PerspectiveCamera, BufferGeometry, BufferAttribute, Mesh, LineBasicMaterial, Line, Color, Loader, FileLoader, EventDispatcher, MOUSE, TOUCH, Spherical, Quaternion, Controls, Clock, Float32BufferAttribute, DoubleSide, Plane, Object3D, Vector4, AmbientLight, DirectionalLight, PMREMGenerator, OrthographicCamera, CylinderGeometry, Sprite, CanvasTexture, SRGBColorSpace, SpriteMaterial, WebGLRenderer, LinearToneMapping } from "three";
2
2
 
3
3
  import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
4
4
 
5
+ import { USDZLoader } from "three/examples/jsm/loaders/USDZLoader.js";
6
+
5
7
  import Konva from "konva";
6
8
 
7
9
  import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
@@ -43,7 +45,7 @@ class Commands {
43
45
  }
44
46
  const {handler: handler, thisArg: thisArg} = command;
45
47
  const result = handler.apply(thisArg, [ viewer, ...args ]);
46
- viewer === null || viewer === void 0 ? void 0 : viewer.emit({
48
+ viewer === null || viewer === undefined ? undefined : viewer.emit({
47
49
  type: "command",
48
50
  data: id,
49
51
  args: args
@@ -569,12 +571,12 @@ commands("ThreeJS").registerCommand("explode", explode);
569
571
  commands("ThreeJS").registerCommand("collect", (viewer => explode(viewer, 0)));
570
572
 
571
573
  const defaultViewPositions = {
572
- top: new Vector3(0, 0, 1),
573
- bottom: new Vector3(0, 0, -1),
574
+ top: new Vector3(0, 1, 0),
575
+ bottom: new Vector3(0, -1, 0),
574
576
  left: new Vector3(-1, 0, 0),
575
577
  right: new Vector3(1, 0, 0),
576
- front: new Vector3(0, -1, 0),
577
- back: new Vector3(0, 1, 0),
578
+ front: new Vector3(0, 0, 1),
579
+ back: new Vector3(0, 0, -1),
578
580
  sw: new Vector3(-.5, -.5, 1).normalize(),
579
581
  se: new Vector3(.5, -.5, 1).normalize(),
580
582
  ne: new Vector3(.5, .5, 1).normalize(),
@@ -658,7 +660,7 @@ commands("ThreeJS").registerCommand("getModels", getModels);
658
660
  function getSelected(viewer) {
659
661
  return viewer.selected.map((object => {
660
662
  var _a;
661
- return (_a = object.userData) === null || _a === void 0 ? void 0 : _a.handle;
663
+ return (_a = object.userData) === null || _a === undefined ? undefined : _a.handle;
662
664
  })).filter((handle => handle));
663
665
  }
664
666
 
@@ -750,7 +752,7 @@ function setSelected(viewer, handles = []) {
750
752
  const objects = [];
751
753
  viewer.scene.traverseVisible((child => {
752
754
  var _a;
753
- if (handleSet.has((_a = child.userData) === null || _a === void 0 ? void 0 : _a.handle)) objects.push(child);
755
+ if (handleSet.has((_a = child.userData) === null || _a === undefined ? undefined : _a.handle)) objects.push(child);
754
756
  }));
755
757
  const selection = new SelectionComponent(viewer);
756
758
  selection.clearSelection();
@@ -800,7 +802,7 @@ function zoomToObjects(viewer, handles = []) {
800
802
  const objects = [];
801
803
  viewer.scene.traverseVisible((child => {
802
804
  var _a;
803
- if (handleSet.has((_a = child.userData) === null || _a === void 0 ? void 0 : _a.handle)) objects.push(child);
805
+ if (handleSet.has((_a = child.userData) === null || _a === undefined ? undefined : _a.handle)) objects.push(child);
804
806
  }));
805
807
  const extents = objects.reduce(((result, object) => result.expandByObject(object)), new Box3);
806
808
  const center = extents.getCenter(new Vector3);
@@ -859,7 +861,7 @@ class GLTFLoadingManager extends LoadingManager {
859
861
  this.setURLModifier((url => {
860
862
  const key = decodeURI(url).replace(this.path, "").replace(this.resourcePath, "").replace(/^(\.?\/)/, "");
861
863
  const dataURL = this.dataURLs.get(key);
862
- return dataURL !== null && dataURL !== void 0 ? dataURL : url;
864
+ return dataURL !== null && dataURL !== undefined ? dataURL : url;
863
865
  }));
864
866
  }
865
867
  dispose() {
@@ -867,6 +869,404 @@ class GLTFLoadingManager extends LoadingManager {
867
869
  }
868
870
  }
869
871
 
872
+ class USDZLoader2 extends USDZLoader {
873
+ parse(buffer) {
874
+ const scene = super.parse(buffer);
875
+ let handle = 0;
876
+ scene.traverse((object => {
877
+ object.userData = {
878
+ ...object.userData,
879
+ handle: handle
880
+ };
881
+ handle++;
882
+ }));
883
+ return scene;
884
+ }
885
+ load(url, onLoad, onProgress, onError) {
886
+ super.load(url, (scene => onLoad({
887
+ scene: scene
888
+ })), onProgress, onError);
889
+ }
890
+ }
891
+
892
+ const THREE = {
893
+ Box3: Box3,
894
+ BufferAttribute: BufferAttribute,
895
+ BufferGeometry: BufferGeometry,
896
+ Color: Color,
897
+ Group: Group,
898
+ Line: Line,
899
+ LineBasicMaterial: LineBasicMaterial,
900
+ Matrix4: Matrix4,
901
+ Mesh: Mesh,
902
+ MeshBasicMaterial: MeshBasicMaterial,
903
+ PerspectiveCamera: PerspectiveCamera,
904
+ Scene: Scene,
905
+ Vector3: Vector3
906
+ };
907
+
908
+ let scene, camera;
909
+
910
+ let datas = [];
911
+
912
+ let autoCamera = true;
913
+
914
+ function init() {
915
+ scene = new THREE.Scene;
916
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, .1, 100);
917
+ camera.up.set(0, 0, 1);
918
+ camera.position.set(50, 50, 50);
919
+ camera.lookAt(0, 0, 0);
920
+ return scene;
921
+ }
922
+
923
+ function getChildByName(root, childName, skip = 0) {
924
+ let fragments = childName.replace(/^<\/|^\/|>$/g, "").split("/");
925
+ for (let i = 0; i < skip; ++i) {
926
+ fragments.shift();
927
+ }
928
+ while (fragments.length && root) {
929
+ let f = fragments.shift();
930
+ root = root.children.find((i => i.name.split("/").reverse()[0] === f));
931
+ }
932
+ return root;
933
+ }
934
+
935
+ function createMaterialFromParent(parent, root) {
936
+ let reference = parent.attributes["UsdShade:MaterialBindingAPI:material:binding"];
937
+ let material = {
938
+ color: new THREE.Color(.6, .6, .6)
939
+ };
940
+ if (reference) {
941
+ const materialNode = getChildByName(root, reference.ref);
942
+ let shader = materialNode.children.find((i => i.type === "UsdShade:Shader"));
943
+ let color = shader.attributes["inputs:diffuseColor"];
944
+ material.color = new THREE.Color(...color);
945
+ if (shader.attributes["inputs:opacity"]) {
946
+ material.transparent = true;
947
+ material.opacity = shader.attributes["inputs:opacity"];
948
+ }
949
+ }
950
+ return material;
951
+ }
952
+
953
+ function createCurveFromJson(node, parent, root) {
954
+ let points = new Float32Array(node.attributes["UsdGeom:BasisCurves:points"].flat());
955
+ const geometry = new THREE.BufferGeometry;
956
+ geometry.setAttribute("position", new THREE.BufferAttribute(points, 3));
957
+ const material = createMaterialFromParent(parent, root);
958
+ let lineMaterial = new THREE.LineBasicMaterial({
959
+ ...material
960
+ });
961
+ lineMaterial.color.multiplyScalar(.8);
962
+ return new THREE.Line(geometry, lineMaterial);
963
+ }
964
+
965
+ function createMeshFromJson(node, parent, root) {
966
+ let points = new Float32Array(node.attributes["UsdGeom:Mesh:points"].flat());
967
+ let indices = new Uint16Array(node.attributes["UsdGeom:Mesh:faceVertexIndices"]);
968
+ const geometry = new THREE.BufferGeometry;
969
+ geometry.setAttribute("position", new THREE.BufferAttribute(points, 3));
970
+ geometry.setIndex(new THREE.BufferAttribute(indices, 1));
971
+ geometry.computeVertexNormals();
972
+ const material = createMaterialFromParent(parent, root);
973
+ let meshMaterial = new THREE.MeshBasicMaterial({
974
+ ...material
975
+ });
976
+ return new THREE.Mesh(geometry, meshMaterial);
977
+ }
978
+
979
+ function traverseTree(node, parent, root, parentNode) {
980
+ let elem;
981
+ if (node.type === "UsdGeom:Xform") {
982
+ elem = new THREE.Group;
983
+ } else if (node.type === "UsdGeom:Mesh" || node.type === "UsdGeom:BasisCurves") {
984
+ if (node.attributes["UsdGeom:VisibilityAPI:visibility:visibility"] === "invisible") {
985
+ return;
986
+ }
987
+ if (node.type === "UsdGeom:Mesh") {
988
+ elem = createMeshFromJson(node, parentNode, root);
989
+ } else {
990
+ elem = createCurveFromJson(node, parentNode, root);
991
+ }
992
+ } else if (node !== root) {
993
+ return;
994
+ }
995
+ if (node !== root) {
996
+ parent.add(elem);
997
+ elem.matrixAutoUpdate = false;
998
+ let matrixNode = node.attributes && node.attributes["xformOp:transform"] ? node.attributes["xformOp:transform"].flat() : null;
999
+ if (matrixNode) {
1000
+ let matrix = new THREE.Matrix4;
1001
+ matrix.set(...matrixNode);
1002
+ matrix.transpose();
1003
+ elem.matrix = matrix;
1004
+ }
1005
+ }
1006
+ (node.children || []).forEach((child => traverseTree(child, elem || parent, root, node)));
1007
+ }
1008
+
1009
+ function* collectNames(node) {
1010
+ yield node.name;
1011
+ for (const child of node.children || []) {
1012
+ yield* collectNames(child);
1013
+ }
1014
+ }
1015
+
1016
+ function compose(datas) {
1017
+ let compositionEdges = {};
1018
+ function flattenAttributes(prim) {
1019
+ if (prim.name !== "Shader" && prim.attributes) {
1020
+ const [k, vs] = Object.entries(prim.attributes)[0];
1021
+ const attrs = Object.fromEntries(Object.entries(vs).map((([kk, vv]) => [ `${k}:${kk}`, vv ])));
1022
+ return {
1023
+ ...prim,
1024
+ attributes: attrs
1025
+ };
1026
+ } else {
1027
+ return {
1028
+ ...prim
1029
+ };
1030
+ }
1031
+ }
1032
+ function addEdge(a, b) {
1033
+ (compositionEdges[a] = compositionEdges[a] || []).push(b);
1034
+ }
1035
+ function collectPaths(nodes) {
1036
+ const paths = {};
1037
+ function traverse(node, parentPathStr) {
1038
+ if (node.name) {
1039
+ const isFullyQualified = node.name.split("/").length > 2;
1040
+ const reverseWhenFullyQualified = isFullyQualified ? a => a.reverse() : a => a;
1041
+ const pathStr = `${parentPathStr}/${node.name.replace(/^\//, "")}`;
1042
+ let nodeId = pathStr;
1043
+ let nodeIdComplete = `${pathStr} complete`;
1044
+ const N = flattenAttributes(node);
1045
+ N.name = pathStr;
1046
+ if (node.def === "over") {
1047
+ nodeId = `${pathStr} over`;
1048
+ addEdge(...reverseWhenFullyQualified([ nodeId, pathStr ]));
1049
+ addEdge(nodeIdComplete, nodeId);
1050
+ }
1051
+ addEdge(nodeIdComplete, pathStr);
1052
+ (paths[nodeId] = paths[nodeId] || []).push(N);
1053
+ for (let ih of node.inherits || []) {
1054
+ const target = ih.substring(1, ih.length - 1);
1055
+ addEdge(nodeId, `${target} complete`);
1056
+ }
1057
+ (node.children || []).forEach((child => {
1058
+ if (child.name && child.def === "def") {
1059
+ const childName = `${pathStr}/${child.name}`;
1060
+ addEdge(...reverseWhenFullyQualified([ pathStr, `${childName} complete` ]));
1061
+ if (nodeId.endsWith("over")) {
1062
+ if (pathStr.split("/").length > 2) {
1063
+ addEdge(childName, `/${pathStr.split("/")[1]}`);
1064
+ }
1065
+ }
1066
+ }
1067
+ traverse(child, pathStr);
1068
+ }));
1069
+ }
1070
+ }
1071
+ nodes.forEach((n => traverse(n, "")));
1072
+ nodes.filter((n => n.name && n.def === "def")).forEach((n => {
1073
+ addEdge("", `/${n.name} complete`);
1074
+ }));
1075
+ return paths;
1076
+ }
1077
+ function removeDuplicates(map_of_arrays) {
1078
+ return Object.fromEntries(Object.entries(map_of_arrays).map((([k, vs]) => [ k, vs.filter(((value, index, array) => array.indexOf(value) === index)) ])));
1079
+ }
1080
+ const maps = datas.map(collectPaths);
1081
+ let compositionEdgesOrig = removeDuplicates(compositionEdges);
1082
+ function composePrim(right, left) {
1083
+ return {
1084
+ def: left.def || (right !== null ? right.def : null),
1085
+ type: left.type || (right !== null ? right.type : null),
1086
+ name: right ? right.name : left.name,
1087
+ attributes: {
1088
+ ...right !== null ? right.attributes : {},
1089
+ ...left !== null ? left.attributes : {}
1090
+ },
1091
+ children: (left.children || []).concat(right ? right.children || [] : [])
1092
+ };
1093
+ }
1094
+ compositionEdges = Object.fromEntries(Object.entries(compositionEdgesOrig).map((([item, dep]) => [ item, new Set([ ...dep ].filter((e => e !== item))) ])));
1095
+ const extraItemsInDeps = new Set([ ...Object.values(compositionEdges).map((st => Array.from(st))).flat() ].filter((value => !compositionEdges.hasOwnProperty(value))));
1096
+ extraItemsInDeps.forEach((item => {
1097
+ if (maps.map((m => m[item])).some((i => i))) {
1098
+ compositionEdges[item] = new Set;
1099
+ }
1100
+ }));
1101
+ const composed = {};
1102
+ const built = new Set;
1103
+ Object.keys(compositionEdges).forEach((p => {
1104
+ const opinions = maps.map((m => m[p])).filter((a => a)).flat(1);
1105
+ if (p == "") {
1106
+ composed[p] = {
1107
+ name: p
1108
+ };
1109
+ } else if (opinions.length === 0) {
1110
+ return;
1111
+ } else if (opinions.length == 1) {
1112
+ composed[p] = composePrim(null, opinions[0]);
1113
+ } else {
1114
+ composed[p] = opinions.reverse().reduce(composePrim);
1115
+ }
1116
+ delete composed[p].children;
1117
+ }));
1118
+ const updateName = (oldPrefix, newPrefix, prim) => ({
1119
+ ...prim,
1120
+ name: prim.name.replace(new RegExp(`^${oldPrefix}(?=/)`), newPrefix),
1121
+ children: prim.children.map((c => updateName(oldPrefix, newPrefix, c)))
1122
+ });
1123
+ let maxIterations = 100;
1124
+ while (maxIterations--) {
1125
+ const bottomRankNodes = Object.entries(compositionEdges).filter((([_, dep]) => dep.size === 0 && (composed[_] || built.has(_) || _.endsWith(" complete")))).map((([k, v]) => k));
1126
+ console.log("Bottom rank prims to resolve:", ...bottomRankNodes);
1127
+ if (bottomRankNodes.length === 0) {
1128
+ break;
1129
+ }
1130
+ const definedPrims = new Set;
1131
+ bottomRankNodes.forEach((k => {
1132
+ Array.from(compositionEdgesOrig[k] || []).forEach((v => {
1133
+ console.log("Processing edge:", k, " --- ", v);
1134
+ if (k.endsWith(" complete") && v.endsWith(" over")) ; else if (v.startsWith(k + "/")) {
1135
+ if (k.split("/").length > 2) ; else {
1136
+ v = v.replace(/ complete$/, "");
1137
+ composed[k].children = composed[k].children || [];
1138
+ composed[k].children.push(composed[v]);
1139
+ Array.from(collectNames(composed[k])).forEach((a => definedPrims.add(a.substring(k.length))));
1140
+ }
1141
+ } else if (k.startsWith(v + "/")) {
1142
+ if (k.endsWith(" complete")) {
1143
+ let child = getChildByName(composed[`/${v.split("/")[1]}`], v, 1);
1144
+ if (child) {
1145
+ k = k.replace(/ complete$/, "");
1146
+ child.children.push(composed[k]);
1147
+ } else {
1148
+ console.error(v, "--\x3e", k, "not applied");
1149
+ }
1150
+ Array.from(collectNames(child)).forEach((a => definedPrims.add(a.substring(child.name.length))));
1151
+ }
1152
+ } else if (k.search(/over$/) !== -1) {
1153
+ if (k.split("/").length > 2) {
1154
+ let child = getChildByName(composed[`/${v.split("/")[1]}`], k.split(" ")[0], 1);
1155
+ if (child) {
1156
+ Object.assign(child.attributes, composed[k].attributes);
1157
+ } else {
1158
+ console.error(k, "--\x3e", v, "not applied");
1159
+ }
1160
+ } else {
1161
+ composed[v] = composePrim(composed[v], composed[k]);
1162
+ }
1163
+ } else if (v.search(/over$/) !== -1) {
1164
+ if (v.split("/").length > 2) {
1165
+ let child = getChildByName(composed[`/${k.split("/")[1]}`], v.split(" ")[0], 1);
1166
+ if (child) {
1167
+ Object.assign(child.attributes, composed[v].attributes);
1168
+ } else {
1169
+ console.error(v, "--\x3e", k, "not registered");
1170
+ }
1171
+ } else {
1172
+ composed[k] = composePrim(composed[k], composed[v]);
1173
+ }
1174
+ } else {
1175
+ if (v.endsWith("complete")) {
1176
+ v = v.replace(/ complete$/, "");
1177
+ composed[k] = updateName(composed[v].name, composed[k].name, composePrim(composed[k], composed[v]));
1178
+ Array.from(collectNames(composed[k])).forEach((a => definedPrims.add(a.substring(k.length))));
1179
+ }
1180
+ }
1181
+ }));
1182
+ }));
1183
+ console.log("Constructed prims:", ...definedPrims);
1184
+ Array.from(definedPrims).forEach((a => built.add(a)));
1185
+ let orderedSet = new Set(bottomRankNodes);
1186
+ compositionEdges = Object.fromEntries(Object.entries(compositionEdges).filter((([item]) => !orderedSet.has(item))).map((([item, dep]) => [ item, new Set([ ...dep ].filter((d => !orderedSet.has(d) && !definedPrims.has(d)))) ])));
1187
+ }
1188
+ if (Object.keys(compositionEdges).length !== 0) {
1189
+ console.error("Unresolved nodes:", ...Object.keys(compositionEdges));
1190
+ }
1191
+ console.log(composed[""]);
1192
+ return composed[""];
1193
+ }
1194
+
1195
+ function composeAndRender() {
1196
+ if (scene) {
1197
+ scene.children = [];
1198
+ }
1199
+ if (datas.length === 0) {
1200
+ return;
1201
+ }
1202
+ const tree = compose(datas.map((arr => arr[1])));
1203
+ if (!tree) {
1204
+ console.error("No result from composition");
1205
+ return;
1206
+ }
1207
+ traverseTree(tree, scene || init(), tree);
1208
+ if (autoCamera) {
1209
+ const boundingBox = new THREE.Box3;
1210
+ boundingBox.setFromObject(scene);
1211
+ if (!boundingBox.isEmpty()) {
1212
+ let avg = boundingBox.min.clone().add(boundingBox.max).multiplyScalar(.5);
1213
+ let ext = boundingBox.max.clone().sub(boundingBox.min).length();
1214
+ camera.position.copy(avg.clone().add(new THREE.Vector3(1, 1, 1).normalize().multiplyScalar(ext)));
1215
+ camera.far = ext * 3;
1216
+ camera.updateProjectionMatrix();
1217
+ autoCamera = false;
1218
+ }
1219
+ }
1220
+ }
1221
+
1222
+ function addModel(name, m) {
1223
+ datas.push([ name, m ]);
1224
+ composeAndRender();
1225
+ return scene;
1226
+ }
1227
+
1228
+ function clear() {
1229
+ scene = undefined;
1230
+ camera = undefined;
1231
+ datas.length = 0;
1232
+ autoCamera = true;
1233
+ }
1234
+
1235
+ class IFCXLoader extends Loader {
1236
+ load(url, onLoad, onProgress, onError) {
1237
+ const loader = new FileLoader(this.manager);
1238
+ loader.setPath(this.path);
1239
+ loader.setResponseType("json");
1240
+ loader.setRequestHeader(this.requestHeader);
1241
+ loader.setWithCredentials(this.withCredentials);
1242
+ loader.load(url, (buffer => {
1243
+ try {
1244
+ const scene = addModel("", buffer);
1245
+ let handle = 0;
1246
+ scene.traverse((object => {
1247
+ object.userData = {
1248
+ ...object.userData,
1249
+ handle: handle
1250
+ };
1251
+ handle++;
1252
+ }));
1253
+ onLoad({
1254
+ scene: scene
1255
+ });
1256
+ } catch (e) {
1257
+ if (onError) {
1258
+ onError(e);
1259
+ } else {
1260
+ console.error(e);
1261
+ }
1262
+ this.manager.itemError(url);
1263
+ } finally {
1264
+ clear();
1265
+ }
1266
+ }), onProgress, onError);
1267
+ }
1268
+ }
1269
+
870
1270
  class EventEmitter2 {
871
1271
  constructor() {
872
1272
  this._listeners = {};
@@ -978,8 +1378,8 @@ class KonvaLine {
978
1378
  const konvaPoints = [];
979
1379
  params.points.forEach((point => konvaPoints.push(point.x, point.y)));
980
1380
  this._ref = new Konva.Line({
981
- stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
982
- strokeWidth: (_b = params.width) !== null && _b !== void 0 ? _b : 4,
1381
+ stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
1382
+ strokeWidth: (_b = params.width) !== null && _b !== undefined ? _b : 4,
983
1383
  globalCompositeOperation: "source-over",
984
1384
  lineCap: "round",
985
1385
  lineJoin: "round",
@@ -1086,12 +1486,12 @@ class KonvaText {
1086
1486
  x: params.position.x,
1087
1487
  y: params.position.y,
1088
1488
  text: params.text,
1089
- fontSize: (_a = params.fontSize) !== null && _a !== void 0 ? _a : 34,
1489
+ fontSize: (_a = params.fontSize) !== null && _a !== undefined ? _a : 34,
1090
1490
  fontFamily: this.TEXT_FONT_FAMILY,
1091
- fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
1491
+ fill: (_b = params.color) !== null && _b !== undefined ? _b : "#ff0000",
1092
1492
  align: "left",
1093
1493
  draggable: true,
1094
- rotation: (_c = params.rotation) !== null && _c !== void 0 ? _c : 0
1494
+ rotation: (_c = params.rotation) !== null && _c !== undefined ? _c : 0
1095
1495
  });
1096
1496
  this._ref.width(this._ref.getTextWidth());
1097
1497
  this._ref.on("transform", (e => {
@@ -1189,15 +1589,15 @@ class KonvaRectangle {
1189
1589
  y: 100
1190
1590
  };
1191
1591
  this._ref = new Konva.Rect({
1192
- stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
1193
- strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
1592
+ stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
1593
+ strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
1194
1594
  globalCompositeOperation: "source-over",
1195
1595
  lineCap: "round",
1196
1596
  lineJoin: "round",
1197
1597
  x: params.position.x,
1198
1598
  y: params.position.y,
1199
- width: (_c = params.width) !== null && _c !== void 0 ? _c : 200,
1200
- height: (_d = params.height) !== null && _d !== void 0 ? _d : 200,
1599
+ width: (_c = params.width) !== null && _c !== undefined ? _c : 200,
1600
+ height: (_d = params.height) !== null && _d !== undefined ? _d : 200,
1201
1601
  draggable: true,
1202
1602
  strokeScaleEnabled: false
1203
1603
  });
@@ -1307,8 +1707,8 @@ class KonvaEllipse {
1307
1707
  y: 25
1308
1708
  };
1309
1709
  this._ref = new Konva.Ellipse({
1310
- stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
1311
- strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
1710
+ stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
1711
+ strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
1312
1712
  globalCompositeOperation: "source-over",
1313
1713
  lineCap: "round",
1314
1714
  lineJoin: "round",
@@ -1437,8 +1837,8 @@ class KonvaArrow {
1437
1837
  y: 100
1438
1838
  };
1439
1839
  this._ref = new Konva.Arrow({
1440
- stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
1441
- fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
1840
+ stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
1841
+ fill: (_b = params.color) !== null && _b !== undefined ? _b : "#ff0000",
1442
1842
  strokeWidth: 4,
1443
1843
  globalCompositeOperation: "source-over",
1444
1844
  lineCap: "round",
@@ -1578,8 +1978,8 @@ class KonvaImage {
1578
1978
  x: params.position.x,
1579
1979
  y: params.position.y,
1580
1980
  image: this._canvasImage,
1581
- width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
1582
- height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
1981
+ width: (_a = params.width) !== null && _a !== undefined ? _a : 0,
1982
+ height: (_b = params.height) !== null && _b !== undefined ? _b : 0,
1583
1983
  draggable: true
1584
1984
  });
1585
1985
  this._ref.on("transform", (e => {
@@ -1689,10 +2089,10 @@ class KonvaCloud {
1689
2089
  this._ref = new Konva.Shape({
1690
2090
  x: params.position.x,
1691
2091
  y: params.position.y,
1692
- width: (_a = params.width) !== null && _a !== void 0 ? _a : 200,
1693
- height: (_b = params.height) !== null && _b !== void 0 ? _b : 200,
1694
- stroke: (_c = params.color) !== null && _c !== void 0 ? _c : "#ff0000",
1695
- strokeWidth: (_d = params.lineWidth) !== null && _d !== void 0 ? _d : 4,
2092
+ width: (_a = params.width) !== null && _a !== undefined ? _a : 200,
2093
+ height: (_b = params.height) !== null && _b !== undefined ? _b : 200,
2094
+ stroke: (_c = params.color) !== null && _c !== undefined ? _c : "#ff0000",
2095
+ strokeWidth: (_d = params.lineWidth) !== null && _d !== undefined ? _d : 4,
1696
2096
  draggable: true,
1697
2097
  strokeScaleEnabled: false,
1698
2098
  globalCompositeOperation: "source-over",
@@ -1941,9 +2341,9 @@ class KonvaMarkup {
1941
2341
  initialize(container, containerEvents, viewer, worldTransformer) {
1942
2342
  if (!Konva) throw new Error('Markup error: Konva is not initialized. Forgot to add <script src="https://unpkg.com/konva@9/konva.min.js"><\/script> to your page?');
1943
2343
  this._viewer = viewer;
1944
- this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
2344
+ this._worldTransformer = worldTransformer !== null && worldTransformer !== undefined ? worldTransformer : new WorldTransform;
1945
2345
  this._container = container;
1946
- this._containerEvents = containerEvents !== null && containerEvents !== void 0 ? containerEvents : [];
2346
+ this._containerEvents = containerEvents !== null && containerEvents !== undefined ? containerEvents : [];
1947
2347
  this._markupContainer = document.createElement("div");
1948
2348
  this._markupContainer.id = "markup-container";
1949
2349
  this._markupContainer.style.position = "absolute";
@@ -1971,9 +2371,9 @@ class KonvaMarkup {
1971
2371
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
1972
2372
  }
1973
2373
  this.destroyKonva();
1974
- (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
2374
+ (_a = this._resizeObserver) === null || _a === undefined ? undefined : _a.disconnect();
1975
2375
  this._resizeObserver = undefined;
1976
- (_b = this._markupContainer) === null || _b === void 0 ? void 0 : _b.remove();
2376
+ (_b = this._markupContainer) === null || _b === undefined ? undefined : _b.remove();
1977
2377
  this._markupContainer = undefined;
1978
2378
  this._container = undefined;
1979
2379
  this._viewer = undefined;
@@ -2005,14 +2405,14 @@ class KonvaMarkup {
2005
2405
  const hexColor = new MarkupColor(r, g, b).asHex();
2006
2406
  this.getObjects().filter((obj => {
2007
2407
  var _a;
2008
- return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
2408
+ return (_a = obj.setColor) === null || _a === undefined ? undefined : _a.call(obj, hexColor);
2009
2409
  }));
2010
2410
  }
2011
2411
  colorizeSelectedMarkups(r, g, b) {
2012
2412
  const hexColor = new MarkupColor(r, g, b).asHex();
2013
2413
  this.getSelectedObjects().filter((obj => {
2014
2414
  var _a;
2015
- return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
2415
+ return (_a = obj.setColor) === null || _a === undefined ? undefined : _a.call(obj, hexColor);
2016
2416
  }));
2017
2417
  }
2018
2418
  setViewpoint(viewpoint) {
@@ -2028,13 +2428,13 @@ class KonvaMarkup {
2028
2428
  x: 0,
2029
2429
  y: 0
2030
2430
  });
2031
- const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || {
2431
+ const markupColor = ((_a = viewpoint.custom_fields) === null || _a === undefined ? undefined : _a.markup_color) || {
2032
2432
  r: 255,
2033
2433
  g: 0,
2034
2434
  b: 0
2035
2435
  };
2036
2436
  this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
2037
- (_b = viewpoint.lines) === null || _b === void 0 ? void 0 : _b.forEach((line => {
2437
+ (_b = viewpoint.lines) === null || _b === undefined ? undefined : _b.forEach((line => {
2038
2438
  const linePoints = [];
2039
2439
  line.points.forEach((point => {
2040
2440
  const screenPoint = this._worldTransformer.worldToScreen(point);
@@ -2043,28 +2443,28 @@ class KonvaMarkup {
2043
2443
  }));
2044
2444
  this.addLine(linePoints, line.color, line.type, line.width, line.id);
2045
2445
  }));
2046
- (_c = viewpoint.texts) === null || _c === void 0 ? void 0 : _c.forEach((text => {
2446
+ (_c = viewpoint.texts) === null || _c === undefined ? undefined : _c.forEach((text => {
2047
2447
  const screenPoint = this._worldTransformer.worldToScreen(text.position);
2048
2448
  this.addText(text.text, screenPoint, text.angle, text.color, text.text_size, text.font_size, text.id);
2049
2449
  }));
2050
- (_d = viewpoint.rectangles) === null || _d === void 0 ? void 0 : _d.forEach((rect => {
2450
+ (_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect => {
2051
2451
  const screenPoint = this._worldTransformer.worldToScreen(rect.position);
2052
2452
  this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
2053
2453
  }));
2054
- (_e = viewpoint.ellipses) === null || _e === void 0 ? void 0 : _e.forEach((ellipse => {
2454
+ (_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse => {
2055
2455
  const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
2056
2456
  this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
2057
2457
  }));
2058
- (_f = viewpoint.arrows) === null || _f === void 0 ? void 0 : _f.forEach((arrow => {
2458
+ (_f = viewpoint.arrows) === null || _f === undefined ? undefined : _f.forEach((arrow => {
2059
2459
  const startPoint = this._worldTransformer.worldToScreen(arrow.start);
2060
2460
  const endPoint = this._worldTransformer.worldToScreen(arrow.end);
2061
2461
  this.addArrow(startPoint, endPoint, arrow.color, arrow.id);
2062
2462
  }));
2063
- (_g = viewpoint.clouds) === null || _g === void 0 ? void 0 : _g.forEach((cloud => {
2463
+ (_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud => {
2064
2464
  const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
2065
2465
  this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
2066
2466
  }));
2067
- (_h = viewpoint.images) === null || _h === void 0 ? void 0 : _h.forEach((image => {
2467
+ (_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image => {
2068
2468
  const screenPoint = this._worldTransformer.worldToScreen(image.position);
2069
2469
  this.addImage(screenPoint, image.src, image.width, image.height, image.id);
2070
2470
  }));
@@ -2358,7 +2758,7 @@ class KonvaMarkup {
2358
2758
  this.removeTextInput();
2359
2759
  this.removeImageInput();
2360
2760
  this.clearOverlay();
2361
- (_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.destroy();
2761
+ (_a = this._konvaStage) === null || _a === undefined ? undefined : _a.destroy();
2362
2762
  this._groupImages = undefined;
2363
2763
  this._groupGeometry = undefined;
2364
2764
  this._groupTexts = undefined;
@@ -2608,7 +3008,7 @@ class KonvaMarkup {
2608
3008
  }
2609
3009
  removeTextInput() {
2610
3010
  var _a;
2611
- (_a = this._textInputRef) === null || _a === void 0 ? void 0 : _a.remove();
3011
+ (_a = this._textInputRef) === null || _a === undefined ? undefined : _a.remove();
2612
3012
  this._textInputRef = null;
2613
3013
  this._textInputPos = null;
2614
3014
  this._textInputAngle = 0;
@@ -2651,14 +3051,14 @@ class KonvaMarkup {
2651
3051
  }
2652
3052
  removeImageInput() {
2653
3053
  var _a;
2654
- (_a = this._imageInputRef) === null || _a === void 0 ? void 0 : _a.remove();
3054
+ (_a = this._imageInputRef) === null || _a === undefined ? undefined : _a.remove();
2655
3055
  this._imageInputRef = null;
2656
3056
  this._imageInputPos = null;
2657
3057
  }
2658
3058
  addText(text, position, angle, color, textSize, fontSize, id) {
2659
3059
  var _a;
2660
3060
  if (!text) return;
2661
- (_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
3061
+ (_a = this.getSelectedObjects().at(0)) === null || _a === undefined ? undefined : _a.delete();
2662
3062
  this.clearSelected();
2663
3063
  this.removeTextInput();
2664
3064
  const tolerance = 1e-6;
@@ -2733,7 +3133,7 @@ class KonvaMarkup {
2733
3133
  addImage(position, src, width, height, id) {
2734
3134
  var _a;
2735
3135
  if (!position || !src) return;
2736
- (_a = this.getSelectedObjects().at(0)) === null || _a === void 0 ? void 0 : _a.delete();
3136
+ (_a = this.getSelectedObjects().at(0)) === null || _a === undefined ? undefined : _a.delete();
2737
3137
  this.clearSelected();
2738
3138
  this.removeImageInput();
2739
3139
  const konvaImage = new KonvaImage({
@@ -4194,7 +4594,8 @@ class MeasureProjector {
4194
4594
  class ExtentsComponent {
4195
4595
  constructor(viewer) {
4196
4596
  this.syncExtents = () => {
4197
- const extents = this.viewer.models.reduce(((result, gltf) => result.expandByObject(gltf.scene)), new Box3);
4597
+ const extents = new Box3;
4598
+ this.viewer.models.forEach((model => model.scene.traverseVisible((object => !object.children.length && extents.expandByObject(object)))));
4198
4599
  this.viewer.extents.copy(extents);
4199
4600
  this.viewer.target.copy(extents.getCenter(new Vector3));
4200
4601
  };
@@ -4202,11 +4603,17 @@ class ExtentsComponent {
4202
4603
  this.viewer.addEventListener("geometryend", this.syncExtents);
4203
4604
  this.viewer.addEventListener("clear", this.syncExtents);
4204
4605
  this.viewer.on("explode", this.syncExtents);
4606
+ this.viewer.on("isolate", this.syncExtents);
4607
+ this.viewer.on("hide", this.syncExtents);
4608
+ this.viewer.on("showall", this.syncExtents);
4205
4609
  }
4206
4610
  dispose() {
4207
4611
  this.viewer.removeEventListener("geometryend", this.syncExtents);
4208
4612
  this.viewer.removeEventListener("clear", this.syncExtents);
4209
4613
  this.viewer.off("explode", this.syncExtents);
4614
+ this.viewer.off("isolate", this.syncExtents);
4615
+ this.viewer.off("hide", this.syncExtents);
4616
+ this.viewer.off("showall", this.syncExtents);
4210
4617
  }
4211
4618
  }
4212
4619
 
@@ -4258,7 +4665,7 @@ class DefaultPositionComponent {
4258
4665
  this.viewer.camera.far = size * 100;
4259
4666
  this.viewer.camera.updateMatrixWorld();
4260
4667
  this.viewer.camera.updateProjectionMatrix();
4261
- this.viewer.executeCommand("setDefaultViewPosition", "sw");
4668
+ this.viewer.executeCommand("setDefaultViewPosition", "front");
4262
4669
  this.viewer.executeCommand("zoomToExtents");
4263
4670
  };
4264
4671
  this.viewer = viewer;
@@ -4556,19 +4963,23 @@ class Viewer extends EventEmitter2 {
4556
4963
  file: file,
4557
4964
  model: file
4558
4965
  });
4559
- let model = undefined;
4560
- if (file) {
4561
- const models = await file.getModels() || [];
4562
- model = models.find((model => model.default)) || models[0];
4966
+ if (!file) throw new Error("No default model found");
4967
+ let database = "";
4968
+ let path = "";
4969
+ const models = await file.getModels() || [];
4970
+ const model = models.find((model => model.default)) || models[0];
4971
+ if (model) {
4972
+ database = model.database;
4973
+ path = model.path;
4974
+ } else {
4975
+ database = file.id + file.type;
4976
+ path = `${file.path}/downloads`;
4563
4977
  }
4564
- if (!model) throw new Error("No default model found");
4565
- const geometryType = model.database.split(".").pop();
4566
- if (geometryType !== "gltf") throw new Error(`Unknown geometry type: ${geometryType}`);
4567
- const url = `${model.httpClient.serverUrl}${model.path}/${model.database}`;
4978
+ const url = `${file.httpClient.serverUrl}${path}/${database}`;
4568
4979
  const params = {
4569
- requestHeader: model.httpClient.headers
4980
+ requestHeader: file.httpClient.headers
4570
4981
  };
4571
- await this.loadReferences(model);
4982
+ await this.loadReferences(file);
4572
4983
  await this.loadGltfFile(url, undefined, params);
4573
4984
  return this;
4574
4985
  }
@@ -4593,12 +5004,22 @@ class Viewer extends EventEmitter2 {
4593
5004
  this.emitEvent({
4594
5005
  type: "geometrystart"
4595
5006
  });
4596
- const loader = new GLTFLoader(manager);
5007
+ const loaders = {
5008
+ gltf: GLTFLoader,
5009
+ usdz: USDZLoader2,
5010
+ ifcx: IFCXLoader
5011
+ };
5012
+ let format = params.fileFormat;
5013
+ if (!format && typeof file === "string") format = file.split(".").pop().toLocaleLowerCase();
5014
+ if (!format && file instanceof globalThis.File) format = file.name.split(".").pop().toLocaleLowerCase();
5015
+ if (!format) format = "gltf";
5016
+ if (!loaders[format]) throw new Error(`Unknown geometry type: ${format}`);
5017
+ const loader = new loaders[format](manager);
4597
5018
  loader.setPath(manager.path);
4598
5019
  loader.setRequestHeader(params.requestHeader);
4599
5020
  loader.setCrossOrigin(params.crossOrigin || loader.crossOrigin);
4600
5021
  loader.setWithCredentials(params.withCredentials || loader.withCredentials);
4601
- const gltf = await loader.loadAsync(manager.fileURL, (event => {
5022
+ const model = await loader.loadAsync(manager.fileURL, (event => {
4602
5023
  const {lengthComputable: lengthComputable, loaded: loaded, total: total} = event;
4603
5024
  const progress = lengthComputable ? loaded / total : 1;
4604
5025
  this.emitEvent({
@@ -4607,18 +5028,19 @@ class Viewer extends EventEmitter2 {
4607
5028
  });
4608
5029
  }));
4609
5030
  if (!this.scene) return this;
4610
- if (!gltf.scene) throw new Error("No glTF scene found");
4611
- this.models.push(gltf);
4612
- this.scene.add(gltf.scene);
5031
+ if (!model.scene) throw new Error("No scene found");
5032
+ this.models.push(model);
5033
+ this.scene.add(model.scene);
4613
5034
  this.syncOptions();
4614
5035
  this.syncOverlay();
4615
5036
  this.update();
5037
+ setTimeout(this.update, 0);
4616
5038
  this.emitEvent({
4617
5039
  type: "databasechunk"
4618
5040
  });
4619
5041
  this.emitEvent({
4620
5042
  type: "geometryend",
4621
- data: gltf.scene
5043
+ data: model.scene
4622
5044
  });
4623
5045
  } catch (error) {
4624
5046
  this.emitEvent({
@@ -4649,8 +5071,8 @@ class Viewer extends EventEmitter2 {
4649
5071
  this.clearSelected();
4650
5072
  this.helpers.traverse(disposeObject);
4651
5073
  this.helpers.clear();
4652
- this.models.forEach((gltf => gltf.scene.traverse(disposeObject)));
4653
- this.models.forEach((gltf => gltf.scene.removeFromParent()));
5074
+ this.models.forEach((model => model.scene.traverse(disposeObject)));
5075
+ this.models.forEach((model => model.scene.removeFromParent()));
4654
5076
  this.models = [];
4655
5077
  this.scene.clear();
4656
5078
  this.syncOptions();
@@ -4798,16 +5220,16 @@ class Viewer extends EventEmitter2 {
4798
5220
  }
4799
5221
  };
4800
5222
  const setClippingPlanes = clipping_planes => {
4801
- clipping_planes === null || clipping_planes === void 0 ? void 0 : clipping_planes.forEach((clipping_plane => {
5223
+ clipping_planes === null || clipping_planes === undefined ? undefined : clipping_planes.forEach((clipping_plane => {
4802
5224
  const plane = new Plane;
4803
5225
  plane.setFromNormalAndCoplanarPoint(getVector3FromPoint3d(clipping_plane.direction), getVector3FromPoint3d(clipping_plane.location));
4804
5226
  this.renderer.clippingPlanes.push(plane);
4805
5227
  }));
4806
5228
  };
4807
5229
  const setSelection = selection => {
4808
- this.setSelected(selection === null || selection === void 0 ? void 0 : selection.map((component => component.handle)));
5230
+ this.setSelected(selection === null || selection === undefined ? undefined : selection.map((component => component.handle)));
4809
5231
  };
4810
- const draggerName = (_a = this._activeDragger) === null || _a === void 0 ? void 0 : _a.name;
5232
+ const draggerName = (_a = this._activeDragger) === null || _a === undefined ? undefined : _a.name;
4811
5233
  this.setActiveDragger();
4812
5234
  this.clearSlices();
4813
5235
  this.clearOverlay();
@@ -4818,7 +5240,7 @@ class Viewer extends EventEmitter2 {
4818
5240
  setClippingPlanes(viewpoint.clipping_planes);
4819
5241
  setSelection(viewpoint.selection);
4820
5242
  this._markup.setViewpoint(viewpoint);
4821
- this.target = getVector3FromPoint3d((_c = (_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.camera_target) !== null && _c !== void 0 ? _c : this.target);
5243
+ this.target = getVector3FromPoint3d((_c = (_b = viewpoint.custom_fields) === null || _b === undefined ? undefined : _b.camera_target) !== null && _c !== undefined ? _c : this.target);
4822
5244
  this.setActiveDragger(draggerName);
4823
5245
  this.emitEvent({
4824
5246
  type: "drawviewpoint",