@nebula-spatial/viewer 0.5.13 → 0.5.14

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 CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to this package are documented in this file.
4
4
 
5
+ ## 0.5.14
6
+
7
+ ### Added
8
+
9
+ - 新增 `@nebula-spatial/viewer/vite` 的 `viewerRuntimeAssets()` 插件:开发服务器以稳定文件名提供 `basis/`、`draco/`,生产构建输出同名目录,并把包内 OpenUSD 的 JS/WASM 作为带哈希的独立静态资产交给打包器。
10
+ - 新增 `./basis/*`、`./draco/*`、`./runtime-assets` 子路径导出;`draco/` 运行时(`draco_wasm_wrapper.js`、`draco_decoder.wasm`)随包发布,`runtime-assets` 提供未安装插件时的回退目录与 URL 常量。
11
+ - 未配置 `openUsdBaseUrl` 时默认使用包内 OpenUSD runtime;`assets.openUsdWasmModule`、本地目录和 CDN 显式覆盖继续可用。
12
+ - 发布流程新增 `check:runtime-assets`,校验包内 Basis/Draco/OpenUSD 文件与导出是否完整。
13
+
14
+ ### Changed
15
+
16
+ - `vite` 成为可选 peer dependency(`>=5.0.0`);Vite 消费方接入插件后不再需要手工复制 Basis/Draco 文件,GLB/glTF Draco 也不再必须显式配置 `dracoDecoderPath`。
17
+ - 移除仓库内 `web/public/{openusd,basis,draco}` 静态副本和 OpenUSD 同步脚本,各 Vite 配置统一通过插件输出运行时资源。
18
+ - 默认资源路径调整:Basis/Draco 改为相对当前页面目录的 `basis/`、`draco/`;OpenUSD 在 Vite 下使用包内资产,无插件时回退到站点根 `/openusd/`。
19
+
20
+ ### Fixed
21
+
22
+ - 保留 `usd-preload` 与公开 `usd-prewarm` 声明文件,避免严格 TypeScript 消费方在发布包类型检查时找不到公开入口。
23
+
24
+ ### Behavior notes
25
+
26
+ - 现有 Vite 消费方需在 `vite.config` 中加入 `viewerRuntimeAssets()`;未加入时需自行提供页面相对的 `basis/`、`draco/` 目录,OpenUSD 回退到 `/openusd/`。
27
+ - 依赖旧版站点根 `/basis/` 默认路径的部署应改为接入插件,或继续显式设置 `assets.ktx2TranscoderPath`、`assets.dracoDecoderPath`;旧静态副本可直接删除。
28
+ - 非 Vite 宿主仍需从 `@nebula-spatial/viewer/openusd|basis|draco` 提供文件,或通过显式 URL 覆盖;单线程 OpenUSD 的 CORS 与跨源要求不变。
29
+ - 本次发布只更新 Viewer;`@nebula-spatial/cad-loader`、私有 `scene-runtime` 和 OpenUSD 运行时文件内容均无变更。
30
+
5
31
  ## 0.5.13
6
32
 
7
33
  ### Added
package/README.md CHANGED
@@ -251,24 +251,22 @@ URDF/XACRO/MJCF 规范即 Z-up,USD 在加载时已按 stage 声明的 up 轴
251
251
  中键缩放),`left-pan` 保留 sim-studio 的左键平移、右键旋转映射。运行期可用
252
252
  `viewer.setPreviewDragPreset('left-rotate' | 'left-pan')` 切换。
253
253
 
254
- GLB/glTF 的 Draco decoder 路径由宿主显式配置,不使用站点根路径默认值:
254
+ Viewer 包携带与当前 Three.js 版本匹配的 OpenUSD、Basis 和 Draco runtime。Vite 消费方接入
255
+ `viewerRuntimeAssets()` 插件后,开发服务器和正式构建会自动提供稳定文件名的 `basis/` 与
256
+ `draco/` 目录;OpenUSD 仍由构建器直接解析包内资产:
255
257
 
256
258
  ```ts
257
- const viewer = createViewer({
258
- viewport,
259
- canvas,
260
- assets: {
261
- dracoDecoderPath: new URL('./draco/', document.baseURI).href,
262
- ktx2TranscoderPath: new URL('./basis/', document.baseURI).href,
263
- },
259
+ import { defineConfig } from 'vite';
260
+ import { viewerRuntimeAssets } from '@nebula-spatial/viewer/vite';
261
+
262
+ export default defineConfig({
263
+ plugins: [viewerRuntimeAssets()],
264
264
  });
265
265
  ```
