@shopware-ag/dive 3.1.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -5
- package/build/chunks/{AssetCache-xpY_N7Yp.cjs → AssetCache-CUVFS7wk.cjs} +1 -1
- package/build/chunks/{AssetCache-C3YXhbaX.mjs → AssetCache-DnAAa719.mjs} +1 -1
- package/build/chunks/AssetExporter-CD2iuQce.mjs +108 -0
- package/build/chunks/AssetExporter-CoL-QXkB.cjs +1 -0
- package/build/chunks/{AssetLoader-MfH5d_Rr.mjs → AssetLoader-Bkp3fWZz.mjs} +9 -9
- package/build/chunks/{AssetLoader-CRxLq0AL.cjs → AssetLoader-DnVvCd41.cjs} +2 -2
- package/build/chunks/FileTypes-B-MjfMGd.cjs +29 -0
- package/build/chunks/FileTypes-D3Dxr2dj.mjs +2294 -0
- package/build/chunks/ModelComponent-Cmu0EX0r.cjs +1 -0
- package/build/chunks/ModelComponent-WA0kLOEY.mjs +87 -0
- package/build/chunks/OrbitController-CAJIiZeE.cjs +1 -0
- package/build/chunks/OrbitController-DxCbrQVB.mjs +612 -0
- package/build/chunks/SpriteTextComponent-BpoKLOjA.cjs +1 -0
- package/build/chunks/SpriteTextComponent-DIZFqao0.mjs +83 -0
- package/build/chunks/collectAnimations-BgYCN1le.mjs +35 -0
- package/build/chunks/collectAnimations-C3HfZHte.cjs +1 -0
- package/build/chunks/contributesToBounds-C1mva__U.cjs +1 -0
- package/build/chunks/contributesToBounds-DYmHYES4.mjs +14 -0
- package/build/chunks/detachTransformControls-B4iRF1bw.mjs +209 -0
- package/build/chunks/detachTransformControls-CZ2cd5hx.cjs +1 -0
- package/build/chunks/{isFileTypeSupported-BBU39V4u.cjs → isFileExtensionSupported-B1q2eWs7.cjs} +1 -1
- package/build/chunks/{isFileTypeSupported-9h8lrIuG.mjs → isFileExtensionSupported-BqOqU3-h.mjs} +1 -1
- package/build/chunks/isVisibleInHierarchy-D9JcLqR5.cjs +1 -0
- package/build/chunks/isVisibleInHierarchy-KzVGvDEw.mjs +21 -0
- package/build/components/boundingbox/BoundingBoxComponent.d.ts +100 -0
- package/build/components/boundingbox/index.d.ts +1 -0
- package/build/components/camera/CameraComponent.d.ts +75 -0
- package/build/components/camera/index.d.ts +2 -0
- package/build/components/camera/perspective/PerspectiveCameraComponent.d.ts +39 -0
- package/build/components/grid/GridComponent.d.ts +50 -0
- package/build/components/index.d.ts +6 -10
- package/build/components/light/LightComponent.d.ts +65 -0
- package/build/components/light/ambient/AmbientLightComponent.d.ts +10 -0
- package/build/components/light/directional/DirectionalLightComponent.d.ts +23 -0
- package/build/components/light/hemi/HemisphereLightComponent.d.ts +21 -0
- package/build/components/light/index.d.ts +5 -3
- package/build/components/light/point/PointLightComponent.d.ts +26 -0
- package/build/components/line/MultiLineComponent.d.ts +133 -0
- package/build/components/line/index.d.ts +1 -0
- package/build/components/mesh/MeshComponent.d.ts +74 -0
- package/build/components/mesh/floor/FloorComponent.d.ts +36 -0
- package/build/components/mesh/index.d.ts +4 -0
- package/build/components/mesh/model/ModelComponent.d.ts +67 -0
- package/build/components/mesh/primitive/PrimitiveComponent.d.ts +43 -0
- package/build/components/spritetext/SpriteTextComponent.d.ts +58 -0
- package/build/constants/VisibilityLayerMask.d.ts +23 -0
- package/build/dive.cjs +1 -1
- package/build/dive.mjs +252 -773
- package/build/engine/Dive.d.ts +11 -13
- package/build/engine/boundingbox/BoundingBox.d.ts +76 -0
- package/build/engine/component/Component.d.ts +236 -0
- package/build/engine/environment/Environment.d.ts +0 -18
- package/build/engine/index.d.ts +4 -1
- package/build/engine/node/Node.d.ts +189 -0
- package/build/engine/promise/abortable/AbortablePromise.d.ts +8 -0
- package/build/engine/renderer/Renderer.d.ts +43 -7
- package/build/engine/scene/Scene.d.ts +88 -4
- package/build/engine/scene/root/Root.d.ts +29 -0
- package/build/engine/scene/xrroot/XRRoot.d.ts +1 -1
- package/build/engine/view/View.d.ts +15 -4
- package/build/helpers/collectAnimations/collectAnimations.d.ts +23 -0
- package/build/helpers/computeProductBounds/computeProductBounds.d.ts +18 -0
- package/build/helpers/contributesToBounds/contributesToBounds.d.ts +17 -0
- package/build/helpers/detachTransformControls/detachTransformControls.d.ts +15 -0
- package/build/helpers/disposeComponents/disposeComponents.d.ts +20 -0
- package/build/helpers/findSceneRecursive/findSceneRecursive.d.ts +7 -3
- package/build/helpers/implementsInterface/implementsInterface.d.ts +11 -0
- package/build/helpers/index.d.ts +6 -1
- package/build/helpers/isVisibleInHierarchy/isVisibleInHierarchy.d.ts +12 -0
- package/build/index.d.ts +0 -1
- package/build/plugins/animation/index.mjs +3 -2
- package/build/plugins/animation/src/system/AnimationSystem.d.ts +3 -2
- package/build/plugins/ar/index.cjs +1 -1
- package/build/plugins/ar/index.mjs +2 -2
- package/build/plugins/ar/src/webxr/WebXR.d.ts +7 -0
- package/build/plugins/assetcache/index.cjs +1 -1
- package/build/plugins/assetcache/index.mjs +1 -1
- package/build/plugins/assetexporter/index.cjs +1 -1
- package/build/plugins/assetexporter/index.mjs +1 -1
- package/build/plugins/assetexporter/src/AssetExporter.d.ts +12 -0
- package/build/plugins/assetloader/index.cjs +1 -1
- package/build/plugins/assetloader/index.mjs +2 -2
- package/build/plugins/mediacreator/index.cjs +1 -1
- package/build/plugins/mediacreator/index.mjs +32 -30
- package/build/plugins/mediacreator/src/MediaCreator.d.ts +1 -2
- package/build/plugins/orbitcontroller/index.cjs +1 -1
- package/build/plugins/orbitcontroller/index.d.ts +1 -0
- package/build/plugins/orbitcontroller/index.mjs +1 -1
- package/build/plugins/orbitcontroller/src/OrbitController.d.ts +39 -6
- package/build/plugins/orientationdisplay/index.cjs +1 -1
- package/build/plugins/orientationdisplay/index.mjs +39 -31
- package/build/plugins/orientationdisplay/src/OrientationDisplay.d.ts +3 -3
- package/build/plugins/quickview/index.cjs +1 -1
- package/build/plugins/quickview/index.mjs +68 -45
- package/build/plugins/quickview/src/QuickView.d.ts +40 -13
- package/build/plugins/quickview/types/index.d.ts +0 -18
- package/build/plugins/state/index.cjs +1 -27
- package/build/plugins/state/index.mjs +1983 -4262
- package/build/plugins/state/src/EngineGateway.d.ts +98 -0
- package/build/plugins/state/src/EntityRegistry.d.ts +51 -0
- package/build/plugins/state/src/State.d.ts +20 -9
- package/build/plugins/state/src/actions/camera/computeencompassingview.d.ts +1 -1
- package/build/plugins/state/src/actions/camera/movecamera.d.ts +2 -2
- package/build/plugins/state/src/actions/media/generatemedia.d.ts +1 -1
- package/build/plugins/state/src/actions/object/addobject.d.ts +2 -3
- package/build/plugins/state/src/actions/object/deleteobject.d.ts +3 -4
- package/build/plugins/state/src/actions/object/deselectobject.d.ts +3 -4
- package/build/plugins/state/src/actions/object/dropit.d.ts +2 -2
- package/build/plugins/state/src/actions/object/getallobjects.d.ts +2 -3
- package/build/plugins/state/src/actions/object/getobjects.d.ts +3 -4
- package/build/plugins/state/src/actions/object/index.d.ts +0 -1
- package/build/plugins/state/src/actions/object/modelloaded.d.ts +2 -2
- package/build/plugins/state/src/actions/object/selectobject.d.ts +3 -4
- package/build/plugins/state/src/actions/object/setparent.d.ts +3 -4
- package/build/plugins/state/src/actions/object/updateobject.d.ts +3 -4
- package/build/plugins/state/src/actions/renderer/startrender.d.ts +1 -1
- package/build/plugins/state/src/actions/scene/exportscene.d.ts +2 -2
- package/build/plugins/state/src/actions/scene/index.d.ts +0 -1
- package/build/plugins/state/src/actions/scene/setbackground.d.ts +2 -2
- package/build/plugins/state/src/actions/scene/updatescene.d.ts +2 -2
- package/build/plugins/state/src/actions/state/getstate.d.ts +1 -1
- package/build/plugins/state/src/actions/state/setstate.d.ts +1 -1
- package/build/plugins/state/src/helpers/copyVectors/copyVectors.d.ts +17 -0
- package/build/plugins/state/src/helpers/updateParentLink/updateParentLink.d.ts +29 -0
- package/build/plugins/state/src/helpers/watchEntity/watchEntity.d.ts +30 -0
- package/build/plugins/state/types/ActionTypes.d.ts +18 -3
- package/build/plugins/state/types/RegisteredEntity.d.ts +27 -0
- package/build/plugins/state/types/StateData.d.ts +1 -1
- package/build/plugins/state/types/index.d.ts +2 -1
- package/build/{types → plugins/state/types}/schema/GroupSchema.d.ts +1 -1
- package/build/{types → plugins/state/types}/schema/ModelSchema.d.ts +7 -4
- package/build/{types → plugins/state/types}/schema/PrimitiveSchema.d.ts +4 -5
- package/build/{types → plugins/state/types}/schema/index.d.ts +0 -3
- package/build/plugins/toolbox/index.cjs +1 -1
- package/build/plugins/toolbox/index.mjs +193 -140
- package/build/plugins/toolbox/src/PointerContext.d.ts +7 -0
- package/build/plugins/toolbox/src/SelectionState.d.ts +21 -0
- package/build/plugins/toolbox/src/Toolbox.d.ts +9 -2
- package/build/{components → plugins/toolbox/src}/gizmo/Gizmo.d.ts +16 -2
- package/build/{components → plugins/toolbox/src}/gizmo/handles/AxisHandle.d.ts +2 -3
- package/build/{components → plugins/toolbox/src}/gizmo/handles/RadialHandle.d.ts +2 -3
- package/build/{components → plugins/toolbox/src}/gizmo/handles/ScaleHandle.d.ts +2 -3
- package/build/{components → plugins/toolbox/src}/gizmo/rotate/RotateGizmo.d.ts +2 -2
- package/build/{components → plugins/toolbox/src}/gizmo/scale/ScaleGizmo.d.ts +3 -3
- package/build/{components → plugins/toolbox/src}/gizmo/translate/TranslateGizmo.d.ts +2 -2
- package/build/types/components/DIVESceneObject.d.ts +13 -6
- package/build/types/components/index.d.ts +0 -1
- package/build/types/events/DIVEComponentEventMap.d.ts +14 -0
- package/build/types/events/DIVEEntityEventMap.d.ts +47 -0
- package/build/types/events/index.d.ts +2 -0
- package/build/types/{schema/GeometrySchema.d.ts → geometry/DIVEGeometry.d.ts} +4 -4
- package/build/types/{schema/GeometryTypeSchema.d.ts → geometry/DIVEGeometryType.d.ts} +1 -1
- package/build/types/geometry/index.d.ts +2 -0
- package/build/types/index.d.ts +3 -1
- package/build/types/{schema/MaterialSchema.d.ts → material/DIVEMaterial.d.ts} +1 -1
- package/build/types/material/index.d.ts +1 -0
- package/package.json +6 -5
- package/build/chunks/AssetExporter-C5MScs9S.mjs +0 -70
- package/build/chunks/AssetExporter-Cdxb04b3.cjs +0 -1
- package/build/chunks/CameraSchema-cgY5WBGW.mjs +0 -10
- package/build/chunks/CameraSchema-twxH-72N.cjs +0 -1
- package/build/chunks/FileTypes-Cgyf8ocm.cjs +0 -29
- package/build/chunks/FileTypes-DiYB3WBp.mjs +0 -2166
- package/build/chunks/PerspectiveCamera-B5TvUzTa.mjs +0 -39
- package/build/chunks/PerspectiveCamera-DwQUmkDv.cjs +0 -1
- package/build/chunks/SpriteText-2lCRglsw.cjs +0 -1
- package/build/chunks/SpriteText-C_CQPvUn.mjs +0 -50
- package/build/chunks/findInterface-C6mrvf_t.cjs +0 -1
- package/build/chunks/findInterface-DbJ5qzbc.mjs +0 -11
- package/build/components/boundingbox/BoundingBox.d.ts +0 -140
- package/build/components/floor/Floor.d.ts +0 -14
- package/build/components/grid/Grid.d.ts +0 -23
- package/build/components/group/Group.d.ts +0 -28
- package/build/components/light/AmbientLight.d.ts +0 -19
- package/build/components/light/PointLight.d.ts +0 -29
- package/build/components/light/SceneLight.d.ts +0 -20
- package/build/components/model/Model.d.ts +0 -26
- package/build/components/node/Node.d.ts +0 -24
- package/build/components/primitive/Primitive.d.ts +0 -27
- package/build/components/root/Root.d.ts +0 -34
- package/build/components/spritetext/SpriteText.d.ts +0 -27
- package/build/engine/camera/PerspectiveCamera.d.ts +0 -24
- package/build/helpers/isFileTypeSupported/isFileTypeSupported.d.ts +0 -9
- package/build/plugins/quickview/src/state/QuickViewState.d.ts +0 -4
- package/build/plugins/quickview/src/uri/QuickViewUri.d.ts +0 -3
- package/build/plugins/state/src/actions/object/placeonfloor.d.ts +0 -12
- package/build/plugins/state/src/actions/scene/getallscenedata.d.ts +0 -12
- package/build/plugins/state/types/StateSceneData.d.ts +0 -5
- package/build/types/components/DIVELight.d.ts +0 -4
- /package/build/{types → plugins/state/types}/schema/BaseEntitySchema.d.ts +0 -0
- /package/build/{types → plugins/state/types}/schema/CameraSchema.d.ts +0 -0
- /package/build/{types → plugins/state/types}/schema/EntitySchema.d.ts +0 -0
- /package/build/{types → plugins/state/types}/schema/EntityTypeSchema.d.ts +0 -0
- /package/build/{types → plugins/state/types}/schema/LightSchema.d.ts +0 -0
- /package/build/{components → plugins/toolbox/src}/gizmo/plane/GizmoPlane.d.ts +0 -0
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
- [Installation](#installation)
|
|
25
25
|
- [Getting Started](#getting-started)
|
|
26
26
|
- [Basic Setup](#basic-setup)
|
|
27
|
+
- [Nodes and Components](#nodes-and-components)
|
|
27
28
|
- [Quick View](#quick-view)
|
|
28
29
|
- [Plugins](#plugins)
|
|
29
30
|
- [Documentation](#documentation)
|
|
@@ -34,8 +35,11 @@ DIVE is a spatial framework made by and optimized for Shopware. It can be used d
|
|
|
34
35
|
in a Shopware frontend such as Storefront or in any other frontend you want to use it in, it is not
|
|
35
36
|
tied to Shopware.
|
|
36
37
|
|
|
37
|
-
DIVE supplies your frontend application with all needed tooling to set up a basic 3D application
|
|
38
|
-
|
|
38
|
+
DIVE supplies your frontend application with all needed tooling to set up a basic 3D application.
|
|
39
|
+
A scene is a tree of nodes, and what a node *does* comes from the components attached to it - the
|
|
40
|
+
model common game engines use.
|
|
41
|
+
Driving a scene from data is the job of the
|
|
42
|
+
[state plugin](src/plugins/state/README.md), which adds event-based controls called "Actions".
|
|
39
43
|
|
|
40
44
|
## Installation
|
|
41
45
|
|
|
@@ -66,16 +70,37 @@ const myCanvasWrapper = document.createElement('div');
|
|
|
66
70
|
myCanvasWrapper.appendChild(dive.canvas);
|
|
67
71
|
```
|
|
68
72
|
|
|
73
|
+
### Nodes and Components
|
|
74
|
+
|
|
75
|
+
Everything in a scene is a `DIVENode`. Geometry, lights and behaviour are components you attach:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { DIVENode, ModelComponent, PointLightComponent } from '@shopware-ag/dive';
|
|
79
|
+
|
|
80
|
+
const model = new DIVENode();
|
|
81
|
+
model.addComponent(new ModelComponent());
|
|
82
|
+
dive.scene.root.add(model);
|
|
83
|
+
await model.requireComponent(ModelComponent).setFromURL('your/asset/uri.glb');
|
|
84
|
+
model.dropIt();
|
|
85
|
+
|
|
86
|
+
const lamp = new DIVENode();
|
|
87
|
+
lamp.addComponent(new PointLightComponent());
|
|
88
|
+
lamp.setPosition({ x: 0, y: 2, z: 0 });
|
|
89
|
+
dive.scene.root.add(lamp);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
You can write your own components too — see
|
|
93
|
+
[Component System Documentation](docs/component-system.md).
|
|
94
|
+
|
|
69
95
|
### Quick View
|
|
70
96
|
|
|
71
97
|
For a simpler setup, you can use QuickView to quickly display your assets within a basic default
|
|
72
98
|
scene setup:
|
|
73
99
|
|
|
74
100
|
```ts
|
|
75
|
-
import {
|
|
101
|
+
import { QuickView } from '@shopware-ag/dive/quickview';
|
|
76
102
|
|
|
77
|
-
|
|
78
|
-
const dive = await DIVE.QuickView('your/asset/uri.glb');
|
|
103
|
+
const dive = await QuickView('your/asset/uri.glb');
|
|
79
104
|
const myCanvasWrapper = document.createElement('div');
|
|
80
105
|
myCanvasWrapper.appendChild(dive.canvas);
|
|
81
106
|
```
|
|
@@ -102,6 +127,7 @@ For detailed information about the plugin system, see
|
|
|
102
127
|
|
|
103
128
|
For detailed documentation, please refer to the following sections:
|
|
104
129
|
|
|
130
|
+
- [Component System](docs/component-system.md) - Nodes, components, ticking and layers
|
|
105
131
|
- [Plugin System](docs/plugin-system.md) - Detailed plugin system architecture and usage
|
|
106
132
|
- [Shopware Integration](docs/shopware-integration.md) - Integration with Shopware projects
|
|
107
133
|
- [Testing and Quality Assurance](docs/testing.md) - Testing guidelines and best practices
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var l=(i,e,t)=>e in i?d(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var s=(i,e,t)=>l(i,typeof e!="symbol"?e+"":e,t);require("./FileTypes-
|
|
1
|
+
"use strict";var d=Object.defineProperty;var l=(i,e,t)=>e in i?d(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var s=(i,e,t)=>l(i,typeof e!="symbol"?e+"":e,t);require("./FileTypes-B-MjfMGd.cjs");require("three/webgpu");require("three/examples/jsm/loaders/HDRLoader.js");require("three/tsl");const _=require("./network-error-CdDXil5g.cjs");class f{constructor(e){s(this,"_promise");s(this,"_resolve");s(this,"_arrayBuffer",null);s(this,"_size",0);s(this,"_createdAt");s(this,"_updatedAt");this._uri=e,this._promise=new Promise(t=>{this._resolve=t}),this._createdAt=new Date,this._updatedAt=new Date}get promise(){return this._promise}get size(){return this._size}get createdAt(){return this._createdAt}get updatedAt(){return this._updatedAt}get arrayBuffer(){return this._arrayBuffer}_getHeader(e,t){var r,a;return((a=(r=e.headers)==null?void 0:r.get)==null?void 0:a.call(r,t))??null}_concatChunks(e,t){const r=new Uint8Array(t);let a=0;for(const n of e)r.set(n,a),a+=n.byteLength;return r.buffer}async _readBodyWithReader(e){const t=e.body.getReader(),r=[];let a=0;try{for(;;){const o=await t.read();if(o.done)break;const u=o.value??new Uint8Array(0);r.push(u),a+=u.byteLength}}finally{t.releaseLock()}return this._concatChunks(r,a)}async load(){var t;const e=await fetch(this._uri);if(!e.ok)throw new _.NetworkError(this._uri);try{(t=e.body)!=null&&t.getReader?this._arrayBuffer=await this._readBodyWithReader(e):this._arrayBuffer=await e.arrayBuffer(),this._size+=this._arrayBuffer.byteLength,this._updatedAt=new Date}catch{throw new _.FileContentError(this._uri)}return this._resolve(this._arrayBuffer),this._arrayBuffer}}class y{constructor(){s(this,"_cache",new Map)}get(){return this._cache}create(e){const t=new f(e);return this._cache.set(e,t),t}write(e,t){this._cache.set(e,t)}read(e){return this._cache.get(e)??null}delete(...e){e.forEach(t=>{this._cache.delete(t)})}clear(){this._cache.clear()}}const h=Symbol.for("@shopware-ag/dive/assetcache"),c=globalThis;c[h]||(c[h]=new y);const w=c[h];exports.AssetCache=w;exports.Chunk=f;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _ = Object.defineProperty;
|
|
2
2
|
var f = (i, e, t) => e in i ? _(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
3
|
var s = (i, e, t) => f(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import "./FileTypes-
|
|
4
|
+
import "./FileTypes-D3Dxr2dj.mjs";
|
|
5
5
|
import "three/webgpu";
|
|
6
6
|
import "three/examples/jsm/loaders/HDRLoader.js";
|
|
7
7
|
import "three/tsl";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var c = (s, t, e) => t in s ? p(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var a = (s, t, e) => c(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { Mesh as u } from "three/webgpu";
|
|
5
|
+
import { GLTFExporter as y } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
6
|
+
import { USDZExporter as l } from "three/examples/jsm/exporters/USDZExporter.js";
|
|
7
|
+
import { F as m, P as o } from "./parse-error-DfOPyLWM.mjs";
|
|
8
|
+
import { c as x } from "./contributesToBounds-DYmHYES4.mjs";
|
|
9
|
+
import { c as i } from "./collectAnimations-BgYCN1le.mjs";
|
|
10
|
+
const f = { onlyVisible: !0 };
|
|
11
|
+
class b {
|
|
12
|
+
constructor() {
|
|
13
|
+
a(this, "_gltfExporter");
|
|
14
|
+
a(this, "_usdzExporter");
|
|
15
|
+
this._gltfExporter = new y(), this._usdzExporter = new l();
|
|
16
|
+
}
|
|
17
|
+
async export(t, e, r) {
|
|
18
|
+
this._computeNormals(t);
|
|
19
|
+
const n = this._hideNonProductGeometry(t);
|
|
20
|
+
try {
|
|
21
|
+
return await this._exportByType(t, e, r);
|
|
22
|
+
} finally {
|
|
23
|
+
n();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async _exportByType(t, e, r) {
|
|
27
|
+
switch (e) {
|
|
28
|
+
case "glb":
|
|
29
|
+
return this._exportGlb(t, r);
|
|
30
|
+
case "gltf":
|
|
31
|
+
return this._exportGltf(t, r);
|
|
32
|
+
case "usdz":
|
|
33
|
+
return this._exportUsdz(
|
|
34
|
+
t,
|
|
35
|
+
r
|
|
36
|
+
);
|
|
37
|
+
default:
|
|
38
|
+
throw new m(`Unsupported file type: ${e}`, e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async _exportGlb(t, e) {
|
|
42
|
+
try {
|
|
43
|
+
const r = await this._gltfExporter.parseAsync(t, {
|
|
44
|
+
animations: i(t),
|
|
45
|
+
...e,
|
|
46
|
+
...f,
|
|
47
|
+
binary: !0
|
|
48
|
+
});
|
|
49
|
+
if (r instanceof ArrayBuffer)
|
|
50
|
+
return r;
|
|
51
|
+
throw new o("Failed to export GLB: expected ArrayBuffer");
|
|
52
|
+
} catch (r) {
|
|
53
|
+
throw r instanceof o ? r : new o("Failed to export GLB", r);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async _exportGltf(t, e) {
|
|
57
|
+
try {
|
|
58
|
+
const r = await this._gltfExporter.parseAsync(t, {
|
|
59
|
+
animations: i(t),
|
|
60
|
+
...e,
|
|
61
|
+
...f,
|
|
62
|
+
binary: !1
|
|
63
|
+
}), n = JSON.stringify(r);
|
|
64
|
+
return new TextEncoder().encode(n).buffer;
|
|
65
|
+
} catch (r) {
|
|
66
|
+
throw r instanceof o ? r : new o("Failed to export GLTF", r);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async _exportUsdz(t, e) {
|
|
70
|
+
try {
|
|
71
|
+
return (await this._usdzExporter.parseAsync(t, {
|
|
72
|
+
animations: i(t),
|
|
73
|
+
...e,
|
|
74
|
+
...f
|
|
75
|
+
})).buffer;
|
|
76
|
+
} catch (r) {
|
|
77
|
+
throw r instanceof o ? r : new o("Failed to export USDZ", r);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Temporarily hides everything drawable that does not count as real geometry.
|
|
82
|
+
*
|
|
83
|
+
* Anything carrying a geometry, not just a `Mesh`: a group's link lines and a
|
|
84
|
+
* bounding box helper are `LineSegments`, and a class-based test left them in
|
|
85
|
+
* the file. The layer decides, so product lines and points are exported and
|
|
86
|
+
* helper meshes are not.
|
|
87
|
+
*
|
|
88
|
+
* @returns A function that restores the previous visibility.
|
|
89
|
+
*/
|
|
90
|
+
_hideNonProductGeometry(t) {
|
|
91
|
+
const e = [];
|
|
92
|
+
return t.traverse((r) => {
|
|
93
|
+
"geometry" in r && (x(r) || r.visible && (r.visible = !1, e.push(r)));
|
|
94
|
+
}), () => {
|
|
95
|
+
e.forEach((r) => {
|
|
96
|
+
r.visible = !0;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
_computeNormals(t) {
|
|
101
|
+
t.traverse((e) => {
|
|
102
|
+
e instanceof u && e.geometry && (e.geometry.getAttribute("normal") || e.geometry.computeVertexNormals());
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
b as A
|
|
108
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var p=(s,e,t)=>e in s?u(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>p(s,typeof e!="symbol"?e+"":e,t);const f=require("three/webgpu"),l=require("three/examples/jsm/exporters/GLTFExporter.js"),y=require("three/examples/jsm/exporters/USDZExporter.js"),o=require("./parse-error-Dy_EE4rL.cjs"),x=require("./contributesToBounds-C1mva__U.cjs"),a=require("./collectAnimations-C3HfZHte.cjs"),c={onlyVisible:!0};class E{constructor(){i(this,"_gltfExporter");i(this,"_usdzExporter");this._gltfExporter=new l.GLTFExporter,this._usdzExporter=new y.USDZExporter}async export(e,t,r){this._computeNormals(e);const n=this._hideNonProductGeometry(e);try{return await this._exportByType(e,t,r)}finally{n()}}async _exportByType(e,t,r){switch(t){case"glb":return this._exportGlb(e,r);case"gltf":return this._exportGltf(e,r);case"usdz":return this._exportUsdz(e,r);default:throw new o.FileTypeError(`Unsupported file type: ${t}`,t)}}async _exportGlb(e,t){try{const r=await this._gltfExporter.parseAsync(e,{animations:a.collectAnimations(e),...t,...c,binary:!0});if(r instanceof ArrayBuffer)return r;throw new o.ParseError("Failed to export GLB: expected ArrayBuffer")}catch(r){throw r instanceof o.ParseError?r:new o.ParseError("Failed to export GLB",r)}}async _exportGltf(e,t){try{const r=await this._gltfExporter.parseAsync(e,{animations:a.collectAnimations(e),...t,...c,binary:!1}),n=JSON.stringify(r);return new TextEncoder().encode(n).buffer}catch(r){throw r instanceof o.ParseError?r:new o.ParseError("Failed to export GLTF",r)}}async _exportUsdz(e,t){try{return(await this._usdzExporter.parseAsync(e,{animations:a.collectAnimations(e),...t,...c})).buffer}catch(r){throw r instanceof o.ParseError?r:new o.ParseError("Failed to export USDZ",r)}}_hideNonProductGeometry(e){const t=[];return e.traverse(r=>{"geometry"in r&&(x.contributesToBounds(r)||r.visible&&(r.visible=!1,t.push(r)))}),()=>{t.forEach(r=>{r.visible=!0})}}_computeNormals(e){e.traverse(t=>{t instanceof f.Mesh&&t.geometry&&(t.geometry.getAttribute("normal")||t.geometry.computeVertexNormals())})}}exports.AssetExporter=E;
|
|
@@ -3,14 +3,14 @@ var F = (_, r, s) => r in _ ? k(_, r, { enumerable: !0, configurable: !0, writab
|
|
|
3
3
|
var h = (_, r, s) => F(_, typeof r != "symbol" ? r + "" : r, s);
|
|
4
4
|
import { GLTFLoader as x } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
5
5
|
import { USDLoader as G } from "three/examples/jsm/loaders/USDLoader.js";
|
|
6
|
-
import { S as B } from "./FileTypes-
|
|
7
|
-
import { Group as C, BufferGeometry as W, BufferAttribute as
|
|
6
|
+
import { S as B } from "./FileTypes-D3Dxr2dj.mjs";
|
|
7
|
+
import { Group as C, BufferGeometry as W, BufferAttribute as T, MeshStandardMaterial as v, Mesh as j } from "three/webgpu";
|
|
8
8
|
import "three/examples/jsm/loaders/HDRLoader.js";
|
|
9
9
|
import "three/tsl";
|
|
10
|
-
import { g as H, i as z } from "./
|
|
10
|
+
import { g as H, i as z } from "./isFileExtensionSupported-BqOqU3-h.mjs";
|
|
11
11
|
import { F as P, P as M } from "./parse-error-DfOPyLWM.mjs";
|
|
12
12
|
import { DRACOLoader as Y } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
13
|
-
import { A as S } from "./AssetCache-
|
|
13
|
+
import { A as S } from "./AssetCache-DnAAa719.mjs";
|
|
14
14
|
function J() {
|
|
15
15
|
let _, r;
|
|
16
16
|
onmessage = function(e) {
|
|
@@ -135,9 +135,9 @@ function J() {
|
|
|
135
135
|
A / i.BYTES_PER_ELEMENT
|
|
136
136
|
);
|
|
137
137
|
let I = 0;
|
|
138
|
-
for (let
|
|
138
|
+
for (let O = 0, N = R.length; O < N; O += l) {
|
|
139
139
|
for (let L = 0; L < l; L++)
|
|
140
|
-
D[I + L] = R[
|
|
140
|
+
D[I + L] = R[O + L];
|
|
141
141
|
I += E;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -384,12 +384,12 @@ class V {
|
|
|
384
384
|
const { position: s, normal: t } = r.attributes, o = r.index ?? r.attributes.index, u = new W();
|
|
385
385
|
u.setAttribute(
|
|
386
386
|
"position",
|
|
387
|
-
new
|
|
387
|
+
new T(new Float32Array(s.array), 3)
|
|
388
388
|
), (d = t == null ? void 0 : t.array) != null && d.length ? u.setAttribute(
|
|
389
389
|
"normal",
|
|
390
|
-
new
|
|
390
|
+
new T(new Float32Array(t.array), 3)
|
|
391
391
|
) : u.computeVertexNormals(), (i = o == null ? void 0 : o.array) != null && i.length && u.setIndex(
|
|
392
|
-
new
|
|
392
|
+
new T(new Uint32Array(o.array), 1)
|
|
393
393
|
);
|
|
394
394
|
const e = r.color, n = new v({
|
|
395
395
|
metalness: 0.3,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var G=Object.create;var C=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var q=(c,t,n)=>t in c?C(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var H=(c,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of v(t))!j.call(c,s)&&s!==n&&C(c,s,{get:()=>t[s],enumerable:!(r=B(t,s))||r.enumerable});return c};var I=(c,t,n)=>(n=c!=null?G(W(c)):{},H(t||!c||!c.__esModule?C(n,"default",{value:c,enumerable:!0}):n,c));var p=(c,t,n)=>q(c,typeof t!="symbol"?t+"":t,n);const z=require("three/examples/jsm/loaders/GLTFLoader.js"),Y=require("three/examples/jsm/loaders/USDLoader.js"),J=require("./FileTypes-
|
|
1
|
+
"use strict";var G=Object.create;var C=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var q=(c,t,n)=>t in c?C(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var H=(c,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of v(t))!j.call(c,s)&&s!==n&&C(c,s,{get:()=>t[s],enumerable:!(r=B(t,s))||r.enumerable});return c};var I=(c,t,n)=>(n=c!=null?G(W(c)):{},H(t||!c||!c.__esModule?C(n,"default",{value:c,enumerable:!0}):n,c));var p=(c,t,n)=>q(c,typeof t!="symbol"?t+"":t,n);const z=require("three/examples/jsm/loaders/GLTFLoader.js"),Y=require("three/examples/jsm/loaders/USDLoader.js"),J=require("./FileTypes-B-MjfMGd.cjs"),w=require("three/webgpu");require("three/examples/jsm/loaders/HDRLoader.js");require("three/tsl");const U=require("./isFileExtensionSupported-B1q2eWs7.cjs"),R=require("./parse-error-Dy_EE4rL.cjs"),$=require("three/examples/jsm/loaders/DRACOLoader.js"),T=require("./AssetCache-CUVFS7wk.cjs");function N(){let c,t;onmessage=function(e){const o=e.data;switch(o.type){case"init":c=o.decoderConfig,t=new Promise(function(i){c.onModuleLoaded=function(_){i({draco:_})},DracoDecoderModule(c)});break;case"decode":const d=o.buffer,l=o.taskConfig;t.then(i=>{const _=i.draco,a=new _.Decoder;try{const u=n(_,a,new Int8Array(d),l),h=u.attributes.map(g=>g.array.buffer);u.index&&h.push(u.index.array.buffer),self.postMessage({type:"decode",id:o.id,geometry:u},h)}catch(u){console.error(u),self.postMessage({type:"error",id:o.id,error:u.message})}finally{_.destroy(a)}});break}};function n(e,o,d,l){const i=l.attributeIDs,_=l.attributeTypes;let a,u;const h=o.GetEncodedGeometryType(d);if(h===e.TRIANGULAR_MESH)a=new e.Mesh,u=o.DecodeArrayToMesh(d,d.byteLength,a);else if(h===e.POINT_CLOUD)a=new e.PointCloud,u=o.DecodeArrayToPointCloud(d,d.byteLength,a);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!u.ok()||a.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+u.error_msg());const g={index:null,attributes:[]};for(const A in i){const D=self[_[A]];let y,m;if(l.useUniqueIDs)m=i[A],y=o.GetAttributeByUniqueId(a,m);else{if(m=o.GetAttributeId(a,e[i[A]]),m===-1)continue;y=o.GetAttribute(a,m)}const E=s(e,o,a,A,D,y);A==="color"&&(E.vertexColorSpace=l.vertexColorSpace),g.attributes.push(E)}return h===e.TRIANGULAR_MESH&&(g.index=r(e,o,a)),e.destroy(a),g}function r(e,o,d){const i=d.num_faces()*3,_=i*4,a=e._malloc(_);o.GetTrianglesUInt32Array(d,_,a);const u=new Uint32Array(e.HEAPF32.buffer,a,i).slice();return e._free(a),{array:u,itemSize:1}}function s(e,o,d,l,i,_){const a=d.num_points(),u=_.num_components(),h=f(e,i),g=u*i.BYTES_PER_ELEMENT,A=Math.ceil(g/4)*4,D=A/i.BYTES_PER_ELEMENT,y=a*g,m=a*A,E=e._malloc(y);o.GetAttributeDataArrayForAllPoints(d,_,h,y,E);const O=new i(e.HEAPF32.buffer,E,y/i.BYTES_PER_ELEMENT);let L;if(g===A)L=O.slice();else{L=new i(m/i.BYTES_PER_ELEMENT);let M=0;for(let b=0,x=O.length;b<x;b+=u){for(let S=0;S<u;S++)L[M+S]=O[b+S];M+=D}}return e._free(E),{name:l,count:a,itemSize:u,array:L,stride:D}}function f(e,o){switch(o){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32}}}const P={LOAD_DRACO_JS_DECODER:async()=>(await import("three/examples/jsm/libs/draco/draco_decoder.js?raw")).default,LOAD_DRACO_WASM_WRAPPER:async()=>(await import("three/examples/jsm/libs/draco/draco_wasm_wrapper.js?raw")).default,LOAD_DRACO_WASM_DECODER:async()=>{const c=(await import("three/examples/jsm/libs/draco/draco_decoder.wasm?url")).default;return await(await fetch(c)).arrayBuffer()}};class k extends $.DRACOLoader{constructor(){super(...arguments);p(this,"decoderPending",null);p(this,"decoderConfig",{type:"js",wasmBinary:null});p(this,"workerSourceURL","")}async _initDecoder(){if(this.decoderPending)return this.decoderPending;const n=typeof WebAssembly!="object"||this.decoderConfig.type==="js",r=[];return n?r.push(P.LOAD_DRACO_JS_DECODER()):(r.push(P.LOAD_DRACO_WASM_WRAPPER()),r.push(P.LOAD_DRACO_WASM_DECODER())),this.decoderPending=Promise.all(r).then(s=>{const f=s[0];n||(this.decoderConfig.wasmBinary=s[1]);const e=N.toString(),o=["/* draco decoder */",f,"","/* worker */",e.substring(e.indexOf("{")+1,e.lastIndexOf("}"))].join(`
|
|
2
2
|
`);this.workerSourceURL=URL.createObjectURL(new Blob([o]))}),this.decoderPending}}function V(){let c=null,t=null;const n=[[/'CONFIG_CONTROL_DESIGN'\s*\)/g,"'AP203_CONFIGURATION_CONTROLLED_3D_DESIGN_OF_MECHANICAL_PARTS_AND_ASSEMBLIES_MIM_LF')"],[/'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF\.\s*\{[\s\S]*?\}\s*'/g,"'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'"]];function r(){return c||(c=occtimportjs({locateFile:function(){return t}})),c}function s(e){for(var o=new TextDecoder("utf-8",{fatal:!1}),d=new TextEncoder,l=o.decode(e),i=0;i<n.length;i++){var _=n[i][0],a=n[i][1];l=l.replace(_,a)}return new Uint8Array(d.encode(l))}function f(e,o){var d=s(o);try{var l=e.ReadStepFile(d,null);if(l.success&&l.root)return l}catch{}try{return e.ReadStepFile(o,null)}catch{return{success:!1,root:{meshes:[],children:[]},meshes:[]}}}onmessage=async function(e){var o=e.data;switch(o.type){case"init":t=o.wasmUrl;break;case"parse":try{var d=await r(),l=new Uint8Array(o.buffer),i=o.fileType,_;if(i==="step"||i==="stp"?_=f(d,l):_=d.ReadIgesFile(l,null),!_.success||!_.root){self.postMessage({type:"error",id:o.id,error:"Failed to parse CAD file"});return}self.postMessage({type:"result",id:o.id,result:_})}catch(a){self.postMessage({type:"error",id:o.id,error:a instanceof Error?a.message:String(a)})}break}}}const F={LOAD_OCCT_JS:async()=>(await Promise.resolve().then(()=>require("./occt-import-js-DdbbsFBH.cjs"))).default,LOAD_OCCT_WASM_URL:async()=>(await Promise.resolve().then(()=>require("./occt-import-js-BQ1yZHCj.cjs"))).default};class Z{constructor(){p(this,"_workerPending",null);p(this,"_worker",null);p(this,"_nextId",0);p(this,"_pending",new Map)}_getWorker(){return this._workerPending?this._workerPending:(this._workerPending=(async()=>{const[t,n]=await Promise.all([F.LOAD_OCCT_JS(),F.LOAD_OCCT_WASM_URL()]),r=V.toString(),s=["/* occt-import-js */",t,"","/* step worker */",r.substring(r.indexOf("{")+1,r.lastIndexOf("}"))].join(`
|
|
3
|
-
`),f=URL.createObjectURL(new Blob([s])),e=new Worker(f),o=new URL(n,window.location.href).href;return e.postMessage({type:"init",wasmUrl:o}),e.onmessage=d=>{const{type:l,id:i,result:_,error:a}=d.data,u=this._pending.get(i);if(u)if(this._pending.delete(i),l==="result")try{u.resolve(this._buildScene(_))}catch(h){u.reject(h instanceof Error?h:new Error(String(h)))}else u.reject(new Error(a??"Worker error"))},e.onerror=d=>{for(const[,{reject:l}]of this._pending)l(new Error(d.message??"Worker error"));this._pending.clear()},this._worker=e,e})(),this._workerPending)}async parseAsync(t,n){const r=this._nextId++,s=await this._getWorker();return new Promise((f,e)=>{this._pending.set(r,{resolve:f,reject:e});const o=t.slice(0);s.postMessage({type:"parse",id:r,buffer:o,fileType:n},[o])})}dispose(){if(this._worker){for(const[,{reject:t}]of this._pending)t(new Error("STEPLoader disposed"));this._pending.clear(),this._worker.terminate(),this._worker=null,this._workerPending=null}}_buildScene(t){const n=new w.Group;return n.name=t.root.name??"CAD Model",this._buildNode(t.root,t.meshes,n),n.rotation.x=-Math.PI/2,n.rotation.z=Math.PI/2,n}_buildNode(t,n,r){const s=new w.Group;s.name=t.name??"Part";for(const f of t.meshes){const e=n[f];if(e!=null&&e.attributes){const o=this._createMesh(e);s.add(o)}}for(const f of t.children)this._buildNode(f,n,s);r.add(s)}_createMesh(t){var l,i;const{position:n,normal:r}=t.attributes,s=t.index??t.attributes.index,f=new w.BufferGeometry;f.setAttribute("position",new w.BufferAttribute(new Float32Array(n.array),3)),(l=r==null?void 0:r.array)!=null&&l.length?f.setAttribute("normal",new w.BufferAttribute(new Float32Array(r.array),3)):f.computeVertexNormals(),(i=s==null?void 0:s.array)!=null&&i.length&&f.setIndex(new w.BufferAttribute(new Uint32Array(s.array),1));const e=t.color,o=new w.MeshStandardMaterial({metalness:.3,roughness:.6});e&&e.length>=3?o.color.setRGB(e[0],e[1],e[2]):o.color.setHex(13421772);const d=new w.Mesh(f,o);return d.name=t.name??"Mesh",d.castShadow=!0,d.receiveShadow=!0,d}}class K{constructor(){p(this,"_gltfLoader");p(this,"_usdLoader");p(this,"_stepLoader");const t=new k;t.setDecoderConfig({type:"wasm"}),this._gltfLoader=new z.GLTFLoader,this._gltfLoader.setDRACOLoader(t),this._usdLoader=new Y.USDLoader,this._stepLoader=new Z}async load(t,n){let r;if(n)r=n;else if(r=U.getFileTypeFromUri(t),r.length===0&&(r=await this._detectFileTypeFromContent(t),r.length===0))throw new R.FileTypeError("No file extension found in URI","");if(!U.
|
|
3
|
+
`),f=URL.createObjectURL(new Blob([s])),e=new Worker(f),o=new URL(n,window.location.href).href;return e.postMessage({type:"init",wasmUrl:o}),e.onmessage=d=>{const{type:l,id:i,result:_,error:a}=d.data,u=this._pending.get(i);if(u)if(this._pending.delete(i),l==="result")try{u.resolve(this._buildScene(_))}catch(h){u.reject(h instanceof Error?h:new Error(String(h)))}else u.reject(new Error(a??"Worker error"))},e.onerror=d=>{for(const[,{reject:l}]of this._pending)l(new Error(d.message??"Worker error"));this._pending.clear()},this._worker=e,e})(),this._workerPending)}async parseAsync(t,n){const r=this._nextId++,s=await this._getWorker();return new Promise((f,e)=>{this._pending.set(r,{resolve:f,reject:e});const o=t.slice(0);s.postMessage({type:"parse",id:r,buffer:o,fileType:n},[o])})}dispose(){if(this._worker){for(const[,{reject:t}]of this._pending)t(new Error("STEPLoader disposed"));this._pending.clear(),this._worker.terminate(),this._worker=null,this._workerPending=null}}_buildScene(t){const n=new w.Group;return n.name=t.root.name??"CAD Model",this._buildNode(t.root,t.meshes,n),n.rotation.x=-Math.PI/2,n.rotation.z=Math.PI/2,n}_buildNode(t,n,r){const s=new w.Group;s.name=t.name??"Part";for(const f of t.meshes){const e=n[f];if(e!=null&&e.attributes){const o=this._createMesh(e);s.add(o)}}for(const f of t.children)this._buildNode(f,n,s);r.add(s)}_createMesh(t){var l,i;const{position:n,normal:r}=t.attributes,s=t.index??t.attributes.index,f=new w.BufferGeometry;f.setAttribute("position",new w.BufferAttribute(new Float32Array(n.array),3)),(l=r==null?void 0:r.array)!=null&&l.length?f.setAttribute("normal",new w.BufferAttribute(new Float32Array(r.array),3)):f.computeVertexNormals(),(i=s==null?void 0:s.array)!=null&&i.length&&f.setIndex(new w.BufferAttribute(new Uint32Array(s.array),1));const e=t.color,o=new w.MeshStandardMaterial({metalness:.3,roughness:.6});e&&e.length>=3?o.color.setRGB(e[0],e[1],e[2]):o.color.setHex(13421772);const d=new w.Mesh(f,o);return d.name=t.name??"Mesh",d.castShadow=!0,d.receiveShadow=!0,d}}class K{constructor(){p(this,"_gltfLoader");p(this,"_usdLoader");p(this,"_stepLoader");const t=new k;t.setDecoderConfig({type:"wasm"}),this._gltfLoader=new z.GLTFLoader,this._gltfLoader.setDRACOLoader(t),this._usdLoader=new Y.USDLoader,this._stepLoader=new Z}async load(t,n){let r;if(n)r=n;else if(r=U.getFileTypeFromUri(t),r.length===0&&(r=await this._detectFileTypeFromContent(t),r.length===0))throw new R.FileTypeError("No file extension found in URI","");if(!U.isFileExtensionSupported(r))throw new R.FileTypeError(`Unsupported file type: ${r}. Supported types: ${J.SUPPORTED_FILE_TYPES.join(", ")}`,r);const s=T.AssetCache.read(t);if(s)return s.arrayBuffer?this._parse(s.arrayBuffer,r):s.promise.then(o=>this._parse(o,r));const e=await T.AssetCache.create(t).load();return this._parse(e,r)}async _detectFileTypeFromContent(t){try{const n=T.AssetCache.read(t);let r;n?n.arrayBuffer?r=n.arrayBuffer:r=await n.promise:r=await T.AssetCache.create(t).load();const s=new Uint8Array(r);return s.length>=12&&String.fromCharCode(s[0],s[1],s[2],s[3])==="glTF"?s[12]===0?"glb":"gltf":s.length>=4&&s[0]===80&&s[1]===75&&(s[2]===3||s[2]===5)&&(s[3]===4||s[3]===6)?"usdz":s.length>=20&&new TextDecoder("ascii").decode(s.subarray(0,20)).startsWith("ISO-10303-21")?"step":s.length>=80&&s[72]===83?"iges":""}catch{return""}}async _parse(t,n){try{switch(n){case"glb":case"gltf":{const r=await this._gltfLoader.parseAsync(t,"");return r.scene.animations=r.animations,r.scene}case"usdz":{const r=this._usdLoader.parse(t);return r.animations=[],r}case"step":case"stp":{const r=await this._stepLoader.parseAsync(t,n);return r.animations=[],r}case"iges":case"igs":{const r=await this._stepLoader.parseAsync(t,n);return r.animations=[],r}}}catch(r){throw r instanceof Error?new R.ParseError(`Failed to parse ${n} file: ${r.message}`,r):new R.ParseError(`Failed to parse ${n} file`)}}}exports.AssetLoader=K;exports.DRACOWorker=N;exports.DracoLoader=k;
|