three-cad-viewer 4.3.4 → 4.3.6
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/dist/scene/clipping.d.ts +6 -0
- package/dist/three-cad-viewer.esm.js +20 -5
- package/dist/three-cad-viewer.esm.js.map +1 -1
- package/dist/three-cad-viewer.esm.min.js +1 -1
- package/dist/three-cad-viewer.js +20 -5
- package/dist/three-cad-viewer.min.js +1 -1
- package/package.json +2 -3
- package/src/_version.ts +0 -1
- package/src/camera/camera.ts +0 -445
- package/src/camera/controls/CADOrbitControls.ts +0 -241
- package/src/camera/controls/CADTrackballControls.ts +0 -598
- package/src/camera/controls.ts +0 -380
- package/src/core/patches.ts +0 -16
- package/src/core/studio-manager.ts +0 -652
- package/src/core/types.ts +0 -892
- package/src/core/viewer-state.ts +0 -784
- package/src/core/viewer.ts +0 -4821
- package/src/index.ts +0 -151
- package/src/rendering/environment.ts +0 -840
- package/src/rendering/light-detection.ts +0 -327
- package/src/rendering/material-factory.ts +0 -735
- package/src/rendering/material-presets.ts +0 -289
- package/src/rendering/raycast.ts +0 -291
- package/src/rendering/room-environment.ts +0 -192
- package/src/rendering/studio-composer.ts +0 -577
- package/src/rendering/studio-floor.ts +0 -108
- package/src/rendering/texture-cache.ts +0 -324
- package/src/rendering/tree-model.ts +0 -542
- package/src/rendering/triplanar.ts +0 -329
- package/src/scene/animation.ts +0 -343
- package/src/scene/axes.ts +0 -108
- package/src/scene/bbox.ts +0 -223
- package/src/scene/clipping.ts +0 -640
- package/src/scene/grid.ts +0 -864
- package/src/scene/nestedgroup.ts +0 -1444
- package/src/scene/objectgroup.ts +0 -866
- package/src/scene/orientation.ts +0 -259
- package/src/scene/render-shape.ts +0 -634
- package/src/tools/cad_tools/measure.ts +0 -811
- package/src/tools/cad_tools/select.ts +0 -100
- package/src/tools/cad_tools/tools.ts +0 -231
- package/src/tools/cad_tools/ui.ts +0 -454
- package/src/tools/cad_tools/zebra.ts +0 -369
- package/src/types/html.d.ts +0 -5
- package/src/types/n8ao.d.ts +0 -28
- package/src/types/three-augmentation.d.ts +0 -60
- package/src/ui/display.ts +0 -3295
- package/src/ui/index.html +0 -505
- package/src/ui/info.ts +0 -177
- package/src/ui/slider.ts +0 -206
- package/src/ui/toolbar.ts +0 -347
- package/src/ui/treeview.ts +0 -945
- package/src/utils/decode-instances.ts +0 -233
- package/src/utils/font.ts +0 -60
- package/src/utils/gpu-tracker.ts +0 -265
- package/src/utils/logger.ts +0 -92
- package/src/utils/sizeof.ts +0 -116
- package/src/utils/timer.ts +0 -69
- package/src/utils/utils.ts +0 -446
package/src/ui/toolbar.ts
DELETED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import { KeyMapper } from "../utils/utils.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Feature flags for toolbar buttons.
|
|
5
|
-
*/
|
|
6
|
-
interface ToolbarFeatures {
|
|
7
|
-
measureTools: boolean;
|
|
8
|
-
selectTool: boolean;
|
|
9
|
-
explodeTool: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Options for configuring a Toolbar instance.
|
|
14
|
-
*/
|
|
15
|
-
interface ToolbarOptions {
|
|
16
|
-
getVisibleWidth: () => number;
|
|
17
|
-
getWidthThreshold: () => number;
|
|
18
|
-
features: ToolbarFeatures;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Manages a collapsible toolbar with buttons and ellipsis indicators.
|
|
23
|
-
*/
|
|
24
|
-
class Toolbar {
|
|
25
|
-
id: string;
|
|
26
|
-
container: HTMLElement;
|
|
27
|
-
getVisibleWidth: () => number;
|
|
28
|
-
getWidthThreshold: () => number;
|
|
29
|
-
features: ToolbarFeatures;
|
|
30
|
-
buttons: Record<string, BaseButton>;
|
|
31
|
-
ellipses: Ellipsis[];
|
|
32
|
-
toggles: Record<number, BaseButton[]>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Create a Toolbar instance.
|
|
36
|
-
* @param container - The container element for the toolbar.
|
|
37
|
-
* @param id - Unique identifier for the toolbar.
|
|
38
|
-
* @param options - Configuration options.
|
|
39
|
-
*/
|
|
40
|
-
constructor(container: HTMLElement, id: string, options: ToolbarOptions) {
|
|
41
|
-
this.id = id;
|
|
42
|
-
this.container = container;
|
|
43
|
-
this.getVisibleWidth = options.getVisibleWidth;
|
|
44
|
-
this.getWidthThreshold = options.getWidthThreshold;
|
|
45
|
-
this.features = options.features;
|
|
46
|
-
|
|
47
|
-
this.container.addEventListener("mouseleave", this._onMouseLeave);
|
|
48
|
-
this.buttons = {};
|
|
49
|
-
this.ellipses = [];
|
|
50
|
-
this.toggles = { 0: [], 1: [], 2: [], 3: [] };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private _onMouseLeave = (): void => {
|
|
54
|
-
if (this.getVisibleWidth() < this.getWidthThreshold()) {
|
|
55
|
-
this.minimize();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
addButton(button: BaseButton, tag: number): void {
|
|
60
|
-
button.setId(this.id);
|
|
61
|
-
this.buttons[button.name] = button;
|
|
62
|
-
if (tag != -1) {
|
|
63
|
-
this.toggles[tag].push(button);
|
|
64
|
-
}
|
|
65
|
-
this.container.appendChild(button.html);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
addSeparator(): void {
|
|
69
|
-
const html = document.createElement("span");
|
|
70
|
-
html.className = "tcv_separator";
|
|
71
|
-
this.container.appendChild(html);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
addEllipsis(ellipsis: Ellipsis): void {
|
|
75
|
-
this.container.appendChild(ellipsis.html);
|
|
76
|
-
this.ellipses.push(ellipsis);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
defineGroup(buttons: ClickButton[]): void {
|
|
80
|
-
for (const button of buttons) {
|
|
81
|
-
for (const button2 of buttons) {
|
|
82
|
-
if (button2 != button) {
|
|
83
|
-
button.addGroupMember(button2);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private _toggle(flag: boolean, id: number | null = null): void {
|
|
90
|
-
let toggles: Record<number, BaseButton[]>;
|
|
91
|
-
let ellipses: Ellipsis[];
|
|
92
|
-
if (id == null) {
|
|
93
|
-
toggles = this.toggles;
|
|
94
|
-
ellipses = this.ellipses;
|
|
95
|
-
} else {
|
|
96
|
-
toggles = {};
|
|
97
|
-
toggles[id] = this.toggles[id];
|
|
98
|
-
ellipses = [this.ellipses[id]];
|
|
99
|
-
}
|
|
100
|
-
for (const ellipsis of ellipses) {
|
|
101
|
-
if (flag) {
|
|
102
|
-
ellipsis.html.classList.remove("tcv_unvisible");
|
|
103
|
-
} else {
|
|
104
|
-
ellipsis.html.classList.add("tcv_unvisible");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
for (const tag in toggles) {
|
|
108
|
-
for (const button of toggles[tag]) {
|
|
109
|
-
if (
|
|
110
|
-
!flag &&
|
|
111
|
-
((button.name === "distance" && !this.features.measureTools) ||
|
|
112
|
-
(button.name === "properties" && !this.features.measureTools) ||
|
|
113
|
-
(button.name === "select" && !this.features.selectTool) ||
|
|
114
|
-
(button.name === "explode" && !this.features.explodeTool))
|
|
115
|
-
) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
button.show(!flag);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
minimize = (id: number | null = null): void => {
|
|
124
|
-
this._toggle(true, id);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
maximize = (id: number | null = null): void => {
|
|
128
|
-
this._toggle(true);
|
|
129
|
-
this._toggle(false, id);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
dispose(): void {
|
|
133
|
-
this.container.removeEventListener("mouseleave", this._onMouseLeave);
|
|
134
|
-
for (const button of Object.values(this.buttons)) {
|
|
135
|
-
button.dispose();
|
|
136
|
-
}
|
|
137
|
-
for (const ellipsis of this.ellipses) {
|
|
138
|
-
ellipsis.dispose();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
class Ellipsis {
|
|
144
|
-
id: number;
|
|
145
|
-
action: (id: number) => void;
|
|
146
|
-
html: HTMLSpanElement;
|
|
147
|
-
|
|
148
|
-
constructor(id: number, action: (id: number) => void) {
|
|
149
|
-
this.id = id;
|
|
150
|
-
this.action = action;
|
|
151
|
-
const html = document.createElement("span");
|
|
152
|
-
html.innerHTML = "...";
|
|
153
|
-
html.className = "tcv_ellipsis tcv_unvisible";
|
|
154
|
-
this.html = html;
|
|
155
|
-
this.html.addEventListener("mouseenter", this._onMouseEnter);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private _onMouseEnter = (): void => {
|
|
159
|
-
this.action(this.id);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
dispose(): void {
|
|
163
|
-
this.html.removeEventListener("mouseenter", this._onMouseEnter);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
class BaseButton {
|
|
168
|
-
name: string;
|
|
169
|
-
html: HTMLSpanElement;
|
|
170
|
-
frame: HTMLSpanElement;
|
|
171
|
-
containerId: string;
|
|
172
|
-
|
|
173
|
-
constructor(_theme: string, icon: string, tooltip: string) {
|
|
174
|
-
this.name = icon;
|
|
175
|
-
this.containerId = "";
|
|
176
|
-
|
|
177
|
-
const html = document.createElement("span");
|
|
178
|
-
html.className = "tcv_tooltip";
|
|
179
|
-
html.setAttribute("data-tooltip", tooltip);
|
|
180
|
-
html.setAttribute("data-base-tooltip", tooltip);
|
|
181
|
-
|
|
182
|
-
const frame = document.createElement("span");
|
|
183
|
-
frame.className = "tcv_button_frame";
|
|
184
|
-
html.appendChild(frame);
|
|
185
|
-
|
|
186
|
-
const input = document.createElement("input");
|
|
187
|
-
input.className = "tcv_reset tcv_btn";
|
|
188
|
-
input.type = "button";
|
|
189
|
-
input.classList.add(`tcv_button_${icon}`);
|
|
190
|
-
frame.appendChild(input);
|
|
191
|
-
|
|
192
|
-
this.html = html;
|
|
193
|
-
this.frame = frame;
|
|
194
|
-
|
|
195
|
-
this.html.addEventListener("click", this._onClick);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private _onClick = (e: Event): void => {
|
|
199
|
-
this.handler(e);
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
dispose(): void {
|
|
203
|
-
this.html.removeEventListener("click", this._onClick);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
setId(id: string): void {
|
|
207
|
-
this.containerId = id;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
handler = (_e: Event): void => {
|
|
211
|
-
// Default handler - override in subclass
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
alignRight(): void {
|
|
215
|
-
this.html.classList.add("tcv_align_right");
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
show(flag: boolean): void {
|
|
219
|
-
this.html.style.display = flag ? "inline-block" : "none";
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
class Button extends BaseButton {
|
|
224
|
-
action: (name: string, shift: boolean) => void;
|
|
225
|
-
|
|
226
|
-
constructor(
|
|
227
|
-
theme: string,
|
|
228
|
-
svg: string,
|
|
229
|
-
tooltip: string,
|
|
230
|
-
action: (name: string, shift: boolean) => void
|
|
231
|
-
) {
|
|
232
|
-
super(theme, svg, tooltip);
|
|
233
|
-
this.action = action;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
handler = (e: Event): void => {
|
|
237
|
-
const shift = e instanceof MouseEvent ? KeyMapper.get(e, "shift") : false;
|
|
238
|
-
this.action(this.name, shift);
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
highlight = (flag: boolean): void => {
|
|
242
|
-
this.frame.classList.toggle("tcv_btn_highlight", flag);
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
class ClickButton extends BaseButton {
|
|
247
|
-
action: (name: string, state: boolean) => void;
|
|
248
|
-
state: boolean;
|
|
249
|
-
dropdown: string[] | null;
|
|
250
|
-
sameGroup: ClickButton[];
|
|
251
|
-
checkElems: Record<string, HTMLInputElement>;
|
|
252
|
-
|
|
253
|
-
constructor(
|
|
254
|
-
theme: string,
|
|
255
|
-
svg: string,
|
|
256
|
-
tooltip: string,
|
|
257
|
-
action: (name: string, state: boolean) => void,
|
|
258
|
-
defaultState: boolean = false,
|
|
259
|
-
dropdown: string[] | null = null,
|
|
260
|
-
) {
|
|
261
|
-
super(theme, svg, tooltip);
|
|
262
|
-
this.action = action;
|
|
263
|
-
this.state = defaultState;
|
|
264
|
-
this.dropdown = dropdown;
|
|
265
|
-
this.sameGroup = [];
|
|
266
|
-
|
|
267
|
-
this.checkElems = {};
|
|
268
|
-
if (dropdown != null) {
|
|
269
|
-
const d = document.createElement("span");
|
|
270
|
-
d.classList.add("tcv_grid-content");
|
|
271
|
-
d.classList.add("tcv_dropdown-content");
|
|
272
|
-
d.classList.add("tcv_round");
|
|
273
|
-
for (const p of dropdown) {
|
|
274
|
-
const dp = document.createElement("div");
|
|
275
|
-
dp.className = "tcv_tooltip";
|
|
276
|
-
dp.setAttribute("data-tooltip", `${tooltip} ${p}`);
|
|
277
|
-
|
|
278
|
-
const checkbox = document.createElement("input");
|
|
279
|
-
checkbox.className = `tcv_grid-${p} tcv_check tcv_dropdown-entry`;
|
|
280
|
-
checkbox.id = `tcv_grid-${p}_${this.containerId}`;
|
|
281
|
-
checkbox.type = "checkbox";
|
|
282
|
-
dp.appendChild(checkbox);
|
|
283
|
-
|
|
284
|
-
const label = document.createElement("label");
|
|
285
|
-
label.htmlFor = checkbox.id;
|
|
286
|
-
label.className = "tcv_label tcv_dropdown-entry";
|
|
287
|
-
label.textContent = p;
|
|
288
|
-
dp.appendChild(label);
|
|
289
|
-
|
|
290
|
-
d.appendChild(dp);
|
|
291
|
-
this.checkElems[p] = checkbox;
|
|
292
|
-
}
|
|
293
|
-
this.frame.appendChild(d);
|
|
294
|
-
this.frame.classList.add("tcv_grid-dropdown");
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
get = (): boolean => {
|
|
299
|
-
return this.state;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
set = (state: boolean): void => {
|
|
303
|
-
this.state = state;
|
|
304
|
-
this.frame.classList.toggle("tcv_btn_click2", this.state);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
clearGroup = (): void => {
|
|
308
|
-
for (const button of this.sameGroup) {
|
|
309
|
-
if (button.state) {
|
|
310
|
-
button.state = false;
|
|
311
|
-
button.frame.classList.remove("tcv_btn_click2");
|
|
312
|
-
button.action(this.name, false);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
extractIdFromName = (name: string): string => {
|
|
318
|
-
const match = "grid-";
|
|
319
|
-
const start = name.indexOf(match) + match.length;
|
|
320
|
-
const end = name.indexOf("_", start);
|
|
321
|
-
const result = name.slice(start, end);
|
|
322
|
-
return result;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
handler = (e: Event): void => {
|
|
326
|
-
if (!(e.target instanceof HTMLInputElement)) return;
|
|
327
|
-
const target = e.target;
|
|
328
|
-
const id = this.extractIdFromName(target.id || "");
|
|
329
|
-
if (this.dropdown != null && id && this.dropdown.includes(id)) {
|
|
330
|
-
const newstate = target.checked;
|
|
331
|
-
this.action(`grid-${id}`, newstate);
|
|
332
|
-
this.checkElems[id].checked = newstate;
|
|
333
|
-
} else if (target.type === "button") {
|
|
334
|
-
if (!this.state) {
|
|
335
|
-
this.clearGroup();
|
|
336
|
-
}
|
|
337
|
-
this.set(!this.state);
|
|
338
|
-
this.action(this.name, this.state);
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
addGroupMember(button: ClickButton): void {
|
|
343
|
-
this.sameGroup.push(button);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export { Toolbar, Button, ClickButton, Ellipsis };
|