266
266
 
267
- USD 的 KTX2 纹理由 Three.js `KTX2Loader` 解码。Viewer 会自动使用宿主 renderer
268
- 检测可用的压缩纹理格式;默认从站点根目录 `/basis/` 读取 `basis_transcoder.js` 与
269
- `basis_transcoder.wasm`,部署在子路径或需要自行托管时通过 `assets.ktx2TranscoderPath`
270
- (或单次 `openAsset` 选项)显式覆盖。发布包在 `basis/` 目录提供与当前 Three.js 版本匹配的
271
- 两个 Transcoder 文件。
267
+ 插件会把文件输出到消费方构建目录的 `basis/` 和 `draco/`,Viewer 默认按当前页面目录加载。
268
+ `assets.ktx2TranscoderPath` 和 `assets.dracoDecoderPath` 仍可覆盖到自有静态目录或 CDN;
269
+ 不配置时无需复制文件。
272
270
 
273
271
  URDF 和 MJCF 以 MuJoCo WASM 运行,仍由 Viewer 唯一的 scene/runtime/RAF 驱动。多文件模型请传
274
272
  `{ kind: 'files', files, entry }`;`entry` 是包内 URDF 或 MJCF XML 路径。USD 会加载视觉与可可靠映射的物理数据,远端 URL 会以根 USD 文件的完整 URL 作为相对子层、纹理和其他资源的解析基址。
@@ -412,7 +410,8 @@ Sdf Layer 上映射至 MEMFS 路径,再进行 composition;支持 USDA/USDC
412
410
  和 subLayers,保留目标 Prim、layer offset 等原始语义。原文件不会被覆盖,每次加载独立目录,
413
411
  关闭或失败时清理;查询参数和不同来源的同名资源不共用缓存。材质资源恢复为宿主标识供现有
414
412
  视觉适配层消费,`OmniPBR.mdl` 等 MDL 模块不按同目录 HTTP 文件预取,现有材质映射与降级不变。
415
- JS bundle、`openusd_probe.js` 和 `.wasm` 必须同步部署;旧运行时缺少映射接口时报
413
+ 默认的包内 runtime 由消费方打包器整体更新;使用自定义 `openUsdBaseUrl` 时,JS bundle、托管目录中的
414
+ `openusd_probe.js` 和 `.wasm` 必须同步部署。旧运行时缺少映射接口时报
416
415
  `E_USD_RUNTIME_VERSION`,不会静默展示丢失引用的场景。资源拒绝、401/403、读取失败或无效 layer
417
416
  仍是加载失败,不通过空 Blob 或 catch-all 忽略。提供 resolver 的业务必须允许完整模式需要的合法
418
417
  包外引用,Viewer 不绕过白名单。本次模式策略复用现有映射接口,不需要再次构建 OpenUSD WASM。
@@ -578,9 +577,11 @@ embed-viewer 的开发与预览服务器移除。
578
577
  仓库的 `vite.config.ts` 和独立消费者验证脚本包含该配置。可通过 `assets.mujocoBaseUrl` 与
579
578
  `assets.openUsdBaseUrl` 指向自行托管的 runtime 文件目录。
580
579
 
581
- `assets.openUsdBaseUrl` 指向存放 `openusd_probe.js` 与 `openusd_probe.wasm` 的目录,默认 `/openusd/`,
582
- 即站点根绝对路径(不随页面所在子目录变化)。单线程构建是普通 ES 模块 + wasm,跨域 CDN 只需允许 CORS,不需要 Blob 模块 Worker
583
- 入口,也不需要上述跨源隔离响应头。
580
+ `assets.openUsdBaseUrl` 可指向消费方本地目录或 CDN 中存放 `openusd_probe.js` 与
581
+ `openusd_probe.wasm` 的目录。未配置时,Viewer 使用包内 runtime 资产;消费方 Vite 构建会从已安装的
582
+ `@nebula-spatial/viewer` 包中解析这两个文件,并把它们输出为带哈希的独立静态资产,不需要手工复制。
583
+ 单线程构建是普通 ES 模块 + wasm,跨域 CDN 只需允许 CORS,不需要 Blob 模块 Worker 入口,也不需要
584
+ 上述跨源隔离响应头。
584
585
 
