From 6fd00e31a7dd69bc5a6c6b7f93421db184b31580 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Wed, 20 Jun 2018 11:07:07 -0700
Subject: [PATCH] cache cylinder primitive

---
 src/mol-geo/shape/mesh-builder.ts | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/mol-geo/shape/mesh-builder.ts b/src/mol-geo/shape/mesh-builder.ts
index 1236736cc..5efda4e2a 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) => {
-- 
GitLab