@nebula-spatial/viewer 0.4.5 → 0.4.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 CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  All notable changes to this package are documented in this file.
4
4
 
5
+ ## 0.4.6
6
+
7
+ ### Added
8
+
9
+ - URDF 内置工作台新增结构图弹窗:以只读 SVG 渲染 Link/Joint 拓扑,支持缩放、重置视图、最大化、拖动窗口与四角拖拽改尺寸,节点与场景选择、结构树双向联动。
10
+ - 新增预览拖拽预设 `ViewerOptions.previewDragPreset` 与 `viewer.setPreviewDragPreset()`:在 `left-rotate`(默认,左键旋转/右键平移)和 `left-pan`(左键平移/右键旋转)之间切换模型与仿真预览的指针映射。
11
+ - 仿真资产(URDF/XACRO/MJCF/USD)新增 `capabilities.canReorientUpAxis` 与 `preview.setUpAxis()` 重定向:运行时已就绪时旋转编译后的物理模型,顶层刚体的参考位姿、当前位姿与速度一并跟随。
12
+ - 新增 `viewerVersion` 导出:包入口在模块加载时打印一次版本 banner,`check-boundary` 校验它与 `package.json` 版本是否漂移。
13
+
14
+ ### Improved
15
+
16
+ - 内置 URDF UI 拆分为结构面板、属性面板、工具栏、状态栏与结构图组件,各自持有各自的 UI 状态;工具栏统一为覆盖层、名称、角度单位、地面、适应视图、主题、仿真与重置。
17
+ - 结构树在选中与关节控制刷新时保留滚动位置和焦点;mimic 联动关节按控制根分组展示,跟随关系与偏移量在同一分组内说明。
18
+ - 仿真上轴切换后按翻转后的包围盒重铺地面与反射,重力保持 -Z、物理地面保持水平;URDF 在运动学与动力学之间切换时上轴旋转不会叠加。
19
+ - GLB/glTF 按 glTF 规范默认使用 Y-up;FBX 仍优先读取文件内的正向 `UpAxis`/`UpAxisSign` 声明,USD/URDF/MJCF 保持默认 Z-up。
20
+
21
+ ### Fixed
22
+
23
+ - 结构图弹窗背景改为半透明,避免遮挡底层模型;四角拖拽限制最小 420×320,并防止窗口被拖出画布范围。
24
+
25
+ ### Behavior notes
26
+
27
+ - 结构图是只读拓扑视图,不编辑资产;不支持的语义仍以严格检查的错误列表为准。
28
+ - 仿真资产的上轴重定向移动的是编译后的物理模型:重力方向与查看器地面保持不变,固定基座机器人只会整体倾斜;无运行时(运动学预览、物理降级预览)退回纯场景图旋转。
29
+ - `left-pan` 仅为兼容 sim-studio 的既有映射,默认的 `left-rotate` 与 OrbitControls 约定一致。
30
+ - 本次发布只更新 Viewer;`@nebula-spatial/cad-loader` 和私有 `scene-runtime` 版本不变。
31
+
5
32
  ## 0.4.5
6
33
 
7
34
  ### Added
@@ -9,8 +36,8 @@ All notable changes to this package are documented in this file.
9
36
  - 新增 USD 视觉材质适配支持矩阵,明确 `UsdPreviewSurface`、MaterialX Standard Surface、OmniPBR 和 OmniGlass 的已转换、有界近似及未适配范围。
10
37
  - 支持常量介质透明、`presence`、`opacityThreshold`、受限透明纹理、MaterialX 薄壁透射,以及 OmniGlass 的覆盖率、反射颜色、粗糙度和受限法线适配。
11
38
  - 支持 USD 实例材质代理中的可确定常量 `UsdPreviewSurface` 输入恢复;保留循环、歧义、程序节点和体积光学语义的诊断。
