@nebula-spatial/viewer 0.4.5 → 0.5.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/CHANGELOG.md +62 -5
- package/README.md +98 -51
- package/dist/assets/types.d.ts +40 -11
- package/dist/cad/types.d.ts +4 -8
- package/dist/{index-CxbZ--5C.js → index-D2vtjYht.js} +2648 -2287
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -2
- package/dist/{mjcf-visual-6_RqDf4z.js → mjcf-visual-NkIASi_6.js} +2 -2
- package/dist/mujoco-runtime-7xiBQNJm.js +324 -0
- package/dist/session-DHPMjyl3.js +809 -0
- package/dist/{session-CnlODeFp.js → session-di9BueA_.js} +152 -163
- package/dist/{stage-BPiGudYP.js → stage-D-BewE6x.js} +198 -150
- package/dist/types.d.ts +11 -0
- package/dist/{urdf-session-CuIZOiCF.js → urdf-session-DsE5uC-u.js} +433 -424
- package/dist/usd-session-yEFMGOIp.js +2240 -0
- package/dist/version.d.ts +5 -0
- package/dist/{xacro-DrBtv-gK.js → xacro-D8OfZ2xw.js} +1 -1
- package/openusd/openusd_probe.js +14 -0
- package/openusd/openusd_probe.wasm +0 -0
- package/package.json +5 -4
- package/dist/mujoco-runtime-C29PXDOl.js +0 -258
- package/dist/session-DNyPmQOW.js +0 -795
- package/dist/usd-session-JDfuDgWv.js +0 -1907
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var a = (
|
|
1
|
+
var w = Object.defineProperty;
|
|
2
|
+
var P = (n, e, t) => e in n ? w(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var a = (n, e, t) => P(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import * as r from "three";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { Quaternion as y, Vector3 as C } from "three";
|
|
6
|
+
import { V as x } from "./index-D2vtjYht.js";
|
|
7
|
+
const m = 1, S = (
|
|
7
8
|
/* glsl */
|
|
8
9
|
`
|
|
9
10
|
uniform mat4 textureMatrix;
|
|
@@ -19,7 +20,7 @@ const p = 1, w = (
|
|
|
19
20
|
gl_Position = projectionMatrix * mvPosition;
|
|
20
21
|
}
|
|
21
22
|
`
|
|
22
|
-
),
|
|
23
|
+
), G = (
|
|
23
24
|
/* glsl */
|
|
24
25
|
`
|
|
25
26
|
uniform sampler2D tDiffuse;
|
|
@@ -86,18 +87,18 @@ const p = 1, w = (
|
|
|
86
87
|
}
|
|
87
88
|
`
|
|
88
89
|
);
|
|
89
|
-
class
|
|
90
|
-
constructor({ size:
|
|
91
|
-
const s = new r.Matrix4(),
|
|
90
|
+
class R extends r.Mesh {
|
|
91
|
+
constructor({ size: t = 20, textureWidth: i = 512, textureHeight: o = 512 } = {}) {
|
|
92
|
+
const s = new r.Matrix4(), u = new r.WebGLRenderTarget(i, o, {
|
|
92
93
|
type: r.HalfFloatType,
|
|
93
94
|
minFilter: r.LinearFilter,
|
|
94
95
|
magFilter: r.LinearFilter,
|
|
95
96
|
format: r.RGBAFormat,
|
|
96
97
|
depthBuffer: !0,
|
|
97
98
|
samples: 0
|
|
98
|
-
}),
|
|
99
|
+
}), l = new r.ShaderMaterial({
|
|
99
100
|
uniforms: {
|
|
100
|
-
tDiffuse: { value:
|
|
101
|
+
tDiffuse: { value: u.texture },
|
|
101
102
|
textureMatrix: { value: s },
|
|
102
103
|
resolution: { value: new r.Vector2(i, o) },
|
|
103
104
|
fineGridColor: { value: new r.Color(2502702) },
|
|
@@ -107,17 +108,17 @@ class C extends r.Mesh {
|
|
|
107
108
|
gridOpacity: { value: 1 },
|
|
108
109
|
gridScale: { value: 0.2 },
|
|
109
110
|
groundCenter: { value: new r.Vector2() },
|
|
110
|
-
maxRadius: { value:
|
|
111
|
-
fadeSoftness: { value:
|
|
111
|
+
maxRadius: { value: t * 0.5 },
|
|
112
|
+
fadeSoftness: { value: t * 0.325 }
|
|
112
113
|
},
|
|
113
|
-
vertexShader:
|
|
114
|
-
fragmentShader:
|
|
114
|
+
vertexShader: S,
|
|
115
|
+
fragmentShader: G,
|
|
115
116
|
transparent: !0,
|
|
116
117
|
depthWrite: !1,
|
|
117
118
|
toneMapped: !0,
|
|
118
119
|
fog: !1
|
|
119
120
|
});
|
|
120
|
-
super(new r.PlaneGeometry(
|
|
121
|
+
super(new r.PlaneGeometry(t, t), l);
|
|
121
122
|
a(this, "renderTarget");
|
|
122
123
|
a(this, "textureMatrix");
|
|
123
124
|
a(this, "virtualCamera");
|
|
@@ -132,9 +133,9 @@ class C extends r.Mesh {
|
|
|
132
133
|
a(this, "view");
|
|
133
134
|
a(this, "target");
|
|
134
135
|
a(this, "q");
|
|
135
|
-
this.renderTarget =
|
|
136
|
+
this.renderTarget = u, this.textureMatrix = s, this.virtualCamera = new r.PerspectiveCamera(), this.virtualCamera.layers.set(m), this.clipBias = 3e-3, this.frustumCulled = !1, this.renderOrder = 1, this.position.z = 2e-3, this.reflectorPlane = new r.Plane(), this.normal = new r.Vector3(), this.reflectorWorldPosition = new r.Vector3(), this.cameraWorldPosition = new r.Vector3(), this.rotationMatrix = new r.Matrix4(), this.lookAtPosition = new r.Vector3(0, 0, -1), this.clipPlane = new r.Vector4(), this.view = new r.Vector3(), this.target = new r.Vector3(), this.q = new r.Vector4();
|
|
136
137
|
}
|
|
137
|
-
renderReflection(
|
|
138
|
+
renderReflection(t, i, o) {
|
|
138
139
|
if (this.reflectorWorldPosition.setFromMatrixPosition(this.matrixWorld), this.cameraWorldPosition.setFromMatrixPosition(o.matrixWorld), this.rotationMatrix.extractRotation(this.matrixWorld), this.normal.set(0, 0, 1).applyMatrix4(this.rotationMatrix), this.view.subVectors(this.reflectorWorldPosition, this.cameraWorldPosition), this.view.dot(this.normal) > 0) return;
|
|
139
140
|
this.view.reflect(this.normal).negate().add(this.reflectorWorldPosition), this.rotationMatrix.extractRotation(o.matrixWorld), this.lookAtPosition.set(0, 0, -1).applyMatrix4(this.rotationMatrix).add(this.cameraWorldPosition), this.target.subVectors(this.reflectorWorldPosition, this.lookAtPosition).reflect(this.normal).negate().add(this.reflectorWorldPosition), this.virtualCamera.position.copy(this.view), this.virtualCamera.up.set(0, 1, 0).applyMatrix4(this.rotationMatrix).reflect(this.normal), this.virtualCamera.lookAt(this.target), this.virtualCamera.near = o.near, this.virtualCamera.far = o.far, this.virtualCamera.updateMatrixWorld(), this.virtualCamera.projectionMatrix.copy(o.projectionMatrix), this.textureMatrix.set(
|
|
140
141
|
0.5,
|
|
@@ -166,19 +167,19 @@ class C extends r.Mesh {
|
|
|
166
167
|
-1,
|
|
167
168
|
(1 + s.elements[10]) / s.elements[14]
|
|
168
169
|
), this.clipPlane.multiplyScalar(2 / this.clipPlane.dot(this.q)), s.elements[2] = this.clipPlane.x, s.elements[6] = this.clipPlane.y, s.elements[10] = this.clipPlane.z + 1 - this.clipBias, s.elements[14] = this.clipPlane.w, this.virtualCamera.projectionMatrixInverse.copy(s).invert();
|
|
169
|
-
const
|
|
170
|
+
const u = t.getRenderTarget(), l = t.xr.enabled, c = t.shadowMap.autoUpdate, d = t.shadowMap.enabled;
|
|
170
171
|
try {
|
|
171
|
-
|
|
172
|
+
t.xr.enabled = !1, t.shadowMap.enabled = !1, t.shadowMap.autoUpdate = !1, t.setRenderTarget(this.renderTarget), t.state.buffers.depth.setMask(!0), t.clear(), t.render(i, this.virtualCamera);
|
|
172
173
|
} finally {
|
|
173
|
-
|
|
174
|
+
t.setRenderTarget(u), t.xr.enabled = l, t.shadowMap.enabled = d, t.shadowMap.autoUpdate = c;
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
|
-
setRenderSize(
|
|
177
|
-
this.renderTarget.setSize(
|
|
177
|
+
setRenderSize(t, i) {
|
|
178
|
+
this.renderTarget.setSize(t, i), this.material.uniforms.resolution.value.set(t, i);
|
|
178
179
|
}
|
|
179
180
|
// Radius is in world units; the outer 65% fades before the square mesh edge.
|
|
180
|
-
setRadius(
|
|
181
|
-
this.scale.setScalar(
|
|
181
|
+
setRadius(t, i, o = this.material.uniforms.groundCenter.value) {
|
|
182
|
+
this.scale.setScalar(t * 2 / this.geometry.parameters.width), this.position.x = o.x, this.position.y = o.y, this.material.uniforms.groundCenter.value.set(o.x, o.y), this.material.uniforms.gridScale.value = i, this.material.uniforms.maxRadius.value = t, this.material.uniforms.fadeSoftness.value = t * 0.65;
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
const v = {
|
|
@@ -196,60 +197,82 @@ const v = {
|
|
|
196
197
|
gridOpacity: 0.9,
|
|
197
198
|
reflectionMix: 0.06
|
|
198
199
|
}
|
|
199
|
-
},
|
|
200
|
+
}, W = {
|
|
200
201
|
simulation: 0.68,
|
|
201
202
|
model: 1.4
|
|
202
203
|
};
|
|
203
|
-
function
|
|
204
|
-
var
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
const c =
|
|
208
|
-
c.geometry &&
|
|
204
|
+
function M(n, e = []) {
|
|
205
|
+
var u;
|
|
206
|
+
const t = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), o = new Set(e), s = /* @__PURE__ */ new Set();
|
|
207
|
+
n.traverse((l) => {
|
|
208
|
+
const c = l;
|
|
209
|
+
c.geometry && t.add(c.geometry);
|
|
209
210
|
for (const d of Array.isArray(c.material) ? c.material : [c.material])
|
|
210
211
|
if (d) {
|
|
211
212
|
i.add(d);
|
|
212
213
|
for (const h of Object.values(d))
|
|
213
|
-
|
|
214
|
+
T(h) && o.add(h);
|
|
214
215
|
}
|
|
215
216
|
});
|
|
216
|
-
for (const
|
|
217
|
-
for (const
|
|
218
|
-
for (const
|
|
219
|
-
const c = (
|
|
220
|
-
c && typeof c.close == "function" && s.add(c),
|
|
217
|
+
for (const l of t) l.dispose();
|
|
218
|
+
for (const l of i) l.dispose();
|
|
219
|
+
for (const l of o) {
|
|
220
|
+
const c = (u = l.source) == null ? void 0 : u.data;
|
|
221
|
+
c && typeof c.close == "function" && s.add(c), l.dispose();
|
|
221
222
|
}
|
|
222
|
-
for (const
|
|
223
|
+
for (const l of s) l.close();
|
|
223
224
|
}
|
|
224
|
-
function
|
|
225
|
-
return !!(
|
|
225
|
+
function T(n) {
|
|
226
|
+
return !!(n && typeof n == "object" && n.isTexture);
|
|
226
227
|
}
|
|
227
|
-
const
|
|
228
|
+
const U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
228
229
|
__proto__: null,
|
|
229
|
-
disposeModelResources:
|
|
230
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
231
|
-
function
|
|
232
|
-
|
|
230
|
+
disposeModelResources: M
|
|
231
|
+
}, Symbol.toStringTag, { value: "Module" })), F = new y().setFromAxisAngle(new C(1, 0, 0), Math.PI / 2), L = new y();
|
|
232
|
+
function D(n) {
|
|
233
|
+
return n === "glb" || n === "gltf" || n === "fbx" ? "y" : "z";
|
|
234
|
+
}
|
|
235
|
+
function b(n) {
|
|
236
|
+
return n === "y" ? F : L;
|
|
237
|
+
}
|
|
238
|
+
function I(n, e) {
|
|
239
|
+
const t = b(e);
|
|
240
|
+
return t.equals(n.quaternion) ? !1 : (n.quaternion.copy(t), n.updateMatrixWorld(!0), !0);
|
|
241
|
+
}
|
|
242
|
+
const f = 2213822, A = 6000111, V = 6;
|
|
243
|
+
function z(n, e, t) {
|
|
244
|
+
e.updateMatrixWorld();
|
|
233
245
|
const i = new r.Vector3();
|
|
234
|
-
return
|
|
246
|
+
return e.getWorldDirection(i).normalize(), n.setFromNormalAndCoplanarPoint(i, t);
|
|
235
247
|
}
|
|
236
|
-
function
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
return
|
|
240
|
-
if (!(
|
|
241
|
-
let i =
|
|
248
|
+
function p(n) {
|
|
249
|
+
n.updateWorldMatrix(!0, !0);
|
|
250
|
+
const e = new r.Box3();
|
|
251
|
+
return n.traverse((t) => {
|
|
252
|
+
if (!(t instanceof r.Mesh)) return;
|
|
253
|
+
let i = t;
|
|
242
254
|
for (; i; ) {
|
|
243
255
|
if (i.userData.excludeFromSimulationFit || !i.visible) return;
|
|
244
256
|
i = i.parent;
|
|
245
257
|
}
|
|
246
|
-
|
|
247
|
-
}),
|
|
258
|
+
t.geometry.boundingBox || t.geometry.computeBoundingBox(), t.geometry.boundingBox && e.union(t.geometry.boundingBox.clone().applyMatrix4(t.matrixWorld));
|
|
259
|
+
}), e.isEmpty() ? new r.Box3().setFromObject(n) : e;
|
|
248
260
|
}
|
|
249
|
-
class
|
|
250
|
-
constructor(
|
|
261
|
+
class k {
|
|
262
|
+
constructor(e, t = "dark", i, o = "simulation") {
|
|
251
263
|
a(this, "root", new r.Group());
|
|
252
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Owns the up-axis rotation for everything that is *not* driven by the
|
|
266
|
+
* physics runtime: the URDF kinematic preview, the static collision overlay
|
|
267
|
+
* and the review guides. When a runtime is attached the rotation moves into
|
|
268
|
+
* the compiled model instead (see `applyUpAxis`), because rotating the scene
|
|
269
|
+
* graph on top of an already-rotated physics pose would apply it twice.
|
|
270
|
+
*/
|
|
271
|
+
a(this, "modelWrapper", new r.Group());
|
|
272
|
+
a(this, "upAxis", "z");
|
|
273
|
+
/** A flip changes the asset footprint; the ground disc follows on the next frame. */
|
|
274
|
+
a(this, "groundNeedsRefit", !1);
|
|
275
|
+
a(this, "reflector", new R({ size: 100, textureWidth: 256, textureHeight: 256 }));
|
|
253
276
|
a(this, "values");
|
|
254
277
|
a(this, "fog");
|
|
255
278
|
a(this, "raycaster", new r.Raycaster());
|
|
@@ -267,107 +290,127 @@ class B {
|
|
|
267
290
|
a(this, "size", "");
|
|
268
291
|
a(this, "groundVisible");
|
|
269
292
|
a(this, "disposed", !1);
|
|
270
|
-
this.model =
|
|
271
|
-
const s = this.values,
|
|
272
|
-
if (!Number.isFinite(
|
|
273
|
-
this.root.add(
|
|
274
|
-
g instanceof r.Mesh && g.layers.enable(
|
|
293
|
+
this.model = e, this.runtime = i, this.presentation = o, this.values = v[t];
|
|
294
|
+
const s = this.values, u = p(e), l = Math.max(...u.getSize(new r.Vector3()).toArray());
|
|
295
|
+
if (!Number.isFinite(l) || l <= 0) throw new Error("Empty simulation geometry.");
|
|
296
|
+
this.modelWrapper.name = "simulation-model-wrapper", this.root.add(this.modelWrapper), this.modelWrapper.add(e), this.forceLine = this.createForceLine(), this.root.add(this.forceLine), e.traverse((g) => {
|
|
297
|
+
g instanceof r.Mesh && g.layers.enable(m);
|
|
275
298
|
}), this.root.add(this.reflector);
|
|
276
|
-
const c = Math.max(
|
|
277
|
-
d.fineGridColor.value.setHex(s.fineGrid), d.coarseGridColor.value.setHex(s.coarseGrid), d.gridOpacity.value = s.gridOpacity, d.reflectionMix.value = s.reflectionMix, this.layoutGround(
|
|
299
|
+
const c = Math.max(u.getSize(new r.Vector3()).length() * 0.5, 0.02), d = this.reflector.material.uniforms;
|
|
300
|
+
d.fineGridColor.value.setHex(s.fineGrid), d.coarseGridColor.value.setHex(s.coarseGrid), d.gridOpacity.value = s.gridOpacity, d.reflectionMix.value = s.reflectionMix, this.layoutGround(u, c), this.groundVisible = o === "simulation", this.setGroundVisible(this.groundVisible);
|
|
278
301
|
const h = c / Math.sin(r.MathUtils.degToRad(38) / 2) * 1.25;
|
|
279
302
|
this.fog = new r.Fog(s.background, h * 2.5, h * 8);
|
|
280
303
|
}
|
|
281
|
-
setRuntime(
|
|
282
|
-
this.disposed || this.runtime ===
|
|
304
|
+
setRuntime(e) {
|
|
305
|
+
this.disposed || this.runtime === e || (this.endGrab(), this.runtime = e, this.bodyGroups.clear(), this.applyUpAxis());
|
|
306
|
+
}
|
|
307
|
+
replaceModel(e, t = !0) {
|
|
308
|
+
this.disposed || e === this.model || (this.endGrab(), this.bodyGroups.clear(), this.model.removeFromParent(), this.model = e, this.modelWrapper.add(e), e.traverse((i) => {
|
|
309
|
+
i instanceof r.Mesh && i.layers.enable(m);
|
|
310
|
+
}), t && this.reseatGround());
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Re-orients the scene to the given authored up axis. The rotation is a real
|
|
314
|
+
* physics transform whenever a runtime is attached: the compiled model is
|
|
315
|
+
* rotated about the origin so collisions, contacts and the force line follow,
|
|
316
|
+
* while gravity stays -Z and the viewer ground is re-seated under the new pose
|
|
317
|
+
* — a cup that was standing topples and settles on its side instead of only
|
|
318
|
+
* its mesh flipping. Without a runtime (kinematic preview, physics fallback)
|
|
319
|
+
* the wrapper carries the rotation, exactly like the model preview path.
|
|
320
|
+
* Returns whether the orientation actually changed.
|
|
321
|
+
*/
|
|
322
|
+
setUpAxis(e) {
|
|
323
|
+
return this.disposed || e === this.upAxis ? !1 : (this.upAxis = e, this.applyUpAxis(), !0);
|
|
324
|
+
}
|
|
325
|
+
getUpAxis() {
|
|
326
|
+
return this.upAxis;
|
|
283
327
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}), e && this.reseatGround());
|
|
328
|
+
applyUpAxis() {
|
|
329
|
+
const e = b(this.upAxis);
|
|
330
|
+
this.runtime ? (this.modelWrapper.quaternion.identity(), this.runtime.setWorldRotation(e)) : this.modelWrapper.quaternion.copy(e), this.modelWrapper.updateMatrixWorld(!0), this.groundNeedsRefit = !0;
|
|
288
331
|
}
|
|
289
332
|
resetGround() {
|
|
290
|
-
var
|
|
291
|
-
this.disposed || (this.reflector.position.z = (((
|
|
333
|
+
var e;
|
|
334
|
+
this.disposed || (this.reflector.position.z = (((e = this.runtime) == null ? void 0 : e.defaultGroundHeight) ?? 0) + 2e-3);
|
|
292
335
|
}
|
|
293
|
-
setTheme(
|
|
336
|
+
setTheme(e) {
|
|
294
337
|
if (this.disposed) return;
|
|
295
|
-
const
|
|
296
|
-
i.fineGridColor.value.setHex(
|
|
338
|
+
const t = this.values = v[e], i = this.reflector.material.uniforms;
|
|
339
|
+
i.fineGridColor.value.setHex(t.fineGrid), i.coarseGridColor.value.setHex(t.coarseGrid), i.gridOpacity.value = t.gridOpacity, i.reflectionMix.value = t.reflectionMix, this.fog.color.setHex(t.background);
|
|
297
340
|
}
|
|
298
|
-
layoutGround(
|
|
299
|
-
this.reflector.setRadius(
|
|
341
|
+
layoutGround(e, t) {
|
|
342
|
+
this.reflector.setRadius(t * 8, Math.pow(10, Math.floor(Math.log10(Math.max(t, 0.01)))), e.getCenter(new r.Vector3()));
|
|
300
343
|
}
|
|
301
344
|
/**
|
|
302
345
|
* Re-fits the ground disc and reflection to the model's current world bounds.
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
346
|
+
* A flip is not rotation invariant for an axis-aligned bounding box, so the
|
|
347
|
+
* floor that was sized to a wide-flat footprint can end up clipping, or
|
|
348
|
+
* sitting off to the side of, the re-oriented model.
|
|
306
349
|
*/
|
|
307
350
|
reseatGround() {
|
|
308
351
|
if (this.disposed) return;
|
|
309
352
|
this.root.updateMatrixWorld(!0);
|
|
310
|
-
const
|
|
311
|
-
|
|
353
|
+
const e = p(this.model);
|
|
354
|
+
e.isEmpty() || this.layoutGround(e, Math.max(e.getSize(new r.Vector3()).length() * 0.5, 0.02));
|
|
312
355
|
}
|
|
313
356
|
createForceLine() {
|
|
314
|
-
const
|
|
357
|
+
const e = new r.BufferGeometry().setFromPoints([
|
|
315
358
|
new r.Vector3(),
|
|
316
359
|
new r.Vector3()
|
|
317
|
-
]),
|
|
360
|
+
]), t = new r.LineBasicMaterial({
|
|
318
361
|
color: f,
|
|
319
362
|
depthTest: !1,
|
|
320
363
|
transparent: !0
|
|
321
|
-
}), i = new r.Line(
|
|
364
|
+
}), i = new r.Line(e, t);
|
|
322
365
|
return i.renderOrder = 1e3, i.visible = !1, i;
|
|
323
366
|
}
|
|
324
|
-
findBodyGroup(
|
|
367
|
+
findBodyGroup(e) {
|
|
325
368
|
var i;
|
|
326
|
-
let
|
|
327
|
-
for (;
|
|
328
|
-
if (typeof ((i =
|
|
329
|
-
|
|
369
|
+
let t = e;
|
|
370
|
+
for (; t && t !== this.model && t !== this.root; ) {
|
|
371
|
+
if (typeof ((i = t.userData) == null ? void 0 : i.bodyId) == "number") return t;
|
|
372
|
+
t = t.parent;
|
|
330
373
|
}
|
|
331
374
|
return null;
|
|
332
375
|
}
|
|
333
|
-
getBodyGroup(
|
|
334
|
-
let
|
|
335
|
-
return
|
|
376
|
+
getBodyGroup(e) {
|
|
377
|
+
let t = this.bodyGroups.get(e);
|
|
378
|
+
return t || this.model.traverse((i) => {
|
|
336
379
|
var o;
|
|
337
|
-
((o = i.userData) == null ? void 0 : o.bodyId) ===
|
|
338
|
-
}),
|
|
380
|
+
((o = i.userData) == null ? void 0 : o.bodyId) === e && (t = i, this.bodyGroups.set(e, i));
|
|
381
|
+
}), t;
|
|
339
382
|
}
|
|
340
|
-
pointerRay(
|
|
383
|
+
pointerRay(e, t, i) {
|
|
341
384
|
const o = i.getBoundingClientRect();
|
|
342
385
|
this.pointer.set(
|
|
343
|
-
(
|
|
344
|
-
-((
|
|
345
|
-
), this.raycaster.setFromCamera(this.pointer,
|
|
386
|
+
(e.clientX - o.left) / o.width * 2 - 1,
|
|
387
|
+
-((e.clientY - o.top) / o.height) * 2 + 1
|
|
388
|
+
), this.raycaster.setFromCamera(this.pointer, t);
|
|
346
389
|
}
|
|
347
|
-
setForceBoost(
|
|
348
|
-
var
|
|
349
|
-
!((
|
|
390
|
+
setForceBoost(e) {
|
|
391
|
+
var t;
|
|
392
|
+
!((t = this.runtime) != null && t.grab) || e === this.forceBoosted || (this.forceBoosted = e, this.runtime.updateGrabStrength(e ? V : 1), this.forceLine.material.color.setHex(e ? A : f));
|
|
350
393
|
}
|
|
351
|
-
beginGrab(
|
|
394
|
+
beginGrab(e, t, i) {
|
|
352
395
|
if (!this.runtime || this.disposed) return !1;
|
|
353
|
-
this.pointerRay(
|
|
396
|
+
this.pointerRay(e, t, i);
|
|
354
397
|
const o = this.raycaster.intersectObject(this.model, !0).find((c) => c.object.isMesh);
|
|
355
398
|
if (!o) return !1;
|
|
356
399
|
const s = this.findBodyGroup(o.object);
|
|
357
400
|
if (!s) return !1;
|
|
358
|
-
const
|
|
359
|
-
this.dragTarget.copy(o.point),
|
|
360
|
-
const
|
|
401
|
+
const u = s.worldToLocal(o.point.clone());
|
|
402
|
+
this.dragTarget.copy(o.point), z(this.dragPlane, t, o.point), this.dragOffset.set(0, 0, 0);
|
|
403
|
+
const l = this.root.worldToLocal(o.point.clone());
|
|
361
404
|
return this.bodyGroups.set(s.userData.bodyId, s), this.runtime.beginGrab({
|
|
362
405
|
bodyId: s.userData.bodyId,
|
|
363
|
-
localPoint: [
|
|
364
|
-
target: [
|
|
365
|
-
}), this.forceBoosted = !1, this.setForceBoost(
|
|
406
|
+
localPoint: [u.x, u.y, u.z],
|
|
407
|
+
target: [l.x, l.y, l.z]
|
|
408
|
+
}), this.forceBoosted = !1, this.setForceBoost(e.shiftKey), this.forceLine.visible = !0, this.updateForceLine(), this.grabCanvas = i, i != null && i.style && (this.previousCursor = i.style.cursor, i.style.cursor = "grabbing"), !0;
|
|
366
409
|
}
|
|
367
|
-
moveGrab(
|
|
410
|
+
moveGrab(e, t, i) {
|
|
368
411
|
var s;
|
|
369
412
|
if (!((s = this.runtime) != null && s.grab)) return;
|
|
370
|
-
if (this.pointerRay(
|
|
413
|
+
if (this.pointerRay(e, t, i), this.setForceBoost(e.shiftKey), i != null && i.style && i.style.cursor !== "grabbing" && (i.style.cursor = "grabbing"), this.raycaster.ray.intersectPlane(this.dragPlane, this.dragIntersection))
|
|
371
414
|
this.dragTarget.copy(this.dragIntersection).add(this.dragOffset);
|
|
372
415
|
else
|
|
373
416
|
return;
|
|
@@ -375,37 +418,37 @@ class B {
|
|
|
375
418
|
this.runtime.updateGrabTarget([o.x, o.y, o.z]), this.updateForceLine();
|
|
376
419
|
}
|
|
377
420
|
endGrab() {
|
|
378
|
-
var
|
|
379
|
-
this.runtime && (this.runtime.endGrab(), this.forceBoosted = !1, this.forceLine.visible = !1, this.forceLine.material.color.setHex(f), (
|
|
421
|
+
var e;
|
|
422
|
+
this.runtime && (this.runtime.endGrab(), this.forceBoosted = !1, this.forceLine.visible = !1, this.forceLine.material.color.setHex(f), (e = this.grabCanvas) != null && e.style && (this.grabCanvas.style.cursor = this.previousCursor), this.grabCanvas = null);
|
|
380
423
|
}
|
|
381
424
|
updateForceLine() {
|
|
382
|
-
var
|
|
383
|
-
const
|
|
384
|
-
if (!t) return;
|
|
385
|
-
const e = this.getBodyGroup(t.bodyId);
|
|
425
|
+
var l;
|
|
426
|
+
const e = (l = this.runtime) == null ? void 0 : l.grab;
|
|
386
427
|
if (!e) return;
|
|
387
|
-
const
|
|
388
|
-
|
|
428
|
+
const t = this.getBodyGroup(e.bodyId);
|
|
429
|
+
if (!t) return;
|
|
430
|
+
const i = new r.Vector3().fromArray(e.localPoint), o = t.localToWorld(i), s = this.root.worldToLocal(o), u = this.forceLine.geometry.attributes.position;
|
|
431
|
+
u.setXYZ(0, s.x, s.y, s.z), u.setXYZ(1, e.target[0], e.target[1], e.target[2]), u.needsUpdate = !0;
|
|
389
432
|
}
|
|
390
|
-
beforeRender(
|
|
391
|
-
var
|
|
433
|
+
beforeRender(e, t, i) {
|
|
434
|
+
var u, l;
|
|
392
435
|
const o = {
|
|
393
|
-
tone:
|
|
394
|
-
exposure:
|
|
395
|
-
color:
|
|
396
|
-
environment:
|
|
397
|
-
fog:
|
|
398
|
-
background:
|
|
436
|
+
tone: e.toneMapping,
|
|
437
|
+
exposure: e.toneMappingExposure,
|
|
438
|
+
color: e.outputColorSpace,
|
|
439
|
+
environment: t.environment,
|
|
440
|
+
fog: t.fog,
|
|
441
|
+
background: t.background
|
|
399
442
|
}, s = () => {
|
|
400
|
-
|
|
443
|
+
e.toneMapping = o.tone, e.toneMappingExposure = o.exposure, e.outputColorSpace = o.color, t.environment = o.environment, t.fog = o.fog, t.background = o.background;
|
|
401
444
|
};
|
|
402
445
|
if (this.disposed) return s;
|
|
403
446
|
try {
|
|
404
|
-
(
|
|
405
|
-
const c = (
|
|
406
|
-
c !== void 0 && (this.reflector.position.z = c + 2e-3),
|
|
407
|
-
const d =
|
|
408
|
-
return h !== this.size && (this.size = h, this.reflector.setRenderSize(Math.max(1, Math.floor(d.x * 0.35)), Math.max(1, Math.floor(d.y * 0.35)))),
|
|
447
|
+
this.groundNeedsRefit && (this.groundNeedsRefit = !1, this.reseatGround()), (u = this.runtime) != null && u.grab && this.updateForceLine();
|
|
448
|
+
const c = (l = this.runtime) == null ? void 0 : l.defaultGroundHeight;
|
|
449
|
+
c !== void 0 && (this.reflector.position.z = c + 2e-3), e.toneMapping = r.ACESFilmicToneMapping, e.toneMappingExposure = W[this.presentation], e.outputColorSpace = r.SRGBColorSpace, t.background = new r.Color(this.values.background), t.fog = this.fog;
|
|
450
|
+
const d = e.getSize(new r.Vector2()), h = `${d.x}:${d.y}`;
|
|
451
|
+
return h !== this.size && (this.size = h, this.reflector.setRenderSize(Math.max(1, Math.floor(d.x * 0.35)), Math.max(1, Math.floor(d.y * 0.35)))), t.updateMatrixWorld(!0), i.updateMatrixWorld(!0), this.groundVisible && i instanceof r.PerspectiveCamera && this.reflector.renderReflection(e, t, i), s;
|
|
409
452
|
} catch (c) {
|
|
410
453
|
throw s(), c;
|
|
411
454
|
}
|
|
@@ -414,8 +457,8 @@ class B {
|
|
|
414
457
|
* The reflector mesh carries both the grid lines and the reflection. Hiding
|
|
415
458
|
* it also skips the reflection render pass, which only feeds its shader.
|
|
416
459
|
*/
|
|
417
|
-
setGroundVisible(
|
|
418
|
-
this.groundVisible =
|
|
460
|
+
setGroundVisible(e) {
|
|
461
|
+
this.groundVisible = e, this.reflector.visible = e;
|
|
419
462
|
}
|
|
420
463
|
getGroundVisible() {
|
|
421
464
|
return this.groundVisible;
|
|
@@ -425,30 +468,35 @@ class B {
|
|
|
425
468
|
* The model subtree is what the reflector pass and `getModelBounds` measure,
|
|
426
469
|
* so nesting hidden aids (collision meshes, which are far larger than the
|
|
427
470
|
* visual shell) would inflate both the reflection extent and the camera fit.
|
|
471
|
+
* Auxiliaries ride in the up-axis wrapper: they are kinematic content, while
|
|
472
|
+
* anything the physics runtime drives is rotated inside the compiled model.
|
|
428
473
|
*/
|
|
429
|
-
attachAuxiliary(
|
|
430
|
-
this.auxiliaries.add(
|
|
474
|
+
attachAuxiliary(e) {
|
|
475
|
+
this.auxiliaries.add(e), this.modelWrapper.add(e);
|
|
431
476
|
}
|
|
432
|
-
detachAuxiliary(
|
|
433
|
-
this.auxiliaries.delete(
|
|
477
|
+
detachAuxiliary(e) {
|
|
478
|
+
this.auxiliaries.delete(e) && e.removeFromParent();
|
|
434
479
|
}
|
|
435
480
|
getModelBounds() {
|
|
436
481
|
this.root.updateMatrixWorld(!0);
|
|
437
|
-
const
|
|
438
|
-
if (!
|
|
439
|
-
const
|
|
440
|
-
return
|
|
482
|
+
const e = p(this.model);
|
|
483
|
+
if (!e.isEmpty()) return e;
|
|
484
|
+
const t = new r.Box3();
|
|
485
|
+
return t.min.set(-5e3, -5e3, -5e3), t.max.set(5e3, 5e3, 5e3), t;
|
|
441
486
|
}
|
|
442
487
|
dispose() {
|
|
443
488
|
if (!this.disposed) {
|
|
444
489
|
this.disposed = !0, this.endGrab(), this.model.removeFromParent();
|
|
445
|
-
for (const
|
|
446
|
-
this.auxiliaries.clear(), this.root.removeFromParent(), this.reflector.renderTarget.dispose(),
|
|
490
|
+
for (const e of this.auxiliaries) e.removeFromParent();
|
|
491
|
+
this.auxiliaries.clear(), this.modelWrapper.removeFromParent(), this.root.removeFromParent(), this.reflector.renderTarget.dispose(), M(this.root);
|
|
447
492
|
}
|
|
448
493
|
}
|
|
449
494
|
}
|
|
450
495
|
export {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
496
|
+
k as S,
|
|
497
|
+
I as a,
|
|
498
|
+
M as b,
|
|
499
|
+
D as d,
|
|
500
|
+
b as m,
|
|
501
|
+
U as r
|
|
454
502
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ export type CadInteractionMode = 'managed' | 'manual' | 'disabled';
|
|
|
11
11
|
* does not re-export the runtime package's type.
|
|
12
12
|
*/
|
|
13
13
|
export type ViewerNavigationPolicy = 'legacy' | 'viewer' | 'preview';
|
|
14
|
+
/**
|
|
15
|
+
* Model/simulation preview pointer mapping. `left-rotate` (default) orbits with
|
|
16
|
+
* the left button and pans with the right; `left-pan` inverts that. Middle
|
|
17
|
+
* always dollies. Own union so the viewer surface does not re-export the
|
|
18
|
+
* runtime package's type.
|
|
19
|
+
*/
|
|
20
|
+
export type ViewerPreviewDragPreset = 'left-rotate' | 'left-pan';
|
|
14
21
|
export type CameraChangeReason = 'pointer' | 'wheel' | 'fit' | 'restore' | 'api' | 'view-mode';
|
|
15
22
|
export type ViewerEnvironment = 'room' | {
|
|
16
23
|
/** Load an external equirectangular HDR texture for image-based lighting. */
|
|
@@ -58,6 +65,8 @@ export interface ViewerOptions {
|
|
|
58
65
|
initialViewMode?: ViewerViewMode;
|
|
59
66
|
/** Image-based lighting environment. Defaults to the built-in room environment. */
|
|
60
67
|
environment?: ViewerEnvironment;
|
|
68
|
+
/** Pointer mapping for model/simulation previews. Defaults to `left-rotate`. */
|
|
69
|
+
previewDragPreset?: ViewerPreviewDragPreset;
|
|
61
70
|
autoSelectOnPick?: boolean;
|
|
62
71
|
pointerPick?: boolean;
|
|
63
72
|
/** CAD click policy. Defaults to managed. */
|
|
@@ -223,6 +232,8 @@ export interface Viewer {
|
|
|
223
232
|
requestRender(): void;
|
|
224
233
|
getActiveCamera(): import('three').Camera;
|
|
225
234
|
setNavigationEnabled(enabled: boolean): void;
|
|
235
|
+
/** Switches the model/simulation preview pointer mapping at runtime. */
|
|
236
|
+
setPreviewDragPreset(preset: ViewerPreviewDragPreset): void;
|
|
226
237
|
dispose(): void;
|
|
227
238
|
use(plugins: readonly import('./plugins').ViewerPlugin[], options?: {
|
|
228
239
|
replace?: boolean;
|