@kitware/vtk.js 29.11.2 → 30.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.
@@ -1,6 +1,10 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import Constants from './RenderWindowHelper/Constants.js';
3
+ import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
4
+ import vtkLineSource from '@kitware/vtk.js/Filters/Sources/LineSource';
5
+ import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
3
6
  import { GET_UNDERLYING_CONTEXT } from '../OpenGL/RenderWindow/ContextProxy.js';
7
+ import { vec3 } from 'gl-matrix';
4
8
 
5
9
  const {
6
10
  XrSessionTypes
@@ -11,6 +15,23 @@ const DEFAULT_RESET_FACTORS = {
11
15
  translateZ: -1.5 // default translation initializes object in front of camera
12
16
  };
13
17
 
18
+ function createRay() {
19
+ const targetRayLineSource = vtkLineSource.newInstance();
20
+ const targetRayMapper = vtkMapper.newInstance();
21
+ targetRayMapper.setInputConnection(targetRayLineSource.getOutputPort());
22
+ const targetRayActor = vtkActor.newInstance();
23
+ targetRayActor.getProperty().setColor(1, 0, 0);
24
+ targetRayActor.getProperty().setLineWidth(5);
25
+ targetRayActor.setMapper(targetRayMapper);
26
+ targetRayActor.setPickable(false);
27
+ return {
28
+ lineSource: targetRayLineSource,
29
+ mapper: targetRayMapper,
30
+ actor: targetRayActor,
31
+ visible: false
32
+ };
33
+ }
34
+
14
35
  // ----------------------------------------------------------------------------
15
36
  // vtkWebXRRenderWindowHelper methods
16
37
  // ----------------------------------------------------------------------------
@@ -145,6 +166,36 @@ function vtkWebXRRenderWindowHelper(publicAPI, model) {
145
166
  model.xrRender = async (t, frame) => {
146
167
  const xrSession = frame.session;
147
168
  const isXrSessionHMD = [XrSessionTypes.HmdVR, XrSessionTypes.HmdAR].includes(model.xrSessionType);
169
+ if (isXrSessionHMD && model.drawControllersRay && model.xrReferenceSpace) {
170
+ const renderer = model.renderWindow.getRenderable().getRenderers()[0];
171
+ const camera = renderer.getActiveCamera();
172
+ const physicalToWorldMatrix = [];
173
+ camera.getPhysicalToWorldMatrix(physicalToWorldMatrix);
174
+ xrSession.inputSources.forEach(inputSource => {
175
+ if (inputSource.targetRaySpace == null || inputSource.gripSpace == null || inputSource.targetRayMode !== 'tracked-pointer') {
176
+ return;
177
+ }
178
+ if (model.inputSourceToRay[inputSource.handedness] == null) {
179
+ model.inputSourceToRay[inputSource.handedness] = createRay();
180
+ }
181
+ const ray = model.inputSourceToRay[inputSource.handedness];
182
+ const targetRayPose = frame.getPose(inputSource.targetRaySpace, model.xrReferenceSpace);
183
+ if (targetRayPose == null) {
184
+ return;
185
+ }
186
+ const targetRayPosition = vec3.fromValues(targetRayPose.transform.position.x, targetRayPose.transform.position.y, targetRayPose.transform.position.z);
187
+ const dir = camera.physicalOrientationToWorldDirection([targetRayPose.transform.orientation.x, targetRayPose.transform.orientation.y, targetRayPose.transform.orientation.z, targetRayPose.transform.orientation.w]);
188
+ const targetRayWorldPosition = vec3.transformMat4([], targetRayPosition, physicalToWorldMatrix);
189
+ const dist = renderer.getActiveCamera().getClippingRange()[1];
190
+ if (!ray.visible) {
191
+ renderer.addActor(ray.actor);
192
+ ray.visible = true;
193
+ }
194
+ ray.lineSource.setPoint1(targetRayWorldPosition[0] - dir[0] * dist, targetRayWorldPosition[1] - dir[1] * dist, targetRayWorldPosition[2] - dir[2] * dist);
195
+ ray.lineSource.setPoint2(...targetRayWorldPosition);
196
+ });
197
+ model.renderWindow.render();
198
+ }
148
199
  model.renderWindow.getRenderable().getInteractor().updateXRGamepads(xrSession, frame, model.xrReferenceSpace);
149
200
  model.xrSceneFrame = model.xrSession.requestAnimationFrame(model.xrRender);
150
201
  const xrPose = frame.getViewerPose(model.xrReferenceSpace);
@@ -202,27 +253,31 @@ function vtkWebXRRenderWindowHelper(publicAPI, model) {
202
253
  // Object factory
203
254
  // ----------------------------------------------------------------------------
204
255
 
205
- const DEFAULT_VALUES = {
206
- initialized: false,
207
- initCanvasSize: null,
208
- initBackground: null,
209
- renderWindow: null,
210
- xrSession: null,
211
- xrSessionType: 0,
212
- xrReferenceSpace: null
213
- };
256
+ function defaultValues() {
257
+ return {
258
+ initialized: false,
259
+ drawControllersRay: false,
260
+ inputSourceToRay: {},
261
+ initCanvasSize: null,
262
+ initBackground: null,
263
+ renderWindow: null,
264
+ xrSession: null,
265
+ xrSessionType: 0,
266
+ xrReferenceSpace: null
267
+ };
268
+ }
214
269
 
215
270
  // ----------------------------------------------------------------------------
216
271
 
217
272
  function extend(publicAPI, model) {
218
273
  let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
219
- Object.assign(model, DEFAULT_VALUES, initialValues);
274
+ Object.assign(model, defaultValues(), initialValues);
220
275
 
221
276
  // Build VTK API
222
277
  macro.obj(publicAPI, model);
223
278
  macro.event(publicAPI, model, 'event');
224
279
  macro.get(publicAPI, model, ['xrSession']);
225
- macro.setGet(publicAPI, model, ['renderWindow']);
280
+ macro.setGet(publicAPI, model, ['renderWindow', 'drawControllersRay']);
226
281
 
227
282
  // Object methods
228
283
  vtkWebXRRenderWindowHelper(publicAPI, model);
@@ -1,5 +1,4 @@
1
1
  import vtkAbstractWidget from '../../Core/AbstractWidget';
2
2
 
3
3
  export default interface vtkResliceCursorWidgetDefaultInstance extends vtkAbstractWidget {
4
- invokeInternalInteractionEvent: () => void;
5
4
  }
@@ -135,7 +135,7 @@ function widgetBehavior(publicAPI, model) {
135
135
  const step = previousPosition.y - callData.position.y;
136
136
  publicAPI.translateCenterOnPlaneDirection(step);
137
137
  previousPosition = callData.position;
138
- publicAPI.invokeInternalInteractionEvent();
138
+ publicAPI.invokeInteractionEvent(publicAPI.getActiveInteraction());
139
139
  }
140
140
  }
141
141
  return macro.VOID;
@@ -164,7 +164,7 @@ function widgetBehavior(publicAPI, model) {
164
164
  const step = calldata.spinY;
165
165
  isScrolling = true;
166
166
  publicAPI.translateCenterOnPlaneDirection(step);
167
- publicAPI.invokeInternalInteractionEvent(
167
+ publicAPI.invokeInteractionEvent(
168
168
  // Force interaction mode because mouse cursor could be above rotation handle
169
169
  InteractionMethodsName.TranslateCenter);
170
170
  isScrolling = false;
@@ -187,20 +187,11 @@ function widgetBehavior(publicAPI, model) {
187
187
  if (model.activeState.getActive()) {
188
188
  const methodName = publicAPI.getActiveInteraction();
189
189
  publicAPI[methodName](callData);
190
- publicAPI.invokeInternalInteractionEvent(methodName);
190
+ publicAPI.invokeInteractionEvent(methodName);
191
191
  return macro.EVENT_ABORT;
192
192
  }
193
193
  return macro.VOID;
194
194
  };
195
- publicAPI.invokeInternalInteractionEvent = function () {
196
- let methodName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : publicAPI.getActiveInteraction();
197
- const computeFocalPointOffset = methodName !== InteractionMethodsName.RotateLine;
198
- const canUpdateFocalPoint = methodName === InteractionMethodsName.RotateLine;
199
- publicAPI.invokeInteractionEvent({
200
- computeFocalPointOffset,
201
- canUpdateFocalPoint
202
- });
203
- };
204
195
  publicAPI.startInteraction = () => {
205
196
  publicAPI.invokeStartInteractionEvent();
206
197
  // When interacting, plane actor and lines must be re-rendered on other views
@@ -33,7 +33,6 @@ export interface vtkResliceCursorWidget<WidgetInstance extends vtkAbstractWidget
33
33
  renderer: vtkRenderer,
34
34
  viewType: ViewTypes,
35
35
  resetFocalPoint: boolean,
36
- keepCenterFocalDistance: boolean,
37
36
  computeFocalPointOffset: boolean
38
37
  ): void;
39
38
 
@@ -215,8 +215,8 @@ function vtkResliceCursorWidget(publicAPI, model) {
215
215
  // Methods
216
216
  // --------------------------------------------------------------------------
217
217
 
218
- publicAPI.updateCameraPoints = (renderer, viewType, resetFocalPoint, keepCenterFocalDistance, computeFocalPointOffset) => {
219
- publicAPI.resetCamera(renderer, viewType, resetFocalPoint, keepCenterFocalDistance);
218
+ publicAPI.updateCameraPoints = (renderer, viewType, resetFocalPoint, computeFocalPointOffset) => {
219
+ publicAPI.resetCamera(renderer, viewType, resetFocalPoint, !computeFocalPointOffset);
220
220
  if (computeFocalPointOffset) {
221
221
  computeFocalPointOffsetFromResliceCursorCenter(viewType, renderer);
222
222
  }
package/index.d.ts CHANGED
@@ -123,6 +123,7 @@
123
123
  /// <reference path="./Interaction/Manipulators/MouseCameraTrackballZoomManipulator.d.ts" />
124
124
  /// <reference path="./Interaction/Manipulators/MouseCameraTrackballZoomToMouseManipulator.d.ts" />
125
125
  /// <reference path="./Interaction/Manipulators/MouseRangeManipulator.d.ts" />
126
+ /// <reference path="./Interaction/Style/InteractorStyleHMDXR.d.ts" />
126
127
  /// <reference path="./Interaction/Style/InteractorStyleImage.d.ts" />
127
128
  /// <reference path="./Interaction/Style/InteractorStyleManipulator.d.ts" />
128
129
  /// <reference path="./Interaction/Style/InteractorStyleTrackballCamera.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "29.11.2",
3
+ "version": "30.1.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",