copper3d 3.4.9 → 3.6.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 (89) hide show
  1. package/dist/Renderer/baseRenderer.d.ts +3 -0
  2. package/dist/Renderer/baseRenderer.js +20 -0
  3. package/dist/Renderer/baseRenderer.js.map +1 -1
  4. package/dist/Renderer/copperMSceneRenderer.d.ts +3 -0
  5. package/dist/Renderer/copperMSceneRenderer.js +22 -0
  6. package/dist/Renderer/copperMSceneRenderer.js.map +1 -1
  7. package/dist/Renderer/copperRenderer.d.ts +0 -2
  8. package/dist/Renderer/copperRenderer.js +0 -5
  9. package/dist/Renderer/copperRenderer.js.map +1 -1
  10. package/dist/Scene/copperScene.d.ts +12 -0
  11. package/dist/Scene/copperScene.js +38 -44
  12. package/dist/Scene/copperScene.js.map +1 -1
  13. package/dist/Utils/segmentation/DrawToolCore.d.ts +3 -0
  14. package/dist/Utils/segmentation/DrawToolCore.js +29 -1
  15. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  16. package/dist/Utils/segmentation/NrrdTools.d.ts +54 -0
  17. package/dist/Utils/segmentation/NrrdTools.js +119 -0
  18. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  19. package/dist/Utils/segmentation/core/index.d.ts +1 -1
  20. package/dist/Utils/segmentation/core/index.js +1 -1
  21. package/dist/Utils/segmentation/core/index.js.map +1 -1
  22. package/dist/Utils/segmentation/core/types.d.ts +11 -1
  23. package/dist/Utils/segmentation/core/types.js +30 -0
  24. package/dist/Utils/segmentation/core/types.js.map +1 -1
  25. package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -0
  26. package/dist/Utils/segmentation/eventRouter/EventRouter.js +37 -6
  27. package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
  28. package/dist/Utils/segmentation/eventRouter/types.d.ts +3 -2
  29. package/dist/Utils/segmentation/tools/AiAssistTool.d.ts +146 -0
  30. package/dist/Utils/segmentation/tools/AiAssistTool.js +470 -0
  31. package/dist/Utils/segmentation/tools/AiAssistTool.js.map +1 -0
  32. package/dist/Utils/surfaceAnnotation/MeshGraph.d.ts +40 -0
  33. package/dist/Utils/surfaceAnnotation/MeshGraph.js +198 -0
  34. package/dist/Utils/surfaceAnnotation/MeshGraph.js.map +1 -0
  35. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.d.ts +103 -0
  36. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js +402 -0
  37. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js.map +1 -0
  38. package/dist/Utils/surfaceAnnotation/annotationStore.d.ts +37 -0
  39. package/dist/Utils/surfaceAnnotation/annotationStore.js +105 -0
  40. package/dist/Utils/surfaceAnnotation/annotationStore.js.map +1 -0
  41. package/dist/Utils/surfaceAnnotation/contourRender.d.ts +7 -0
  42. package/dist/Utils/surfaceAnnotation/contourRender.js +57 -0
  43. package/dist/Utils/surfaceAnnotation/contourRender.js.map +1 -0
  44. package/dist/Utils/surfaceAnnotation/geodesicContour.d.ts +19 -0
  45. package/dist/Utils/surfaceAnnotation/geodesicContour.js +43 -0
  46. package/dist/Utils/surfaceAnnotation/geodesicContour.js.map +1 -0
  47. package/dist/Utils/surfaceAnnotation/index.d.ts +3 -0
  48. package/dist/Utils/surfaceAnnotation/index.js +2 -0
  49. package/dist/Utils/surfaceAnnotation/index.js.map +1 -0
  50. package/dist/Utils/surfaceAnnotation/pointMarkers.d.ts +7 -0
  51. package/dist/Utils/surfaceAnnotation/pointMarkers.js +16 -0
  52. package/dist/Utils/surfaceAnnotation/pointMarkers.js.map +1 -0
  53. package/dist/Utils/surfaceAnnotation/raycastSurface.d.ts +7 -0
  54. package/dist/Utils/surfaceAnnotation/raycastSurface.js +27 -0
  55. package/dist/Utils/surfaceAnnotation/raycastSurface.js.map +1 -0
  56. package/dist/Utils/surfaceAnnotation/strokeContour.d.ts +19 -0
  57. package/dist/Utils/surfaceAnnotation/strokeContour.js +35 -0
  58. package/dist/Utils/surfaceAnnotation/strokeContour.js.map +1 -0
  59. package/dist/Utils/surfaceAnnotation/types.d.ts +40 -0
  60. package/dist/Utils/surfaceAnnotation/types.js +26 -0
  61. package/dist/Utils/surfaceAnnotation/types.js.map +1 -0
  62. package/dist/bundle.esm.js +3701 -201
  63. package/dist/bundle.umd.js +3703 -200
  64. package/dist/index.d.ts +7 -4
  65. package/dist/index.js +4 -3
  66. package/dist/index.js.map +1 -1
  67. package/dist/types/Renderer/baseRenderer.d.ts +3 -0
  68. package/dist/types/Renderer/copperMSceneRenderer.d.ts +3 -0
  69. package/dist/types/Renderer/copperRenderer.d.ts +0 -2
  70. package/dist/types/Scene/copperScene.d.ts +12 -0
  71. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +3 -0
  72. package/dist/types/Utils/segmentation/NrrdTools.d.ts +54 -0
  73. package/dist/types/Utils/segmentation/core/index.d.ts +1 -1
  74. package/dist/types/Utils/segmentation/core/types.d.ts +11 -1
  75. package/dist/types/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -0
  76. package/dist/types/Utils/segmentation/eventRouter/types.d.ts +3 -2
  77. package/dist/types/Utils/segmentation/tools/AiAssistTool.d.ts +146 -0
  78. package/dist/types/Utils/surfaceAnnotation/MeshGraph.d.ts +40 -0
  79. package/dist/types/Utils/surfaceAnnotation/SurfaceAnnotator.d.ts +103 -0
  80. package/dist/types/Utils/surfaceAnnotation/annotationStore.d.ts +37 -0
  81. package/dist/types/Utils/surfaceAnnotation/contourRender.d.ts +7 -0
  82. package/dist/types/Utils/surfaceAnnotation/geodesicContour.d.ts +19 -0
  83. package/dist/types/Utils/surfaceAnnotation/index.d.ts +3 -0
  84. package/dist/types/Utils/surfaceAnnotation/pointMarkers.d.ts +7 -0
  85. package/dist/types/Utils/surfaceAnnotation/raycastSurface.d.ts +7 -0
  86. package/dist/types/Utils/surfaceAnnotation/strokeContour.d.ts +19 -0
  87. package/dist/types/Utils/surfaceAnnotation/types.d.ts +40 -0
  88. package/dist/types/index.d.ts +7 -4
  89. package/package.json +1 -1
