@nebula-spatial/viewer 0.5.3 → 0.5.4
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 +36 -0
- package/README.md +44 -5
- package/USD-VISUAL-MATERIAL-SUPPORT.md +29 -2
- package/dist/assets/types.d.ts +3 -0
- package/dist/{index-DmGuwbBM.js → index-8TD-Puyo.js} +918 -797
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -8
- package/dist/{mjcf-visual-CFXIhVyT.js → mjcf-visual-qlID4stF.js} +7 -7
- package/dist/mujoco-runtime-DTxVmIzc.js +349 -0
- package/dist/{session-BzIziNzg.js → session-CCDMlwej.js} +79 -75
- package/dist/session-um40A-5F.js +878 -0
- package/dist/stage-DAhe0IZz.js +597 -0
- package/dist/ui/types.d.ts +1 -0
- package/dist/{urdf-session-BleSrYNu.js → urdf-session-DceYWCib.js} +737 -731
- package/dist/usd-session-BBtKxubs.js +4174 -0
- package/dist/version.d.ts +1 -1
- package/dist/{xacro-D1hcJ9kB.js → xacro-DPEhwEml.js} +1 -1
- package/package.json +1 -1
- package/dist/mujoco-runtime-7xiBQNJm.js +0 -324
- package/dist/session-Boljcc3d.js +0 -844
- package/dist/stage-C7B1_qJ0.js +0 -502
- package/dist/usd-session-DFbFB8bP.js +0 -2392
package/dist/stage-C7B1_qJ0.js
DELETED
|
@@ -1,502 +0,0 @@
|
|
|
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
|
-
import * as r from "three";
|
|
5
|
-
import { Quaternion as y, Vector3 as C } from "three";
|
|
6
|
-
import { V as x } from "./index-DmGuwbBM.js";
|
|
7
|
-
const m = 1, S = (
|
|
8
|
-
/* glsl */
|
|
9
|
-
`
|
|
10
|
-
uniform mat4 textureMatrix;
|
|
11
|
-
varying vec4 vReflectionUv;
|
|
12
|
-
varying vec3 vWorldPosition;
|
|
13
|
-
|
|
14
|
-
void main() {
|
|
15
|
-
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
|
|
16
|
-
vWorldPosition = worldPosition.xyz;
|
|
17
|
-
vReflectionUv = textureMatrix * vec4(position, 1.0);
|
|
18
|
-
// Match Three.js built-in materials: transform to view space before projection.
|
|
19
|
-
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
|
20
|
-
gl_Position = projectionMatrix * mvPosition;
|
|
21
|
-
}
|
|
22
|
-
`
|
|
23
|
-
), G = (
|
|
24
|
-
/* glsl */
|
|
25
|
-
`
|
|
26
|
-
uniform sampler2D tDiffuse;
|
|
27
|
-
uniform vec2 resolution;
|
|
28
|
-
uniform vec3 fineGridColor;
|
|
29
|
-
uniform vec3 coarseGridColor;
|
|
30
|
-
uniform float blurIntensity;
|
|
31
|
-
uniform float reflectionMix;
|
|
32
|
-
uniform float gridOpacity;
|
|
33
|
-
uniform float gridScale;
|
|
34
|
-
uniform vec2 groundCenter;
|
|
35
|
-
uniform float maxRadius;
|
|
36
|
-
uniform float fadeSoftness;
|
|
37
|
-
|
|
38
|
-
varying vec4 vReflectionUv;
|
|
39
|
-
varying vec3 vWorldPosition;
|
|
40
|
-
|
|
41
|
-
vec4 blur9(sampler2D image, vec2 uv, vec2 res, float radius) {
|
|
42
|
-
vec4 color = vec4(0.0);
|
|
43
|
-
vec2 stepSize = radius / res;
|
|
44
|
-
color += texture2D(image, uv + vec2(-stepSize.x, -stepSize.y)) * 0.0625;
|
|
45
|
-
color += texture2D(image, uv + vec2(0.0, -stepSize.y)) * 0.125;
|
|
46
|
-
color += texture2D(image, uv + vec2(stepSize.x, -stepSize.y)) * 0.0625;
|
|
47
|
-
color += texture2D(image, uv + vec2(-stepSize.x, 0.0)) * 0.125;
|
|
48
|
-
color += texture2D(image, uv) * 0.25;
|
|
49
|
-
color += texture2D(image, uv + vec2(stepSize.x, 0.0)) * 0.125;
|
|
50
|
-
color += texture2D(image, uv + vec2(-stepSize.x, stepSize.y)) * 0.0625;
|
|
51
|
-
color += texture2D(image, uv + vec2(0.0, stepSize.y)) * 0.125;
|
|
52
|
-
color += texture2D(image, uv + vec2(stepSize.x, stepSize.y)) * 0.0625;
|
|
53
|
-
return color;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
float gridLine(vec2 position, float scale) {
|
|
57
|
-
vec2 coordinate = position / scale;
|
|
58
|
-
vec2 width = max(fwidth(coordinate), vec2(0.0001));
|
|
59
|
-
vec2 distanceToLine = abs(fract(coordinate - 0.5) - 0.5) / width;
|
|
60
|
-
return 1.0 - min(min(distanceToLine.x, distanceToLine.y), 1.0);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
void main() {
|
|
64
|
-
vec2 groundPosition = vWorldPosition.xy;
|
|
65
|
-
float edgeDistance = length(groundPosition - groundCenter);
|
|
66
|
-
float edgeFade = 1.0 - smoothstep(maxRadius - fadeSoftness, maxRadius, edgeDistance);
|
|
67
|
-
|
|
68
|
-
float fineLine = gridLine(groundPosition, gridScale);
|
|
69
|
-
float coarseLine = gridLine(groundPosition, gridScale * 10.0);
|
|
70
|
-
float gridAlpha = max(fineLine * 0.16, coarseLine * 0.42) * gridOpacity * edgeFade;
|
|
71
|
-
vec3 gridColor = mix(fineGridColor, coarseGridColor, coarseLine);
|
|
72
|
-
|
|
73
|
-
vec2 reflectionUv = vReflectionUv.xy / vReflectionUv.w;
|
|
74
|
-
bool validReflection = reflectionUv.x >= 0.0 && reflectionUv.x <= 1.0
|
|
75
|
-
&& reflectionUv.y >= 0.0 && reflectionUv.y <= 1.0;
|
|
76
|
-
vec4 reflection = validReflection
|
|
77
|
-
? blur9(tDiffuse, reflectionUv, resolution, blurIntensity)
|
|
78
|
-
: vec4(0.0);
|
|
79
|
-
float reflectionAlpha = reflectionMix * edgeFade * (validReflection ? 1.0 : 0.0);
|
|
80
|
-
|
|
81
|
-
float alpha = reflectionAlpha + gridAlpha * (1.0 - reflectionAlpha);
|
|
82
|
-
if (alpha <= 0.001) discard;
|
|
83
|
-
vec3 color = mix(reflection.rgb, gridColor, gridAlpha / max(alpha, 0.001));
|
|
84
|
-
gl_FragColor = vec4(color, alpha);
|
|
85
|
-
#include <tonemapping_fragment>
|
|
86
|
-
#include <colorspace_fragment>
|
|
87
|
-
}
|
|
88
|
-
`
|
|
89
|
-
);
|
|
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, {
|
|
93
|
-
type: r.HalfFloatType,
|
|
94
|
-
minFilter: r.LinearFilter,
|
|
95
|
-
magFilter: r.LinearFilter,
|
|
96
|
-
format: r.RGBAFormat,
|
|
97
|
-
depthBuffer: !0,
|
|
98
|
-
samples: 0
|
|
99
|
-
}), l = new r.ShaderMaterial({
|
|
100
|
-
uniforms: {
|
|
101
|
-
tDiffuse: { value: u.texture },
|
|
102
|
-
textureMatrix: { value: s },
|
|
103
|
-
resolution: { value: new r.Vector2(i, o) },
|
|
104
|
-
fineGridColor: { value: new r.Color(2502702) },
|
|
105
|
-
coarseGridColor: { value: new r.Color(7897726) },
|
|
106
|
-
blurIntensity: { value: 1.7 },
|
|
107
|
-
reflectionMix: { value: 0.07 },
|
|
108
|
-
gridOpacity: { value: 1 },
|
|
109
|
-
gridScale: { value: 0.2 },
|
|
110
|
-
groundCenter: { value: new r.Vector2() },
|
|
111
|
-
maxRadius: { value: t * 0.5 },
|
|
112
|
-
fadeSoftness: { value: t * 0.325 }
|
|
113
|
-
},
|
|
114
|
-
vertexShader: S,
|
|
115
|
-
fragmentShader: G,
|
|
116
|
-
transparent: !0,
|
|
117
|
-
depthWrite: !1,
|
|
118
|
-
toneMapped: !0,
|
|
119
|
-
fog: !1
|
|
120
|
-
});
|
|
121
|
-
super(new r.PlaneGeometry(t, t), l);
|
|
122
|
-
a(this, "renderTarget");
|
|
123
|
-
a(this, "textureMatrix");
|
|
124
|
-
a(this, "virtualCamera");
|
|
125
|
-
a(this, "clipBias");
|
|
126
|
-
a(this, "reflectorPlane");
|
|
127
|
-
a(this, "normal");
|
|
128
|
-
a(this, "reflectorWorldPosition");
|
|
129
|
-
a(this, "cameraWorldPosition");
|
|
130
|
-
a(this, "rotationMatrix");
|
|
131
|
-
a(this, "lookAtPosition");
|
|
132
|
-
a(this, "clipPlane");
|
|
133
|
-
a(this, "view");
|
|
134
|
-
a(this, "target");
|
|
135
|
-
a(this, "q");
|
|
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();
|
|
137
|
-
}
|
|
138
|
-
renderReflection(t, i, o) {
|
|
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;
|
|
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(
|
|
141
|
-
0.5,
|
|
142
|
-
0,
|
|
143
|
-
0,
|
|
144
|
-
0.5,
|
|
145
|
-
0,
|
|
146
|
-
0.5,
|
|
147
|
-
0,
|
|
148
|
-
0.5,
|
|
149
|
-
0,
|
|
150
|
-
0,
|
|
151
|
-
0.5,
|
|
152
|
-
0.5,
|
|
153
|
-
0,
|
|
154
|
-
0,
|
|
155
|
-
0,
|
|
156
|
-
1
|
|
157
|
-
).multiply(this.virtualCamera.projectionMatrix).multiply(this.virtualCamera.matrixWorldInverse).multiply(this.matrixWorld), this.reflectorPlane.setFromNormalAndCoplanarPoint(this.normal, this.reflectorWorldPosition).applyMatrix4(this.virtualCamera.matrixWorldInverse), this.clipPlane.set(
|
|
158
|
-
this.reflectorPlane.normal.x,
|
|
159
|
-
this.reflectorPlane.normal.y,
|
|
160
|
-
this.reflectorPlane.normal.z,
|
|
161
|
-
this.reflectorPlane.constant
|
|
162
|
-
);
|
|
163
|
-
const s = this.virtualCamera.projectionMatrix;
|
|
164
|
-
this.q.set(
|
|
165
|
-
(Math.sign(this.clipPlane.x) + s.elements[8]) / s.elements[0],
|
|
166
|
-
(Math.sign(this.clipPlane.y) + s.elements[9]) / s.elements[5],
|
|
167
|
-
-1,
|
|
168
|
-
(1 + s.elements[10]) / s.elements[14]
|
|
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();
|
|
170
|
-
const u = t.getRenderTarget(), l = t.xr.enabled, c = t.shadowMap.autoUpdate, d = t.shadowMap.enabled;
|
|
171
|
-
try {
|
|
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);
|
|
173
|
-
} finally {
|
|
174
|
-
t.setRenderTarget(u), t.xr.enabled = l, t.shadowMap.enabled = d, t.shadowMap.autoUpdate = c;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
setRenderSize(t, i) {
|
|
178
|
-
this.renderTarget.setSize(t, i), this.material.uniforms.resolution.value.set(t, i);
|
|
179
|
-
}
|
|
180
|
-
// Radius is in world units; the outer 65% fades before the square mesh edge.
|
|
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;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
const v = {
|
|
186
|
-
light: {
|
|
187
|
-
background: x.light,
|
|
188
|
-
fineGrid: 5859168,
|
|
189
|
-
coarseGrid: 3427136,
|
|
190
|
-
gridOpacity: 0.85,
|
|
191
|
-
reflectionMix: 0.06
|
|
192
|
-
},
|
|
193
|
-
dark: {
|
|
194
|
-
background: x.dark,
|
|
195
|
-
fineGrid: 7375236,
|
|
196
|
-
coarseGrid: 5552554,
|
|
197
|
-
gridOpacity: 0.9,
|
|
198
|
-
reflectionMix: 0.06
|
|
199
|
-
}
|
|
200
|
-
}, W = {
|
|
201
|
-
simulation: 1.2,
|
|
202
|
-
model: 1.2
|
|
203
|
-
};
|
|
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);
|
|
210
|
-
for (const d of Array.isArray(c.material) ? c.material : [c.material])
|
|
211
|
-
if (d) {
|
|
212
|
-
i.add(d);
|
|
213
|
-
for (const h of Object.values(d))
|
|
214
|
-
T(h) && o.add(h);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
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();
|
|
222
|
-
}
|
|
223
|
-
for (const l of s) l.close();
|
|
224
|
-
}
|
|
225
|
-
function T(n) {
|
|
226
|
-
return !!(n && typeof n == "object" && n.isTexture);
|
|
227
|
-
}
|
|
228
|
-
const U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
229
|
-
__proto__: null,
|
|
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();
|
|
245
|
-
const i = new r.Vector3();
|
|
246
|
-
return e.getWorldDirection(i).normalize(), n.setFromNormalAndCoplanarPoint(i, t);
|
|
247
|
-
}
|
|
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;
|
|
254
|
-
for (; i; ) {
|
|
255
|
-
if (i.userData.excludeFromSimulationFit || !i.visible) return;
|
|
256
|
-
i = i.parent;
|
|
257
|
-
}
|
|
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;
|
|
260
|
-
}
|
|
261
|
-
class k {
|
|
262
|
-
constructor(e, t = "dark", i, o = "simulation") {
|
|
263
|
-
a(this, "root", new r.Group());
|
|
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 }));
|
|
276
|
-
a(this, "values");
|
|
277
|
-
a(this, "fog");
|
|
278
|
-
a(this, "raycaster", new r.Raycaster());
|
|
279
|
-
a(this, "pointer", new r.Vector2());
|
|
280
|
-
a(this, "dragPlane", new r.Plane());
|
|
281
|
-
a(this, "dragTarget", new r.Vector3());
|
|
282
|
-
a(this, "dragIntersection", new r.Vector3());
|
|
283
|
-
a(this, "dragOffset", new r.Vector3());
|
|
284
|
-
a(this, "bodyGroups", /* @__PURE__ */ new Map());
|
|
285
|
-
a(this, "auxiliaries", /* @__PURE__ */ new Set());
|
|
286
|
-
a(this, "forceLine");
|
|
287
|
-
a(this, "forceBoosted", !1);
|
|
288
|
-
a(this, "grabCanvas", null);
|
|
289
|
-
a(this, "previousCursor", "");
|
|
290
|
-
a(this, "size", "");
|
|
291
|
-
a(this, "groundVisible");
|
|
292
|
-
a(this, "disposed", !1);
|
|
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);
|
|
298
|
-
}), this.root.add(this.reflector);
|
|
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);
|
|
301
|
-
const h = c / Math.sin(r.MathUtils.degToRad(38) / 2) * 1.25;
|
|
302
|
-
this.fog = new r.Fog(s.background, h * 2.5, h * 8);
|
|
303
|
-
}
|
|
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;
|
|
327
|
-
}
|
|
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;
|
|
331
|
-
}
|
|
332
|
-
resetGround() {
|
|
333
|
-
var e;
|
|
334
|
-
this.disposed || (this.reflector.position.z = (((e = this.runtime) == null ? void 0 : e.defaultGroundHeight) ?? 0) + 2e-3);
|
|
335
|
-
}
|
|
336
|
-
setTheme(e) {
|
|
337
|
-
if (this.disposed) return;
|
|
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);
|
|
340
|
-
}
|
|
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()));
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Re-fits the ground disc and reflection to the model's current world bounds.
|
|
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.
|
|
349
|
-
*/
|
|
350
|
-
reseatGround() {
|
|
351
|
-
if (this.disposed) return;
|
|
352
|
-
this.root.updateMatrixWorld(!0);
|
|
353
|
-
const e = p(this.model);
|
|
354
|
-
e.isEmpty() || this.layoutGround(e, Math.max(e.getSize(new r.Vector3()).length() * 0.5, 0.02));
|
|
355
|
-
}
|
|
356
|
-
createForceLine() {
|
|
357
|
-
const e = new r.BufferGeometry().setFromPoints([
|
|
358
|
-
new r.Vector3(),
|
|
359
|
-
new r.Vector3()
|
|
360
|
-
]), t = new r.LineBasicMaterial({
|
|
361
|
-
color: f,
|
|
362
|
-
depthTest: !1,
|
|
363
|
-
transparent: !0
|
|
364
|
-
}), i = new r.Line(e, t);
|
|
365
|
-
return i.renderOrder = 1e3, i.visible = !1, i;
|
|
366
|
-
}
|
|
367
|
-
findBodyGroup(e) {
|
|
368
|
-
var i;
|
|
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;
|
|
373
|
-
}
|
|
374
|
-
return null;
|
|
375
|
-
}
|
|
376
|
-
getBodyGroup(e) {
|
|
377
|
-
let t = this.bodyGroups.get(e);
|
|
378
|
-
return t || this.model.traverse((i) => {
|
|
379
|
-
var o;
|
|
380
|
-
((o = i.userData) == null ? void 0 : o.bodyId) === e && (t = i, this.bodyGroups.set(e, i));
|
|
381
|
-
}), t;
|
|
382
|
-
}
|
|
383
|
-
pointerRay(e, t, i) {
|
|
384
|
-
const o = i.getBoundingClientRect();
|
|
385
|
-
this.pointer.set(
|
|
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);
|
|
389
|
-
}
|
|
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));
|
|
393
|
-
}
|
|
394
|
-
beginGrab(e, t, i) {
|
|
395
|
-
if (!this.runtime || this.disposed) return !1;
|
|
396
|
-
this.pointerRay(e, t, i);
|
|
397
|
-
const o = this.raycaster.intersectObject(this.model, !0).find((c) => c.object.isMesh);
|
|
398
|
-
if (!o) return !1;
|
|
399
|
-
const s = this.findBodyGroup(o.object);
|
|
400
|
-
if (!s) return !1;
|
|
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());
|
|
404
|
-
return this.bodyGroups.set(s.userData.bodyId, s), this.runtime.beginGrab({
|
|
405
|
-
bodyId: s.userData.bodyId,
|
|
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;
|
|
409
|
-
}
|
|
410
|
-
moveGrab(e, t, i) {
|
|
411
|
-
var s;
|
|
412
|
-
if (!((s = this.runtime) != null && s.grab)) return;
|
|
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))
|
|
414
|
-
this.dragTarget.copy(this.dragIntersection).add(this.dragOffset);
|
|
415
|
-
else
|
|
416
|
-
return;
|
|
417
|
-
const o = this.root.worldToLocal(this.dragTarget.clone());
|
|
418
|
-
this.runtime.updateGrabTarget([o.x, o.y, o.z]), this.updateForceLine();
|
|
419
|
-
}
|
|
420
|
-
endGrab() {
|
|
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);
|
|
423
|
-
}
|
|
424
|
-
updateForceLine() {
|
|
425
|
-
var l;
|
|
426
|
-
const e = (l = this.runtime) == null ? void 0 : l.grab;
|
|
427
|
-
if (!e) return;
|
|
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;
|
|
432
|
-
}
|
|
433
|
-
beforeRender(e, t, i) {
|
|
434
|
-
var u, l;
|
|
435
|
-
const o = {
|
|
436
|
-
tone: e.toneMapping,
|
|
437
|
-
exposure: e.toneMappingExposure,
|
|
438
|
-
color: e.outputColorSpace,
|
|
439
|
-
environment: t.environment,
|
|
440
|
-
fog: t.fog,
|
|
441
|
-
background: t.background
|
|
442
|
-
}, s = () => {
|
|
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;
|
|
444
|
-
};
|
|
445
|
-
if (this.disposed) return s;
|
|
446
|
-
try {
|
|
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;
|
|
452
|
-
} catch (c) {
|
|
453
|
-
throw s(), c;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* The reflector mesh carries both the grid lines and the reflection. Hiding
|
|
458
|
-
* it also skips the reflection render pass, which only feeds its shader.
|
|
459
|
-
*/
|
|
460
|
-
setGroundVisible(e) {
|
|
461
|
-
this.groundVisible = e, this.reflector.visible = e;
|
|
462
|
-
}
|
|
463
|
-
getGroundVisible() {
|
|
464
|
-
return this.groundVisible;
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* Adds a debug/auxiliary object next to the model rather than inside it.
|
|
468
|
-
* The model subtree is what the reflector pass and `getModelBounds` measure,
|
|
469
|
-
* so nesting hidden aids (collision meshes, which are far larger than the
|
|
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.
|
|
473
|
-
*/
|
|
474
|
-
attachAuxiliary(e) {
|
|
475
|
-
this.auxiliaries.add(e), this.modelWrapper.add(e);
|
|
476
|
-
}
|
|
477
|
-
detachAuxiliary(e) {
|
|
478
|
-
this.auxiliaries.delete(e) && e.removeFromParent();
|
|
479
|
-
}
|
|
480
|
-
getModelBounds() {
|
|
481
|
-
this.root.updateMatrixWorld(!0);
|
|
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;
|
|
486
|
-
}
|
|
487
|
-
dispose() {
|
|
488
|
-
if (!this.disposed) {
|
|
489
|
-
this.disposed = !0, this.endGrab(), this.model.removeFromParent();
|
|
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);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
export {
|
|
496
|
-
k as S,
|
|
497
|
-
I as a,
|
|
498
|
-
M as b,
|
|
499
|
-
D as d,
|
|
500
|
-
b as m,
|
|
501
|
-
U as r
|
|
502
|
-
};
|