585
586
  运行时 URL 自动使用同一个 `?v=<runtimeId>`,其中 `runtimeId` 来自随包发布的
586
587
  `openusd-runtime-manifest.json`,由 JS + WASM 内容哈希生成。因此升级任一文件都会同时绕过 ESM 和
@@ -609,9 +610,7 @@ let openUsdModulePromise: Promise<WebAssembly.Module> | null = null;
609
610
  let mujocoModulePromise: Promise<WebAssembly.Module> | null = null;
610
611
 
611
612
  function getOpenUsdModule() {
612
- return openUsdModulePromise ??= compileOpenUsdWasmModule({
613
- openUsdBaseUrl: '/openusd/',
614
- }).catch((error) => {
613
+ return openUsdModulePromise ??= compileOpenUsdWasmModule().catch((error) => {
615
614
  openUsdModulePromise = null;
616
615
  throw error;
617
616
  });
@@ -628,7 +627,6 @@ const viewer = createViewer({
628
627
  viewport,
629
628
  canvas,
630
629
  assets: {
631
- openUsdBaseUrl: '/openusd/',
632
630
  openUsdWasmModule: getOpenUsdModule(),
633
631
  mujocoWasmModule: getMujocoModule(),
634
632
  },
@@ -659,24 +657,23 @@ Node 和非 Worker 宿主继续使用共享 in-process runtime。
659
657
  异步查询接口,调用方不应再依赖同步 Embind `model.stage`。
660
658
 
661
659
  两个 runtime 文件及 `openusd-runtime-manifest.json` 随包发布,位于
662
- `@nebula-spatial/viewer/openusd/`(`exports` 已暴露 `./openusd/*`)。它们必须保持同名同目录地被站点
663
- 提供,再按需覆盖 `assets.openUsdBaseUrl`:
660
+ `@nebula-spatial/viewer/openusd/`(`exports` 已暴露 `./openusd/*`)。未配置
661
+ `assets.openUsdBaseUrl` 时,Viewer 的内部资产 URL 会交给消费方打包器处理;默认无需复制文件,也无需
662
+ 维护站点根下的 `/openusd/`。需要完全控制交付路径时,再覆盖 `assets.openUsdBaseUrl`:
664
663
 
665
664
  ```ts
666
- // 1. 拷到站点静态目录(public/openusd/):默认的 `/openusd/` 直接生效。
667
- // 2. 用打包器的静态拷贝插件从 node_modules 搬运同一目录。
668
- // 3. 上传到自有 CDN,再把 `assets.openUsdBaseUrl` 指向该目录 URL。
665
+ // 默认:包内 runtime 由消费方打包器自动输出,无需配置。
666
+ // 本地覆盖:把两个同名文件放到自选目录,再设置对应的 openUsdBaseUrl。
667
+ // CDN 覆盖:上传两个同名文件,再把 openUsdBaseUrl 指向该目录 URL。
669
668
  ```
670
669
 
671
- 本仓库自身由 `web/public/openusd/` 提供静态文件,那是构建期副本、不入版本控制;真源是
672
- `packages/viewer/openusd/`,用 `npm run sync:openusd` 刷新。`npm run dev`、
673
- `npm run dev:playground`、`npm run build`、`npm run build:url-viewer` 与
674
- `npm run build:local-viewer` 已自动前置该同步。
670
+ 本仓库自身不再维护 `web/public/openusd/`、`web/public/basis/` 或 `web/public/draco/` 副本;
671
+ 所有 runtime 真源都在 `packages/viewer/`。各 Vite 配置统一接入 `viewerRuntimeAssets()`。
675
672
 
676
673
  替换 `packages/viewer/openusd/` 的 JS 或 WASM 后,在仓库根目录执行 `npm run update:openusd`。
677
- 该命令将 JS 的 CRLF 换行统一为 LF,根据实际 JS / WASM 字节更新清单并同步站点副本;
678
- 检查结果后,将变化的运行时文件和清单一起提交。`.gitattributes` 固定 JS 的提交与检出换行,
679
- WASM 按二进制处理。普通开发和构建只校验与同步,不会自动重新生成清单。
674
+ 该命令将 JS 的 CRLF 换行统一为 LF,并根据实际 JS / WASM 字节更新清单;检查结果后,将变化的
675
+ 运行时文件和清单一起提交。`.gitattributes` 固定 JS 的提交与检出换行,WASM 按二进制处理。
676
+ 普通开发和构建只校验,不会自动重新生成清单。
680
677
 
681
678
 
682
679
  ## CAD 快速开始
@@ -910,7 +907,8 @@ open/close 生命周期被提升到 Viewer。`viewer.cad.open()` / `viewer.cad.c
910
907
  ### 2. 模型与仿真接入
911
908
 
912
909
  - 不再由 Embed/业务代码自行创建 GLTFLoader、挂载模型、管理 loading/failed overlay 或维护独立 RAF。
913
- - GLB/glTF 的 Draco decoder 必须通过 `assets.dracoDecoderPath`(或单次打开选项)由宿主显式配置。
910
+ - GLB/glTF 的 Draco decoder 默认来自 Viewer 包;Vite 消费方需在配置中加入
911
+ `viewerRuntimeAssets()`。自有目录或 CDN 仍可通过 `assets.dracoDecoderPath` 覆盖。
914
912
  - URDF/MJCF 需要 MuJoCo runtime,USD 需要 OpenUSD runtime;可用 `assets.mujocoBaseUrl` 与
915
913
  `assets.openUsdBaseUrl` 指向自托管目录。
916
914
  - 远端目录型资产传入口文件 URL,并保持相对依赖目录;`{ kind:'files' }` 只用于本地 `File | Blob`
@@ -36,9 +36,17 @@ export interface UsdVariantSelection {
36
36
  readonly selection: string;
37
37
  }
38
38
  export interface ViewerAssetOptions {
39
+ /** Directory containing the Draco wrapper and decoder WASM. */
39
40
  readonly dracoDecoderPath?: string;
40
- /** Directory containing `basis_transcoder.js` and `basis_transcoder.wasm`. */
41
+ /**
42
+ * Directory containing `basis_transcoder.js` and `basis_transcoder.wasm`.
43
+ * Defaults to the Viewer-managed runtime directory.
44
+ */
41
45
  readonly ktx2TranscoderPath?: string;
46
+ /**
47
+ * Directory containing `openusd_probe.js` and `openusd_probe.wasm`.
48
+ * Defaults to the runtime bundled with the Viewer package.
49
+ */
42
50
  readonly openUsdBaseUrl?: string;
43
51
  /** Runtime build id appended as `?v=` to the OpenUSD JS and WASM URLs. */
44
52
  readonly openUsdRuntimeId?: string;
@@ -92,6 +100,7 @@ export interface OpenAssetOptions {
92
100
  /** Overrides `assets.ktx2TranscoderPath` for this open operation. */
93
101
  readonly ktx2TranscoderPath?: string;
94
102
  readonly mujocoBaseUrl?: string;
103
+ /** Overrides `assets.openUsdBaseUrl` for this open operation. */
95
104
  readonly openUsdBaseUrl?: string;
96
105
  /** Overrides the packaged runtime id when hosting a matching CDN build. */
97
106
  readonly openUsdRuntimeId?: string;
@@ -3,7 +3,7 @@ var On = (n, t, e) => t in n ? Cn(n, t, { enumerable: !0, configurable: !0, writ
3
3
  var K = (n, t, e) => On(n, typeof t != "symbol" ? t + "" : t, e);
4
4
  import { Vector3 as U, Box3 as st, Matrix4 as mt, BufferAttribute as bn, Line3 as ct, Plane as An, Vector2 as ht, Triangle as Et, BackSide as Fn, DoubleSide as _n, REVISION as Sn, Ray as zn, FrontSide as He, Mesh as $t, LineSegments as Ve, LineLoop as Bn, Line as Tn, Points as Pn, Sphere as Vn, BatchedMesh as jn, LineBasicMaterial as $n, MeshBasicMaterial as kn, WireframeGeometry as qn, EdgesGeometry as we } from "three";
5
5
  import { disposeModelResources as Jn } from "./resources-CHhCm2f7.js";
6
- import { t as Lt, u as We, v as Hn, w as Wn, x as Yn, U as Xn, p as Gn } from "./index-DbJbq4N_.js";
6
+ import { t as Lt, u as We, v as Hn, w as Wn, x as Yn, U as Xn, p as Gn } from "./index-BSDalKkd.js";
7
7
  const Zn = /* @__PURE__ */ new Set([
8
8
  "E_MJCF_INCLUDE_CYCLE",
9
9
  "E_MJCF_PARSE",