@nebula-spatial/cad-loader 0.1.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.
Files changed (59) hide show
  1. package/README.md +46 -0
  2. package/dist/core/cad-types.d.ts +26 -0
  3. package/dist/core/errors.d.ts +5 -0
  4. package/dist/core/index.d.ts +24 -0
  5. package/dist/core/index.js +2262 -0
  6. package/dist/core/parser/bin-group-reader.d.ts +9 -0
  7. package/dist/core/parser/bin-parser.d.ts +65 -0
  8. package/dist/core/parser/dxbs-sidecar.d.ts +24 -0
  9. package/dist/core/parser/geometry-segments.d.ts +20 -0
  10. package/dist/core/parser/text-roundtrip.d.ts +4 -0
  11. package/dist/core/parser/types.d.ts +80 -0
  12. package/dist/core/runtime-text-decoder.d.ts +8 -0
  13. package/dist/core/types.d.ts +147 -0
  14. package/dist/core/utils/insert-bbox.d.ts +10 -0
  15. package/dist/core/utils/viewport-rect.d.ts +21 -0
  16. package/dist/index.d.ts +26 -0
  17. package/dist/index.js +4435 -0
  18. package/dist/loader/geo-loader.d.ts +56 -0
  19. package/dist/loader/internal/external-variant-sidecar-fetch.d.ts +13 -0
  20. package/dist/loader/internal/flow-control.d.ts +29 -0
  21. package/dist/loader/internal/frame-budget-scheduler.d.ts +21 -0
  22. package/dist/loader/internal/geo-compact-executor.d.ts +19 -0
  23. package/dist/loader/internal/geo-loader-local-adapter.d.ts +2 -0
  24. package/dist/loader/internal/geo-loader-pipeline.d.ts +81 -0
  25. package/dist/loader/internal/geo-loader-worker-adapter.d.ts +7 -0
  26. package/dist/loader/internal/geo-node-builder.d.ts +29 -0
  27. package/dist/loader/internal/geo-node-load-sink.d.ts +28 -0
  28. package/dist/loader/internal/geo-node.d.ts +284 -0
  29. package/dist/loader/internal/geo-prepare-worker-types.d.ts +87 -0
  30. package/dist/loader/internal/geo-prepare.d.ts +38 -0
  31. package/dist/loader/internal/geo-prepare.worker.d.ts +1 -0
  32. package/dist/loader/internal/insert-model-builder.d.ts +10 -0
  33. package/dist/loader/internal/insert-runtime-geometry.d.ts +15 -0
  34. package/dist/loader/internal/line-canonical.d.ts +37 -0
  35. package/dist/loader/internal/line-quality.d.ts +9 -0
  36. package/dist/loader/internal/prepare-credit-gate.d.ts +20 -0
  37. package/dist/loader/internal/transport.d.ts +2 -0
  38. package/dist/scene/geo-cad-line-geometry.d.ts +28 -0
  39. package/dist/scene/geo-cad-line-material.d.ts +18 -0
  40. package/dist/scene/instancing/block-geometry-registry.d.ts +35 -0
  41. package/dist/scene/instancing/insert-instance-table.d.ts +23 -0
  42. package/dist/scene/instancing/viewport-instance-presenter.d.ts +66 -0
  43. package/dist/selection/cad-insert-selection.d.ts +35 -0
  44. package/dist/session/load-session.d.ts +90 -0
  45. package/dist/shared/abort.d.ts +3 -0
  46. package/dist/shared/cad-display-color.d.ts +55 -0
  47. package/dist/shared/cad-load-source.d.ts +8 -0
  48. package/dist/shared/color-buffer.d.ts +6 -0
  49. package/dist/shared/constants.d.ts +11 -0
  50. package/dist/shared/display-color-buffer.d.ts +27 -0
  51. package/dist/shared/errors.d.ts +2 -0
  52. package/dist/shared/text-font.d.ts +12 -0
  53. package/dist/shared/types.d.ts +57 -0
  54. package/dist/shared/utils/insert-bbox.d.ts +1 -0
  55. package/dist/shared/utils/timing.d.ts +2 -0
  56. package/dist/shared/utils/viewport-rect.d.ts +1 -0
  57. package/dist/shared/viewer-theme.d.ts +2 -0
  58. package/dist/workers/geo-prepare.worker.js +2166 -0
  59. package/package.json +61 -0
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @nebula-spatial/cad-loader
2
+
3
+ 浏览器侧 DXB3/DXBS CAD pack Loader。它接收 URL、File、ArrayBuffer 或兼容的
4
+ 结构化 source,保留 Worker、主线程 fallback、增量构建、flow control、abort
5
+ 和 dispose 生命周期,并直接返回可挂载到 Three.js 场景的 `GeoNode`。
6
+
7
+ ```ts
8
+ import { loadGeo } from '@nebula-spatial/cad-loader';
9
+
10
+ const node = loadGeo('/api/files/demo/result');
11
+ scene.add(node);
12
+ await node.ready;
13
+ ```
14
+
15
+ CAD 产品可以在 Viewer 提供世界坐标后,通过 Loader 的只读语义查询解析
16
+ Block/INSERT。该能力不包含选择状态或属性面板 UI:
17
+
18
+ ```ts
19
+ import {
20
+ pickCadInsertAtPoint,
21
+ resolveCadInsertDetails,
22
+ } from '@nebula-spatial/cad-loader';
23
+
24
+ const selection = pickCadInsertAtPoint(node, worldPoint);
25
+ const details = selection ? resolveCadInsertDetails(node, selection) : null;
26
+ ```
27
+
28
+ 对于 URL source,V3.3 pack 的 external geometry 与 scene/block annotation 默认会在
29
+ `node.ready` 前完成请求、校验、解码和挂接;不需要标注时可传入
30
+ `{ loadAnnotations: false }`。Product App 若要按视口渐进加载,应先使用
31
+ `ArrayBuffer` 和显式 sidecar 计划,再自行编排 annotation 的加载时机。
32
+
33
+ 上传、任务轮询、文件目录和原始 DXF/DWG 解析不属于此包。
34
+
35
+ DXB3/DXBS 协议解析和纯数据契约通过稳定的 `/core` 子路径提供。该入口不依赖
36
+ Three.js、DOM、Canvas 或 WebGL,可以在 Worker、Node.js 和 CLI 中独立使用:
37
+
38
+ ```ts
39
+ import { parseBinBounds } from '@nebula-spatial/cad-loader/core';
40
+
41
+ const bounds = parseBinBounds(buffer);
42
+ ```
43
+
44
+ 默认 Worker 使用包内的 ESM 资源路径。使用非 Vite bundler 或自行托管 Worker
45
+ 资源时,可以通过 `LoadGeoOptions.workerUrl` 指定 URL,或通过 `workerFactory`
46
+ 接管 Worker 创建。
@@ -0,0 +1,26 @@
1
+ import type { ExternalBlockVariantManifestEntry, GeoMeta, LayerSnapshot, TextEntity } from './types';
2
+ import type { GeoChunk, GeoGeometryChunk, InsertRuntimeInstance, InsertRuntimeVariant, ParsedHeader } from './parser/types';
3
+ /** Stable renderer-neutral public vocabulary for decoded CAD packs. */
4
+ export type CadPackHeader = ParsedHeader;
5
+ export type CadPackDocumentHeader = ParsedHeader;
6
+ export type CadPackMeta = GeoMeta;
7
+ export type CadLayer = LayerSnapshot;
8
+ export type CadDisplayChunk = GeoGeometryChunk;
9
+ export type CadTextChunk = TextEntity;
10
+ export type CadBlockDefinition = InsertRuntimeVariant;
11
+ export type CadInsertInstance = InsertRuntimeInstance;
12
+ export type CadExternalVariantManifestEntry = ExternalBlockVariantManifestEntry;
13
+ export type CadExternalVariantManifest = readonly ExternalBlockVariantManifestEntry[];
14
+ export interface CadExternalVariantDelta {
15
+ readonly header: ParsedHeader;
16
+ readonly chunks: readonly GeoChunk[];
17
+ }
18
+ /**
19
+ * A decoded pack document. Parsers may keep typed-array payloads backed by the
20
+ * original buffer; `rawBytes` records the source size for diagnostics.
21
+ */
22
+ export interface CadPackDocument {
23
+ readonly header: ParsedHeader;
24
+ readonly chunks: readonly GeoChunk[];
25
+ readonly rawBytes: number;
26
+ }
@@ -0,0 +1,5 @@
1
+ export type GeoLoaderErrorCode = 'E_SOURCE' | 'E_HEADER' | 'E_HEADER_JSON' | 'E_GROUP_RANGE' | 'E_UNSUPPORTED_PACK_VERSION' | 'E_EXPANSION_BUDGET' | 'E_SEGMENT_SUM' | 'E_TEXT_ROUNDTRIP' | 'E_DISPOSED' | 'E_PACK_HTTP' | 'E_PACK_NETWORK';
2
+ export declare class GeoLoaderError extends Error {
3
+ readonly code: GeoLoaderErrorCode;
4
+ constructor(code: GeoLoaderErrorCode, message: string);
5
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Public, renderer-neutral entry point for the DXB3/DXBS pack protocol.
3
+ *
4
+ * Keep this file deliberately boring: consumers (including cad-loader) should
5
+ * only need the package root and must not reach into parser implementation
6
+ * paths. The `Cad*` names below are stable vocabulary aliases over the
7
+ * protocol records that predate this package extraction.
8
+ */
9
+ export { GeoLoaderError, GeoLoaderError as CadPackError } from './errors';
10
+ export type { GeoLoaderErrorCode, GeoLoaderErrorCode as CadPackErrorCode, } from './errors';
11
+ export { captureGroupSnapshot, groupLayerEncodingForV3Minor, readGroup, streamGroupChunks, STREAM_VERTEX_WINDOW, } from './parser/bin-group-reader';
12
+ export { parseBinBounds, parseBinPayload, parseBinStreaming, parseBinToChunks, readExternalAnnotationManifest, readExternalBlockAnnotations, readExternalVariantDependencyPlan, readExternalVariantGeometrySidecar, readExternalVariantManifest, } from './parser/bin-parser';
13
+ export type { ExternalVariantDependencyOptions, ExternalVariantDependencyPlan, ParseBinOptions, } from './parser/bin-parser';
14
+ export { getDxbsSection, isDxbsPayload, readBlockAnnotationSidecar, readDxbsContainer, readSceneAnnotationSidecar, } from './parser/dxbs-sidecar';
15
+ export type { DecodedAnnotationSidecar, DxbsContainer, DxbsSectionEntry, } from './parser/dxbs-sidecar';
16
+ export { emptyGeometryChunk, expandGeometryChunkMetadata, mergeAdjacentSegments, normalizeGeometrySegments, offsetGeometrySegments, remapGeometrySegmentLayers, sliceGeometrySegments, } from './parser/geometry-segments';
17
+ export type { ExpandedGeometryMetadata, GeometrySegmentSource, } from './parser/geometry-segments';
18
+ export { assertStrictTextRoundtrip, isStrictTextRoundtripEnabled, shouldAssertStrictTextRoundtrip, } from './parser/text-roundtrip';
19
+ export type * from './types';
20
+ export type * from './parser/types';
21
+ export type * from './cad-types';
22
+ export type { InsertInstanceTransform } from './utils/insert-bbox';
23
+ export { transformBBoxByInstance } from './utils/insert-bbox';
24
+ export { cloneViewportRect, computeViewportRectFromPositions, expandViewportRect, intersectViewportRects, mergeViewportRects, normalizeViewportRect, transformViewportRect, viewportRectCenterDistance, viewportRectDiagonal, viewportRectContains, viewportRectEquals, viewportRectIntersects, } from './utils/viewport-rect';