12
- - 本地 Viewer 文件包入口支持 `root.usd`、`root.usda`、`root.usdc` 和 `root.usdz`,不受上传顺序影响。
13
- - 支持浏览器 Xacro 子集展开,包含宏、属性、参数、条件、块参数、嵌套 include 与 ROS package 映射;不支持的 Python/ROS 语义会显式失败。
39
+ - 本地 Viewer 文件包入口支持 `root.usd`、`root.usda`、`root.usdc` 和 `root.usdz`,不受上传顺序影响。
40
+ - 支持浏览器 Xacro 子集展开,包含宏、属性、参数、条件、块参数、嵌套 include 与 ROS package 映射;不支持的 Python/ROS 语义会显式失败。
14
41
  - 支持 URDF mimic 联动、可行控制范围、浏览器 COLLADA 网格、内嵌材质,以及本地文件包目录浏览和入口切换。
15
42
 
16
43
  ### Improved
@@ -18,20 +45,20 @@ All notable changes to this package are documented in this file.
18
45
  - 统一 URDF/MJCF 视觉材质的线性颜色、粗糙度、金属度、法线、透明度、发光和纹理通道转换,并补充纹理资源释放与诊断。
19
46
  - URDF 审查工作台补充惯性姿态、惯量信息展开、连续关节控制范围、关节扫描和侧栏交互保持。
20
47
  - USD 视觉过滤按 `purpose` 隔离辅助几何;修正世界侧关节参考系、单位/up-axis 转换和显式惯性处理。
21
- - 物理模型取景忽略环境平面,避免地面或辅助几何主导模型缩放;补充跨格式材质审计页面及 Chromium 验证脚本。
48
+ - 物理模型取景忽略环境平面,避免地面或辅助几何主导模型缩放;补充跨格式材质审计页面及 Chromium 验证脚本。
22
49
  - 恢复分离 USD 视觉树到刚体的引用归属,支持显式引用 Prim 路径与 defaultPrim 引用,并对歧义、缺失和格式错误保留诊断。
23
50
 
24
51
  ### Fixed
25
52
 
26
53
  - 玻璃透射材质按 USD `doubleSided` 声明应用单面/双面策略,避免共享材质被错误修改;纯金属材质不被误判为玻璃。
27
54
  - 修复 USD 透明度、覆盖率阈值、透明纹理、OmniGlass 法线与反射参数的边界转换;无法可靠表达的体积吸收、实体光程和复杂光学效果继续报告诊断,不生成猜测值。
28
- - 允许具有完整显式质量、质心、惯量和主轴数据的 USD 刚体缺少碰撞几何;仅有不完整惯性时仍明确失败,不虚构碰撞形状。
55
+ - 允许具有完整显式质量、质心、惯量和主轴数据的 USD 刚体缺少碰撞几何;仅有不完整惯性时仍明确失败,不虚构碰撞形状。
29
56
  - 修复 URDF 固定轴 RPY、惯性坐标旋转、mimic 初始姿态与 MuJoCo equality 约束;修复 USD 聚合视觉网格不随对应刚体更新的问题。
30
57
 
31
58
  ### Behavior notes
32
59
 
33
60
  - 本版本继续使用有边界的 Three.js 材质映射,不执行 MDL 或完整 MaterialX 节点网络,也不承诺与 Blender、Omniverse 或路径追踪渲染逐像素一致。
34
- - `USD-VISUAL-MATERIAL-SUPPORT.md` 随 npm 包发布,记录具体支持矩阵;材质适配报告和诊断仍是判断单个资产结果的依据。
61
+ - `USD-VISUAL-MATERIAL-SUPPORT.md` 随 npm 包发布,记录具体支持矩阵;材质适配报告和诊断仍是判断单个资产结果的依据。
35
62
  - Xacro 是受限浏览器预处理子集,不执行外部 ROS 命令或环境访问;复杂 Python/YAML 语义应先使用官方工具展开。
36
63
  - 本次发布只更新 Viewer;`@nebula-spatial/cad-loader` 和私有 `scene-runtime` 版本不变。
37
64
 
package/README.md CHANGED
@@ -223,15 +223,30 @@ stop();
223
223
  旧句柄的 `close()` 只等待自己的资源清理,不会关闭后来打开的资产。`closeAsset()` 关闭调用瞬间
