bounding-box.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Vec3 } from 'mol-math/linear-algebra';
  7. import { Box3D } from 'mol-math/geometry';
  8. import { MeshBuilder } from '../mesh-builder';
  9. import { CylinderProps } from '../../../primitive/cylinder';
  10. import { addCylinder } from './cylinder';
  11. import { addSphere } from './sphere';
  12. const tmpStart = Vec3.zero()
  13. const tmpEnd = Vec3.zero()
  14. const cylinderProps: CylinderProps = {}
  15. export function addBoundingBox(state: MeshBuilder.State, box: Box3D, radius: number, detail: number, radialSegments: number) {
  16. const { min, max } = box
  17. cylinderProps.radiusTop = radius
  18. cylinderProps.radiusBottom = radius
  19. cylinderProps.radialSegments = radialSegments
  20. Vec3.set(tmpStart, max[0], max[1], max[2])
  21. addSphere(state, tmpStart, radius, detail)
  22. Vec3.set(tmpEnd, max[0], max[1], min[2])
  23. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  24. Vec3.set(tmpEnd, max[0], min[1], max[2])
  25. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  26. Vec3.set(tmpEnd, min[0], max[1], max[2])
  27. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  28. Vec3.set(tmpStart, min[0], min[1], min[2])
  29. addSphere(state, tmpStart, radius, detail)
  30. Vec3.set(tmpEnd, min[0], min[1], max[2])
  31. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  32. Vec3.set(tmpEnd, min[0], max[1], min[2])
  33. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  34. Vec3.set(tmpEnd, max[0], min[1], min[2])
  35. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  36. Vec3.set(tmpStart, max[0], min[1], min[2])
  37. addSphere(state, tmpStart, radius, detail)
  38. Vec3.set(tmpEnd, max[0], min[1], max[2])
  39. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  40. Vec3.set(tmpEnd, max[0], max[1], min[2])
  41. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  42. Vec3.set(tmpStart, min[0], min[1], max[2])
  43. addSphere(state, tmpStart, radius, detail)
  44. Vec3.set(tmpEnd, min[0], max[1], max[2])
  45. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  46. Vec3.set(tmpEnd, max[0], min[1], max[2])
  47. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  48. Vec3.set(tmpStart, min[0], max[1], min[2])
  49. addSphere(state, tmpStart, radius, detail)
  50. Vec3.set(tmpEnd, max[0], max[1], min[2])
  51. addSphere(state, tmpEnd, radius, detail)
  52. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  53. Vec3.set(tmpEnd, min[0], max[1], max[2])
  54. addSphere(state, tmpEnd, radius, detail)
  55. addCylinder(state, tmpStart, tmpEnd, 1, cylinderProps)
  56. }