@nebula-spatial/viewer 0.4.0 → 0.4.2

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,18 @@
2
2
 
3
3
  All notable changes to this package are documented in this file.
4
4
 
5
+ ## 0.4.2
6
+
7
+ ### Fixed
8
+
9
+ - 修复 `assets.openUsdBaseUrl` 指向跨域 runtime 时,OpenUSD pthread Worker 因入口同源限制抛出 `SecurityError` 的问题;通过 Blob 模块入口导入远端 runtime,保留同源与 Node 加载行为,并补充回归测试及 CORS、CSP 部署说明。
10
+
11
+ ## 0.4.1
12
+
13
+ ### Added
14
+
15
+ - 内置普通模型预览新增 FBX 格式,支持按 `.fbx` 扩展名自动识别,并复用模型舞台、相机适配、up-axis 切换和资源释放契约;FBX 优先按文件 `GlobalSettings` 的正向 Y/Z up-axis 声明转换到 Viewer 的 Z-up 世界,无法判断时回退 Y-up,并可由显式 `upAxis` 覆盖;FBXLoader 生成的传统 Lambert/Phong 材质会转换为可由 Viewer 环境光照明的 PBR 材质。
16
+
5
17
  ## 0.4.0
6
18
 
7
19
  0.4.0 将 Viewer 从以 CAD 为主的 facade 扩展为统一资产预览器,并把 3D 模型与仿真资产接入同一个 Three.js 场景、相机、渲染器和帧循环。CAD 专属状态仍保留在 `viewer.cad`,但资产生命周期、内置 UI、加载状态和扩展机制已统一。
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @nebula-spatial/viewer
2
2
 
3
3
  浏览器侧只读 Three.js 统一资产 Viewer Facade。负责场景运行时、相机、输入、拾取、渲染循环和
4
- 资源释放;`openAsset()` 统一加载 CAD、GLB/glTF、URDF、MJCF 与 USD,`viewer.cad` 保留与
4
+ 资源释放;`openAsset()` 统一加载 CAD、GLB/glTF、FBX、URDF、MJCF 与 USD,`viewer.cad` 保留与
5
5
  `@nebula-spatial/cad-loader` 集成的兼容能力。
6
6
 
7
7
  Viewer 不解析 DXF/DWG,也不提供编辑命令、历史记录或业务状态管理。
@@ -211,6 +211,8 @@ Three.js Camera。应用成功后会同步发布 `camera-change` 和 `viewport-c
211
211
 
212
212
  ```ts
213
213
  const preview = viewer.openAsset('/models/robot.glb', { format: 'auto' });
214
+ // .fbx 扩展名同样可自动识别:
215
+ const fbxPreview = viewer.openAsset('/models/chair.fbx');
214
216
  const stop = preview.subscribe((snapshot) => updateLoadingUi(snapshot));
215
217
  await preview.ready;
216
218
  await preview.close();
@@ -221,7 +223,7 @@ stop();
221
223
  旧句柄的 `close()` 只等待自己的资源清理,不会关闭后来打开的资产。`closeAsset()` 关闭调用瞬间
222
224
  的活动资产。普通模型以 borrowed 方式挂入唯一 scene runtime,GPU 资源只由模型 session 释放。
223
225
 
224
- GLB/glTF 文件没有权威的 up 轴声明(规范 Y-up,CAD 导出常为 Z-up)。预览世界固定 Z-up;
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;
225
227
  对轴向错误的模型传 `upAxis: 'y'` 打开(仅旋转资产根节点,不移动相机与世界),或运行期用
226
228
  `preview.setUpAxis('y' | 'z')` / `preview.getUpAxis()` 切换(切换后自动重铺地面并重新适配
227
229
  相机,不平移贴地)。能力标志为 `capabilities.canReorientUpAxis`。仿真资产的格式自带 up 轴,
@@ -286,21 +288,22 @@ const preview = viewer.openAsset('https://cdn.example.com/robot/scene.xml', {
286
288
  },
287
289
  },
