@nebula-spatial/cad-loader 0.1.0 → 0.2.1

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 ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this package are documented in this file.
4
+
5
+ ## 0.2.1
6
+
7
+ - Added geometry Worker overrides to document sessions and external variant delta loading.
8
+
9
+ ## 0.2.0
10
+
11
+ - Added document-level CAD sessions with progressive content loading and viewport demand control.
12
+ - Added read-only CAD render resources, INSERT and text selection helpers, and CAD session metadata.
13
+ - Added public APIs for font resolution, document rendering, and scene annotations.
14
+ - Retained the existing `loadGeo()`, load session, and `core` APIs.
15
+
16
+ ## 0.1.0
17
+
18
+ - Initial public release of the browser-side DXB3/DXBS CAD pack loader.
package/README.md CHANGED
@@ -1,46 +1,86 @@
1
1
  # @nebula-spatial/cad-loader
2
2
 
3
- 浏览器侧 DXB3/DXBS CAD pack Loader。它接收 URL、File、ArrayBuffer 或兼容的
4
- 结构化 source,保留 Worker、主线程 fallback、增量构建、flow control、abort
5
- 和 dispose 生命周期,并直接返回可挂载到 Three.js 场景的 `GeoNode`。
3
+ 浏览器侧 DXB3/DXBS CAD pack 加载运行时。负责解析文档、构建 Three.js 渲染资源,并
4
+ 提供图层、INSERT、文本和外部资源的文档级访问能力。
6
5
 
7
- ```ts
8
- import { loadGeo } from '@nebula-spatial/cad-loader';
6
+ 有完整视图需求的应用通常通过 `@nebula-spatial/viewer` 的 `viewer.cad.open()` 接入。
7
+ 本包适用于需要自行管理 Three.js 场景或 CAD 文档生命周期的集成。
9
8
 
10
- const node = loadGeo('/api/files/demo/result');
11
- scene.add(node);
12
- await node.ready;
13
- ```
9
+ ## 文档会话
14
10
 
15
- CAD 产品可以在 Viewer 提供世界坐标后,通过 Loader 的只读语义查询解析
16
- Block/INSERT。该能力不包含选择状态或属性面板 UI:
11
+ `createCadDocumentSession()` 是推荐的文档级入口。会话提供 header、基础内容就绪状态、
12
+ 视口需求和只读渲染资源;调用方负责场景挂载和相机/视口同步。
17
13
 
18
14
  ```ts
19
15
  import {
20
- pickCadInsertAtPoint,
21
- resolveCadInsertDetails,
16
+ createCadDocumentSession,
17
+ getCadDocumentRenderResource,
22
18
  } from '@nebula-spatial/cad-loader';
23
19
 
24
- const selection = pickCadInsertAtPoint(node, worldPoint);
25
- const details = selection ? resolveCadInsertDetails(node, selection) : null;
20
+ const session = createCadDocumentSession('/api/files/demo/result', {
21
+ filename: 'demo.dxf',
22
+ });
23
+ const renderNode = getCadDocumentRenderResource(session);
24
+
25
+ scene.add(renderNode.object);
26
+ const stopChanges = renderNode.onChange(() => requestRender());
27
+
28
+ const header = await session.headerReady;
29
+ fitCamera(header.bounds);
30
+
31
+ session.setDisplayContext(displayContext);
32
+ session.setViewportDemand(viewportDemand);
33
+ await session.initialContentReady;
34
+
35
+ stopChanges();
36
+ scene.remove(renderNode.object);
37
+ session.dispose();
38
+ ```
39
+
40
+ `headerReady` 提供文档边界和图层元数据,`initialContentReady` 表示基础内容已可用。
41
+ 通过 `content-appended`、`demand-progress`、`phase-change` 和错误事件可监听后续变化。
42
+
43
+ 默认几何准备 Worker 从包内的相对资源路径加载。使用非 Vite bundler、CSP 限制环境或自行托管
44
+ Worker 资源时,可在会话选项中传入 `workerUrl`;需要完全控制 Worker 创建时,可传入优先级更高的
45
+ `workerFactory`:
46
+
47
+ ```ts
48
+ const session = createCadDocumentSession(source, {
49
+ workerUrl: new URL('/assets/geo-prepare.worker.js', window.location.href),
50
+ // workerFactory: () => new Worker('/assets/geo-prepare.worker.js', { type: 'module' }),
51
+ });
26
52
  ```
27
53
 
28
- 对于 URL source,V3.3 pack 的 external geometry 与 scene/block annotation 默认会在
29
- `node.ready` 前完成请求、校验、解码和挂接;不需要标注时可传入
30
- `{ loadAnnotations: false }`。Product App 若要按视口渐进加载,应先使用
31
- `ArrayBuffer` 和显式 sidecar 计划,再自行编排 annotation 的加载时机。
54
+ `CadRenderNode` 是只读渲染资源。选择状态、属性面板、编辑命令和历史记录由产品层维护。
32
55
 
33
- 上传、任务轮询、文件目录和原始 DXF/DWG 解析不属于此包。
56
+ ## 其他入口
34
57
 
35
- DXB3/DXBS 协议解析和纯数据契约通过稳定的 `/core` 子路径提供。该入口不依赖
36
- Three.js、DOM、Canvas WebGL,可以在 Worker、Node.js 和 CLI 中独立使用:
58
+ - `loadGeo()`:简单的 `GeoNode` 增量加载。适合不需要文档会话的 Three.js 集成。
59
+ - `createLoadSession()`:以异步事件流消费 CAD pack,适合自定义渲染器或流量控制。
60
+ - `@nebula-spatial/cad-loader/core`:不依赖 Three.js、DOM 或 WebGL 的协议解析 API,可用于
61
+ Worker、Node.js 和 CLI。
37
62
 
