@nebula-spatial/viewer 0.4.6 → 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 CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  All notable changes to this package are documented in this file.
4
4
 
5
+ ## 0.5.0
6
+
7
+ ### Changed
8
+
9
+ - USD 改用单线程 OpenUSD WASM 运行时(无 pthread、无 `SharedArrayBuffer`):浏览器不再需要 `Cross-Origin-Opener-Policy` / `Cross-Origin-Embedder-Policy` 跨源隔离响应头,也不再需要同源的 Blob 模块 Worker 入口;跨域 CDN 只需放行 CORS。
10
+ - USD 场景改用参考包纯 JS 的构建器,`USDSceneData` 抽取、引用发现与 Stage 生命周期由包内适配层负责。宿主提供的 `resourceResolver` 继续按引用逐项解析,语义与原先的引用预取一致。
11
+ - `@openusd-wasm/pxr` 不再是本包的直接依赖:Viewer 不再实例化 threaded PXR runtime,绕过 `USDSceneData` 的动态 Prim/Attribute 读取改由内置探针提供。
12
+ - 统一资产 source 类型:新增 `AssetSingleSource`,明确单源与 `{ kind: 'files' }` 文件包的区别;`Blob` 现已在公开类型中显式声明,CAD 的 `CadLoadSource` 与 `packFile` 兼容形态保留。
13
+
14
+ ### Added
15
+
16
+ - 新增 `openusd/` 运行时目录并随包发布:`openusd_probe.js` 与 `openusd_probe.wasm`,通过 `exports` 的 `./openusd/*` 暴露。`assets.openUsdBaseUrl` 缺省值改为 `/openusd/`(站点根绝对路径,不随页面所在子目录变化)。
17
+ - 新增单线程 USD 回归覆盖:真实关节资产(24 刚体 / 23 关节)走通 `compileUsdPhysics` → MuJoCo 的编译、步进与重置;GeomSubset 的 UV 重排与逐面子集材质分组与参考栈结果一致;引用解析的标识符归一、去重与 403 授权失败不再回退。
18
+ - 自动格式识别文档明确为“扩展名优先,loader `match()` 兜底”;无法从两者确定格式时,错误信息会提示提供入口文件名或显式 `format`。
19
+
20
+ ### Removed
21
+
22
+ - 移除 `resolveUsdResourcePackage`:它只服务 threaded PXR 运行时的引用预取,职责已并入包内适配层的引用解析。
23
+
24
+ ### Fixed
25
+
26
+ - 修复发布产物中丢失的 `viewerVersion`:包入口此前只做副作用导入、没有重新导出该常量,模块级版本 banner 会被打包器整块摇掉,消费方既看不到 banner 也无法 `import { viewerVersion }`。现在入口显式导出该常量,`sideEffects` 如实标记为含副作用,构建产物与独立消费方产物都会校验 banner 与导出仍在。
27
+ - 修复 USDZ 包内纹理在 URL + `resourceResolver` 场景下被错误当作包外依赖请求的问题;包内条目优先由 USDZ 包解析器提供,resolver 仅处理真正的包外资源。
28
+
29
+ ### Behavior notes
30
+
31
+ - 接入方需让 `openusd_probe.js` 与 `openusd_probe.wasm` 以同名同目录出现在站点可访问的路径下(拷入站点静态目录、由打包器的静态拷贝插件搬运,或上传到自有 CDN 后覆盖 `assets.openUsdBaseUrl`)。`assets.openUsdBaseUrl` 缺省为站点根下的 `/openusd/`,部署在子路径或 CDN 时需显式覆盖。
32
+ - 跨源隔离响应头不再是 USD 预览的必需项;playground / embed-viewer 的开发与预览服务器也不再发送它们,仓库内已无依赖 `SharedArrayBuffer` 的浏览器侧运行时代码。
33
+ - 本次发布只更新 Viewer;`@nebula-spatial/cad-loader` 和私有 `scene-runtime` 版本不变。
34
+
5
35
  ## 0.4.6
6
36
 
7
37
  ### Added
package/README.md CHANGED
@@ -197,6 +197,10 @@ resolve;增量几何和 sidecar 仍通过 `load-progress`、`document-change`
197
197
  替换中的 open 会以 `E_SUPERSEDED` 结束,外部 `AbortSignal` 取消会以 `E_ABORTED` 结束。
198
198
  旧的 `viewer.cad.open()` 仅作为兼容入口保留,已标记为 deprecated。
199
199
 