288
290
  });
289
- await preview.ready;
290
- ```
291
-
292
- 对于私有 OSS/S3/CDN,常见的预签名 URL 只授权一个具体 Object Key。`root.usd` 的签名通常不能
293
- 复用于 `asset.usdc`、`physics/physics.usda`、纹理等兄弟资源,也不能把入口 URL 的 query
294
- 原样拼接到其他路径。`resourceResolver.resolve(path)` 必须为每个 `path` 返回独立有效的签名 URL
295
- 或已经取得的 `Blob`;入口 URL 自身也必须仍在有效期内。USD loader 会先提取分层 USD 的外部
296
- 引用,再通过该 resolver 递归取得 layer、mesh、material 和 texture 资源;任一依赖返回 401/403
297
- 都会作为鉴权加载失败报告,不会进入视觉降级流程。
298
-
299
- `{ kind: 'files', files, entry }` 只表示浏览器已经持有的本地 `File | Blob` 文件包,不能把远端
291
+ await preview.ready;
292
+ ```
293
+
294
+ 对于私有 OSS/S3/CDN,常见的预签名 URL 只授权一个具体 Object Key。`root.usd` 的签名通常不能
295
+ 复用于 `asset.usdc`、`physics/physics.usda`、纹理等兄弟资源,也不能把入口 URL 的 query
296
+ 原样拼接到其他路径。`resourceResolver.resolve(path)` 必须为每个 `path` 返回独立有效的签名 URL
297
+ 或已经取得的 `Blob`;入口 URL 自身也必须仍在有效期内。USD loader 会先提取分层 USD 的外部
298
+ 引用,再通过该 resolver 递归取得 layer、mesh、material 和 texture 资源;任一依赖返回 401/403
299
+ 都会作为鉴权加载失败报告,不会进入视觉降级流程。
300
+
301
+ `{ kind: 'files', files, entry }` 只表示浏览器已经持有的本地 `File | Blob` 文件包,不能把远端
300
302
  URL 字符串放进 `files[].file`。业务层负责入口选择、必要的格式判断、鉴权和依赖映射;不能只依赖
301
- Viewer 自动识别所有资产形态,也不能把本地样本验证等同于任意远端资产都兼容。普通 glTF 的
302
- 外部资源仍由 `GLTFLoader` 按 URL 请求,不应假设所有格式的子资源都经过 `resourceResolver`;
303
- 私有 glTF 资产优先采用同源/签名目录,或交付为 GLB。
303
+ Viewer 自动识别所有资产形态,也不能把本地样本验证等同于任意远端资产都兼容。普通 glTF 与 FBX
304
+ 外部资源仍由对应 Three.js loader 按 URL 请求,不应假设这些格式的子资源都经过 `resourceResolver`;
305
+ 私有 glTF/FBX 资产优先采用同源或可独立鉴权的资源目录。单个本地 FBX 文件适合使用内嵌纹理;
306
+ 若纹理是外置文件,应使用可保持相对目录结构的远端 URL。
304
307
 
305
308
  OpenUSD 使用 pthread WASM,部署必须在安全上下文中提供以下响应头:
306
309
 
@@ -312,7 +315,10 @@ Cross-Origin-Embedder-Policy: require-corp
312
315
  `@mujoco/mujoco` 和 `@openusd-wasm/three-loader` 保持动态加载。Vite 浏览器构建需要将 MuJoCo
313
316
  包中的 Node-only 裸模块 `module` 精确 alias 到一个导出 `createRequire()` 的浏览器拒绝模块;
314
317
  仓库的 `vite.config.ts` 和独立消费者验证脚本包含该配置。可通过 `assets.mujocoBaseUrl` 与
