@combeenation/3d-viewer 19.0.0 → 19.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.
@@ -3,6 +3,10 @@ import { Color3, HtmlAnchorOptions, LinesMesh, TransformNode, Vector3, Viewer }
3
3
  * Options for dimension line creation
4
4
  */
5
5
  export declare type DimensionLineOptions = Pick<HtmlAnchorOptions, 'occlusion' | 'scaling'> & {
6
+ /**
7
+ * Can be used to filter affected html anchors in {@link DimensionLineManager.removeAllDimensionLines}
8
+ */
9
+ group?: string;
6
10
  /**
7
11
  * Default: `Color3.Black()`
8
12
  */
@@ -48,7 +52,8 @@ export declare class DimensionLineManager {
48
52
  protected _dimensionLineObjs: {
49
53
  [name: string]: {
50
54
  linesMesh: LinesMesh;
51
- htmlLabelName: string;
55
+ htmlSpanElement: HTMLSpanElement;
56
+ options: DimensionLineOptions;
52
57
  };
53
58
  };
54
59
  /**
@@ -65,7 +70,8 @@ export declare class DimensionLineManager {
65
70
  */
66
71
  setDefaultDimensionLineOptions(defaultLineOptions: Partial<DimensionLineOptions>): void;
67
72
  /**
68
- * Create dimension line between two points
73
+ * Create dimension line between two points.\
74
+ * Already existing dimension line gets updated in place, which is useful for dynamic operations like dragging.
69
75
  */
70
76
  addDimensionLine(name: string, startPoint: Vector3, endPoint: Vector3, options?: Partial<DimensionLineOptions>): void;
71
77
  /**
@@ -74,6 +80,9 @@ export declare class DimensionLineManager {
74
80
  removeDimensionLine(name: string): void;
75
81
  /**
76
82
  * Remove all dimension lines that have been created with the `DimensionLineManager`
83
+ *
84
+ * @param groups if set, only dimension lines which are part of these groups will be removed\
85
+ * if left `undefined`, ALL dimension lines will be removed
77
86
  */
78
- removeAllDimensionLines(): void;
87
+ removeAllDimensionLines(groups?: string[]): void;
79
88
  }
@@ -39,16 +39,15 @@ class DimensionLineManager {
39
39
  (0, lodash_es_1.merge)(this._defaultLineOptions, defaultLineOptions);
40
40
  }
41
41
  /**
42
- * Create dimension line between two points
42
+ * Create dimension line between two points.\
43
+ * Already existing dimension line gets updated in place, which is useful for dynamic operations like dragging.
43
44
  */
44
45
  addDimensionLine(name, startPoint, endPoint, options) {
45
- if (this._dimensionLineObjs[name]) {
46
- console.warn(`Dimension line "${name}" already exists`);
47
- return;
48
- }
49
- const resDefaultOptions = Object.assign({}, this._defaultLineOptions);
50
- (0, lodash_es_1.merge)(resDefaultOptions, options);
51
- const { lineColor, closingLineHeight, closingLineDirection: closingLineDirectionIn, parentNode, occlusion, scaling, labelTextCb, labelCssClass, } = resDefaultOptions;
46
+ var _a;
47
+ const existingDimLine = this._dimensionLineObjs[name];
48
+ const resOptions = Object.assign({}, this._defaultLineOptions);
49
+ (0, lodash_es_1.merge)(resOptions, options);
50
+ const { lineColor, closingLineHeight, closingLineDirection: closingLineDirectionIn, parentNode, occlusion, scaling, labelTextCb, labelCssClass, } = resOptions;
52
51
  let closingLineDirection = closingLineDirectionIn;
53
52
  if (!closingLineDirection) {
54
53
  // evaluate closing line direction if not given
@@ -65,6 +64,9 @@ class DimensionLineManager {
65
64
  const closingLineEndPts = [relEndPt.add(closingLineOffsetVector), relEndPt.subtract(closingLineOffsetVector)];
66
65
  const linesMesh = index_1.MeshBuilder.CreateLineSystem(`${DimensionLineManager.DIMENSION_LINE_KEY}_${name}`, {
67
66
  lines: [[relStartPt, relEndPt], closingLineStartPts, closingLineEndPts],
67
+ // updates existing lines mesh if available
68
+ instance: existingDimLine === null || existingDimLine === void 0 ? void 0 : existingDimLine.linesMesh,
69
+ updatable: true,
68
70
  });
69
71
  linesMesh.position = lineCenter;
70
72
  linesMesh.color = lineColor;
@@ -77,33 +79,34 @@ class DimensionLineManager {
77
79
  }
78
80
  const lengthM = index_1.Vector3.Distance(startPoint, endPoint);
79
81
  const labelText = labelTextCb(lengthM);
80
- // create default html element
81
- const span = document.createElement('span');
82
- span.textContent = labelText;
82
+ // create default html element or update existing one
83
+ const htmlSpanElement = (_a = existingDimLine === null || existingDimLine === void 0 ? void 0 : existingDimLine.htmlSpanElement) !== null && _a !== void 0 ? _a : document.createElement('span');
84
+ htmlSpanElement.textContent = labelText;
83
85
  if (labelCssClass) {
84
- span.classList.add(labelCssClass);
86
+ htmlSpanElement.classList.add(labelCssClass);
85
87
  }
86
88
  else {
87
89
  const labelHeight = 24;
88
- span.style.display = 'block';
89
- span.style.height = `${labelHeight}px`;
90
- span.style.lineHeight = `${labelHeight}px`;
91
- span.style.fontSize = `${(labelHeight * 2) / 3}px`;
92
- span.style.fontFamily = 'Arial';
93
- span.style.border = `1px solid black`;
94
- span.style.paddingLeft = `${labelHeight / 2}px`;
95
- span.style.paddingRight = `${labelHeight / 2}px`;
96
- span.style.borderRadius = `${labelHeight / 2}px`;
97
- span.style.background = 'white';
90
+ htmlSpanElement.style.display = 'block';
91
+ htmlSpanElement.style.height = `${labelHeight}px`;
92
+ htmlSpanElement.style.lineHeight = `${labelHeight}px`;
93
+ htmlSpanElement.style.fontSize = `${(labelHeight * 2) / 3}px`;
94
+ htmlSpanElement.style.fontFamily = 'Arial';
95
+ htmlSpanElement.style.border = `1px solid black`;
96
+ htmlSpanElement.style.paddingLeft = `${labelHeight / 2}px`;
97
+ htmlSpanElement.style.paddingRight = `${labelHeight / 2}px`;
98
+ htmlSpanElement.style.borderRadius = `${labelHeight / 2}px`;
99
+ htmlSpanElement.style.background = 'white';
98
100
  }
99
- const htmlLabelName = `${DimensionLineManager.DIMENSION_LINE_KEY}_${name}`;
100
- this.viewer.htmlAnchorManager.addHtmlAnchor(name, span, index_1.Vector3.Zero(), {
101
- parentNode: linesMesh,
102
- group: DimensionLineManager.DIMENSION_LINE_KEY,
103
- occlusion,
104
- scaling,
105
- });
106
- this._dimensionLineObjs[name] = { linesMesh, htmlLabelName };
101
+ if (!existingDimLine) {
102
+ this.viewer.htmlAnchorManager.addHtmlAnchor(name, htmlSpanElement, index_1.Vector3.Zero(), {
103
+ parentNode: linesMesh,
104
+ group: DimensionLineManager.DIMENSION_LINE_KEY,
105
+ occlusion,
106
+ scaling,
107
+ });
108
+ }
109
+ this._dimensionLineObjs[name] = { linesMesh, htmlSpanElement, options: resOptions };
107
110
  }
108
111
  /**
109
112
  * Remove dimension line and disposes all associated ressources
@@ -120,9 +123,13 @@ class DimensionLineManager {
120
123
  }
121
124
  /**
122
125
  * Remove all dimension lines that have been created with the `DimensionLineManager`
126
+ *
127
+ * @param groups if set, only dimension lines which are part of these groups will be removed\
128
+ * if left `undefined`, ALL dimension lines will be removed
123
129
  */
124
- removeAllDimensionLines() {
125
- Object.keys(this._dimensionLineObjs).forEach(dimLineName => {
130
+ removeAllDimensionLines(groups) {
131
+ const entriesToRemove = Object.entries(this._dimensionLineObjs).filter(([_, { options }]) => groups === undefined || (options.group !== undefined && groups.includes(options.group)));
132
+ entriesToRemove.forEach(([dimLineName]) => {
126
133
  this.removeDimensionLine(dimLineName);
127
134
  });
128
135
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dimension-line-manager.js","sourceRoot":"","sources":["../../../src/manager/dimension-line-manager.ts"],"names":[],"mappings":";;;AAAA,oCAAmH;AACnH,yCAAkC;AA0ClC;;GAEG;AACH,MAAa,oBAAoB;IA+B/B,gBAAgB;IAChB,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QA7BjC,wBAAmB,GAAyB;YACpD,SAAS,EAAE,cAAM,CAAC,KAAK,EAAE;YACzB,iBAAiB,EAAE,IAAI;YACvB,WAAW,EAAE,CAAC,OAAO,EAAU,EAAE;gBAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;gBAC7D,OAAO,GAAG,aAAa,KAAK,CAAC;YAC/B,CAAC;YACD,aAAa,EAAE,EAAE;SAClB,CAAC;QAEF,uEAAuE;QACvE,sDAAsD;QAC5C,uBAAkB,GAKxB,EAAE,CAAC;IAYuC,CAAC;IAV/C;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAA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AAI,EAAE,eAAO,CAAC,IAAI,EAAE,EAAE;YACtE,UAAU,EAAE,SAAS;YACrB,KAAK,EAAE,oBAAoB,CAAC,kBAAkB;YAC9C,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;IAC/D,CAAC;IAED;;OAEG;IACI,mBAAmB,CAAC,IAAY;QACrC,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO,CAAC,IAAI,CAAC,mBAAmB,IAAI,kBAAkB,CAAC,CAAC;YACxD,OAAO;SACR;QAED,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACrD,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAE7C,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACI,uBAAuB;QAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YACzD,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;;AA3JH,oDA4JC;AA3JwB,uCAAkB,GAAG,UAAU,CAAC"}
1
+ {"version":3,"file":"dimension-line-manager.js","sourceRoot":"","sources":["../../../src/manager/dimension-line-manager.ts"],"names":[],"mappings":";;;AAAA,oCAAmH;AACnH,yCAAkC;AA8ClC;;GAEG;AACH,MAAa,oBAAoB;IAgC/B,gBAAgB;IAChB,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QA9BjC,wBAAmB,GAAyB;YACpD,SAAS,EAAE,cAAM,CAAC,KAAK,EAAE;YACzB,i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C,kBAAkB,CAAC,CAAC,MAAM,CACpE,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAC9G,CAAC;QAEF,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;YACxC,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;;AArKH,oDAsKC;AArKwB,uCAAkB,GAAG,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combeenation/3d-viewer",
3
- "version": "19.0.0",
3
+ "version": "19.1.0",
4
4
  "description": "Combeenation 3D Viewer",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "bugs": {
@@ -5,6 +5,10 @@ import { merge } from 'lodash-es';
5
5
  * Options for dimension line creation
6
6
  */
7
7
  export type DimensionLineOptions = Pick<HtmlAnchorOptions, 'occlusion' | 'scaling'> & {
8
+ /**
9
+ * Can be used to filter affected html anchors in {@link DimensionLineManager.removeAllDimensionLines}
10
+ */
11
+ group?: string;
8
12
  /**
9
13
  * Default: `Color3.Black()`
10
14
  */
@@ -62,7 +66,8 @@ export class DimensionLineManager {
62
66
  protected _dimensionLineObjs: {
63
67
  [name: string]: {
64
68
  linesMesh: LinesMesh;
65
- htmlLabelName: string;
69
+ htmlSpanElement: HTMLSpanElement;
70
+ options: DimensionLineOptions;
66
71
  };
67
72
  } = {};
68
73
 
@@ -87,7 +92,8 @@ export class DimensionLineManager {
87
92
  }
88
93
 
89
94
  /**
90
- * Create dimension line between two points
95
+ * Create dimension line between two points.\
96
+ * Already existing dimension line gets updated in place, which is useful for dynamic operations like dragging.
91
97
  */
92
98
  public addDimensionLine(
93
99
  name: string,
@@ -95,13 +101,10 @@ export class DimensionLineManager {
95
101
  endPoint: Vector3,
96
102
  options?: Partial<DimensionLineOptions>
97
103
  ): void {
98
- if (this._dimensionLineObjs[name]) {
99
- console.warn(`Dimension line "${name}" already exists`);
100
- return;
101
- }
104
+ const existingDimLine = this._dimensionLineObjs[name];
102
105
 
103
- const resDefaultOptions = { ...this._defaultLineOptions };
104
- merge(resDefaultOptions, options);
106
+ const resOptions = { ...this._defaultLineOptions };
107
+ merge(resOptions, options);
105
108
  const {
106
109
  lineColor,
107
110
  closingLineHeight,
@@ -111,7 +114,7 @@ export class DimensionLineManager {
111
114
  scaling,
112
115
  labelTextCb,
113
116
  labelCssClass,
114
- } = resDefaultOptions;
117
+ } = resOptions;
115
118
 
116
119
  let closingLineDirection = closingLineDirectionIn;
117
120
  if (!closingLineDirection) {
@@ -131,6 +134,9 @@ export class DimensionLineManager {
131
134
 
132
135
  const linesMesh = MeshBuilder.CreateLineSystem(`${DimensionLineManager.DIMENSION_LINE_KEY}_${name}`, {
133
136
  lines: [[relStartPt, relEndPt], closingLineStartPts, closingLineEndPts],
137
+ // updates existing lines mesh if available
138
+ instance: existingDimLine?.linesMesh,
139
+ updatable: true,
134
140
  });
135
141
  linesMesh.position = lineCenter;
136
142
  linesMesh.color = lineColor;
@@ -145,35 +151,36 @@ export class DimensionLineManager {
145
151
  const lengthM = Vector3.Distance(startPoint, endPoint);
146
152
  const labelText = labelTextCb(lengthM);
147
153
 
148
- // create default html element
149
- const span = document.createElement('span');
150
- span.textContent = labelText;
154
+ // create default html element or update existing one
155
+ const htmlSpanElement = existingDimLine?.htmlSpanElement ?? document.createElement('span');
156
+ htmlSpanElement.textContent = labelText;
151
157
 
152
158
  if (labelCssClass) {
153
- span.classList.add(labelCssClass);
159
+ htmlSpanElement.classList.add(labelCssClass);
154
160
  } else {
155
161
  const labelHeight = 24;
156
- span.style.display = 'block';
157
- span.style.height = `${labelHeight}px`;
158
- span.style.lineHeight = `${labelHeight}px`;
159
- span.style.fontSize = `${(labelHeight * 2) / 3}px`;
160
- span.style.fontFamily = 'Arial';
161
- span.style.border = `1px solid black`;
162
- span.style.paddingLeft = `${labelHeight / 2}px`;
163
- span.style.paddingRight = `${labelHeight / 2}px`;
164
- span.style.borderRadius = `${labelHeight / 2}px`;
165
- span.style.background = 'white';
162
+ htmlSpanElement.style.display = 'block';
163
+ htmlSpanElement.style.height = `${labelHeight}px`;
164
+ htmlSpanElement.style.lineHeight = `${labelHeight}px`;
165
+ htmlSpanElement.style.fontSize = `${(labelHeight * 2) / 3}px`;
166
+ htmlSpanElement.style.fontFamily = 'Arial';
167
+ htmlSpanElement.style.border = `1px solid black`;
168
+ htmlSpanElement.style.paddingLeft = `${labelHeight / 2}px`;
169
+ htmlSpanElement.style.paddingRight = `${labelHeight / 2}px`;
170
+ htmlSpanElement.style.borderRadius = `${labelHeight / 2}px`;
171
+ htmlSpanElement.style.background = 'white';
166
172
  }
167
173
 
168
- const htmlLabelName = `${DimensionLineManager.DIMENSION_LINE_KEY}_${name}`;
169
- this.viewer.htmlAnchorManager.addHtmlAnchor(name, span, Vector3.Zero(), {
170
- parentNode: linesMesh,
171
- group: DimensionLineManager.DIMENSION_LINE_KEY,
172
- occlusion,
173
- scaling,
174
- });
174
+ if (!existingDimLine) {
175
+ this.viewer.htmlAnchorManager.addHtmlAnchor(name, htmlSpanElement, Vector3.Zero(), {
176
+ parentNode: linesMesh,
177
+ group: DimensionLineManager.DIMENSION_LINE_KEY,
178
+ occlusion,
179
+ scaling,
180
+ });
181
+ }
175
182
 
176
- this._dimensionLineObjs[name] = { linesMesh, htmlLabelName };
183
+ this._dimensionLineObjs[name] = { linesMesh, htmlSpanElement, options: resOptions };
177
184
  }
178
185
 
179
186
  /**
@@ -194,9 +201,16 @@ export class DimensionLineManager {
194
201
 
195
202
  /**
196
203
  * Remove all dimension lines that have been created with the `DimensionLineManager`
204
+ *
205
+ * @param groups if set, only dimension lines which are part of these groups will be removed\
206
+ * if left `undefined`, ALL dimension lines will be removed
197
207
  */
198
- public removeAllDimensionLines(): void {
199
- Object.keys(this._dimensionLineObjs).forEach(dimLineName => {
208
+ public removeAllDimensionLines(groups?: string[]): void {
209
+ const entriesToRemove = Object.entries(this._dimensionLineObjs).filter(
210
+ ([_, { options }]) => groups === undefined || (options.group !== undefined && groups.includes(options.group))
211
+ );
212
+
213
+ entriesToRemove.forEach(([dimLineName]) => {
200
214
  this.removeDimensionLine(dimLineName);
201
215
  });
202
216
  }