224
224
  的活动资产。普通模型以 borrowed 方式挂入唯一 scene runtime,GPU 资源只由模型 session 释放。
225
225
 
226
- GLB/glTF 与 FBX 模型的 authored up 轴在 Viewer 中统一由 `upAxis` 声明。预览世界固定 Z-up;FBX 会先读取 `GlobalSettings` 中正向的 Y/Z `UpAxis` 与 `UpAxisSign` 声明,声明缺失、损坏或当前不支持时才回退到 Y-up。显式传入的 `upAxis` 始终优先;GLB/glTF 为兼容 CAD-kernel 导出继续默认使用 Z-up;
226
+ 模型的 authored up 轴在 Viewer 中由 `upAxis` 声明。预览世界固定 Z-up;FBX 会先读取
227
+ `GlobalSettings` 中正向的 Y/Z `UpAxis` 与 `UpAxisSign` 声明,声明缺失、损坏或当前不支持时才
228
+ 回退到 Y-up;GLB/glTF 没有任何文件内声明可读,按 glTF 规范默认使用 Y-up,
229
+ 只能由调用方声明。显式传入的 `upAxis` 始终优先。
227
230
  对轴向错误的模型传 `upAxis: 'y'` 打开(仅旋转资产根节点,不移动相机与世界),或运行期用
228
231
  `preview.setUpAxis('y' | 'z')` / `preview.getUpAxis()` 切换(切换后自动重铺地面并重新适配
229
- 相机,不平移贴地)。能力标志为 `capabilities.canReorientUpAxis`。仿真资产的格式自带 up 轴,
230
- 不提供该能力。
232
+ 相机,不平移贴地)。能力标志为 `capabilities.canReorientUpAxis`。
233
+
234
+ 仿真资产(URDF/XACRO/MJCF/USD)同样暴露 `canReorientUpAxis`,切换语义是**旋转编译后的物理模型**:
235
+ 把所有顶层刚体绕世界原点按该轴向旋转(free joint 的参考位姿与当前位姿、速度一并跟随),重力仍为
236
+ -Z、物理地面仍是原有的水平面,因此杯子这类资产切换后会真的倾倒并沉降到地面,碰撞代理、力线、
237
+ 抓取换算都和渲染保持一致。地面会随翻转自适应:物理平面重新落到翻转后资产的最低点,地面盘的
238
+ 中心与范围按新包围盒重铺;相机**不**重新适配。URDF 固定基座机器人只会整体倾斜(基座焊接在世界上,
239
+ 不会倒);无运行时(运动学预览、物理降级预览)时退回纯场景图旋转。
240
+ URDF/XACRO/MJCF 规范即 Z-up,USD 在加载时已按 stage 声明的 up 轴烘焙到 Z-up 世界朝向,所以三者的
241
+ 初始值都是 `'z'`;`OpenAssetOptions.upAxis` 可覆盖初始值。
231
242
 
232
243
  地面(网格线 + 反射 + 接影地板)可通过 `preview.setGroundVisible(false)` 整体隐藏、`preview.getGroundVisible()`
233
244
  查询,对应 `capabilities.canToggleGround`;模型与仿真预览均支持。隐藏时跳过反射 pass,接影地板与地面阴影一并隐藏。
234
245
 
246
+ 模型与仿真预览的鼠标拖拽映射由 `previewDragPreset` 决定,默认 `left-rotate`(左键旋转、右键平移、
247
+ 中键缩放),`left-pan` 保留 sim-studio 的左键平移、右键旋转映射。运行期可用
248
+ `viewer.setPreviewDragPreset('left-rotate' | 'left-pan')` 切换。
249
+
235
250
  GLB/glTF 的 Draco decoder 路径由宿主显式配置,不使用站点根路径默认值:
236
251
 
