|
| 1 | +import { vec3 } from 'gl-matrix'; |
| 2 | +import macro from 'vtk.js/Sources/macros'; |
| 3 | +import vtkMath from 'vtk.js/Sources/Common/Core/Math'; |
| 4 | +import { IDENTITY } from 'vtk.js/Sources/Common/Core/Math/Constants'; |
| 5 | + |
| 6 | +// ---------------------------------------------------------------------------- |
| 7 | +// vtkTransform methods |
| 8 | +// ---------------------------------------------------------------------------- |
| 9 | +// eslint-disable-next-line import/no-mutable-exports |
| 10 | +let newInstance; |
| 11 | + |
| 12 | +function vtkTransform(publicAPI, model) { |
| 13 | + // Set our className |
| 14 | + model.classHierarchy.push( |
| 15 | + 'vtkAbstractTransform', |
| 16 | + 'vtkHomogeneousTransform', |
| 17 | + 'vtkTransform' |
| 18 | + ); |
| 19 | + |
| 20 | + publicAPI.transformPoint = (point, out) => { |
| 21 | + vec3.transformMat4(out, point, model.matrix); |
| 22 | + return out; |
| 23 | + }; |
| 24 | + |
| 25 | + publicAPI.getInverse = () => |
| 26 | + newInstance({ |
| 27 | + matrix: vtkMath.invertMatrix(Array.from(model.matrix), [], 4), |
| 28 | + }); |
| 29 | +} |
| 30 | + |
| 31 | +// ---------------------------------------------------------------------------- |
| 32 | +// Object factory |
| 33 | +// ---------------------------------------------------------------------------- |
| 34 | + |
| 35 | +const DEFAULT_VALUES = { |
| 36 | + matrix: [...IDENTITY], |
| 37 | +}; |
| 38 | + |
| 39 | +// ---------------------------------------------------------------------------- |
| 40 | + |
| 41 | +export function extend(publicAPI, model, initialValues = {}) { |
| 42 | + Object.assign(model, DEFAULT_VALUES, initialValues); |
| 43 | + macro.obj(publicAPI, model); |
| 44 | + |
| 45 | + macro.setGetArray(publicAPI, model, ['matrix'], 16); |
| 46 | + |
| 47 | + vtkTransform(publicAPI, model); |
| 48 | +} |
| 49 | + |
| 50 | +// ---------------------------------------------------------------------------- |
| 51 | +newInstance = macro.newInstance(extend, 'vtkTransform'); |
| 52 | +export { newInstance }; |
| 53 | + |
| 54 | +// ---------------------------------------------------------------------------- |
| 55 | + |
| 56 | +export default { newInstance, extend }; |
0 commit comments