import { mat3, mat4 } from 'gl-matrix';
import * as macro from 'vtk.js/Sources/macros'; import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode';
import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory';
function vtkOpenGLActor(publicAPI, model) { model.classHierarchy.push('vtkOpenGLActor');
publicAPI.buildPass = (prepass) => { if (prepass) { model._openGLRenderWindow = publicAPI.getLastAncestorOfType( 'vtkOpenGLRenderWindow' ); model._openGLRenderer = publicAPI.getFirstAncestorOfType('vtkOpenGLRenderer'); model.context = model._openGLRenderWindow.getContext(); publicAPI.prepareNodes(); publicAPI.addMissingNodes(model.renderable.getTextures()); publicAPI.addMissingNode(model.renderable.getMapper()); publicAPI.removeUnusedNodes();
model.ogltextures = null; model.activeTextures = null; for (let index = 0; index < model.children.length; index++) { const child = model.children[index]; if (child.isA('vtkOpenGLTexture')) { if (!model.ogltextures) { model.ogltextures = []; } model.ogltextures.push(child); } else { model.oglmapper = child; } } } };
publicAPI.traverseZBufferPass = (renderPass) => { if ( !model.renderable || !model.renderable.getNestedVisibility() || (model._openGLRenderer.getSelector() && !model.renderable.getNestedPickable()) ) { return; }
publicAPI.apply(renderPass, true); model.oglmapper.traverse(renderPass);
publicAPI.apply(renderPass, false); };
publicAPI.traverseOpaqueZBufferPass = (renderPass) => publicAPI.traverseOpaquePass(renderPass);
publicAPI.traverseOpaquePass = (renderPass) => { if ( !model.renderable || !model.renderable.getNestedVisibility() || !model.renderable.getIsOpaque() || (model._openGLRenderer.getSelector() && !model.renderable.getNestedPickable()) ) { return; }
publicAPI.apply(renderPass, true);
model.oglmapper.traverse(renderPass);
publicAPI.apply(renderPass, false); };
publicAPI.traverseTranslucentPass = (renderPass) => { if ( !model.renderable || !model.renderable.getNestedVisibility() || model.renderable.getIsOpaque() || (model._openGLRenderer.getSelector() && !model.renderable.getNestedPickable()) ) { return; }
publicAPI.apply(renderPass, true);
model.oglmapper.traverse(renderPass);
publicAPI.apply(renderPass, false); };
publicAPI.activateTextures = () => { if (!model.ogltextures) { return; }
model.activeTextures = []; for (let index = 0; index < model.ogltextures.length; index++) { const child = model.ogltextures[index]; child.render(); if (child.getHandle()) { model.activeTextures.push(child); } } };
publicAPI.queryPass = (prepass, renderPass) => { if (prepass) { if (!model.renderable || !model.renderable.getVisibility()) { return; } if (model.renderable.getIsOpaque()) { renderPass.incrementOpaqueActorCount(); } else { renderPass.incrementTranslucentActorCount(); } } };
publicAPI.zBufferPass = (prepass, renderPass) => publicAPI.opaquePass(prepass, renderPass);
publicAPI.opaqueZBufferPass = (prepass, renderPass) => publicAPI.opaquePass(prepass, renderPass);
publicAPI.opaquePass = (prepass, renderPass) => { if (prepass) { model.context.depthMask(true); publicAPI.activateTextures(); } else if (model.activeTextures) { for (let index = 0; index < model.activeTextures.length; index++) { model.activeTextures[index].deactivate(); } } };
publicAPI.translucentPass = (prepass, renderPass) => { if (prepass) { model.context.depthMask( model._openGLRenderer.getSelector() && model.renderable.getNestedPickable() ); publicAPI.activateTextures(); } else if (model.activeTextures) { for (let index = 0; index < model.activeTextures.length; index++) { model.activeTextures[index].deactivate(); } } };
publicAPI.getKeyMatrices = () => { if (model.renderable.getMTime() > model.keyMatrixTime.getMTime()) { model.renderable.computeMatrix(); mat4.copy(model.keyMatrices.mcwc, model.renderable.getMatrix()); mat4.transpose(model.keyMatrices.mcwc, model.keyMatrices.mcwc);
if (model.renderable.getIsIdentity()) { mat3.identity(model.keyMatrices.normalMatrix); } else { mat3.fromMat4(model.keyMatrices.normalMatrix, model.keyMatrices.mcwc); mat3.invert( model.keyMatrices.normalMatrix, model.keyMatrices.normalMatrix ); mat3.transpose( model.keyMatrices.normalMatrix, model.keyMatrices.normalMatrix ); } model.keyMatrixTime.modified(); }
return model.keyMatrices; }; }
const DEFAULT_VALUES = { context: null, keyMatrixTime: null, keyMatrices: null, activeTextures: null, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
vtkViewNode.extend(publicAPI, model, initialValues);
model.keyMatrixTime = {}; macro.obj(model.keyMatrixTime, { mtime: 0 }); model.keyMatrices = { normalMatrix: mat3.identity(new Float64Array(9)), mcwc: mat4.identity(new Float64Array(16)), };
macro.setGet(publicAPI, model, ['context']);
macro.get(publicAPI, model, ['activeTextures']);
vtkOpenGLActor(publicAPI, model); }
export const newInstance = macro.newInstance(extend);
export default { newInstance, extend };
registerOverride('vtkActor', newInstance);
|