237
252
  ```ts
@@ -348,7 +363,7 @@ USD 仿真继续以 OpenUSD Stage 和 USD Physics 为语义权威;视觉适配
348
363
  PBR 参数转换之后查漏补缺。它不会重建 loader 已正确生成的材质,也不会修改刚体、关节、碰撞体
349
364
  或 MuJoCo 绑定。
350
365
 
351
- USD 视觉引用归属:当视觉几何位于独立聚合树、刚体树中的 `Visual` Prim 通过 USD reference 指向该聚合树时,Viewer 会按引用的目标 Prim 路径将网格绑定到对应刚体,使其跟随 MuJoCo 运行时位姿。支持显式引用 Prim 路径及 defaultPrim 引用;多个刚体映射到同一视觉尾路径、引用元数据缺失或格式无法解析时不会猜测归属,而是保留视觉诊断。
366
+ USD 视觉引用归属:当视觉几何位于独立聚合树、刚体树中的 `Visual` Prim 通过 USD reference 指向该聚合树时,Viewer 会按引用的目标 Prim 路径将网格绑定到对应刚体,使其跟随 MuJoCo 运行时位姿。支持显式引用 Prim 路径及 defaultPrim 引用;多个刚体映射到同一视觉尾路径、引用元数据缺失或格式无法解析时不会猜测归属,而是保留视觉诊断。
352
367
  实例化材质:当 Loader 遗漏实例代理中的 Shader 时,适配层沿 `outputs:surface` 读取
353
368
  标准 `UsdPreviewSurface`,解析其输入到材质实例常量的连接,再复用 Loader 的材质转换。
354
369
  当前只补齐可确定解析的常量网络;缺失、循环、歧义连接或纹理/程序节点网络保留原诊断。
@@ -636,7 +651,7 @@ CAD 类型改为 `ViewerCadUiOptions`、`ViewerCadUiParts`、`ViewerCadUiKeyboar
636
651
 
637
652
  URDF 默认打开为静止的**运动学预览**:关节控制由确定性 FK 驱动,不会自动加载或启动 MuJoCo。只有用户调用 `preview.play()`、`ctx.commands.play()` 或点击内置“动力学仿真”播放按钮后,Viewer 才按需初始化现有物理运行时。
638
653
 
639
- 内置工作台包括可折叠结构树、搜索/过滤、关节滑块与范围扫描、Collision/关节轴与正方向/质心/惯量覆盖层、属性面板、XML 只读定位,以及只报告确定错误的严格检查。可通过 `ui.urdf: false` 关闭内置界面,或通过 `ui.preset: 'none'` 完全 Headless 使用。
654
+ 内置工作台包括可折叠结构树、搜索/过滤、关节滑块与范围扫描、Collision/关节轴与正方向/质心/惯量覆盖层、结构图弹窗、属性面板、XML 只读定位,以及只报告确定错误的严格检查。可通过 `ui.urdf: false` 关闭内置界面,或通过 `ui.preset: 'none'` 完全 Headless 使用。
640
655
 
641
656
  ### 交互与仿真状态
642
657
 
@@ -645,6 +660,7 @@ URDF 默认打开为静止的**运动学预览**:关节控制由确定性 FK
645
660
  - 仿真运行时关节控制与部件选择只读,但保留物理拖拽;关节轴、质心、惯量可以开关并跟随实时姿态。
646
661
  - 暂停后恢复点选与关节调整,再次播放使用当前姿态;重置恢复初始运动学状态。选中关节时,其 child link 的质心和惯量使用区别色。
647
662
  - 场景工具栏提供播放/暂停、重置、地面显隐、适应视图及主题切换;侧栏支持调宽和折叠,结构树选择保留滚动位置。
663
+ - 结构图弹窗以只读 SVG 渲染 Link/Joint 拓扑,支持缩放、重置视图、最大化、拖动窗口和四角拖拽改尺寸;节点选中与结构树、场景选择双向同步。
648
664
 
649
665
  ### 默认地面的防穿透与重置
650
666
 
@@ -721,6 +737,10 @@ Viewer 自行拥有 SceneRuntime、Renderer、Camera、Controls、事件监听
721
737
  `dispose()` 会统一释放这些资源。运行时依赖为 `three` peer dependency,要求 Node.js 18
722
738
  或更高版本。
723
739
 
