diff options
author | Stan Seibert <stan@mtrr.org> | 2012-01-31 10:50:47 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:38 -0700 |
commit | 1cb14febb8b7ab2d3ff3be1a8c2ac6f4dcd3f317 (patch) | |
tree | e8c182609610fd7cb59f2089618be4ec62472cad | |
parent | 9562e103e310d7861676d88a711a51ebce5fb4ea (diff) | |
download | chroma-1cb14febb8b7ab2d3ff3be1a8c2ac6f4dcd3f317.tar.gz chroma-1cb14febb8b7ab2d3ff3be1a8c2ac6f4dcd3f317.tar.bz2 chroma-1cb14febb8b7ab2d3ff3be1a8c2ac6f4dcd3f317.zip |
Make Geometry.flatten() idempotent and avoid loading the BVH twice when using the Camera class.
-rw-r--r-- | chroma/geometry.py | 5 | ||||
-rw-r--r-- | 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 |