@nebula-spatial/viewer 0.4.1 → 0.4.3
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 +30 -0
- package/FBX-MATERIAL-CONVERSION.md +97 -0
- package/README.md +115 -6
- package/dist/assets/types.d.ts +16 -0
- package/dist/{index-D0lW4RQP.js → index-BDo6voB2.js} +618 -524
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mjcf-visual--X39MVO9.js +63 -0
- package/dist/session-1duLyM88.js +964 -0
- package/dist/session-DhZXy40-.js +653 -0
- package/dist/{stage-CFr9ZkwQ.js → stage-BKqg5vNe.js} +137 -134
- package/dist/urdf-session-C_LAfkkM.js +439 -0
- package/dist/usd-session-zyj46Bcg.js +1192 -0
- package/package.json +2 -1
- package/dist/session-B4uKXhdV.js +0 -266
- package/dist/session-DNMxzxd5.js +0 -762
- package/dist/usd-session-DDWM5msM.js +0 -522
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { ViewerSceneUiOptions, ViewerSceneUiParts } from './ui/types';
|
|
2
2
|
export { createViewer } from './viewer';
|
|
3
|
-
export type { AssetChangeEvent, AssetControlState, AssetControlChangeEvent, AssetDetectionResult, AssetErrorEvent, AssetErrorSnapshot, AssetFileEntry, AssetFormat, AssetLoaderContext, AssetLoaderContribution, AssetPresentationProfile, AssetPreview, AssetPreviewCapabilities, AssetPreviewKind, AssetPreviewPhase, AssetPreviewSnapshot, AssetResourceResolver, AssetSession, AssetSource, AssetUpAxis, NormalizedAssetSource, OpenAssetOptions, ViewerAssetOptions, } from './assets/types';
|
|
3
|
+
export type { AssetChangeEvent, AssetControlState, AssetControlChangeEvent, AssetDetectionResult, AssetErrorEvent, AssetErrorSnapshot, AssetFileEntry, AssetFormat, AssetLoaderContext, AssetLoaderContribution, AssetPhysicsState, AssetPresentationProfile, AssetPreview, AssetPreviewCapabilities, AssetPreviewKind, AssetPreviewPhase, AssetPreviewSnapshot, AssetResourceResolver, AssetSession, AssetSource, AssetUpAxis, NormalizedAssetSource, OpenAssetOptions, ViewerAssetOptions, } from './assets/types';
|
|
4
4
|
export type { Disposable, ToolbarItem, ViewerState, ViewerInteractionHooks, ViewerContributionPoint, ViewerPlugin, ViewerPluginContext, ViewerPluginRegistry, } from './plugins';
|
|
5
5
|
export { configureViewerText } from './cad/text';
|
|
6
6
|
export type { ViewerTextBuilderOptions } from './cad/text';
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Group as A, Euler as C, BoxGeometry as E, SphereGeometry as F, CylinderGeometry as x, CapsuleGeometry as J, PlaneGeometry as q, MeshStandardMaterial as G, Mesh as z } from "three";
|
|
2
|
+
import { d as S } from "./stage-BKqg5vNe.js";
|
|
3
|
+
function v(d) {
|
|
4
|
+
const f = d.extension.documents, l = new A();
|
|
5
|
+
l.name = d.name;
|
|
6
|
+
try {
|
|
7
|
+
if (f.size !== 1) throw new Error("MJCF 独立预览暂不支持 include");
|
|
8
|
+
const c = [...f.values()][0];
|
|
9
|
+
if (c.querySelector("default, include, attach, replicate, composite, flexcomp, skin, hfield, plugin")) throw new Error("MJCF 独立预览包含尚不支持的继承、组合或扩展语义");
|
|
10
|
+
const n = c.querySelector("compiler");
|
|
11
|
+
if ((n == null ? void 0 : n.getAttribute("coordinate")) === "global" || n != null && n.hasAttribute("eulerseq")) throw new Error("MJCF 独立预览不支持此坐标设置");
|
|
12
|
+
const w = (n == null ? void 0 : n.getAttribute("angle")) === "radian" ? 1 : Math.PI / 180, b = (a, u) => {
|
|
13
|
+
const e = a ? a.trim().split(/\s+/).map(Number) : u;
|
|
14
|
+
if (e.some((o) => !Number.isFinite(o))) throw new Error("MJCF 视觉坐标无效");
|
|
15
|
+
return e;
|
|
16
|
+
}, m = (a, u, e) => {
|
|
17
|
+
const o = b(a, u);
|
|
18
|
+
if (o.length !== e) throw new Error(`MJCF 视觉变换需要 ${e} 个分量`);
|
|
19
|
+
return o;
|
|
20
|
+
}, p = (a, u) => {
|
|
21
|
+
for (const e of a.children) {
|
|
22
|
+
if (!["body", "geom"].includes(e.tagName)) continue;
|
|
23
|
+
if (["class", "childclass", "fromto", "axisangle", "xyaxes", "zaxis"].some((r) => e.hasAttribute(r))) throw new Error("MJCF 独立预览不支持此变换或默认类");
|
|
24
|
+
const o = new A();
|
|
25
|
+
if (o.name = e.getAttribute("name") ?? e.tagName, o.position.fromArray(m(e.getAttribute("pos"), [0, 0, 0], 3)), e.hasAttribute("quat")) {
|
|
26
|
+
const r = m(e.getAttribute("quat"), [1, 0, 0, 0], 4);
|
|
27
|
+
if (Math.hypot(...r) === 0) throw new Error("MJCF 视觉四元数不能为零");
|
|
28
|
+
o.quaternion.set(r[1], r[2], r[3], r[0]).normalize();
|
|
29
|
+
} else {
|
|
30
|
+
const r = m(e.getAttribute("euler"), [0, 0, 0], 3);
|
|
31
|
+
o.quaternion.setFromEuler(new C(r[0] * w, r[1] * w, r[2] * w, "XYZ"));
|
|
32
|
+
}
|
|
33
|
+
if (u.add(o), e.tagName === "body") {
|
|
34
|
+
p(e, o);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const s = e.getAttribute("type") ?? (e.hasAttribute("mesh") ? "mesh" : "sphere"), t = b(e.getAttribute("size"), []);
|
|
38
|
+
if (e.hasAttribute("material") || t.length === 0) throw new Error("MJCF 独立预览缺少可直接解析的几何或材质");
|
|
39
|
+
const y = { box: 3, sphere: 1, cylinder: 2, capsule: 2, plane: 3 }[s];
|
|
40
|
+
if (y && (t.length < y || t.some((r) => s === "plane" ? r < 0 : r <= 0)))
|
|
41
|
+
throw new Error(`MJCF geom ${s} 的尺寸缺失或无效`);
|
|
42
|
+
let i;
|
|
43
|
+
if (s === "box") i = new E(2 * t[0], 2 * t[1], 2 * t[2]);
|
|
44
|
+
else if (s === "sphere") i = new F(t[0]);
|
|
45
|
+
else if (s === "cylinder")
|
|
46
|
+
i = new x(t[0], t[0], 2 * t[1]), i.rotateX(Math.PI / 2);
|
|
47
|
+
else if (s === "capsule")
|
|
48
|
+
i = new J(t[0], 2 * t[1]), i.rotateX(Math.PI / 2);
|
|
49
|
+
else if (s === "plane") i = new q(2 * (t[0] || 5), 2 * (t[1] || 5));
|
|
50
|
+
else throw new Error(`MJCF 独立预览暂不支持 geom ${s}`);
|
|
51
|
+
const h = m(e.getAttribute("rgba"), [0.5, 0.5, 0.5, 1], 4), M = new G({ opacity: h[3], transparent: h[3] < 1 });
|
|
52
|
+
M.color.setRGB(h[0], h[1], h[2]), o.add(new z(i, M));
|
|
53
|
+
}
|
|
54
|
+
}, g = c.querySelector("worldbody");
|
|
55
|
+
if (!g) throw new Error("MJCF 缺少 worldbody");
|
|
56
|
+
return p(g, l), l.updateMatrixWorld(!0), l;
|
|
57
|
+
} catch (c) {
|
|
58
|
+
throw S(l), c;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
v as compileMjcfPreview
|
|
63
|
+
};
|