38
63
  ```ts
39
- import { parseBinBounds } from '@nebula-spatial/cad-loader/core';
64
+ import { loadGeo } from '@nebula-spatial/cad-loader';
40
65
 
41
- const bounds = parseBinBounds(buffer);
66
+ const node = loadGeo('/api/files/demo/result');
67
+ scene.add(node);
68
+ node.setViewportSize(canvas.clientWidth, canvas.clientHeight);
69
+ await node.ready;
42
70
  ```
43
71
 
44
- 默认 Worker 使用包内的 ESM 资源路径。使用非 Vite bundler 或自行托管 Worker
45
- 资源时,可以通过 `LoadGeoOptions.workerUrl` 指定 URL,或通过 `workerFactory`
46
- 接管 Worker 创建。
72
+ 默认 Worker 使用包内 ESM 资源路径。使用非 Vite bundler 或自行托管 Worker 资源时,可通过
73
+ `LoadGeoOptions.workerUrl` `workerFactory` 配置 Worker 创建方式。
74
+
75
+ ## 边界
76
+
77
+ 本包不处理上传、任务轮询、文件目录或原始 DXF/DWG 解析。运行时依赖为 `three` peer
78
+ dependency,要求 Node.js 18 或更高版本。
79
+
80
+ ## 开发
81
+
82
+ ```bash
83
+ npm run typecheck --workspace @nebula-spatial/cad-loader
84
+ npm test --workspace @nebula-spatial/cad-loader
85
+ npm run build --workspace @nebula-spatial/cad-loader
86
+ ```
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export type { CadExternalVariantFetchSource, CadLoadErrorEvent, CadLoadEvent, Ca
10
10
  export { appendExternalVariantDeltaToGeoNode, assertValidSourceOrThrow, loadExternalVariantDeltaFromBuffer, loadGeo, normalizeGeoError, parseBuffer, parseBufferBounds, parseBufferHeader, readBufferExternalAnnotationManifest, readBufferExternalBlockAnnotations, readBufferExternalVariantDependencyPlan, readBufferExternalVariantManifest, } from './loader/geo-loader';
11
11
  export type { ExternalVariantDependencyOptions, ExternalVariantDependencyPlan, ExternalVariantFetchSource, LoadExternalVariantDeltaFetchSourceOptions, LoadExternalVariantDeltaOptions, LoadGeoOptions, } from './loader/geo-loader';
12
12
  export { GEO_NODE_STRUCTURE_CHANGE, GEO_NODE_VISUAL_CHANGE, GeoNode, } from './loader/internal/geo-node';
13
- export type { ColorPipelineStatsSnapshot, GeoNodeInternalChange, GeoNodeInternalChangeKind, InsertInstanceMatrix2D, } from './loader/internal/geo-node';
13
+ export type { ColorPipelineStatsSnapshot, GeoNodeChange, GeoNodeChangeKind, GeoNodeChangeListener, GeoNodeInternalChange, GeoNodeInternalChangeKind, InsertInstanceMatrix2D, } from './loader/internal/geo-node';
14
14
  export type { LineMemoryStatsSnapshot, LineCanonicalMemoryStats, } from './loader/internal/line-canonical';
15
15
  export { readBlockAnnotationSidecar, readSceneAnnotationSidecar, } from './core';
16
16
  export type { DecodedAnnotationSidecar, DxbsContainer, DxbsSectionEntry, ParsedHeader, } from './core';
@@ -24,3 +24,11 @@ export type { BlockGeometryKind, VariantGeometry, } from './scene/instancing/blo
24
24
  export type { InsertInstanceRecord } from './scene/instancing/insert-instance-table';
25
25
  export { cadInsertSelectionEquals, pickCadInsertAtPoint, resolveCadInsertDetails, } from './selection/cad-insert-selection';
26
26
  export type { CadInsertDetails, CadInsertPickOptions, CadInsertSelectionId, CadPoint2D, } from './selection/cad-insert-selection';
27
+ export { cadTextSelectionEquals, pickCadTextAtPoint, resolveCadTextDetails, } from './selection/cad-text-selection';
28
+ export type { CadTextDetails, CadTextPickOptions, CadTextSelection, CadTextSelectionId, } from './selection/cad-text-selection';
29
+ export { CAD_SESSION_PHASES } from './session/cad-document-session';
30
+ export { createCadDocumentSession, getCadDocumentRenderResource } from './session/create-cad-document-session';
31
+ export { formatCadInsertId, parseCadInsertId } from './session/cad-insert-id';
32
+ export type { CadDisplayContext, CadDocumentHeader, CadDocumentSession, CadDocumentSessionOptions, CadFontResolver, CadInsertUsageSummary, CadLayerMeta, CadSessionEventMap, CadSessionPhase, CadViewportDemand, CadViewportRect, CadVisibilityFilter, CadWorldBounds, CadWorldPoint, } from './session/cad-document-session';
33
+ export { CAD_RENDER_NODE_EDIT_METHODS, isCadRenderNodeEditMethod } from './render-resource/cad-render-node';
34
+ export type { CadInsertPreviewResource, CadRenderContentChunk, CadRenderNode, } from './render-resource/cad-render-node';