@xtctwins/tctwins-core 1.1.5 → 1.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtctwins/tctwins-core",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "private": false,
5
5
  "description": "Web Programming Toolkit for 3D/2D BIM and CAD",
6
6
  "module": "./dist/tctwins-core.es5.js",
@@ -11,7 +11,7 @@
11
11
  "dev": "webpack --config webpack.min.config.js",
12
12
  "publish": "npm publish --access public",
13
13
  "release": "npm version patch && npm publish --access public",
14
- "vite-dev": "vite --open --mode dev"
14
+ "serve": "vite --open --mode dev"
15
15
  },
16
16
  "keywords": [
17
17
  "webgl",
@@ -75,4 +75,4 @@
75
75
  "/dist",
76
76
  "/types"
77
77
  ]
78
- }
78
+ }
@@ -0,0 +1,242 @@
1
+ import { Plugin, Viewer } from "../../viewer";
2
+
3
+ export declare type ObjectEditPluginConfiguration = {
4
+ /** 可选 ID,用于通过 {@link Viewer.plugins} 查找此插件。 */
5
+ id?: string;
6
+ };
7
+
8
+ /**
9
+ * ObjectEditPlugin 是 {@link Viewer} 插件,提供交互式 3D 变换控件(平移 / 旋转 / 缩放),
10
+ * 以及构件的染色、透视、隐藏等快捷操作。
11
+ *
12
+ * 同时支持 Instance 层和 Batch(VBO)层构件。Batch 构件的旋转通过 GPU 逐顶点矩阵实现。
13
+ *
14
+ * ## 快速开始
15
+ * ```js
16
+ * const edit = new ObjectEditPlugin(viewer);
17
+ *
18
+ * // 1. 选中构件
19
+ * edit.setTargets(["entityId1", "entityId2"]);
20
+ *
21
+ * // 2. 显示 Gizmo(平移箭头 + 旋转圆环 + 缩放方块)
22
+ * edit.showControl();
23
+ *
24
+ * // 3. 拖拽 Gizmo 手柄进行交互式编辑
25
+ *
26
+ * // 4. 或通过代码控制:
27
+ * edit.translate([1, 0, 0]); // 沿 X 平移 1 单位
28
+ * edit.rotate([0, 1, 0], 45); // 绕 Y 轴旋转 45°
29
+ * edit.setRotation([0, 0.707, 0, 0.707]); // 设置绝对旋转(四元数)
30
+ * edit.animateRotation([0, 1, 0], 90); // 绕 Y 轴持续旋转 90°/s
31
+ * edit.setScale([1.5, 1.5, 1.5]); // 缩放 1.5 倍
32
+ * edit.resetTransform(); // 重置所有变换
33
+ *
34
+ * // 5. 样式编辑
35
+ * edit.colorize([1, 0.2, 0.2]); // 染红
36
+ * edit.setXRayed(true); // 透视模式
37
+ * edit.setHidden(true); // 隐藏
38
+ *
39
+ * // 6. 隐藏 Gizmo
40
+ * edit.hideControl();
41
+ * ```
42
+ *
43
+ * ## 事件
44
+ * ```js
45
+ * edit.on("editStart", () => {});
46
+ * edit.on("editEnd", () => {});
47
+ * edit.on("translated", (delta: number[]) => {});
48
+ * edit.on("rotated", ({ axis, degrees }: { axis: number[]; degrees: number }) => {});
49
+ * edit.on("rotationSet", (quat: number[]) => {});
50
+ * edit.on("scaleSet", (scale: number[]) => {});
51
+ * edit.on("transformReset", () => {});
52
+ * edit.on("animStart", ({ axis, degreesPerSec, duration }: { axis: number[]; degreesPerSec: number; duration?: number }) => {});
53
+ * edit.on("animStop", () => {});
54
+ * edit.on("controlVisible", (visible: boolean) => {});
55
+ * edit.on("colorized", (rgb: number[]) => {});
56
+ * edit.on("xrayed", (on: boolean) => {});
57
+ * edit.on("hidden", (on: boolean) => {});
58
+ * ```
59
+ *
60
+ * ## Gizmo 手柄
61
+ *
62
+ * | 手柄 | 颜色 | 操作 |
63
+ * |------------|--------|----------|
64
+ * | 箭头杆 | R/G/B | 平移 |
65
+ * | 弯曲圆环 | R/G/B | 旋转 |
66
+ * | 方形盒子 | R/G/B | 单轴缩放 |
67
+ * | 中央黄盒 | 黄 | 均匀缩放 |
68
+ */
69
+ export declare class ObjectEditPlugin extends Plugin {
70
+ /**
71
+ * @constructor
72
+ * @param viewer Viewer 实例。
73
+ * @param cfg 插件配置。
74
+ */
75
+ constructor(viewer: Viewer, cfg?: ObjectEditPluginConfiguration);
76
+
77
+ // ═══ 目标管理 ═══
78
+
79
+ /**
80
+ * 设置要变换的目标构件 ID 列表。
81
+ *
82
+ * Gizmo 将定位在这些构件 AABB 的质心处。
83
+ * 调用此方法会重置累计旋转状态。
84
+ *
85
+ * @param ids {@link Entity.id} 数组。
86
+ */
87
+ setTargets(ids: string[]): void;
88
+
89
+ /**
90
+ * 获取当前目标构件 ID 列表。
91
+ *
92
+ * @returns {@link Entity.id} 数组。
93
+ */
94
+ getTargets(): string[];
95
+
96
+ // ═══ Gizmo 显示控制 ═══
97
+
98
+ /**
99
+ * 显示变换 Gizmo。
100
+ */
101
+ showControl(): void;
102
+
103
+ /**
104
+ * 隐藏变换 Gizmo。
105
+ */
106
+ hideControl(): void;
107
+
108
+ /**
109
+ * Gizmo 是否可见。
110
+ *
111
+ * @returns 是否可见。
112
+ */
113
+ isControlVisible(): boolean;
114
+
115
+ /**
116
+ * 设置 Gizmo 的世界坐标位置(手动)。
117
+ *
118
+ * @param pos 3D 位置 [x, y, z]。
119
+ */
120
+ setPosition(pos: number[]): void;
121
+
122
+ /**
123
+ * 设置 Gizmo 的剔除状态(用于快照等场景)。
124
+ *
125
+ * @param culled 是否剔除。
126
+ */
127
+ setCulled(culled: boolean): void;
128
+
129
+ // ═══ 变换操作(Batch + Instance 构件均支持) ═══
130
+
131
+ /**
132
+ * 按世界空间增量平移目标构件。
133
+ *
134
+ * @param delta 平移增量 [dx, dy, dz]。
135
+ */
136
+ translate(delta: number[]): void;
137
+
138
+ /**
139
+ * 绕指定轴增量旋转目标构件。
140
+ *
141
+ * @param axis 归一化旋转轴 [x, y, z]。
142
+ * @param degrees 旋转角度(度)。
143
+ */
144
+ rotate(axis: number[], degrees: number): void;
145
+
146
+ /**
147
+ * 设置目标构件的绝对旋转(四元数)。
148
+ *
149
+ * 对 Batch 和 Instance 构件均生效。Batch 构件绕自身中心旋转。
150
+ *
151
+ * @param quat 四元数 [x, y, z, w]。
152
+ */
153
+ setRotation(quat: number[]): void;
154
+
155
+ /**
156
+ * 设置目标构件的缩放(仅 Instance 层构件)。
157
+ *
158
+ * @param scale 缩放因子 [sx, sy, sz]。
159
+ */
160
+ setScale(scale: number[]): void;
161
+
162
+ /**
163
+ * 重置目标构件的所有变换(旋转 + 缩放归零/归一)。
164
+ */
165
+ resetTransform(): void;
166
+
167
+ // ═══ 动画旋转 ═══
168
+
169
+ /**
170
+ * 启动绕指定轴的持续旋转动画。
171
+ *
172
+ * 使用 requestAnimationFrame 驱动,带 delta-time 修正。
173
+ * 再次调用会停止当前动画并启动新的。
174
+ *
175
+ * @param axis 归一化旋转轴 [x, y, z]。
176
+ * @param degreesPerSec 旋转速度(度/秒)。
177
+ * @param duration 可选,最大持续秒数。省略则持续旋转直到手动停止。
178
+ *
179
+ * @example
180
+ * edit.animateRotation([0, 1, 0], 90); // 绕 Y 轴 90°/s 持续旋转
181
+ * edit.animateRotation([0, 0, 1], 180, 3); // 绕 Z 轴 180°/s 旋转 3 秒后自动停止
182
+ */
183
+ animateRotation(axis: number[], degreesPerSec: number, duration?: number): void;
184
+
185
+ /**
186
+ * 停止旋转动画。
187
+ */
188
+ stopAnimation(): void;
189
+
190
+ /**
191
+ * 动画是否正在运行。
192
+ *
193
+ * @returns 是否正在动画。
194
+ */
195
+ isAnimating(): boolean;
196
+
197
+ // ═══ 状态查询 ═══
198
+
199
+ /**
200
+ * 获取当前世界空间质心位置。
201
+ *
202
+ * @returns 位置 [x, y, z]。
203
+ */
204
+ getPosition(): number[];
205
+
206
+ /**
207
+ * 获取当前累计旋转四元数。
208
+ *
209
+ * @returns 四元数 [x, y, z, w],无旋转时返回 null。
210
+ */
211
+ getRotation(): number[] | null;
212
+
213
+ // ═══ 样式快捷操作 ═══
214
+
215
+ /**
216
+ * 染色选中构件。
217
+ *
218
+ * @param rgb RGB 颜色,各分量范围 0..1。
219
+ */
220
+ colorize(rgb: number[]): void;
221
+
222
+ /**
223
+ * 切换选中构件的透视模式。
224
+ *
225
+ * @param on 是否开启透视。
226
+ */
227
+ setXRayed(on: boolean): void;
228
+
229
+ /**
230
+ * 切换选中构件的可见性。
231
+ *
232
+ * @param on true=隐藏,false=显示。
233
+ */
234
+ setHidden(on: boolean): void;
235
+
236
+ // ═══ 生命周期 ═══
237
+
238
+ /**
239
+ * 销毁此插件。停止动画、解绑事件、销毁 Gizmo。
240
+ */
241
+ destroy(): void;
242
+ }
@@ -0,0 +1 @@
1
+ export * from "./ObjectEditPlugin";
@@ -12,6 +12,7 @@ export * from "./TreeViewPlugin";
12
12
  export * from "./ViewCullPlugin";