740
+ 包入口导出 `viewerVersion`,与 `package.json` 的版本保持一致,并在模块首次加载时打印一次
741
+ 版本 banner;`npm run check:boundary --workspace @nebula-spatial/viewer` 会在构建前校验两者
742
+ 是否漂移。
743
+
724
744
  ## 开发
725
745
 
726
746
  ```bash
@@ -765,39 +785,39 @@ ready 等待纹理解码及转换完成;中断和关闭清理源纹理、转
765
785
 
766
786
  材质参数对齐不等于截图逐像素对齐:还需相同 HDR、环境旋转、曝光、视角与色彩管理。
767
787
  Viewer 不会为了匹配单个 Blender 截图而覆盖全局曝光或灯光。
768
-
769
- ## Xacro preview
770
-
771
- `.xacro` and `.urdf.xacro` use `xacro-parser@0.3.11` as an optional, lazily loaded
772
- preprocessing stage before the existing URDF kinematic review. They do not autoplay.
773
- Upload the entire description directory, not only its entry XML, or provide a
774
- `baseUrl` / `resourceResolver` for includes and meshes.
775
-
776
- ```ts
777
- const preview = viewer.openAsset({ kind: 'files', entry: 'robot/urdf/main.urdf.xacro', files }, {
778
- xacro: {
779
- arguments: { prefix: 'arm_', size: 0.2 },
780
- packages: { robot_description: 'robot' },
781
- },
782
- });
783
- await preview.ready;
784
- ```
785
-
786
- `xacro.packages` maps ROS package names to directories relative to the uploaded
787
- file package or `baseUrl`. Local `package.xml` files supply mappings automatically;
788
- explicit mappings override discovery. Ambiguous package names fail. External ROS
789
- commands and environment access are not executed. Mesh/texture `package://` paths
790
- use the same mapping. Resource requests retain the existing resolver and abort signal.
791
-
792
- Supported subset: macros, properties, arguments/defaults, numeric expressions,
793
- if/unless, block parameters and nested includes. Python expressions are **not**
794
- fully compatible: `xacro.load_yaml`, include namespaces, dynamic `xacro:call`, and
795
- `param:=^|default` are unsupported. Expansion errors are fatal `E_XACRO_EXPAND`
796
- errors; there is no fallback that renders incomplete raw Xacro as URDF. Inputs are
797
- limited to 4 MiB each and 128 include reads, but this is not a sandbox or a complete
798
- CPU/memory limit for untrusted macro expansion.
799
-
800
- Review source ranges are labeled `(expanded URDF)`; they do not map back to the
801
- original macro definition. The current Universal Robots ROS2 description uses
802
- Python/YAML expressions and is not covered by this browser subset. For full ROS
788
+
789
+ ## Xacro preview
790
+
791
+ `.xacro` and `.urdf.xacro` use `xacro-parser@0.3.11` as an optional, lazily loaded
792
+ preprocessing stage before the existing URDF kinematic review. They do not autoplay.
793
+ Upload the entire description directory, not only its entry XML, or provide a
794
+ `baseUrl` / `resourceResolver` for includes and meshes.
795
+
796
+ ```ts
797
+ const preview = viewer.openAsset({ kind: 'files', entry: 'robot/urdf/main.urdf.xacro', files }, {
798
+ xacro: {
799
+ arguments: { prefix: 'arm_', size: 0.2 },
800
+ packages: { robot_description: 'robot' },
801
+ },
802
+ });
803
+ await preview.ready;
804
+ ```
805
+
806
+ `xacro.packages` maps ROS package names to directories relative to the uploaded
807
+ file package or `baseUrl`. Local `package.xml` files supply mappings automatically;
808
+ explicit mappings override discovery. Ambiguous package names fail. External ROS
809
+ commands and environment access are not executed. Mesh/texture `package://` paths
810
+ use the same mapping. Resource requests retain the existing resolver and abort signal.
811
+
812
+ Supported subset: macros, properties, arguments/defaults, numeric expressions,
813
+ if/unless, block parameters and nested includes. Python expressions are **not**
814
+ fully compatible: `xacro.load_yaml`, include namespaces, dynamic `xacro:call`, and
815
+ `param:=^|default` are unsupported. Expansion errors are fatal `E_XACRO_EXPAND`
816
+ errors; there is no fallback that renders incomplete raw Xacro as URDF. Inputs are
817
+ limited to 4 MiB each and 128 include reads, but this is not a sandbox or a complete
818
+ CPU/memory limit for untrusted macro expansion.
819
+
820
+ Review source ranges are labeled `(expanded URDF)`; they do not map back to the
821
+ original macro definition. The current Universal Robots ROS2 description uses
822
+ Python/YAML expressions and is not covered by this browser subset. For full ROS
803
823
  compatibility, expand with the official Xacro tool first and open the resulting URDF.
