From 8bbe5c944865dade54ae28dae3c69d174c7af10e Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Wed, 29 Aug 2018 18:04:42 -0700 Subject: [PATCH] added bounding-box to mesh-builder --- src/mol-geo/mesh/builder/bounding-box.ts | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/mol-geo/mesh/builder/bounding-box.ts diff --git a/src/mol-geo/mesh/builder/bounding-box.ts b/src/mol-geo/mesh/builder/bounding-box.ts new file mode 100644 index 000000000..ba3636045 --- /dev/null +++ b/src/mol-geo/mesh/builder/bounding-box.ts @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +import { Vec3 } from 'mol-math/linear-algebra'; +import { Box3D } from 'mol-math/geometry'; +import { MeshBuilder } from '../mesh-builder'; +import { CylinderProps } from '../../primitive/cylinder'; +import { addCylinder } from './cylinder'; +import { addSphere } from './sphere'; + +const tmpStart = Vec3.zero() +const tmpEnd = Vec3.zero() +const cylinderProps: CylinderProps = {} + +export function addBoundingBox(builder: MeshBuilder, box: Box3D, radius: number, detail: number, radialSegments: number) { + const { min, max } = box + + cylinderProps.radiusTop = radius + cylinderProps.radiusBottom = radius + cylinderProps.radialSegments = radialSegments + + Vec3.set(tmpStart, max[0], max[1], max[2]) + addSphere(builder, tmpStart, radius, detail) + Vec3.set(tmpEnd, max[0], max[1], min[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + Vec3.set(tmpEnd, max[0], min[1], max[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + Vec3.set(tmpEnd, min[0], max[1], max[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + + Vec3.set(tmpStart, min[0], min[1], min[2]) + addSphere(builder, tmpStart, radius, detail) + Vec3.set(tmpEnd, min[0], min[1], max[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + Vec3.set(tmpEnd, min[0], max[1], min[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + Vec3.set(tmpEnd, max[0], min[1], min[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + + Vec3.set(tmpStart, max[0], min[1], min[2]) + addSphere(builder, tmpStart, radius, detail) + Vec3.set(tmpEnd, max[0], min[1], max[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + Vec3.set(tmpEnd, max[0], max[1], min[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + + Vec3.set(tmpStart, min[0], min[1], max[2]) + addSphere(builder, tmpStart, radius, detail) + Vec3.set(tmpEnd, min[0], max[1], max[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + Vec3.set(tmpEnd, max[0], min[1], max[2]) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + + Vec3.set(tmpStart, min[0], max[1], min[2]) + addSphere(builder, tmpStart, radius, detail) + Vec3.set(tmpEnd, max[0], max[1], min[2]) + addSphere(builder, tmpEnd, radius, detail) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) + Vec3.set(tmpEnd, min[0], max[1], max[2]) + addSphere(builder, tmpEnd, radius, detail) + addCylinder(builder, tmpStart, tmpEnd, 1, cylinderProps) +} \ No newline at end of file -- GitLab