13
13
  export * from "./XTCLoaderPlugin";
14
14
  export * from "./WebIFCLoaderPlugin";
15
+ export * from "./ObjectEditPlugin";
15
16
  export * from "./LASLoaderPlugin";
16
17
 
17
18
  export declare type ModelStats = {
@@ -267,4 +267,14 @@ export declare class Viewer {
267
267
  /** Destroys this Viewer.
268
268
  */
269
269
  destroy(callback?: Function): void;
270
+
271
+ /**
272
+ * Focus camera on a given model (by ID or instance).
273
+ * @param {String|Number|Object} modelId Model id or SceneModel instance
274
+ * @param {*} [options] Options: { hideOthers: boolean, duration: number, callback: Function }
275
+ */
276
+ focusModel(
277
+ modelId: string | number | any,
278
+ options?: { hideOthers?: boolean; duration?: number; callback?: Function }
279
+ ): void;
270
280
  }
@@ -249,7 +249,7 @@ export declare class Scene extends Component {
249
249
  */
250
250
  get highlightedObjects(): { [key: string]: Entity };
251
251
 
252
- get edgesObjects(): { [key: string]: Entity }
252
+ get edgesObjects(): { [key: string]: Entity };
253
253
 
254
254
  /**
255
255
  * Map of currently selected {@link Entity}s that represent objects.
@@ -862,7 +862,7 @@ export declare class Scene extends Component {
862
862
  * @param {Number[]} [colorize=(1,1,1)] RGB colorize factors, multiplied by the rendered pixel colors.
863
863
  * @returns {Boolean} True if any {@link Entity}s changed opacity, else false if all updates were redundant and not applied.
864
864
  */
865
- setObjectsColorized(ids: string[], colorize: number[]|null): boolean;
865
+ setObjectsColorized(ids: string[], colorize: number[] | null): boolean;
866
866
 
867
867
  /**
868
868
  * Batch-updates {@link Entity.opacity} on {@link Entity}s that represent objects.
@@ -896,6 +896,160 @@ export declare class Scene extends Component {
896
896
  */
897
897
  setObjectsOffset(ids: string[], offset: number[]): void;
898
898
 
899
+ /**
900
+ * Batch-updates local translation on {@link Entity}s that represent objects.
901
+ *
902
+ * An {@link Entity} represents an object when {@link Entity.isObject} is ````true````.
903
+ *
904
+ * Only works on Entity types that have a ````position```` property
905
+ * (e.g. {@link Mesh}, {@link SceneModelTransform}).
906
+ *
907
+ * @param {String[]} ids Array of {@link Entity.id} values.
908
+ * @param {Number[]} position 3D position vector ````[x, y, z]````.
909
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
910
+ */
911
+ setObjectsPosition(ids: string | string[], position: number[]): boolean;
912
+
913
+ /**
914
+ * Gets the local translation of an object {@link Entity}.
915
+ *
916
+ * @param {String} id The {@link Entity.id}.
917
+ * @returns {Number[]|null} 3D position vector ````[x, y, z]````, or ````null````.
918
+ */
919
+ getObjectPosition(id: string): number[] | null;
920
+
921
+ /**
922
+ * Batch-updates local translation on {@link Entity}s, with per-object values.
923
+ *
924
+ * @param positionMap Map from {@link Entity.id} to 3D position vector ````[x, y, z]````.
925
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
926
+ */
927
+ setObjectsPositionMap(positionMap: { [id: string]: number[] }): boolean;
928
+
929
+ /**
930
+ * Batch-updates local rotation on {@link Entity}s that represent objects.
931
+ *
932
+ * Only works on Entity types that have a ````rotation```` property.
933
+ *
934
+ * @param {String[]} ids Array of {@link Entity.id} values.
935
+ * @param {Number[]} rotation Euler angles in degrees ````[rx, ry, rz]````.
936
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
937
+ */
938
+ setObjectsRotation(ids: string | string[], rotation: number[]): boolean;
939
+
940
+ /**
941
+ * Gets the local rotation of an object {@link Entity}.
942
+ *
943
+ * @param {String} id The {@link Entity.id}.
944
+ * @returns {Number[]|null} Euler angles in degrees ````[rx, ry, rz]````, or ````null````.
945
+ */
946
+ getObjectRotation(id: string): number[] | null;
947
+
948
+ /**
949
+ * Batch-updates local rotation on {@link Entity}s, with per-object values.
950
+ *
951
+ * @param rotationMap Map from {@link Entity.id} to Euler angles in degrees ````[rx, ry, rz]````.
952
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
953
+ */
954
+ setObjectsRotationMap(rotationMap: { [id: string]: number[] }): boolean;
955
+
956
+ /**
957
+ * Batch-updates local scale on {@link Entity}s that represent objects.
958
+ *
959
+ * Only works on Entity types that have a ````scale```` property.
960
+ *
961
+ * @param {String[]} ids Array of {@link Entity.id} values.
962
+ * @param {Number[]} scale 3D scale vector ````[sx, sy, sz]````.
963
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
964
+ */
965
+ setObjectsScale(ids: string | string[], scale: number[]): boolean;
966
+
967
+ /**
968
+ * Gets the local scale of an object {@link Entity}.
969
+ *
970
+ * @param {String} id The {@link Entity.id}.
971
+ * @returns {Number[]|null} 3D scale vector ````[sx, sy, sz]````, or ````null````.
972
+ */
973
+ getObjectScale(id: string): number[] | null;
974
+
975
+ /**
976
+ * Batch-updates local scale on {@link Entity}s, with per-object values.
977
+ *
978
+ * @param scaleMap Map from {@link Entity.id} to 3D scale vector ````[sx, sy, sz]````.
979
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
980
+ */
981
+ setObjectsScaleMap(scaleMap: { [id: string]: number[] }): boolean;
982
+
983
+ /**
984
+ * Batch-updates local rotation quaternion on {@link Entity}s that represent objects.
985
+ *
986
+ * Only works on Entity types that have a ````quaternion```` property.
987
+ *
988
+ * @param {String[]} ids Array of {@link Entity.id} values.
989
+ * @param {Number[]} quaternion Quaternion ````[x, y, z, w]````.
990
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
991
+ */
992
+ setObjectsQuaternion(ids: string | string[], quaternion: number[]): boolean;
993
+
994
+ /**
995
+ * Gets the local rotation quaternion of an object {@link Entity}.
996
+ *
997
+ * @param {String} id The {@link Entity.id}.
998
+ * @returns {Number[]|null} Quaternion ````[x, y, z, w]````, or ````null````.
999
+ */
1000
+ getObjectQuaternion(id: string): number[] | null;
1001
+
1002
+ /**
1003
+ * Batch-updates local rotation quaternion on {@link Entity}s, with per-object values.
1004
+ *
1005
+ * @param quaternionMap Map from {@link Entity.id} to quaternion ````[x, y, z, w]````.
1006
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
1007
+ */
1008
+ setObjectsQuaternionMap(quaternionMap: { [id: string]: number[] }): boolean;
1009
+
1010
+ /**
1011
+ * Batch-updates local modeling transform matrix on {@link Entity}s that represent objects.
1012
+ *
1013
+ * Only works on Entity types that have a ````matrix```` property.
1014
+ *
1015
+ * @param {String[]} ids Array of {@link Entity.id} values.
1016
+ * @param {Number[]} matrix 16-element 4x4 column-major matrix.
1017
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
1018
+ */
1019
+ setObjectsMatrix(ids: string | string[], matrix: number[]): boolean;
1020
+
1021
+ /**
1022
+ * Gets the local modeling transform matrix of an object {@link Entity}.
1023
+ *
1024
+ * @param {String} id The {@link Entity.id}.
1025
+ * @returns {Number[]|null} 16-element 4x4 column-major matrix, or ````null````.
1026
+ */
1027
+ getObjectMatrix(id: string): number[] | null;
1028
+
1029
+ /**
1030
+ * Batch-updates local modeling transform matrix on {@link Entity}s, with per-object values.
1031
+ *
1032
+ * @param matrixMap Map from {@link Entity.id} to 16-element 4x4 column-major matrix.
1033
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false.
1034
+ */
1035
+ setObjectsMatrixMap(matrixMap: { [id: string]: number[] }): boolean;
1036
+
1037
+ /**
1038
+ * Gets the World-space matrix of an object {@link Entity}.
1039
+ *
1040
+ * @param {String} id The {@link Entity.id}.
1041
+ * @returns {Number[]|null} 16-element 4x4 column-major World matrix, or ````null````.
1042
+ */
1043
+ getObjectWorldMatrix(id: string): number[] | null;
1044
+
1045
+ /**
1046
+ * Gets the World-space axis-aligned bounding box of an object {@link Entity}.
1047
+ *
1048
+ * @param {String} id The {@link Entity.id}.
1049
+ * @returns {Float64Array|number[]|null} Six-element AABB, or ````null````.
1050
+ */
1051
+ getObjectAABB(id: string): number[] | null;
1052
+
899
1053
  /**
900
1054
  * Iterates with a callback over {@link Entity}s that represent objects.
901
1055
  *
@@ -912,4 +1066,3 @@ export declare class Scene extends Component {
912
1066
  */
913
1067
  destroy(callback?: Function): void;
914
1068
  }
915
-