diff --git a/src/mol-geo/shape/mesh-builder.ts b/src/mol-geo/shape/mesh-builder.ts index 1236736cce4e310e301bbe6fbc0a37a074f7d054..5efda4e2a1514e8f8eeb12b87a11eb871cb5dc06 100644 --- a/src/mol-geo/shape/mesh-builder.ts +++ b/src/mol-geo/shape/mesh-builder.ts @@ -45,6 +45,7 @@ export namespace MeshBuilder { let currentId = -1 + const cylinderMap = new Map<string, Primitive>() const icosahedronMap = new Map<string, Primitive>() const add = (t: Mat4, _vertices: Float32Array, _normals: Float32Array, _indices: Uint32Array) => { @@ -75,7 +76,12 @@ export namespace MeshBuilder { return add(t, box.vertices, box.normals, box.indices) }, addCylinder: (t: Mat4, props?: CylinderProps) => { - const cylinder = Cylinder(props) + const key = JSON.stringify(props) + let cylinder = cylinderMap.get(key) + if (cylinder === undefined) { + cylinder = Cylinder(props) + cylinderMap.set(key, cylinder) + } return add(t, cylinder.vertices, cylinder.normals, cylinder.indices) }, addIcosahedron: (t: Mat4, props: IcosahedronProps) => {