@@ -44,12 +44,17 @@ export interface OpenAssetOptions {
44
44
  readonly mujocoBaseUrl?: string;
45
45
  readonly openUsdBaseUrl?: string;
46
46
  /**
47
- * Which authored axis is "up" for a plain model asset. FBX first uses a
48
- * supported positive Y/Z declaration from GlobalSettings, then falls back to
49
- * 'y' when it is missing or cannot be read. GLB/glTF retain the existing 'z'
50
- * default for CAD-kernel compatibility. An explicit value always wins. 'y'
51
- * rotates the model root into world +Z.
52
- * Ignored by simulation assets, whose formats declare their own up axis.
47
+ * Which authored axis is "up". FBX first uses a supported positive Y/Z
48
+ * declaration from GlobalSettings, then falls back to 'y' when it is missing
49
+ * or cannot be read. GLB/glTF default to 'y' per the glTF coordinate
50
+ * convention. An explicit value always wins. 'y' rotates the model root into
51
+ * world +Z.
52
+ *
53
+ * Also seeds the initial up axis of simulation assets. URDF/XACRO/MJCF are
54
+ * Z-up by specification; USD defaults to 'z' because the loader has already
55
+ * applied the stage's declared axis. For simulation the rotation is applied
56
+ * to the compiled model itself, so collisions, contacts and gravity stay
57
+ * consistent with what is rendered.
53
58
  */
54
59
  readonly upAxis?: AssetUpAxis;
55
60
  /** CAD-specific compatibility options. `filename` and `signal` above take precedence. */
@@ -63,9 +68,12 @@ export interface AssetPreviewCapabilities {
63
68
  readonly canReset: boolean;
64
69
  readonly hasPhysics: boolean;
65
70
  /**
66
- * A plain model whose authored up axis can be re-oriented at runtime.
67
- * Optional (absent means false) so pre-existing third-party asset sessions
68
- * that build this literal keep compiling; only the model session opts in.
71
+ * The asset's authored up axis can be re-oriented at runtime. Declared by
72
+ * model and simulation sessions. For simulation assets the compiled physics
73
+ * is rotated with it (gravity and the viewer ground stay put), so a toggled
74
+ * asset keeps rendering and simulating the same pose. Optional (absent means
75
+ * false) so pre-existing third-party asset sessions that build this literal
76
+ * keep compiling.
69
77
  */
70
78
  readonly canReorientUpAxis?: boolean;
71
79
  /**
@@ -137,7 +145,12 @@ export interface AssetPreview {
137
145
  /** USD visual report and diagnostics, including static assets. */
138
146
  getVisualDiagnostics?(): Readonly<Record<string, unknown>> | null;
139
147
  setCollisionVisible(visible: boolean): void;
140
- /** Re-orients a plain model's authored up axis without moving the camera. */
148
+ /**
149
+ * Re-orients the asset's authored up axis without moving the camera. Model
150
+ * previews re-seat the ground and refit the camera; simulation assets rotate
151
+ * the physics itself, re-seat the ground under the new pose and leave the
152
+ * camera alone.
153
+ */
141
154
  setUpAxis(axis: AssetUpAxis): void;
142
155
  getUpAxis(): AssetUpAxis | null;
143
156
  /** Shows or hides the staged ground (grid + reflection). */