axes.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Vec3, Mat4 } from '../../../../mol-math/linear-algebra';
  7. import { MeshBuilder } from '../mesh-builder';
  8. import { Axes3D } from '../../../../mol-math/geometry';
  9. import { createCage } from '../../../primitive/cage';
  10. const tmpVec = Vec3();
  11. const tmpMatrix = Mat4.identity();
  12. const tmpVertices = new Float32Array(6 * 3);
  13. const tmpEdges = new Uint8Array([0, 1, 2, 3, 4, 5]);
  14. export function addAxes(state: MeshBuilder.State, axes: Axes3D, radiusScale: number, detail: number, radialSegments: number) {
  15. const { origin, dirA, dirB, dirC } = axes;
  16. Vec3.add(tmpVec, origin, dirA);
  17. Vec3.toArray(Vec3.add(tmpVec, origin, dirA), tmpVertices, 0);
  18. Vec3.toArray(Vec3.sub(tmpVec, origin, dirA), tmpVertices, 3);
  19. Vec3.toArray(Vec3.add(tmpVec, origin, dirB), tmpVertices, 6);
  20. Vec3.toArray(Vec3.sub(tmpVec, origin, dirB), tmpVertices, 9);
  21. Vec3.toArray(Vec3.add(tmpVec, origin, dirC), tmpVertices, 12);
  22. Vec3.toArray(Vec3.sub(tmpVec, origin, dirC), tmpVertices, 15);
  23. const cage = createCage(tmpVertices, tmpEdges);
  24. const volume = Axes3D.volume(axes);
  25. const radius = (Math.cbrt(volume) / 300) * radiusScale;
  26. MeshBuilder.addCage(state, tmpMatrix, cage, radius, detail, radialSegments);
  27. }