import { mat4 } from 'gl-matrix';
import macro from 'vtk.js/Sources/macros'; import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop'; import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode';
import { registerOverride } from 'vtk.js/Sources/Rendering/WebGPU/ViewNodeFactory';
const { CoordinateSystem } = vtkProp;
function vtkWebGPUActor(publicAPI, model) { model.classHierarchy.push('vtkWebGPUActor');
publicAPI.buildPass = (prepass) => { if (prepass) { model.WebGPURenderer = publicAPI.getFirstAncestorOfType('vtkWebGPURenderer'); model.WebGPURenderWindow = model.WebGPURenderer.getFirstAncestorOfType( 'vtkWebGPURenderWindow' ); if (model.propID === undefined) { model.propID = model.WebGPURenderWindow.getUniquePropID(); } publicAPI.prepareNodes(); publicAPI.addMissingNode(model.renderable.getMapper()); publicAPI.removeUnusedNodes(); } };
publicAPI.traverseOpaquePass = (renderPass) => { if ( !model.renderable || !model.renderable.getNestedVisibility() || !model.renderable.getIsOpaque() || (model.WebGPURenderer.getSelector() && !model.renderable.getNestedPickable()) ) { return; }
publicAPI.apply(renderPass, true);
if (model.children[0]) { model.children[0].traverse(renderPass); }
publicAPI.apply(renderPass, false); };
publicAPI.traverseTranslucentPass = (renderPass) => { if ( !model.renderable || !model.renderable.getNestedVisibility() || model.renderable.getIsOpaque() || (model.WebGPURenderer.getSelector() && !model.renderable.getNestedPickable()) ) { return; }
publicAPI.apply(renderPass, true);
if (model.children[0]) { model.children[0].traverse(renderPass); }
publicAPI.apply(renderPass, false); };
publicAPI.queryPass = (prepass, renderPass) => { if (prepass) { if (!model.renderable || !model.renderable.getVisibility()) { return; } if (model.renderable.getIsOpaque()) { renderPass.incrementOpaqueActorCount(); } else { renderPass.incrementTranslucentActorCount(); } } };
publicAPI.getBufferShift = (wgpuRen) => { publicAPI.getKeyMatrices(wgpuRen); return model.bufferShift; };
publicAPI.getKeyMatrices = (wgpuRen) => { if ( Math.max(model.renderable.getMTime(), wgpuRen.getStabilizedTime()) > model.keyMatricesTime.getMTime() ) { model.renderable.computeMatrix();
const mcwc = model.renderable.getMatrix();
model.bufferShift[0] = mcwc[3]; model.bufferShift[1] = mcwc[7]; model.bufferShift[2] = mcwc[11]; const center = wgpuRen.getStabilizedCenterByReference(); if (model.renderable.getCoordinateSystem() === CoordinateSystem.WORLD) { model.bufferShift[0] -= center[0]; model.bufferShift[1] -= center[1]; model.bufferShift[2] -= center[2]; }
mat4.transpose(model.keyMatrices.bcwc, mcwc);
if (model.renderable.getIsIdentity()) { mat4.identity(model.keyMatrices.normalMatrix); } else { mat4.copy(model.keyMatrices.normalMatrix, model.keyMatrices.bcwc); model.keyMatrices.normalMatrix[3] = 0.0; model.keyMatrices.normalMatrix[7] = 0.0; model.keyMatrices.normalMatrix[11] = 0.0; mat4.invert( model.keyMatrices.normalMatrix, model.keyMatrices.normalMatrix ); mat4.transpose( model.keyMatrices.normalMatrix, model.keyMatrices.normalMatrix ); }
mat4.translate(model.keyMatrices.bcwc, model.keyMatrices.bcwc, [ -model.bufferShift[0], -model.bufferShift[1], -model.bufferShift[2], ]);
if (model.renderable.getCoordinateSystem() === CoordinateSystem.WORLD) { mat4.translate(model.keyMatrices.bcsc, model.keyMatrices.bcwc, [ -center[0], -center[1], -center[2], ]); } else { mat4.copy(model.keyMatrices.bcsc, model.keyMatrices.bcwc); }
model.keyMatricesTime.modified(); }
return model.keyMatrices; }; }
const DEFAULT_VALUES = { keyMatricesTime: null, keyMatrices: null, propID: undefined, bufferShift: undefined, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
vtkViewNode.extend(publicAPI, model, initialValues);
model.keyMatricesTime = {}; macro.obj(model.keyMatricesTime, { mtime: 0 }); model.keyMatrices = { normalMatrix: new Float64Array(16), bcwc: new Float64Array(16), bcsc: new Float64Array(16), };
macro.get(publicAPI, model, ['propID', 'keyMatricesTime']);
model.bufferShift = [0, 0, 0, 0];
vtkWebGPUActor(publicAPI, model); }
export const newInstance = macro.newInstance(extend);
export default { newInstance, extend };
registerOverride('vtkActor', newInstance);
|