modeling/src/geometries/geom3/transform.js

  1. const mat4 = require('../../maths/mat4')
  2. /**
  3. * Transform the given geometry using the given matrix.
  4. * This is a lazy transform of the polygons, as this function only adjusts the transforms.
  5. * See applyTransforms() for the actual application of the transforms to the polygons.
  6. * @param {mat4} matrix - the matrix to transform with
  7. * @param {geom3} geometry - the geometry to transform
  8. * @returns {geom3} a new geometry
  9. * @alias module:modeling/geometries/geom3.transform
  10. *
  11. * @example
  12. * let newgeometry = transform(fromXRotation(degToRad(90)), geometry)
  13. */
  14. const transform = (matrix, geometry) => {
  15. const transforms = mat4.multiply(mat4.create(), matrix, geometry.transforms)
  16. return Object.assign({}, geometry, { transforms })
  17. }
  18. module.exports = transform