200
+ 省略 `format` 与传入 `format: 'auto'` 等价。Viewer 先使用入口 URL、文件名或文件包 `entry` 的
201
+ 扩展名选择 loader;扩展名缺失、未知或没有匹配 loader 时,再按注册顺序调用 loader 的
202
+ `match()` 做内容识别。只有两条路径都无法确定格式时,才需要调用方显式传入 `format`。
203
+
200
204
  `viewer.cad.getSnapshot()` 返回深冻结快照(包括独立的 `CadInspectorSnapshot` / `CadHudSnapshot` 数据形状),适合状态管理;图层可用
201
205
  `layers.setVisible(index, visible)` / `setVisibleBatch()` 做确定性更新。无参
202
206
  `viewer.fitView()` 与 `viewer.fitAll()` 适配全部内容,`viewer.cad.fitSelection()` 只适配当前
@@ -330,6 +334,9 @@ const preview = viewer.openAsset('https://cdn.example.com/robot/scene.xml', {
330
334
  await preview.ready;
331
335
  ```
332
336
 
337
+ USDZ 是自包含 ZIP 包。包内 layer、mesh 和纹理由 Viewer 从包内读取,即使同时传入
338
+ `resourceResolver` 也不会把包内条目当作 CDN 兄弟资源请求;resolver 只处理包外引用。
339
+
333
340
  对于私有 OSS/S3/CDN,常见的预签名 URL 只授权一个具体 Object Key。`root.usd` 的签名通常不能
334
341
  复用于 `asset.usdc`、`physics/physics.usda`、纹理等兄弟资源,也不能把入口 URL 的 query
335
342
  原样拼接到其他路径。`resourceResolver.resolve(path)` 必须为每个 `path` 返回独立有效的签名 URL
@@ -419,19 +426,35 @@ USD 视觉引用归属:当视觉几何位于独立聚合树、刚体树中的
419
426
  `getPhysicsProperties().diagnostics` 读取诊断列表。首个视觉降级也会作为 asset warning 发布,`stage` 为 `visual-adaptation`。如果同时发生物理降级,
420
427
  物理 warning 优先显示,完整视觉诊断仍保留在 diagnostics 中。
421
428
 
422
- OpenUSD 使用 pthread WASM,部署必须在安全上下文中提供以下响应头:
429
+ OpenUSD 现在使用单线程 WASM 构建(无 pthread、无 `SharedArrayBuffer`),因此**不再需要**跨源隔离
430
+ 响应头:`Cross-Origin-Opener-Policy` 与 `Cross-Origin-Embedder-Policy` 已从 playground /
431
+ embed-viewer 的开发与预览服务器移除。
423
432
 
424
- ```text
425
- Cross-Origin-Opener-Policy: same-origin
426
- Cross-Origin-Embedder-Policy: require-corp
427
- ```
433
+ 仓库里已没有依赖 `SharedArrayBuffer` 的运行时:playground 的 material-audit 也从参考包的 threaded
434
+ `USDLoader` 换成了本包的单线程 `createSingleThreadUsd`。
428
435
 
429
436
  `@mujoco/mujoco` 和 `@openusd-wasm/three-loader` 保持动态加载。Vite 浏览器构建需要将 MuJoCo
430
437
  包中的 Node-only 裸模块 `module` 精确 alias 到一个导出 `createRequire()` 的浏览器拒绝模块;
431
438
  仓库的 `vite.config.ts` 和独立消费者验证脚本包含该配置。可通过 `assets.mujocoBaseUrl` 与
432
439
  `assets.openUsdBaseUrl` 指向自行托管的 runtime 文件目录。
433
- 跨域 OpenUSD runtime 使用 Blob 模块 Worker 入口导入原始 runtime;CDN 仍需允许 CORS,
434
- 若部署配置了 CSP,还需允许 `worker-src blob:` 及对应 CDN 的脚本加载。该入口不替代上述跨源隔离响应头。
440
+
441
+ `assets.openUsdBaseUrl` 指向存放 `openusd_probe.js` 与 `openusd_probe.wasm` 的目录,默认 `/openusd/`,
442
+ 即站点根绝对路径(不随页面所在子目录变化)。单线程构建是普通 ES 模块 + wasm,跨域 CDN 只需允许 CORS,不需要 Blob 模块 Worker
443
+ 入口,也不需要上述跨源隔离响应头。
444
+
445
+ 两个 runtime 文件随包发布,位于 `@nebula-spatial/viewer/openusd/`(`exports` 已暴露
446
+ `./openusd/*`)。它们必须保持同名同目录地被站点提供,再按需覆盖 `assets.openUsdBaseUrl`:
447
+
448
+ ```ts
449
+ // 1. 拷到站点静态目录(public/openusd/):默认的 `/openusd/` 直接生效。
450
+ // 2. 用打包器的静态拷贝插件从 node_modules 搬运同一目录。
451
+ // 3. 上传到自有 CDN,再把 `assets.openUsdBaseUrl` 指向该目录 URL。
452
+ ```
453
+
454
+ 本仓库自身由 `web/public/openusd/` 提供静态文件,那是构建期副本、不入版本控制;真源是
455
+ `packages/viewer/openusd/`,用 `npm run sync:openusd` 刷新。`npm run dev`、
456
+ `npm run dev:playground`、`npm run build`、`npm run build:url-viewer` 与
457
+ `npm run build:local-viewer` 已自动前置该同步。
435
458
 
436
459
 
437
460
  ## CAD 快速开始
@@ -504,7 +527,10 @@ Troika 全局、模块级、一次性配置语义。字体资源和 `resolveText
504
527
  需要自行托管 Worker 或满足特定 CSP 时,可通过 `CadOpenOptions.workerUrl` 或
505
528
  `workerFactory` 覆盖 Worker 创建方式。
506
529
 
507
- `CadLoadSource` 支持 URL、`ArrayBuffer`、`File` 及对应的 `{ kind: ... }` 形式。`openAsset()`
530
+ 通用 `AssetSingleSource` 支持 URL、`ArrayBuffer`、`Blob`、`File` 及对应的 `{ kind: ... }` 形式。
531
+ `AssetSource` 还支持 `{ kind: 'files', files, entry }` 文件包;包内文件优先使用,传入的
532
+ `resourceResolver` 只用于包外依赖。CAD 的 `CadLoadSource` 在此基础上保留专用的
533
+ `{ kind: 'packFile' }` 兼容形态。`openAsset()`
508
534
  会替换当前活动资产;调用 `viewer.closeAsset()` 关闭活动资产。旧的 `viewer.cad.open()` /
509
535
  `viewer.cad.close()` 会保留兼容行为,但已标记为 deprecated;新代码不应再使用它们管理生命周期。
510
536
 
@@ -602,7 +628,7 @@ open/close 生命周期被提升到 Viewer。`viewer.cad.open()` / `viewer.cad.c
602
628
  - URDF/MJCF 需要 MuJoCo runtime,USD 需要 OpenUSD runtime;可用 `assets.mujocoBaseUrl` 与
603
629
  `assets.openUsdBaseUrl` 指向自托管目录。
604
630
  - 远端目录型资产传入口文件 URL,并保持相对依赖目录;`{ kind:'files' }` 只用于本地 `File | Blob`
605
- 文件包。跨域部署还要配置 CORS、MIME 与鉴权;USD 页面必须满足 HTTPS 和 COOP/COEP。
631
+ 文件包。跨域部署还要配置 CORS、MIME 与鉴权;USD 页面必须满足 HTTPS,但不再需要 COOP/COEP。
606
632
  - `format:'auto'` 只识别明确扩展名/loader match。通用 `.xml`、无扩展名和目录 URL 应显式传 format,
607
633
  不再通过 `unknownFormatPolicy:'cad'` 猜测。
608
634
 
@@ -644,8 +670,9 @@ CAD 类型改为 `ViewerCadUiOptions`、`ViewerCadUiParts`、`ViewerCadUiKeyboar
644
670
  - [ ] CAD 业务状态仍从 `viewer.cad` 读取,没有把 CAD 专属能力混入通用 asset API。
645
671
  - [ ] 旧 `ui.parts`、`ui.preview`、顶层 CAD persistence/keyboard 配置已完成分组迁移。
646
672
  - [ ] Embed 中重复 UI、GLTF 加载、clearColor 分支、抓取监听和 resize/inset 状态机已移除。
647
- - [ ] Draco、MuJoCo、OpenUSD runtime URL 由宿主明确配置并已在真实部署路径验证。
648
- - [ ] 远端资产的 CORS、MIME、鉴权、相对资源路径以及 USD 的跨源隔离已端到端验证。
673
+ - [ ] Draco、MuJoCo runtime URL 由宿主明确配置;OpenUSD 探针随包发布(默认 `/openusd/`,可用
674
+ `assets.openUsdBaseUrl` 覆盖),并已在真实部署路径验证。
675
+ - [ ] 远端资产的 CORS、MIME、鉴权、相对资源路径已端到端验证(USD 单线程构建不再需要跨源隔离)。
649
676
 
650
677
  ## URDF Viewer 审查工作台(0.4.4)
651
678
 
@@ -1,6 +1,7 @@
1
1
  import type { AssetInspection } from '../inspection/types';
2
2
  import type { Object3D, WebGLRenderer, Scene, Camera, Box3, ColorRepresentation } from 'three';
3
3
  import type { CadLoadSource, CadOpenOptions } from '../cad/types';
4
+ import type { AssetSingleSource } from './source-types';
4
5
  import type { ViewerViewMode } from '../types';
5
6
  export type AssetPreviewKind = 'cad' | 'model' | 'simulation';
6
7
  export type BuiltinAssetFormat = 'cad' | 'glb' | 'gltf' | 'fbx' | 'urdf' | 'xacro' | 'mjcf' | 'usd' | 'usda' | 'usdc' | 'usdz';
@@ -9,10 +10,15 @@ export interface AssetFileEntry {
9
10
  readonly path: string;
10
11
  readonly file: File | Blob;
11
12
  }
12
- export type AssetSource = CadLoadSource | {
13
+ export type { AssetSingleSource } from './source-types';
14
+ /** A single source or a browser-held multi-file package. */
15
+ export type AssetSource = AssetSingleSource | Extract<CadLoadSource, {
16
+ readonly kind: 'packFile';
17
+ }> | {
13
18
  readonly kind: 'files';
14
19
  readonly files: readonly AssetFileEntry[];
15
20
  readonly entry?: string;
21
+ /** Aborts this package operation; combined with OpenAssetOptions.signal. */
16
22
  readonly signal?: AbortSignal;
17
23
  };
18
24
  export interface AssetResourceResolver {
@@ -33,10 +39,13 @@ export interface OpenAssetOptions {
33
39
  readonly packages?: Readonly<Record<string, string>>;
34
40
  };
35
41
  readonly simulationTheme?: 'dark' | 'light';
42
+ /** Defaults to automatic detection: extension first, then registered loader matchers. */
36
43
  readonly format?: AssetFormat | 'auto';
37
44
  readonly filename?: string;
38
45
  readonly signal?: AbortSignal;
46
+ /** Base URL for package-external relative resources. */
39
47
  readonly baseUrl?: string;
48
+ /** Resolves package-external resources; local package entries take precedence. */
40
49
  readonly resourceResolver?: AssetResourceResolver;
41
50
  /** @deprecated Auto detection never falls back to CAD; pass an explicit format instead. */
42
51
  readonly unknownFormatPolicy?: 'cad' | 'error';
@@ -87,6 +96,13 @@ export interface AssetPreviewCapabilities {
87
96
  * bodies, so this must not be inferred from `hasPhysics`.
88
97
  */
89
98
  readonly canToggleCollision?: boolean;
99
+ /**
100
+ * The session drives authored clips (skeletal/xform animation) without a
101
+ * physics runtime. Playing them is not "running a simulation", so hosts can
102
+ * relabel the playback controls. Optional, same rationale as
103
+ * `canReorientUpAxis`; only sessions that actually reference clips set it.
104
+ */
105
+ readonly hasAnimation?: boolean;
90
106
  }
91
107
  export type AssetPreviewPhase = 'detecting' | 'loading' | 'ready' | 'failed' | 'closing' | 'closed';
92
108
  export interface AssetErrorSnapshot {
@@ -1,6 +1,7 @@
1
1
  import type { RenderDebugBreakdownEntry, SplitBlockLayerDetail } from '@nebula-spatial/cad-loader';
2
2
  import type { CadSessionLoadTiming } from '@nebula-spatial/cad-loader';
3
3
  import type { ViewerViewMode } from '../types';
4
+ import type { AssetSingleSource } from '../assets/source-types';
4
5
  export type { ViewerUiOptions, ViewerSceneUiOptions, ViewerSceneUiParts, ViewerUiPreset, ViewerUiTheme, ViewerUiTokens } from '../ui/types';
5
6
  export type { CadSessionLoadTiming } from '@nebula-spatial/cad-loader';
6
7
  export type { RenderDebugBreakdownEntry, SplitBlockLayerDetail } from '@nebula-spatial/cad-loader';
@@ -14,14 +15,9 @@ export interface CadWorldBounds {
14
15
  readonly maxZ: number;
15
16
  readonly planar: boolean;
16
17
  }
17
- export type CadLoadSource = ArrayBuffer | string | URL | Pick<File, 'arrayBuffer'> | {
18
- readonly kind: 'buffer';
19
- readonly buffer: ArrayBuffer;
20
- } | {
21
- readonly kind: 'url';
22
- readonly url: string;
23
- readonly signal?: AbortSignal;
24
- } | {
18
+ /** CAD accepts the common single-source forms plus its legacy packFile form. */
19
+ export type CadLoadSource = AssetSingleSource | {
20
+ /** CAD-specific package source; do not use AssetSource's { kind: 'files' }. */
25
21
  readonly kind: 'packFile';
26
22
  readonly file: Pick<File, 'arrayBuffer'>;
27
23
  };