From 1cb14febb8b7ab2d3ff3be1a8c2ac6f4dcd3f317 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Tue, 31 Jan 2012 10:50:47 -0500 Subject: Make Geometry.flatten() idempotent and avoid loading the BVH twice when using the Camera class. --- chroma/geometry.py | 5 +++++ chroma/loader.py | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/chroma/geometry.py b/chroma/geometry.py index a7e85ee..41b24a9 100644 --- a/chroma/geometry.py +++ b/chroma/geometry.py @@ -238,6 +238,11 @@ class Geometry(object): This does not build the BVH! If you want to use the geometry for rendering or simulation, you should call build() instead. """ + + # Don't run this function twice! + if hasattr(self, 'mesh'): + return + nv = np.cumsum([0] + [len(solid.mesh.vertices) for solid in self.solids]) nt = np.cumsum([0] + [len(solid.mesh.triangles) for solid in self.solids]) diff --git a/chroma/loader.py b/chroma/loader.py index 6a0bf87..e5ff6ed 100644 --- a/chroma/loader.py +++ b/chroma/loader.py @@ -141,6 +141,7 @@ def load_bvh(geometry, bvh_name="default", bvh = None if read_bvh_cache and cache.exist_bvh(mesh_hash, bvh_name): logger.info('Loading BVH "%s" for geometry from cache.' % bvh_name) + import pdb; pdb.set_trace() bvh = cache.load_bvh(mesh_hash, bvh_name) elif auto_build_bvh: logger.info('Building new BVH using simple algorithm.') @@ -181,10 +182,11 @@ def create_geometry_from_obj(obj, bvh_name="default", geometry.flatten() - geometry.bvh = load_bvh(geometry, auto_build_bvh=auto_build_bvh, - read_bvh_cache=read_bvh_cache, - update_bvh_cache=update_bvh_cache, - cache_dir=cache_dir, - cuda_device=cuda_device) + if geometry.bvh is None: + geometry.bvh = load_bvh(geometry, auto_build_bvh=auto_build_bvh, + read_bvh_cache=read_bvh_cache, + update_bvh_cache=update_bvh_cache, + cache_dir=cache_dir, + cuda_device=cuda_device) return geometry -- cgit