diff options
Diffstat (limited to 'geometry.py')
| -rw-r--r-- | geometry.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/geometry.py b/geometry.py index 875d403..c76b089 100644 --- a/geometry.py +++ b/geometry.py @@ -58,7 +58,7 @@ class Mesh(object): return Mesh(np.concatenate((self.vertices, other.vertices)), np.concatenate((self.triangles, other.triangles + len(self.vertices)))) class Solid(object): - def __init__(self, mesh, material1=None, material2=None, surface=None, color=0xffffffff): + def __init__(self, mesh, material1=None, material2=None, surface=None, color=0xffffff): self.mesh = mesh if np.iterable(material1): @@ -349,7 +349,19 @@ class Geometry(object): if unique_bit_shifted_zvalues.size == 1: break - def load(self, module, color=False): + def load_colors(self, module): + self.colors = \ + np.concatenate([solid.color for solid in self.solids])[reorder] + + if not hasattr(self, 'colors_gpu'): + raise Exception('cannot load colors before geometry is loaded.') + + self.colors_gpu.set(self.colors.astype(np.uint32)) + + set_colors = module.get_function('set_colors') + set_colors(self.colors_gpu, block=(1,1,1), grid=(1,1)) + + def load(self, module): """ Load the bounding volume hierarchy onto the GPU module, bind it to the appropriate textures, and return a list @@ -404,11 +416,7 @@ class Geometry(object): triangles['x'] = self.mesh.triangles[:,0] triangles['y'] = self.mesh.triangles[:,1] triangles['z'] = self.mesh.triangles[:,2] - - if color: - triangles['w'] = self.colors - else: - triangles['w'] = ((self.material1_index & 0xff) << 24) | ((self.material2_index & 0xff) << 16) | ((self.surface_index & 0xff) << 8) + triangles['w'] = ((self.material1_index & 0xff) << 24) | ((self.material2_index & 0xff) << 16) | ((self.surface_index & 0xff) << 8) lower_bounds = np.empty(self.lower_bounds.shape[0], dtype=gpuarray.vec.float4) lower_bounds['x'] = self.lower_bounds[:,0] @@ -422,6 +430,7 @@ class Geometry(object): self.vertices_gpu = cuda.to_device(vertices) self.triangles_gpu = cuda.to_device(triangles) + self.colors_gpu = gpuarray.to_gpu(self.colors.astype(np.uint32)) self.lower_bounds_gpu = cuda.to_device(lower_bounds) self.upper_bounds_gpu = cuda.to_device(upper_bounds) self.node_map_gpu = cuda.to_device(self.node_map) @@ -449,12 +458,8 @@ class Geometry(object): print format_array('node_length', self.node_length) print '%-15s %6s %6s' % ('total', '', format_size(vertices.nbytes + triangles.nbytes + self.lower_bounds.nbytes + self.upper_bounds.nbytes + self.node_map.nbytes + self.node_length.nbytes)) - #set_pointer = module.get_function('set_pointer') - #set_pointer(self.triangles_gpu, self.vertices_gpu, - # block=(1,1,1), grid=(1,1)) - set_global_mesh_variables = module.get_function('set_global_mesh_variables') - set_global_mesh_variables(self.triangles_gpu, self.vertices_gpu, np.int32(self.node_map.size-1), np.int32(self.first_node), block=(1,1,1), grid=(1,1)) + set_global_mesh_variables(self.triangles_gpu, self.vertices_gpu, self.colors_gpu, np.uint32(self.node_map.size-1), np.uint32(self.first_node), block=(1,1,1), grid=(1,1)) self.lower_bounds_tex = module.get_texref('lower_bounds') self.upper_bounds_tex = module.get_texref('upper_bounds') |
