@kitware/vtk.js 30.5.0 → 30.5.1

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.
@@ -1,5 +1,5 @@
1
1
  import { m as macro } from '../../../macros2.js';
2
- import { handleTypeFromName, AXES, transformVec3, rotateVec3 } from './helpers.js';
2
+ import { handleTypeFromName, AXES, calculateCropperCenter, calculateDirection, transformVec3 } from './helpers.js';
3
3
 
4
4
  function widgetBehavior(publicAPI, model) {
5
5
  model._isDragging = false;
@@ -47,23 +47,20 @@ function widgetBehavior(publicAPI, model) {
47
47
  worldCoords = manipulator.handleEvent(callData, model._apiSpecificRenderWindow).worldCoords;
48
48
  }
49
49
  if (type === 'faces') {
50
- // constraint axis is line defined by the index and center point.
51
- // Since our index point is defined inside a box [0, 2, 0, 2, 0, 2],
52
- // center point is [1, 1, 1].
53
- const constraintAxis = [1 - index[0], 1 - index[1], 1 - index[2]];
54
-
55
50
  // get center of current crop box
56
- const center = [(planes[0] + planes[1]) / 2, (planes[2] + planes[3]) / 2, (planes[4] + planes[5]) / 2];
57
-
58
- // manipulator should be a line manipulator
59
- manipulator.setHandleOrigin(transformVec3(center, indexToWorldT));
60
- manipulator.setHandleNormal(rotateVec3(constraintAxis, indexToWorldT));
51
+ const worldCenter = calculateCropperCenter(planes, indexToWorldT);
52
+ manipulator.setHandleOrigin(worldCenter);
53
+ manipulator.setHandleNormal(calculateDirection(model.activeState.getOrigin(), worldCenter));
61
54
  worldCoords = manipulator.handleEvent(callData, model._apiSpecificRenderWindow).worldCoords;
62
55
  }
63
56
  if (type === 'edges') {
64
57
  // constrain to a plane with a normal parallel to the edge
65
58
  const edgeAxis = index.map(a => a === 1 ? a : 0);
66
- manipulator.setHandleNormal(rotateVec3(edgeAxis, indexToWorldT));
59
+ const faceName = edgeAxis.map(i => AXES[i + 1]).join('');
60
+ const handle = model.widgetState.getStatesWithLabel(faceName)[0];
61
+ // get center of current crop box
62
+ const worldCenter = calculateCropperCenter(planes, indexToWorldT);
63
+ manipulator.setHandleNormal(calculateDirection(handle.getOrigin(), worldCenter));
67
64
  worldCoords = manipulator.handleEvent(callData, model._apiSpecificRenderWindow).worldCoords;
68
65
  }
69
66
  if (worldCoords.length) {
@@ -34,5 +34,16 @@ function handleTypeFromName(name) {
34
34
  }
35
35
  return 'faces';
36
36
  }
37
+ function calculateCropperCenter(planes, transform) {
38
+ // get center of current crop box
39
+ const center = [(planes[0] + planes[1]) / 2, (planes[2] + planes[3]) / 2, (planes[4] + planes[5]) / 2];
40
+ return transformVec3(center, transform);
41
+ }
42
+ function calculateDirection(v1, v2) {
43
+ const direction = vec3.create();
44
+ vec3.subtract(direction, v1, v2);
45
+ vec3.normalize(direction, direction);
46
+ return direction;
47
+ }
37
48
 
38
- export { AXES, handleTypeFromName, rotateVec3, transformVec3 };
49
+ export { AXES, calculateCropperCenter, calculateDirection, handleTypeFromName, rotateVec3, transformVec3 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "30.5.0",
3
+ "version": "30.5.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",