315
- `assets.openUsdBaseUrl` 指向自行托管的 runtime 文件目录。
318
+ `assets.openUsdBaseUrl` 指向自行托管的 runtime 文件目录。
319
+ 跨域 OpenUSD runtime 使用 Blob 模块 Worker 入口导入原始 runtime;CDN 仍需允许 CORS,
320
+ 若部署配置了 CSP,还需允许 `worker-src blob:` 及对应 CDN 的脚本加载。该入口不替代上述跨源隔离响应头。
321
+
316
322
 
317
323
  ## CAD 快速开始
318
324
 
@@ -2,7 +2,7 @@ import type { Object3D, WebGLRenderer, Scene, Camera, Box3, ColorRepresentation
2
2
  import type { CadLoadSource, CadOpenOptions } from '../cad/types';
3
3
  import type { ViewerViewMode } from '../types';
4
4
  export type AssetPreviewKind = 'cad' | 'model' | 'simulation';
5
- export type BuiltinAssetFormat = 'cad' | 'glb' | 'gltf' | 'urdf' | 'mjcf' | 'usd' | 'usda' | 'usdc' | 'usdz';
5
+ export type BuiltinAssetFormat = 'cad' | 'glb' | 'gltf' | 'fbx' | 'urdf' | 'mjcf' | 'usd' | 'usda' | 'usdc' | 'usdz';
6
6
  export type AssetFormat = BuiltinAssetFormat | (string & {});
7
7
  export interface AssetFileEntry {
8
8
  readonly path: string;
@@ -37,10 +37,11 @@ export interface OpenAssetOptions {
37
37
  readonly mujocoBaseUrl?: string;
38
38
  readonly openUsdBaseUrl?: string;
39
39
  /**
40
- * Which authored axis is "up" for a plain model asset. glTF's normative
41
- * coordinate system is Y-up, but CAD-kernel exporters emit Z-up files with no
42
- * in-file declaration, so this cannot be inferred reliably. Defaults to 'z',
43
- * matching the preview world; 'y' rotates the model root into world +Z.
40
+ * Which authored axis is "up" for a plain model asset. FBX first uses a
41
+ * supported positive Y/Z declaration from GlobalSettings, then falls back to
42
+ * 'y' when it is missing or cannot be read. GLB/glTF retain the existing 'z'
43
+ * default for CAD-kernel compatibility. An explicit value always wins. 'y'
44
+ * rotates the model root into world +Z.
44
45
  * Ignored by simulation assets, whose formats declare their own up axis.
45
46
  */
46
47
  readonly upAxis?: AssetUpAxis;
@@ -5758,7 +5758,7 @@ const ss = {
5758
5758
  kind: "asset-loader",
5759
5759
  id: "nebula.model-loader",
5760
5760
  assetKind: "model",
5761
- formats: ["glb", "gltf"],
5761
+ formats: ["glb", "gltf", "fbx"],
5762
5762
  presentation: {
5763
5763
  preferredViewMode: "3d",
5764
5764
  interactionMode: "object",
@@ -5769,7 +5769,7 @@ const ss = {
5769
5769
  clearColor: B.dark
5770
5770
  },
5771
5771
  async createSession(e, t) {
5772
- const { createModelSession: i } = await import("./session-CGaj14lM.js");
5772
+ const { createModelSession: i } = await import("./session-B2SfkK9o.js");
5773
5773
  return i(e, t);
5774
5774
  }
5775
5775
  });
@@ -5853,7 +5853,7 @@ const cs = {
5853
5853
  clearColor: B.dark
5854
5854
  },
5855
5855
  async createSession(e, t) {
5856
- const { createSimulationSession: i } = await import("./session-B_UiRctl.js").then((r) => r.s);
5856
+ const { createSimulationSession: i } = await import("./session-B-qVl3Yy.js").then((r) => r.s);
5857
5857
  return i(e, t);
5858
5858
  }
5859
5859
  });
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as o } from "./index-Lsk3kHNe.js";
1
+ import { c as o } from "./index-C9CW-EyW.js";
2
2
  import { configureCadTextBuilder as t } from "@nebula-spatial/cad-loader";
3
3
  export {
4
4
  t as configureViewerText,