def import_nitristrips(self, bhk_shape): """Import a NiTriStrips block as a Triangle-Mesh collision object""" # no factor 7 correction!!! verts = [(v.x, v.y, v.z) for v in bhk_shape.vertices] faces = list(bhk_shape.get_triangles()) b_obj = Object.mesh_from_data("poly", verts, faces) # TODO [collision] self.havok_mat! self.set_b_collider(b_obj, bounds_type="MESH", radius=bhk_shape.radius) return [b_obj]
def import_bhkconvex_vertices_shape(self, bhk_shape): """Import a BhkConvexVertex block as a convex hull collision object""" NifLog.debug(f"Importing {bhk_shape.__class__.__name__}") # find vertices (and fix scale) scaled_verts = [(self.HAVOK_SCALE * n_vert.x, self.HAVOK_SCALE * n_vert.y, self.HAVOK_SCALE * n_vert.z) for n_vert in bhk_shape.vertices] verts, faces = qhull3d(scaled_verts) b_obj = Object.mesh_from_data("convexpoly", verts, faces) radius = bhk_shape.radius * self.HAVOK_SCALE self.set_b_collider(b_obj, bounds_type="CONVEX_HULL", radius=radius, n_obj=bhk_shape) return [b_obj]
def import_bhkpackednitristrips_shape(self, bhk_shape): """Import a BhkPackedNiTriStrips block as a Triangle-Mesh collision object""" NifLog.debug(f"Importing {bhk_shape.__class__.__name__}") # create mesh for each sub shape hk_objects = [] vertex_offset = 0 subshapes = bhk_shape.sub_shapes if not subshapes: # fallout 3 stores them in the data subshapes = bhk_shape.data.sub_shapes for subshape_num, subshape in enumerate(subshapes): verts = [] faces = [] for vert_index in range(vertex_offset, vertex_offset + subshape.num_vertices): n_vert = bhk_shape.data.vertices[vert_index] verts.append( (n_vert.x * self.HAVOK_SCALE, n_vert.y * self.HAVOK_SCALE, n_vert.z * self.HAVOK_SCALE)) for bhk_triangle in bhk_shape.data.triangles: bhk_tri = bhk_triangle.triangle if (vertex_offset <= bhk_tri.v_1) and ( bhk_tri.v_1 < vertex_offset + subshape.num_vertices): faces.append((bhk_tri.v_1 - vertex_offset, bhk_tri.v_2 - vertex_offset, bhk_tri.v_3 - vertex_offset)) else: continue b_obj = Object.mesh_from_data(f'poly{subshape_num:d}', verts, faces) radius = min(vert.co.length for vert in b_obj.data.vertices) self.set_b_collider(b_obj, bounds_type="MESH", radius=radius, n_obj=subshape) vertex_offset += subshape.num_vertices hk_objects.append(b_obj) return hk_objects