@nebula-spatial/viewer 0.5.4 → 0.5.6
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 +67 -0
- package/README.md +97 -54
- package/USD-VISUAL-MATERIAL-SUPPORT.md +5 -3
- package/basis/basis_transcoder.js +19 -0
- package/basis/basis_transcoder.wasm +0 -0
- package/dist/assets/ground-grid.d.ts +6 -0
- package/dist/assets/types.d.ts +37 -0
- package/dist/assets/usd-worker-CnpILBYh.js +1352 -0
- package/dist/collision-debug-CqRm6cC8.js +479 -0
- package/dist/{index-8TD-Puyo.js → index-D6-ClMfm.js} +2512 -1768
- package/dist/index.d.ts +5 -1
- package/dist/index.js +15 -12
- package/dist/{mjcf-visual-qlID4stF.js → mjcf-visual-B8RE9CqV.js} +7 -7
- package/dist/mujoco-runtime-ZuEJSHnD.js +396 -0
- package/dist/resources-CHhCm2f7.js +27 -0
- package/dist/{session-CCDMlwej.js → session-CDrNB1J2.js} +6 -5
- package/dist/session-DgvOdcLe.js +632 -0
- package/dist/simulation/usd-query.d.ts +50 -0
- package/dist/simulation/usd-resource-policy.d.ts +28 -0
- package/dist/{stage-DAhe0IZz.js → stage-CSRMl8kx.js} +158 -170
- package/dist/{urdf-session-DceYWCib.js → urdf-session-DD3HOAib.js} +552 -542
- package/dist/usd-session-BCCp_YDr.js +6217 -0
- package/dist/version.d.ts +1 -1
- package/dist/{xacro-DPEhwEml.js → xacro-BpICdIYd.js} +1 -1
- package/openusd/openusd-runtime-manifest.json +15 -0
- package/openusd/openusd_probe.js +1 -1
- package/openusd/openusd_probe.wasm +0 -0
- package/package.json +4 -2
- package/dist/mujoco-runtime-DTxVmIzc.js +0 -349
- package/dist/session-um40A-5F.js +0 -878
- package/dist/usd-session-BBtKxubs.js +0 -4174
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read policy for USD composition resources.
|
|
3
|
+
*
|
|
4
|
+
* The viewer never inspects host error messages: only stable `code` values (or
|
|
5
|
+
* the HTTP status those messages carry) decide whether a failed reference is a
|
|
6
|
+
* degraded visual resource or a real load failure. Denial, authentication
|
|
7
|
+
* failure, cancellation and unclassified faults always stay fatal.
|
|
8
|
+
*/
|
|
9
|
+
export type UsdResourceFailureKind = 'missing' | 'invalid' | 'unavailable' | 'denied' | 'aborted' | 'unknown';
|
|
10
|
+
/** Stable codes a host resolver may attach to a rejected resource read. */
|
|
11
|
+
export declare const USD_RESOURCE_NOT_FOUND = "E_ASSET_RESOURCE_NOT_FOUND";
|
|
12
|
+
export declare const USD_RESOURCE_INVALID = "E_ASSET_RESOURCE_INVALID";
|
|
13
|
+
export declare const USD_RESOURCE_FETCH = "E_ASSET_FETCH";
|
|
14
|
+
export declare const USD_RESOURCE_EXTERNAL_DENIED = "E_ASSET_EXTERNAL_DENIED";
|
|
15
|
+
export declare const USD_RESOURCE_AUTH = "E_ASSET_AUTH";
|
|
16
|
+
/**
|
|
17
|
+
* Only recognized visual resources may degrade. Everything else — USD layers,
|
|
18
|
+
* MDL modules, unknown file types — keeps its failure.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isDegradableUsdResource(identifier: string): boolean;
|
|
21
|
+
export declare function codedUsdResourceError(message: string, code: string): Error;
|
|
22
|
+
export declare function classifyUsdResourceFailure(error: unknown): UsdResourceFailureKind;
|
|
23
|
+
/** Host denial, auth failure, cancellation and unknown faults are never swallowed. */
|
|
24
|
+
export declare function isDegradableUsdResourceFailure(error: unknown): boolean;
|
|
25
|
+
/** A 2xx status does not make an HTML error page or an empty body a usable resource. */
|
|
26
|
+
export declare function invalidUsdResourceContent(contentType: string | null, bytes: Uint8Array): string | null;
|
|
27
|
+
/** Blob equivalent of {@link invalidUsdResourceContent}, reading only a short prefix. */
|
|
28
|
+
export declare function invalidUsdResourceBlob(blob: Blob): Promise<string | null>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var s = (
|
|
4
|
-
import * as
|
|
5
|
-
import { Quaternion as
|
|
6
|
-
import { V as
|
|
7
|
-
|
|
1
|
+
var R = Object.defineProperty;
|
|
2
|
+
var S = (a, t, e) => t in a ? R(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
|
+
var s = (a, t, e) => S(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import * as i from "three";
|
|
5
|
+
import { Quaternion as C, Vector3 as V } from "three";
|
|
6
|
+
import { V as b, D as A, v as W } from "./index-D6-ClMfm.js";
|
|
7
|
+
import { disposeModelResources as T } from "./resources-CHhCm2f7.js";
|
|
8
|
+
const v = 1, B = (
|
|
8
9
|
/* glsl */
|
|
9
10
|
`
|
|
10
11
|
uniform mat4 textureMatrix;
|
|
@@ -20,7 +21,7 @@ const y = 1, A = (
|
|
|
20
21
|
gl_Position = projectionMatrix * mvPosition;
|
|
21
22
|
}
|
|
22
23
|
`
|
|
23
|
-
),
|
|
24
|
+
), L = (
|
|
24
25
|
/* glsl */
|
|
25
26
|
`
|
|
26
27
|
uniform sampler2D tDiffuse;
|
|
@@ -87,38 +88,38 @@ const y = 1, A = (
|
|
|
87
88
|
}
|
|
88
89
|
`
|
|
89
90
|
);
|
|
90
|
-
class
|
|
91
|
-
constructor({ size: e = 20, textureWidth: r = 512, textureHeight:
|
|
92
|
-
const n = new
|
|
93
|
-
type:
|
|
94
|
-
minFilter:
|
|
95
|
-
magFilter:
|
|
96
|
-
format:
|
|
91
|
+
class O extends i.Mesh {
|
|
92
|
+
constructor({ size: e = 20, textureWidth: r = 512, textureHeight: o = 512 } = {}) {
|
|
93
|
+
const n = new i.Matrix4(), l = new i.WebGLRenderTarget(r, o, {
|
|
94
|
+
type: i.HalfFloatType,
|
|
95
|
+
minFilter: i.LinearFilter,
|
|
96
|
+
magFilter: i.LinearFilter,
|
|
97
|
+
format: i.RGBAFormat,
|
|
97
98
|
depthBuffer: !0,
|
|
98
99
|
samples: 0
|
|
99
|
-
}),
|
|
100
|
+
}), u = new i.ShaderMaterial({
|
|
100
101
|
uniforms: {
|
|
101
102
|
tDiffuse: { value: l.texture },
|
|
102
103
|
textureMatrix: { value: n },
|
|
103
|
-
resolution: { value: new
|
|
104
|
-
fineGridColor: { value: new
|
|
105
|
-
coarseGridColor: { value: new
|
|
104
|
+
resolution: { value: new i.Vector2(r, o) },
|
|
105
|
+
fineGridColor: { value: new i.Color(2502702) },
|
|
106
|
+
coarseGridColor: { value: new i.Color(7897726) },
|
|
106
107
|
blurIntensity: { value: 1.7 },
|
|
107
108
|
reflectionMix: { value: 0.07 },
|
|
108
109
|
gridOpacity: { value: 1 },
|
|
109
110
|
gridScale: { value: 0.2 },
|
|
110
|
-
groundCenter: { value: new
|
|
111
|
+
groundCenter: { value: new i.Vector2() },
|
|
111
112
|
maxRadius: { value: e * 0.5 },
|
|
112
113
|
fadeSoftness: { value: e * 0.325 }
|
|
113
114
|
},
|
|
114
|
-
vertexShader:
|
|
115
|
-
fragmentShader:
|
|
115
|
+
vertexShader: B,
|
|
116
|
+
fragmentShader: L,
|
|
116
117
|
transparent: !0,
|
|
117
118
|
depthWrite: !1,
|
|
118
119
|
toneMapped: !0,
|
|
119
120
|
fog: !1
|
|
120
121
|
});
|
|
121
|
-
super(new
|
|
122
|
+
super(new i.PlaneGeometry(e, e), u);
|
|
122
123
|
s(this, "renderTarget");
|
|
123
124
|
s(this, "textureMatrix");
|
|
124
125
|
s(this, "virtualCamera");
|
|
@@ -133,11 +134,11 @@ class T extends o.Mesh {
|
|
|
133
134
|
s(this, "view");
|
|
134
135
|
s(this, "target");
|
|
135
136
|
s(this, "q");
|
|
136
|
-
this.renderTarget = l, this.textureMatrix = n, this.virtualCamera = new
|
|
137
|
+
this.renderTarget = l, this.textureMatrix = n, this.virtualCamera = new i.PerspectiveCamera(), this.virtualCamera.layers.set(v), this.clipBias = 3e-3, this.frustumCulled = !1, this.renderOrder = 1, this.position.z = 2e-3, this.reflectorPlane = new i.Plane(), this.normal = new i.Vector3(), this.reflectorWorldPosition = new i.Vector3(), this.cameraWorldPosition = new i.Vector3(), this.rotationMatrix = new i.Matrix4(), this.lookAtPosition = new i.Vector3(0, 0, -1), this.clipPlane = new i.Vector4(), this.view = new i.Vector3(), this.target = new i.Vector3(), this.q = new i.Vector4();
|
|
137
138
|
}
|
|
138
|
-
renderReflection(e, r,
|
|
139
|
-
if (this.reflectorWorldPosition.setFromMatrixPosition(this.matrixWorld), this.cameraWorldPosition.setFromMatrixPosition(
|
|
140
|
-
this.view.reflect(this.normal).negate().add(this.reflectorWorldPosition), this.rotationMatrix.extractRotation(
|
|
139
|
+
renderReflection(e, r, o) {
|
|
140
|
+
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;
|
|
141
|
+
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(
|
|
141
142
|
0.5,
|
|
142
143
|
0,
|
|
143
144
|
0,
|
|
@@ -167,100 +168,89 @@ class T extends o.Mesh {
|
|
|
167
168
|
-1,
|
|
168
169
|
(1 + n.elements[10]) / n.elements[14]
|
|
169
170
|
), this.clipPlane.multiplyScalar(2 / this.clipPlane.dot(this.q)), n.elements[2] = this.clipPlane.x, n.elements[6] = this.clipPlane.y, n.elements[10] = this.clipPlane.z + 1 - this.clipBias, n.elements[14] = this.clipPlane.w, this.virtualCamera.projectionMatrixInverse.copy(n).invert();
|
|
170
|
-
const l = e.getRenderTarget(),
|
|
171
|
+
const l = e.getRenderTarget(), u = e.xr.enabled, d = e.shadowMap.autoUpdate, c = e.shadowMap.enabled;
|
|
171
172
|
try {
|
|
172
173
|
e.xr.enabled = !1, e.shadowMap.enabled = !1, e.shadowMap.autoUpdate = !1, e.setRenderTarget(this.renderTarget), e.state.buffers.depth.setMask(!0), e.clear(), e.render(r, this.virtualCamera);
|
|
173
174
|
} finally {
|
|
174
|
-
e.setRenderTarget(l), e.xr.enabled =
|
|
175
|
+
e.setRenderTarget(l), e.xr.enabled = u, e.shadowMap.enabled = c, e.shadowMap.autoUpdate = d;
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
setRenderSize(e, r) {
|
|
178
179
|
this.renderTarget.setSize(e, r), this.material.uniforms.resolution.value.set(e, r);
|
|
179
180
|
}
|
|
180
181
|
// Radius is in world units; the outer 65% fades before the square mesh edge.
|
|
181
|
-
setRadius(e, r,
|
|
182
|
-
this.scale.setScalar(e * 2 / this.geometry.parameters.width), this.position.x =
|
|
182
|
+
setRadius(e, r, o = this.material.uniforms.groundCenter.value) {
|
|
183
|
+
this.scale.setScalar(e * 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 = r, this.material.uniforms.maxRadius.value = e, this.material.uniforms.fadeSoftness.value = e * 0.65;
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
|
-
const
|
|
186
|
+
const G = {
|
|
186
187
|
light: {
|
|
187
|
-
background:
|
|
188
|
+
background: b.light,
|
|
188
189
|
fineGrid: 5859168,
|
|
189
190
|
coarseGrid: 3427136,
|
|
190
191
|
gridOpacity: 0.85,
|
|
191
192
|
reflectionMix: 0.06
|
|
192
193
|
},
|
|
193
194
|
dark: {
|
|
194
|
-
background:
|
|
195
|
+
background: b.dark,
|
|
195
196
|
fineGrid: 7375236,
|
|
196
197
|
coarseGrid: 5552554,
|
|
197
198
|
gridOpacity: 0.9,
|
|
198
199
|
reflectionMix: 0.06
|
|
199
200
|
}
|
|
200
|
-
},
|
|
201
|
+
}, E = {
|
|
201
202
|
simulation: 1.2,
|
|
202
203
|
model: 1.2
|
|
203
|
-
};
|
|
204
|
-
function
|
|
205
|
-
|
|
206
|
-
const e = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = new Set(t), n = /* @__PURE__ */ new Set();
|
|
207
|
-
u.traverse((a) => {
|
|
208
|
-
const d = a;
|
|
209
|
-
d.geometry && e.add(d.geometry);
|
|
210
|
-
for (const c of Array.isArray(d.material) ? d.material : [d.material])
|
|
211
|
-
if (c) {
|
|
212
|
-
r.add(c);
|
|
213
|
-
for (const h of Object.values(c))
|
|
214
|
-
L(h) && i.add(h);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
for (const a of e) a.dispose();
|
|
218
|
-
for (const a of r) a.dispose();
|
|
219
|
-
for (const a of i) {
|
|
220
|
-
const d = (l = a.source) == null ? void 0 : l.data;
|
|
221
|
-
d && typeof d.close == "function" && n.add(d), a.dispose();
|
|
222
|
-
}
|
|
223
|
-
for (const a of n) a.close();
|
|
224
|
-
}
|
|
225
|
-
function L(u) {
|
|
226
|
-
return !!(u && typeof u == "object" && u.isTexture);
|
|
204
|
+
}, I = new C().setFromAxisAngle(new V(1, 0, 0), Math.PI / 2), D = new C();
|
|
205
|
+
function tt(a) {
|
|
206
|
+
return a === "glb" || a === "gltf" || a === "fbx" ? "y" : "z";
|
|
227
207
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
disposeModelResources: M
|
|
231
|
-
}, Symbol.toStringTag, { value: "Module" })), O = new G().setFromAxisAngle(new F(1, 0, 0), Math.PI / 2), B = new G();
|
|
232
|
-
function J(u) {
|
|
233
|
-
return u === "glb" || u === "gltf" || u === "fbx" ? "y" : "z";
|
|
208
|
+
function F(a) {
|
|
209
|
+
return a === "y" ? I : D;
|
|
234
210
|
}
|
|
235
|
-
function
|
|
236
|
-
|
|
211
|
+
function et(a, t) {
|
|
212
|
+
const e = F(t);
|
|
213
|
+
return e.equals(a.quaternion) ? !1 : (a.quaternion.copy(e), a.updateMatrixWorld(!0), !0);
|
|
237
214
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return e.equals(u.quaternion) ? !1 : (u.quaternion.copy(e), u.updateMatrixWorld(!0), !0);
|
|
241
|
-
}
|
|
242
|
-
const m = 2213822, E = 6000111, _ = 6, x = 2e-3, D = 1e-4, z = 1e-4, I = 0.18, U = 0.35, N = 0.18, H = 0.75, k = Math.PI / 3;
|
|
243
|
-
function q(u, t, e) {
|
|
215
|
+
const m = 2213822, _ = 6000111, z = 6, x = 2e-3, U = 1e-4, N = 1e-4, H = 0.18, k = 0.35, q = 0.18, j = 0.75, Y = Math.PI / 3, y = new i.Vector3(), M = new i.Matrix4(), w = new i.Matrix4();
|
|
216
|
+
function Q(a, t, e) {
|
|
244
217
|
t.updateMatrixWorld();
|
|
245
|
-
const r = new
|
|
246
|
-
return t.getWorldDirection(r).normalize(),
|
|
218
|
+
const r = new i.Vector3();
|
|
219
|
+
return t.getWorldDirection(r).normalize(), a.setFromNormalAndCoplanarPoint(r, e);
|
|
247
220
|
}
|
|
248
|
-
function p(
|
|
249
|
-
|
|
250
|
-
const t = new
|
|
251
|
-
return
|
|
252
|
-
if (!(e instanceof
|
|
221
|
+
function p(a) {
|
|
222
|
+
a.updateWorldMatrix(!0, !0);
|
|
223
|
+
const t = new i.Box3();
|
|
224
|
+
return a.traverse((e) => {
|
|
225
|
+
if (!(e instanceof i.Mesh)) return;
|
|
253
226
|
let r = e;
|
|
254
227
|
for (; r; ) {
|
|
255
228
|
if (r.userData.excludeFromSimulationFit || !r.visible) return;
|
|
256
229
|
r = r.parent;
|
|
257
230
|
}
|
|
258
|
-
|
|
259
|
-
}), t.isEmpty() ? new
|
|
231
|
+
X(t, e);
|
|
232
|
+
}), t.isEmpty() ? new i.Box3().setFromObject(a) : t;
|
|
233
|
+
}
|
|
234
|
+
function X(a, t) {
|
|
235
|
+
const e = t.geometry.getAttribute("position");
|
|
236
|
+
if (!e) {
|
|
237
|
+
t.geometry.boundingBox || t.geometry.computeBoundingBox(), t.geometry.boundingBox && a.union(t.geometry.boundingBox.clone().applyMatrix4(t.matrixWorld));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (t instanceof i.InstancedMesh) {
|
|
241
|
+
for (let r = 0; r < t.count; r += 1)
|
|
242
|
+
t.getMatrixAt(r, M), w.multiplyMatrices(t.matrixWorld, M), P(a, t, e.count, w);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
P(a, t, e.count, t.matrixWorld);
|
|
246
|
+
}
|
|
247
|
+
function P(a, t, e, r) {
|
|
248
|
+
for (let o = 0; o < e; o += 1)
|
|
249
|
+
t.getVertexPosition(o, y), y.applyMatrix4(r), a.expandByPoint(y);
|
|
260
250
|
}
|
|
261
|
-
class
|
|
262
|
-
constructor(t, e = "dark", r,
|
|
263
|
-
s(this, "root", new
|
|
251
|
+
class rt {
|
|
252
|
+
constructor(t, e = "dark", r, o = "simulation", n) {
|
|
253
|
+
s(this, "root", new i.Group());
|
|
264
254
|
/**
|
|
265
255
|
* Owns the up-axis rotation for everything that is *not* driven by the
|
|
266
256
|
* physics runtime: the URDF kinematic preview, the static collision overlay
|
|
@@ -268,30 +258,30 @@ class Z {
|
|
|
268
258
|
* the compiled model instead (see `applyUpAxis`), because rotating the scene
|
|
269
259
|
* graph on top of an already-rotated physics pose would apply it twice.
|
|
270
260
|
*/
|
|
271
|
-
s(this, "modelWrapper", new
|
|
261
|
+
s(this, "modelWrapper", new i.Group());
|
|
272
262
|
s(this, "upAxis", "z");
|
|
273
263
|
/** A flip changes the asset footprint; the ground disc follows on the next frame. */
|
|
274
264
|
s(this, "groundNeedsRefit", !1);
|
|
275
|
-
s(this, "reflector", new
|
|
265
|
+
s(this, "reflector", new O({ size: 100, textureWidth: 256, textureHeight: 256 }));
|
|
276
266
|
s(this, "values");
|
|
277
267
|
s(this, "fog");
|
|
278
|
-
s(this, "raycaster", new
|
|
279
|
-
s(this, "pointer", new
|
|
280
|
-
s(this, "dragPlane", new
|
|
281
|
-
s(this, "dragTarget", new
|
|
282
|
-
s(this, "dragIntersection", new
|
|
283
|
-
s(this, "dragOffset", new
|
|
284
|
-
s(this, "groundPlane", new
|
|
285
|
-
s(this, "groundRaycaster", new
|
|
286
|
-
s(this, "groundNdc", new
|
|
287
|
-
s(this, "groundHit", new
|
|
288
|
-
s(this, "groundGrabPoint", new
|
|
289
|
-
s(this, "groundCenter", new
|
|
290
|
-
s(this, "groundModelFocus", new
|
|
291
|
-
s(this, "groundCameraFocus", new
|
|
292
|
-
s(this, "groundGrabFocus", new
|
|
293
|
-
s(this, "groundCameraPosition", new
|
|
294
|
-
s(this, "groundCameraQuaternion", new
|
|
268
|
+
s(this, "raycaster", new i.Raycaster());
|
|
269
|
+
s(this, "pointer", new i.Vector2());
|
|
270
|
+
s(this, "dragPlane", new i.Plane());
|
|
271
|
+
s(this, "dragTarget", new i.Vector3());
|
|
272
|
+
s(this, "dragIntersection", new i.Vector3());
|
|
273
|
+
s(this, "dragOffset", new i.Vector3());
|
|
274
|
+
s(this, "groundPlane", new i.Plane(new i.Vector3(0, 0, 1), 0));
|
|
275
|
+
s(this, "groundRaycaster", new i.Raycaster());
|
|
276
|
+
s(this, "groundNdc", new i.Vector2());
|
|
277
|
+
s(this, "groundHit", new i.Vector3());
|
|
278
|
+
s(this, "groundGrabPoint", new i.Vector3());
|
|
279
|
+
s(this, "groundCenter", new i.Vector2());
|
|
280
|
+
s(this, "groundModelFocus", new i.Vector2());
|
|
281
|
+
s(this, "groundCameraFocus", new i.Vector2());
|
|
282
|
+
s(this, "groundGrabFocus", new i.Vector2());
|
|
283
|
+
s(this, "groundCameraPosition", new i.Vector3());
|
|
284
|
+
s(this, "groundCameraQuaternion", new i.Quaternion());
|
|
295
285
|
s(this, "bodyGroups", /* @__PURE__ */ new Map());
|
|
296
286
|
s(this, "auxiliaries", /* @__PURE__ */ new Set());
|
|
297
287
|
s(this, "forceLine");
|
|
@@ -300,7 +290,7 @@ class Z {
|
|
|
300
290
|
s(this, "previousCursor", "");
|
|
301
291
|
s(this, "size", "");
|
|
302
292
|
s(this, "groundVisible");
|
|
303
|
-
s(this, "groundGridScale",
|
|
293
|
+
s(this, "groundGridScale", A);
|
|
304
294
|
s(this, "groundPlacement");
|
|
305
295
|
s(this, "groundFollowDirty", !0);
|
|
306
296
|
s(this, "groundInteractionActive", !1);
|
|
@@ -308,23 +298,23 @@ class Z {
|
|
|
308
298
|
s(this, "groundGrabBlend", 0);
|
|
309
299
|
s(this, "groundCameraPoseValid", !1);
|
|
310
300
|
s(this, "disposed", !1);
|
|
311
|
-
this.model = t, this.runtime = r, this.presentation =
|
|
312
|
-
const l = this.values,
|
|
301
|
+
this.model = t, this.runtime = r, this.presentation = o, this.groundPlacement = n ?? (o === "model" ? "visual" : "physics"), this.values = G[e];
|
|
302
|
+
const l = this.values, u = p(t), d = Math.max(...u.getSize(new i.Vector3()).toArray());
|
|
313
303
|
if (!Number.isFinite(d) || d <= 0) throw new Error("Empty simulation geometry.");
|
|
314
304
|
this.modelWrapper.name = "simulation-model-wrapper", this.root.add(this.modelWrapper), this.modelWrapper.add(t), this.forceLine = this.createForceLine(), this.root.add(this.forceLine), t.traverse((g) => {
|
|
315
|
-
g instanceof
|
|
305
|
+
g instanceof i.Mesh && g.layers.enable(v);
|
|
316
306
|
}), this.root.add(this.reflector);
|
|
317
|
-
const c = Math.max(
|
|
318
|
-
h.fineGridColor.value.setHex(l.fineGrid), h.coarseGridColor.value.setHex(l.coarseGrid), h.gridOpacity.value = l.gridOpacity, h.reflectionMix.value = l.reflectionMix, this.layoutGround(
|
|
319
|
-
const f = c / Math.sin(
|
|
320
|
-
this.fog = new
|
|
307
|
+
const c = Math.max(u.getSize(new i.Vector3()).length() * 0.5, 0.02), h = this.reflector.material.uniforms;
|
|
308
|
+
h.fineGridColor.value.setHex(l.fineGrid), h.coarseGridColor.value.setHex(l.coarseGrid), h.gridOpacity.value = l.gridOpacity, h.reflectionMix.value = l.reflectionMix, this.layoutGround(u, c), this.groundVisible = !0, this.setGroundVisible(this.groundVisible);
|
|
309
|
+
const f = c / Math.sin(i.MathUtils.degToRad(38) / 2) * 1.25;
|
|
310
|
+
this.fog = new i.Fog(l.background, f * 2.5, f * 8);
|
|
321
311
|
}
|
|
322
312
|
setRuntime(t) {
|
|
323
313
|
this.disposed || this.runtime === t || (this.endGrab(), this.runtime = t, t && (this.groundPlacement = "physics"), this.bodyGroups.clear(), this.groundGrabFocusValid = !1, this.groundGrabBlend = 0, this.groundFollowDirty = !0, this.applyUpAxis());
|
|
324
314
|
}
|
|
325
315
|
replaceModel(t, e = !0) {
|
|
326
316
|
this.disposed || t === this.model || (this.endGrab(), this.bodyGroups.clear(), this.model.removeFromParent(), this.model = t, this.modelWrapper.add(t), t.traverse((r) => {
|
|
327
|
-
r instanceof
|
|
317
|
+
r instanceof i.Mesh && r.layers.enable(v);
|
|
328
318
|
}), e && this.reseatGround());
|
|
329
319
|
}
|
|
330
320
|
/**
|
|
@@ -344,7 +334,7 @@ class Z {
|
|
|
344
334
|
return this.upAxis;
|
|
345
335
|
}
|
|
346
336
|
applyUpAxis() {
|
|
347
|
-
const t =
|
|
337
|
+
const t = F(this.upAxis);
|
|
348
338
|
this.runtime ? (this.modelWrapper.quaternion.identity(), this.runtime.setWorldRotation(t)) : this.modelWrapper.quaternion.copy(t), this.modelWrapper.updateMatrixWorld(!0), this.groundNeedsRefit = !0;
|
|
349
339
|
}
|
|
350
340
|
resetGround() {
|
|
@@ -359,14 +349,14 @@ class Z {
|
|
|
359
349
|
}
|
|
360
350
|
setTheme(t) {
|
|
361
351
|
if (this.disposed) return;
|
|
362
|
-
const e = this.values =
|
|
352
|
+
const e = this.values = G[t], r = this.reflector.material.uniforms;
|
|
363
353
|
r.fineGridColor.value.setHex(e.fineGrid), r.coarseGridColor.value.setHex(e.coarseGrid), r.gridOpacity.value = e.gridOpacity, r.reflectionMix.value = e.reflectionMix, this.fog.color.setHex(e.background);
|
|
364
354
|
}
|
|
365
355
|
layoutGround(t, e) {
|
|
366
|
-
this.groundGridScale =
|
|
356
|
+
this.groundGridScale = W(t.getSize(new i.Vector3()).length()), this.setGroundModelFocus(t), this.groundCenter.copy(this.groundModelFocus), this.groundInteractionActive = !1, this.groundGrabFocusValid = !1, this.groundGrabBlend = 0, this.groundFollowDirty = !0, this.reflector.setRadius(e * 8, this.groundGridScale, this.groundCenter), this.positionGround(t);
|
|
367
357
|
}
|
|
368
358
|
setGroundModelFocus(t) {
|
|
369
|
-
const e = t.getCenter(new
|
|
359
|
+
const e = t.getCenter(new i.Vector3());
|
|
370
360
|
this.groundModelFocus.set(e.x, e.y);
|
|
371
361
|
}
|
|
372
362
|
/**
|
|
@@ -384,8 +374,8 @@ class Z {
|
|
|
384
374
|
this.reflector.position.z = x;
|
|
385
375
|
return;
|
|
386
376
|
}
|
|
387
|
-
const r = t.getSize(new
|
|
388
|
-
this.reflector.position.z = t.min.z -
|
|
377
|
+
const r = t.getSize(new i.Vector3()).length(), o = Math.max(r * U, N);
|
|
378
|
+
this.reflector.position.z = t.min.z - o;
|
|
389
379
|
}
|
|
390
380
|
/**
|
|
391
381
|
* The ground keeps its model-sized fade radius; only this local pool follows
|
|
@@ -393,28 +383,28 @@ class Z {
|
|
|
393
383
|
* stationary while the illuminated patch moves like a handheld light.
|
|
394
384
|
*/
|
|
395
385
|
refreshGroundFocus(t) {
|
|
396
|
-
const e = this.reflector.material.uniforms.maxRadius.value, r = this.detectGroundCameraJump(t, e),
|
|
386
|
+
const e = this.reflector.material.uniforms.maxRadius.value, r = this.detectGroundCameraJump(t, e), o = this.groundInteractionActive && this.measureGrabbedBodyFocus(), n = this.measureCameraGroundFocus(t, this.reflector.position.z);
|
|
397
387
|
n && (this.limitCameraGroundFocus(e), this.groundCameraFocus.set(this.groundHit.x, this.groundHit.y));
|
|
398
388
|
const l = this.groundInteractionActive && this.groundGrabFocusValid ? 1 : 0;
|
|
399
|
-
if (this.groundGrabBlend += (l - this.groundGrabBlend) *
|
|
400
|
-
|
|
389
|
+
if (this.groundGrabBlend += (l - this.groundGrabBlend) * q, Math.abs(l - this.groundGrabBlend) < 1e-3 && (this.groundGrabBlend = l), this.groundFollowDirty) {
|
|
390
|
+
o ? this.groundCenter.copy(this.groundGrabFocus) : this.groundCenter.copy(this.groundModelFocus), this.reflector.setRadius(e, this.groundGridScale, this.groundCenter), this.reflector.updateMatrixWorld(!0), this.groundFollowDirty = !1;
|
|
401
391
|
return;
|
|
402
392
|
}
|
|
403
|
-
let
|
|
404
|
-
|
|
405
|
-
const c =
|
|
393
|
+
let u = n ? this.groundCameraFocus.x : this.groundCenter.x, d = n ? this.groundCameraFocus.y : this.groundCenter.y;
|
|
394
|
+
o && this.groundModelFocus.copy(this.groundGrabFocus), this.groundGrabFocusValid && this.groundGrabBlend > 0 && (u += (this.groundGrabFocus.x - u) * this.groundGrabBlend, d += (this.groundGrabFocus.y - d) * this.groundGrabBlend);
|
|
395
|
+
const c = u - this.groundCenter.x, h = d - this.groundCenter.y, f = Math.hypot(c, h);
|
|
406
396
|
if (!(!r && f <= Math.max(e * 5e-4, 1e-5))) {
|
|
407
397
|
if (r)
|
|
408
|
-
this.groundCenter.set(
|
|
398
|
+
this.groundCenter.set(u, d);
|
|
409
399
|
else {
|
|
410
|
-
const g = this.groundInteractionActive ?
|
|
400
|
+
const g = this.groundInteractionActive ? k : H;
|
|
411
401
|
this.groundCenter.x += c * g, this.groundCenter.y += h * g;
|
|
412
402
|
}
|
|
413
403
|
this.reflector.setRadius(e, this.groundGridScale, this.groundCenter), this.reflector.updateMatrixWorld(!0);
|
|
414
404
|
}
|
|
415
405
|
}
|
|
416
406
|
detectGroundCameraJump(t, e) {
|
|
417
|
-
const r = this.groundCameraPoseValid && (t.position.distanceTo(this.groundCameraPosition) > Math.max(e *
|
|
407
|
+
const r = this.groundCameraPoseValid && (t.position.distanceTo(this.groundCameraPosition) > Math.max(e * j, 0.1) || t.quaternion.angleTo(this.groundCameraQuaternion) > Y);
|
|
418
408
|
return this.groundCameraPosition.copy(t.position), this.groundCameraQuaternion.copy(t.quaternion), this.groundCameraPoseValid = !0, r;
|
|
419
409
|
}
|
|
420
410
|
measureGrabbedBodyFocus() {
|
|
@@ -425,10 +415,10 @@ class Z {
|
|
|
425
415
|
return e ? (this.groundGrabPoint.fromArray(t.localPoint), e.localToWorld(this.groundGrabPoint), this.root.worldToLocal(this.groundGrabPoint), this.groundHit.copy(this.groundGrabPoint), this.groundGrabFocus.set(this.groundGrabPoint.x, this.groundGrabPoint.y), this.groundGrabFocusValid = !0, !0) : !1;
|
|
426
416
|
}
|
|
427
417
|
limitCameraGroundFocus(t) {
|
|
428
|
-
const e = t * 0.25, r = this.groundHit.x - this.groundModelFocus.x,
|
|
418
|
+
const e = t * 0.25, r = this.groundHit.x - this.groundModelFocus.x, o = this.groundHit.y - this.groundModelFocus.y, n = Math.hypot(r, o);
|
|
429
419
|
if (n <= e || n <= 0) return;
|
|
430
420
|
const l = e / n;
|
|
431
|
-
this.groundHit.x = this.groundModelFocus.x + r * l, this.groundHit.y = this.groundModelFocus.y +
|
|
421
|
+
this.groundHit.x = this.groundModelFocus.x + r * l, this.groundHit.y = this.groundModelFocus.y + o * l;
|
|
432
422
|
}
|
|
433
423
|
measureCameraGroundFocus(t, e) {
|
|
434
424
|
return this.groundPlane.constant = -e, this.groundNdc.set(0, 0), this.groundRaycaster.setFromCamera(this.groundNdc, t), this.groundRaycaster.ray.intersectPlane(this.groundPlane, this.groundHit) !== null;
|
|
@@ -443,18 +433,18 @@ class Z {
|
|
|
443
433
|
if (this.disposed) return;
|
|
444
434
|
this.root.updateMatrixWorld(!0);
|
|
445
435
|
const t = p(this.model);
|
|
446
|
-
t.isEmpty() || this.layoutGround(t, Math.max(t.getSize(new
|
|
436
|
+
t.isEmpty() || this.layoutGround(t, Math.max(t.getSize(new i.Vector3()).length() * 0.5, 0.02));
|
|
447
437
|
}
|
|
448
438
|
createForceLine() {
|
|
449
|
-
const t = new
|
|
450
|
-
new
|
|
451
|
-
new
|
|
452
|
-
]), e = new
|
|
439
|
+
const t = new i.BufferGeometry().setFromPoints([
|
|
440
|
+
new i.Vector3(),
|
|
441
|
+
new i.Vector3()
|
|
442
|
+
]), e = new i.LineBasicMaterial({
|
|
453
443
|
color: m,
|
|
454
444
|
depthTest: !1,
|
|
455
445
|
transparent: !0
|
|
456
|
-
}), r = new
|
|
457
|
-
return r.renderOrder = 1e3, r.visible = !1, r;
|
|
446
|
+
}), r = new i.Line(t, e);
|
|
447
|
+
return r.frustumCulled = !1, r.renderOrder = 1e3, r.visible = !1, r;
|
|
458
448
|
}
|
|
459
449
|
findBodyGroup(t) {
|
|
460
450
|
var r;
|
|
@@ -468,35 +458,35 @@ class Z {
|
|
|
468
458
|
getBodyGroup(t) {
|
|
469
459
|
let e = this.bodyGroups.get(t);
|
|
470
460
|
return e || this.model.traverse((r) => {
|
|
471
|
-
var
|
|
472
|
-
((
|
|
461
|
+
var o;
|
|
462
|
+
((o = r.userData) == null ? void 0 : o.bodyId) === t && (e = r, this.bodyGroups.set(t, r));
|
|
473
463
|
}), e;
|
|
474
464
|
}
|
|
475
465
|
pointerRay(t, e, r) {
|
|
476
|
-
const
|
|
466
|
+
const o = r.getBoundingClientRect();
|
|
477
467
|
this.pointer.set(
|
|
478
|
-
(t.clientX -
|
|
479
|
-
-((t.clientY -
|
|
468
|
+
(t.clientX - o.left) / o.width * 2 - 1,
|
|
469
|
+
-((t.clientY - o.top) / o.height) * 2 + 1
|
|
480
470
|
), this.raycaster.setFromCamera(this.pointer, e);
|
|
481
471
|
}
|
|
482
472
|
setForceBoost(t) {
|
|
483
473
|
var e;
|
|
484
|
-
!((e = this.runtime) != null && e.grab) || t === this.forceBoosted || (this.forceBoosted = t, this.runtime.updateGrabStrength(t ?
|
|
474
|
+
!((e = this.runtime) != null && e.grab) || t === this.forceBoosted || (this.forceBoosted = t, this.runtime.updateGrabStrength(t ? z : 1), this.forceLine.material.color.setHex(t ? _ : m));
|
|
485
475
|
}
|
|
486
476
|
beginGrab(t, e, r) {
|
|
487
477
|
if (!this.runtime || this.disposed) return !1;
|
|
488
478
|
this.pointerRay(t, e, r);
|
|
489
|
-
const
|
|
490
|
-
if (!
|
|
491
|
-
const n = this.findBodyGroup(
|
|
479
|
+
const o = this.raycaster.intersectObject(this.model, !0).find((d) => d.object.isMesh);
|
|
480
|
+
if (!o) return !1;
|
|
481
|
+
const n = this.findBodyGroup(o.object);
|
|
492
482
|
if (!n) return !1;
|
|
493
|
-
const l = n.worldToLocal(
|
|
494
|
-
this.dragTarget.copy(
|
|
495
|
-
const
|
|
483
|
+
const l = n.worldToLocal(o.point.clone());
|
|
484
|
+
this.dragTarget.copy(o.point), Q(this.dragPlane, e, o.point), this.dragOffset.set(0, 0, 0);
|
|
485
|
+
const u = this.root.worldToLocal(o.point.clone());
|
|
496
486
|
return this.groundInteractionActive = !0, this.bodyGroups.set(n.userData.bodyId, n), this.runtime.beginGrab({
|
|
497
487
|
bodyId: n.userData.bodyId,
|
|
498
488
|
localPoint: [l.x, l.y, l.z],
|
|
499
|
-
target: [
|
|
489
|
+
target: [u.x, u.y, u.z]
|
|
500
490
|
}), this.forceBoosted = !1, this.setForceBoost(t.shiftKey), this.forceLine.visible = !0, this.updateForceLine(), this.grabCanvas = r, r != null && r.style && (this.previousCursor = r.style.cursor, r.style.cursor = "grabbing"), !0;
|
|
501
491
|
}
|
|
502
492
|
moveGrab(t, e, r) {
|
|
@@ -506,25 +496,25 @@ class Z {
|
|
|
506
496
|
this.dragTarget.copy(this.dragIntersection).add(this.dragOffset);
|
|
507
497
|
else
|
|
508
498
|
return;
|
|
509
|
-
const
|
|
510
|
-
this.runtime.updateGrabTarget([
|
|
499
|
+
const o = this.root.worldToLocal(this.dragTarget.clone());
|
|
500
|
+
this.runtime.updateGrabTarget([o.x, o.y, o.z]), this.updateForceLine();
|
|
511
501
|
}
|
|
512
502
|
endGrab() {
|
|
513
503
|
var t;
|
|
514
504
|
this.runtime && (this.runtime.endGrab(), this.groundInteractionActive = !1, this.forceBoosted = !1, this.forceLine.visible = !1, this.forceLine.material.color.setHex(m), (t = this.grabCanvas) != null && t.style && (this.grabCanvas.style.cursor = this.previousCursor), this.grabCanvas = null);
|
|
515
505
|
}
|
|
516
506
|
updateForceLine() {
|
|
517
|
-
var
|
|
518
|
-
const t = (
|
|
507
|
+
var u;
|
|
508
|
+
const t = (u = this.runtime) == null ? void 0 : u.grab;
|
|
519
509
|
if (!t) return;
|
|
520
510
|
const e = this.getBodyGroup(t.bodyId);
|
|
521
511
|
if (!e) return;
|
|
522
|
-
const r = new
|
|
512
|
+
const r = new i.Vector3().fromArray(t.localPoint), o = e.localToWorld(r), n = this.root.worldToLocal(o), l = this.forceLine.geometry.attributes.position;
|
|
523
513
|
l.setXYZ(0, n.x, n.y, n.z), l.setXYZ(1, t.target[0], t.target[1], t.target[2]), l.needsUpdate = !0;
|
|
524
514
|
}
|
|
525
515
|
beforeRender(t, e, r) {
|
|
526
|
-
var l,
|
|
527
|
-
const
|
|
516
|
+
var l, u;
|
|
517
|
+
const o = {
|
|
528
518
|
tone: t.toneMapping,
|
|
529
519
|
exposure: t.toneMappingExposure,
|
|
530
520
|
color: t.outputColorSpace,
|
|
@@ -532,15 +522,15 @@ class Z {
|
|
|
532
522
|
fog: e.fog,
|
|
533
523
|
background: e.background
|
|
534
524
|
}, n = () => {
|
|
535
|
-
t.toneMapping =
|
|
525
|
+
t.toneMapping = o.tone, t.toneMappingExposure = o.exposure, t.outputColorSpace = o.color, e.environment = o.environment, e.fog = o.fog, e.background = o.background;
|
|
536
526
|
};
|
|
537
527
|
if (this.disposed) return n;
|
|
538
528
|
try {
|
|
539
529
|
this.groundNeedsRefit && (this.groundNeedsRefit = !1, this.reseatGround()), (l = this.runtime) != null && l.grab && this.updateForceLine();
|
|
540
|
-
const d = (
|
|
541
|
-
d !== void 0 && (this.reflector.position.z = d + 2e-3), t.toneMapping =
|
|
542
|
-
const c = t.getSize(new
|
|
543
|
-
return h !== this.size && (this.size = h, this.reflector.setRenderSize(Math.max(1, Math.floor(c.x * 0.35)), Math.max(1, Math.floor(c.y * 0.35)))), e.updateMatrixWorld(!0), r.updateMatrixWorld(!0), this.groundVisible && this.refreshGroundFocus(r), this.groundVisible && r instanceof
|
|
530
|
+
const d = (u = this.runtime) == null ? void 0 : u.defaultGroundHeight;
|
|
531
|
+
d !== void 0 && (this.reflector.position.z = d + 2e-3), t.toneMapping = i.ACESFilmicToneMapping, t.toneMappingExposure = E[this.presentation], t.outputColorSpace = i.SRGBColorSpace, e.background = new i.Color(this.values.background), e.fog = this.fog;
|
|
532
|
+
const c = t.getSize(new i.Vector2()), h = `${c.x}:${c.y}`;
|
|
533
|
+
return h !== this.size && (this.size = h, this.reflector.setRenderSize(Math.max(1, Math.floor(c.x * 0.35)), Math.max(1, Math.floor(c.y * 0.35)))), e.updateMatrixWorld(!0), r.updateMatrixWorld(!0), this.groundVisible && this.refreshGroundFocus(r), this.groundVisible && r instanceof i.PerspectiveCamera && this.reflector.renderReflection(t, e, r), n;
|
|
544
534
|
} catch (d) {
|
|
545
535
|
throw n(), d;
|
|
546
536
|
}
|
|
@@ -576,22 +566,20 @@ class Z {
|
|
|
576
566
|
this.root.updateMatrixWorld(!0);
|
|
577
567
|
const t = p(this.model);
|
|
578
568
|
if (!t.isEmpty()) return t;
|
|
579
|
-
const e = new
|
|
569
|
+
const e = new i.Box3();
|
|
580
570
|
return e.min.set(-5e3, -5e3, -5e3), e.max.set(5e3, 5e3, 5e3), e;
|
|
581
571
|
}
|
|
582
572
|
dispose() {
|
|
583
573
|
if (!this.disposed) {
|
|
584
574
|
this.disposed = !0, this.endGrab(), this.model.removeFromParent();
|
|
585
575
|
for (const t of this.auxiliaries) t.removeFromParent();
|
|
586
|
-
this.auxiliaries.clear(), this.modelWrapper.removeFromParent(), this.root.removeFromParent(), this.reflector.renderTarget.dispose(),
|
|
576
|
+
this.auxiliaries.clear(), this.modelWrapper.removeFromParent(), this.root.removeFromParent(), this.reflector.renderTarget.dispose(), T(this.root);
|
|
587
577
|
}
|
|
588
578
|
}
|
|
589
579
|
}
|
|
590
580
|
export {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
w as m,
|
|
596
|
-
X as r
|
|
581
|
+
rt as S,
|
|
582
|
+
et as a,
|
|
583
|
+
tt as d,
|
|
584
|
+
F as m
|
|
597
585
|
};
|