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 vtkOpenGLCamera(publicAPI, model) { model.classHierarchy.push('vtkOpenGLCamera');
publicAPI.buildPass = (prepass) => { if (prepass) { model._openGLRenderer = publicAPI.getFirstAncestorOfType('vtkOpenGLRenderer'); model._openGLRenderWindow = model._openGLRenderer.getParent(); model.context = model._openGLRenderWindow.getContext(); } };
publicAPI.opaquePass = (prepass) => { if (prepass) { const tsize = model._openGLRenderer.getTiledSizeAndOrigin(); model.context.viewport( tsize.lowerLeftU, tsize.lowerLeftV, tsize.usize, tsize.vsize ); model.context.scissor( tsize.lowerLeftU, tsize.lowerLeftV, tsize.usize, tsize.vsize ); } }; publicAPI.translucentPass = publicAPI.opaquePass; publicAPI.zBufferPass = publicAPI.opaquePass; publicAPI.opaqueZBufferPass = publicAPI.opaquePass; publicAPI.volumePass = publicAPI.opaquePass;
publicAPI.getKeyMatrices = (ren) => { if ( ren !== model.lastRenderer || model._openGLRenderWindow.getMTime() > model.keyMatrixTime.getMTime() || publicAPI.getMTime() > model.keyMatrixTime.getMTime() || ren.getMTime() > model.keyMatrixTime.getMTime() || model.renderable.getMTime() > model.keyMatrixTime.getMTime() ) { mat4.copy(model.keyMatrices.wcvc, model.renderable.getViewMatrix());
mat3.fromMat4(model.keyMatrices.normalMatrix, model.keyMatrices.wcvc); mat3.invert( model.keyMatrices.normalMatrix, model.keyMatrices.normalMatrix ); mat4.transpose(model.keyMatrices.wcvc, model.keyMatrices.wcvc);
const aspectRatio = model._openGLRenderer.getAspectRatio();
mat4.copy( model.keyMatrices.vcpc, model.renderable.getProjectionMatrix(aspectRatio, -1, 1) ); mat4.transpose(model.keyMatrices.vcpc, model.keyMatrices.vcpc);
mat4.multiply( model.keyMatrices.wcpc, model.keyMatrices.vcpc, model.keyMatrices.wcvc );
model.keyMatrixTime.modified(); model.lastRenderer = ren; }
return model.keyMatrices; }; }
const DEFAULT_VALUES = { context: null, lastRenderer: null, keyMatrixTime: null, keyMatrices: null, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
vtkViewNode.extend(publicAPI, model, initialValues);
model.keyMatrixTime = {}; macro.obj(model.keyMatrixTime);
model.keyMatrices = { normalMatrix: new Float64Array(9), vcpc: new Float64Array(16), wcvc: new Float64Array(16), wcpc: new Float64Array(16), };
macro.setGet(publicAPI, model, ['context', 'keyMatrixTime']);
vtkOpenGLCamera(publicAPI, model); }
export const newInstance = macro.newInstance(extend);
export default { newInstance, extend };
registerOverride('vtkCamera', newInstance);
|