three-cad-viewer 0.9.18 → 0.9.19

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.
@@ -52954,6 +52954,7 @@ class Animation {
52954
52954
  this.delim = delim;
52955
52955
  this.tracks = [];
52956
52956
  this.mixer = null;
52957
+ this.clip = null;
52957
52958
  this.clipAction = null;
52958
52959
  this.clock = new Clock();
52959
52960
  }
@@ -53029,17 +53030,25 @@ class Animation {
53029
53030
  }
53030
53031
 
53031
53032
  animate(duration, speed) {
53032
- const clip = new AnimationClip("track", duration, this.tracks);
53033
+ this.clip = new AnimationClip("track", duration, this.tracks);
53033
53034
  this.mixer = new AnimationMixer(this.root);
53034
53035
  this.mixer.timeScale = speed;
53035
53036
  // this.mixer.addEventListener('finished', (e) => { console.log("finished", e) });
53036
53037
  // this.mixer.addEventListener('loop', (e) => { console.log("loop", e) });
53037
53038
 
53038
- this.clipAction = this.mixer.clipAction(clip);
53039
+ this.clipAction = this.mixer.clipAction(this.clip);
53039
53040
 
53040
53041
  return this.clipAction;
53041
53042
  }
53042
53043
 
53044
+ dispose() {
53045
+ this.mixer = null;
53046
+ this.clipAction = null;
53047
+ this.clip = null;
53048
+ this.tracks = [];
53049
+ this.root = null;
53050
+ }
53051
+
53043
53052
  update() {
53044
53053
  if (this.mixer) {
53045
53054
  this.mixer.update(this.clock.getDelta());
@@ -55183,7 +55192,6 @@ class Viewer {
55183
55192
  this.nestedGroup.rootGroup,
55184
55193
  this.nestedGroup.delim
55185
55194
  );
55186
- this.display.setAnimationControl(true);
55187
55195
  }
55188
55196
  this.animation.addTrack(
55189
55197
  selector,
@@ -55202,9 +55210,23 @@ class Viewer {
55202
55210
  initAnimation(duration, speed) {
55203
55211
  if (!this.needsAnimationLoop) {
55204
55212
  console.error("Start viewer with animation loop");
55205
- return;
55213
+ } else if (this.animation == null) {
55214
+ console.error("Animation does not have tracks");
55215
+ } else {
55216
+ this.display.setAnimationControl(true);
55217
+ this.clipAction = this.animation.animate(duration, speed);
55206
55218
  }
55207
- this.clipAction = this.animation.animate(duration, speed);
55219
+ }
55220
+
55221
+ /**
55222
+ * Clear the animation obect and dispose dependent objects
55223
+ */
55224
+ clearAnimation() {
55225
+ if (this.animation) {
55226
+ this.animation.dispose();
55227
+ this.animation = null;
55228
+ }
55229
+ this.display.setAnimationControl(false);
55208
55230
  }
55209
55231
 
55210
55232
  /**
@@ -56167,28 +56189,64 @@ class Viewer {
56167
56189
  }
56168
56190
 
56169
56191
  /**
56170
- * Set the normal at index to the current viewing direction
56192
+ * Set the normal at index to a given normal
56171
56193
  * @function
56172
- * @param {boolean} index - index of the normal: 0, 1 ,2
56194
+ * @param {number} index - index of the normal: 0, 1 ,2
56195
+ * @param {number[]} normal - 3 dim array representing the normal
56173
56196
  * @param {boolean} [notify=true] - whether to send notification or not.
56174
56197
  */
56175
- setClipNormal = (index, notify = true) => {
56176
- const cameraPosition = this.camera.getPosition().clone();
56177
- const normal = cameraPosition
56178
- .sub(this.controls.getTarget())
56179
- .normalize()
56180
- .negate();
56181
-
56198
+ setClipNormal(index, normal, notify = true) {
56182
56199
  this.clipNormal[index] = normal;
56183
56200
 
56184
- this.clipping.setNormal(index, normal);
56201
+ this.clipping.setNormal(index, new Vector3(...normal));
56185
56202
  var notifyObject = {};
56186
- notifyObject[`clip_normal_${index}`] = normal.toArray();
56203
+ notifyObject[`clip_normal_${index}`] = normal;
56187
56204
 
56188
56205
  this.checkChanges(notifyObject, notify);
56189
56206
 
56190
56207
  this.nestedGroup.setClipPlanes(this.clipping.clipPlanes);
56191
56208
  this.update(true, false);
56209
+ }
56210
+
56211
+ /**
56212
+ * Set the normal at index to the current viewing direction
56213
+ * @function
56214
+ * @param {number} index - index of the normal: 0, 1 ,2
56215
+ * @param {boolean} [notify=true] - whether to send notification or not.
56216
+ */
56217
+ setClipNormalFromPosition = (index, notify = true) => {
56218
+ const cameraPosition = this.camera.getPosition().clone();
56219
+ const normal = cameraPosition
56220
+ .sub(this.controls.getTarget())
56221
+ .normalize()
56222
+ .negate()
56223
+ .toArray();
56224
+ this.setClipNormal(index, normal, notify);
56225
+ };
56226
+
56227
+ /**
56228
+ * Get clipping slider value.
56229
+ * @function
56230
+ * @param {number} index - index of the normal: 0, 1 ,2
56231
+ * @returns {boolean} clip plane visibility value.
56232
+ **/
56233
+ getClipSlider = (index) => {
56234
+ return this.display.clipSliders[index].getValue();
56235
+ };
56236
+
56237
+ /**
56238
+ * Set clipping slider value.
56239
+ * @function
56240
+ * @param {number} index - index of the normal: 0, 1 ,2
56241
+ * @param {number} value - value for the clipping slide. will be trimmed to slide min/max limits
56242
+ * @param {boolean} [notify=true] - whether to send notification or not.
56243
+ */
56244
+ setClipSlider = (index, value, notify = true) => {
56245
+ this.display.clipSliders[index].setValue(value, notify);
56246
+ // var notifyObject = {};
56247
+ // notifyObject[`clip_slider_${index}`] = value;
56248
+
56249
+ // this.checkChanges(notifyObject, notify);
56192
56250
  };
56193
56251
  }
56194
56252
 
@@ -56360,10 +56418,10 @@ class Slider {
56360
56418
  this.input.addEventListener("change", this.inputChange);
56361
56419
  }
56362
56420
 
56363
- _notify = (value) => {
56421
+ _notify = (value, notify = true) => {
56364
56422
  const change = {};
56365
56423
  change[`clip_slider_${this.index - 1}`] = parseFloat(value);
56366
- this.display.viewer.checkChanges(change);
56424
+ this.display.viewer.checkChanges(change, notify);
56367
56425
  };
56368
56426
 
56369
56427
  sliderChange = (e) => {
@@ -56395,6 +56453,21 @@ class Slider {
56395
56453
  this.input.value = Math.round(1000 * this.slider.max) / 1000;
56396
56454
  this.display.refreshPlane(this.index, this.input.value);
56397
56455
  }
56456
+
56457
+ getValue() {
56458
+ return parseFloat(this.input.value);
56459
+ }
56460
+
56461
+ setValue(value, notify = true) {
56462
+ const trimmed_value = Math.max(
56463
+ Math.min(value, this.slider.max),
56464
+ this.slider.min
56465
+ );
56466
+ this.input.value = trimmed_value;
56467
+ this.slider.value = value;
56468
+ this.display.refreshPlane(this.index, this.input.value);
56469
+ this._notify(value, notify);
56470
+ }
56398
56471
  }
56399
56472
 
56400
56473
  class Display {
@@ -56588,7 +56661,7 @@ class Display {
56588
56661
  for (i = 1; i < 4; i++) {
56589
56662
  this._setupClickEvent(
56590
56663
  `tcv_btn_norm_plane${i}`,
56591
- this.setClipNormal,
56664
+ this.setClipNormalFromPosition,
56592
56665
  false
56593
56666
  );
56594
56667
  }
@@ -56851,9 +56924,9 @@ class Display {
56851
56924
  * @function
56852
56925
  * @param {Event} e - a DOM click event
56853
56926
  */
56854
- setClipNormal = (e) => {
56927
+ setClipNormalFromPosition = (e) => {
56855
56928
  const index = parseInt(e.target.classList[0].slice(-1));
56856
- this.viewer.setClipNormal(index - 1);
56929
+ this.viewer.setClipNormalFromPosition(index - 1);
56857
56930
  };
56858
56931
 
56859
56932
  /**