@@ -0,0 +1,198 @@
1
+ import * as THREE from "three";
2
+ /**
3
+ * 从 BufferGeometry 的索引构建顶点邻接图,用于模式 B(测地线)的最短路径。
4
+ * 顶点坐标按 local 存;传入的查询点需先转为 local(mesh.worldToLocal)。
5
+ *
6
+ * 说明:几何须为已索引(indexed)。modelLoader 用 mergeVertices 焊接重复顶点,
7
+ * 保证同一表面位置共享顶点,邻接图才连通。
8
+ *
9
+ * 性能:O(V²) Dijkstra + O(V) 最近顶点查找。对几万顶点单次点击可接受;
10
+ * 若过大可后续换二叉堆 + 空间网格加速(留作升级)。
11
+ */
12
+ export class MeshGraph {
13
+ constructor(geometry) {
14
+ this.adj = [];
15
+ const pos = geometry.getAttribute("position");
16
+ this.positions = pos.array;
17
+ const nrm = geometry.getAttribute("normal");
18
+ this.normals = nrm ? nrm.array : null;
19
+ this.vertexCount = pos.count;
20
+ for (let i = 0; i < this.vertexCount; i++)
21
+ this.adj.push(new Set());
22
+ const addEdge = (a, b) => {
23
+ this.adj[a].add(b);
24
+ this.adj[b].add(a);
25
+ };
26
+ const index = geometry.getIndex();
27
+ if (index) {
28
+ for (let i = 0; i < index.count; i += 3) {
29
+ const a = index.getX(i);
30
+ const b = index.getX(i + 1);
31
+ const c = index.getX(i + 2);
32
+ addEdge(a, b);
33
+ addEdge(b, c);
34
+ addEdge(c, a);
35
+ }
36
+ }
37
+ else {
38
+ // 非索引兜底(连通性差,仅避免崩溃)。
39
+ for (let i = 0; i + 2 < this.vertexCount; i += 3) {
40
+ addEdge(i, i + 1);
41
+ addEdge(i + 1, i + 2);
42
+ addEdge(i + 2, i);
43
+ }
44
+ }
45
+ }
46
+ px(i) {
47
+ return this.positions[i * 3];
48
+ }
49
+ py(i) {
50
+ return this.positions[i * 3 + 1];
51
+ }
52
+ pz(i) {
53
+ return this.positions[i * 3 + 2];
54
+ }
55
+ /** 最近顶点(传入 local 坐标)。 */
56
+ nearestVertex(localPoint) {
57
+ let best = -1;
58
+ let bestD = Infinity;
59
+ for (let i = 0; i < this.vertexCount; i++) {
60
+ const dx = this.px(i) - localPoint.x;
61
+ const dy = this.py(i) - localPoint.y;
62
+ const dz = this.pz(i) - localPoint.z;
63
+ const d = dx * dx + dy * dy + dz * dz;
64
+ if (d < bestD) {
65
+ bestD = d;
66
+ best = i;
67
+ }
68
+ }
69
+ return best;
70
+ }
71
+ /**
72
+ * 两顶点间最短路径(含端点的顶点索引序列)。二叉堆 Dijkstra,O(E log V)。
73
+ * 不连通时返回 [start,end] 兜底。
74
+ */
75
+ shortestPath(startV, endV) {
76
+ if (startV === endV)
77
+ return [startV];
78
+ const dist = new Float64Array(this.vertexCount).fill(Infinity);
79
+ const prev = new Int32Array(this.vertexCount).fill(-1);
80
+ const done = new Uint8Array(this.vertexCount);
81
+ dist[startV] = 0;
82
+ const heap = new MinHeap();
83
+ heap.push(startV, 0);
84
+ while (heap.size > 0) {
85
+ const u = heap.pop();
86
+ if (done[u])
87
+ continue;
88
+ done[u] = 1;
89
+ if (u === endV)
90
+ break;
91
+ const ud = dist[u];
92
+ const ux = this.px(u);
93
+ const uy = this.py(u);
94
+ const uz = this.pz(u);
95
+ for (const w of this.adj[u]) {
96
+ if (done[w])
97
+ continue;
98
+ const dx = this.px(w) - ux;
99
+ const dy = this.py(w) - uy;
100
+ const dz = this.pz(w) - uz;
101
+ const nd = ud + Math.sqrt(dx * dx + dy * dy + dz * dz);
102
+ if (nd < dist[w]) {
103
+ dist[w] = nd;
104
+ prev[w] = u;
105
+ heap.push(w, nd);
106
+ }
107
+ }
108
+ }
109
+ if (prev[endV] === -1 && startV !== endV)
110
+ return [startV, endV];
111
+ const path = [];
112
+ for (let c = endV; c !== -1; c = prev[c]) {
113
+ path.push(c);
114
+ if (c === startV)
115
+ break;
116
+ }
117
+ return path.reverse();
118
+ }
119
+ vertexWorld(i, matrixWorld) {
120
+ return new THREE.Vector3(this.px(i), this.py(i), this.pz(i)).applyMatrix4(matrixWorld);
121
+ }
122
+ vertexNormalWorld(i, mesh) {
123
+ const n = new THREE.Vector3(0, 0, 1);
124
+ if (this.normals) {
125
+ n.set(this.normals[i * 3], this.normals[i * 3 + 1], this.normals[i * 3 + 2]);
126
+ }
127
+ const nm = new THREE.Matrix3().getNormalMatrix(mesh.matrixWorld);
128
+ return n.applyMatrix3(nm).normalize();
129
+ }
130
+ /** 顶点的 local 坐标 + local 法线(图几何即 local 空间)。 */
131
+ vertexLocal(i) {
132
+ return {
133
+ x: this.px(i),
134
+ y: this.py(i),
135
+ z: this.pz(i),
136
+ nx: this.normals ? this.normals[i * 3] : 0,
137
+ ny: this.normals ? this.normals[i * 3 + 1] : 0,
138
+ nz: this.normals ? this.normals[i * 3 + 2] : 1,
139
+ faceIndex: -1,
140
+ };
141
+ }
142
+ }
143
+ /** 极简二叉最小堆(按 priority 排序,存顶点索引)。用于 Dijkstra。 */
144
+ class MinHeap {
145
+ constructor() {
146
+ this.ids = [];
147
+ this.prio = [];
148
+ }
149
+ get size() {
150
+ return this.ids.length;
151
+ }
152
+ push(id, priority) {
153
+ this.ids.push(id);
154
+ this.prio.push(priority);
155
+ let i = this.ids.length - 1;
156
+ while (i > 0) {
157
+ const parent = (i - 1) >> 1;
158
+ if (this.prio[parent] <= this.prio[i])
159
+ break;
160
+ this.swap(i, parent);
161
+ i = parent;
162
+ }
163
+ }
164
+ pop() {
165
+ const topId = this.ids[0];
166
+ const lastId = this.ids.pop();
167
+ const lastPrio = this.prio.pop();
168
+ if (this.ids.length > 0) {
169
+ this.ids[0] = lastId;
170
+ this.prio[0] = lastPrio;
171
+ let i = 0;
172
+ const n = this.ids.length;
173
+ for (;;) {
174
+ const l = 2 * i + 1;
175
+ const r = 2 * i + 2;
176
+ let smallest = i;
177
+ if (l < n && this.prio[l] < this.prio[smallest])
178
+ smallest = l;
179
+ if (r < n && this.prio[r] < this.prio[smallest])
180
+ smallest = r;
181
+ if (smallest === i)
182
+ break;
183
+ this.swap(i, smallest);
184
+ i = smallest;
185
+ }
186
+ }
187
+ return topId;
188
+ }
189
+ swap(a, b) {
190
+ const ti = this.ids[a];
191
+ this.ids[a] = this.ids[b];
192
+ this.ids[b] = ti;
193
+ const tp = this.prio[a];
194
+ this.prio[a] = this.prio[b];
195
+ this.prio[b] = tp;
196
+ }
197
+ }
198
+ //# sourceMappingURL=MeshGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MeshGraph.js","sourceRoot":"","sources":["../../../src/Utils/surfaceAnnotation/MeshGraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IAMpB,YAAY,QAA8B;QAHlC,QAAG,GAAuB,EAAE,CAAC;QAInC,MAAM,GAAG,GAAG,QAAQ,CAAC,YAAY,CAAC,UAAU,CAA0B,CAAC;QACvE,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,KAAqB,CAAC;QAC3C,MAAM,GAAG,GAAG,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAE7B,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAE,GAAG,CAAC,KAAsB,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC;QAE7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;QACpE,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE;YACvC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC;QAEF,MAA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9D,IAAI,QAAQ,KAAK,CAAC;oBAAE,MAAM;gBAC1B,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;gBACvB,CAAC,GAAG,QAAQ,CAAC;aACd;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,IAAI,CAAC,CAAS,EAAE,CAAS;QAC/B,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACjB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,103 @@
1
+ import * as THREE from "three";
2
+ import type { Annotation, AnnotationMode, ExportOptions } from "./types";
3
+ import { AnnotationStore } from "./annotationStore";
4
+ export interface SurfaceAnnotatorOptions {
5
+ scene: THREE.Scene;
6
+ camera: THREE.PerspectiveCamera;
7
+ container: HTMLElement;
8
+ controls: {
9
+ enabled: boolean;
10
+ };
11
+ mesh: THREE.Mesh;
12
+ /** 缺省时从 mesh 几何包围盒对角线自算。 */
13
+ bboxDiagonal?: number;
14
+ /** 自由手绘 contour 颜色,默认 #e5006e。 */
15
+ freehandColor?: string;
16
+ /** 测地线 contour 颜色,默认 #ffa24e。 */
17
+ geodesicColor?: string;
18
+ /** 放点标记颜色,默认 #ffd166。 */
19
+ pointColor?: string;
20
+ /** 线宽(像素),默认 3。 */
21
+ lineWidth?: number;
22
+ /** 标记小球半径,默认 bboxDiagonal*0.006。 */
23
+ markerRadius?: number;
24
+ onModeChange?: (m: AnnotationMode) => void;
25
+ /** 标注列表变化回调(增删/撤销/清空)。 */
26
+ onChange?: (annotations: Annotation[]) => void;
27
+ }
28
+ /**
29
+ * 表面标注主控制器(Phase 4):navigate / freehand / geodesic / point 四模式,
30
+ * Enter 闭合,数据交给 AnnotationStore 管理(多条带颜色标签、撤销/删除/清空、导出)。
31
+ * 渲染层据 store.list() 做场景对账(reconcile),撤销/删除自动加/移 three 对象。
32
+ */
33
+ export declare class SurfaceAnnotator {
34
+ private o;
35
+ private mode;
36
+ private spaceHeld;
37
+ private pointerDown;
38
+ private readonly markerRadius;
39
+ private readonly epsilon;
40
+ private readonly minGap;
41
+ private graph;
42
+ private store;
43
+ private managed;
44
+ private seq;
45
+ private selectedId;
46
+ private activeStroke?;
47
+ private activeLine?;
48
+ private lastFreehand?;
49
+ private activeGeo?;
50
+ private activeGeoLine?;
51
+ constructor(opts: SurfaceAnnotatorOptions);
52
+ /** 窗口尺寸变化时更新所有 fat line 的像素分辨率,否则线宽会失真。 */
53
+ private onResize;
54
+ private get freehandColor();
55
+ private get geodesicColor();
56
+ private get pointColorVal();
57
+ getMode(): AnnotationMode;
58
+ setMode(m: AnnotationMode): void;
59
+ getStore(): AnnotationStore;
60
+ /** 当前标注列表快照。 */
61
+ getAnnotations(): Annotation[];
62
+ undo(): void;
63
+ clearAll(): void;
64
+ deleteAnnotation(id: string): void;
65
+ selectAnnotation(id: string | null): void;
66
+ /** 颜色变更后重画对应 three 对象。 */
67
+ refreshAnnotation(id: string): void;
68
+ exportJSON(modelName: string, opts?: ExportOptions): {
69
+ model: string;
70
+ exportedAt: string;
71
+ space: "local" | "world";
72
+ annotations: {
73
+ id: string;
74
+ type: "contour" | "points";
75
+ mode: "freehand" | "geodesic" | null;
76
+ label: string;
77
+ color: string;
78
+ closed: boolean;
79
+ points: number[][];
80
+ }[];
81
+ };
82
+ private applyCameraGating;
83
+ /** 据 store.list() 对账场景:补齐缺失对象、移除已删对象(不 dispose,留给撤销恢复)。 */
84
+ private reconcile;
85
+ private applySelection;
86
+ private disposeObject;
87
+ private nextId;
88
+ private hit;
89
+ /** 事件目标是否落在标注容器内(排除面板/页面其它区域的点击)。 */
90
+ private insideContainer;
91
+ private onPointerDown;
92
+ private onPointerMove;
93
+ private onPointerUp;
94
+ private closeLastContour;
95
+ /** 沿网格表面求 a→b 的测地路径(local 顶点),去掉与 a 重合的首点。a/b 已是 local。 */
96
+ private surfacePathBetween;
97
+ /** 结束当前测地线:闭合成环并落定为一条 contour。 */
98
+ private finishGeodesic;
99
+ private isTypingTarget;
100
+ private onKeyDown;
101
+ private onKeyUp;
102
+ dispose(): void;
103
+ }