def import_bhkconvex_vertices_shape(self, bhkshape, upbflags="", bsxflags=2): """Import a BhkConvexVertex block as a convex hull collision object""" # find vertices (and fix scale) n_vertices, n_triangles = qhull3d([ (self.nif_common.HAVOK_SCALE * n_vert.x, self.nif_common.HAVOK_SCALE * n_vert.y, self.nif_common.HAVOK_SCALE * n_vert.z) for n_vert in bhkshape.vertices ]) # create convex mesh b_mesh = bpy.data.meshes.new('convexpoly') for n_vert in n_vertices: b_mesh.vertices.add(1) b_mesh.vertices[-1].co = n_vert for n_triangle in n_triangles: b_mesh.faces.add(1) b_mesh.faces[-1].vertices = n_triangle # link mesh to scene and set transform b_obj = bpy.data.objects.new('Convexpoly', b_mesh) bpy.context.scene.objects.link(b_obj) b_obj.show_wire = True b_obj.draw_type = 'WIRE' b_obj.game.use_collision_bounds = True b_obj.game.collision_bounds_type = 'CONVEX_HULL' # radius: quick estimate b_obj.game.radius = max(vert.co.length for vert in b_mesh.vertices) b_obj.nifcollision.havok_material = NifFormat.HavokMaterial._enumkeys[ bhkshape.material] # also remove duplicate vertices numverts = len(b_mesh.vertices) # 0.005 = 1/200 ''' numdel = b_mesh.remove_doubles(0.005) if numdel: self.info( "Removed %i duplicate vertices" " (out of %i) from collision mesh" % (numdel, numverts)) ''' # Recalculate mesh to render correctly b_mesh.update() b_mesh.calc_normals() 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_bhkconvex_vertices_shape(self, bhkshape, upbflags="", bsxflags=2): """Import a BhkConvexVertex block as a convex hull collision object""" # find vertices (and fix scale) n_vertices, n_triangles = qhull3d( [ (self.nif_common.HAVOK_SCALE * n_vert.x, self.nif_common.HAVOK_SCALE * n_vert.y, self.nif_common.HAVOK_SCALE * n_vert.z) for n_vert in bhkshape.vertices ]) # create convex mesh b_mesh = bpy.data.meshes.new('convexpoly') for n_vert in n_vertices: b_mesh.vertices.add(1) b_mesh.vertices[-1].co = n_vert for n_triangle in n_triangles: b_mesh.faces.add(1) b_mesh.faces[-1].vertices = n_triangle # link mesh to scene and set transform b_obj = bpy.data.objects.new('Convexpoly', b_mesh) bpy.context.scene.objects.link(b_obj) b_obj.show_wire = True b_obj.draw_type = 'WIRE' b_obj.game.use_collision_bounds = True b_obj.game.collision_bounds_type = 'CONVEX_HULL' # radius: quick estimate b_obj.game.radius = max(vert.co.length for vert in b_mesh.vertices) b_obj.nifcollision.havok_material = NifFormat.HavokMaterial._enumkeys[bhkshape.material] # also remove duplicate vertices numverts = len(b_mesh.vertices) # 0.005 = 1/200 ''' numdel = b_mesh.remove_doubles(0.005) if numdel: self.info( "Removed %i duplicate vertices" " (out of %i) from collision mesh" % (numdel, numverts)) ''' # Recalculate mesh to render correctly b_mesh.update() b_mesh.calc_normals() return [ b_obj ]
def import_bhkconvex_vertices_shape(self, bhkshape): """Import a BhkConvexVertex block as a convex hull collision object""" # find vertices (and fix scale) n_vertices, n_triangles = qhull3d([ (self.HAVOK_SCALE * n_vert.x, self.HAVOK_SCALE * n_vert.y, self.HAVOK_SCALE * n_vert.z) for n_vert in bhkshape.vertices ]) # create convex mesh b_mesh = bpy.data.meshes.new('convexpoly') for n_vert in n_vertices: b_mesh.vertices.add(1) b_mesh.vertices[-1].co = n_vert poly_gens = n_triangles b_mesh = poly_gen.col_poly_gen(b_mesh, poly_gens) # link mesh to scene and set transform b_obj = bpy.data.objects.new('Convexpoly', b_mesh) bpy.context.scene.objects.link(b_obj) scn = bpy.context.scene scn.objects.active = b_obj b_obj.show_wire = True b_obj.draw_type = 'WIRE' b_obj.draw_bounds_type = 'BOX' b_obj.game.use_collision_bounds = True b_obj.game.collision_bounds_type = 'CONVEX_HULL' # radius: quick estimate b_obj.game.radius = bhkshape.radius b_obj_nif_collision = b_obj.nifcollision self.nif_import.get_havok_material(bhkshape.material.material, b_obj_nif_collision) # Recalculate mesh to render correctly b_mesh = b_obj.data b_mesh.validate() b_mesh.update() b_obj.select = True return [b_obj]
def import_bhkconvex_vertices_shape(self, bhkshape): """Import a BhkConvexVertex block as a convex hull collision object""" # find vertices (and fix scale) verts, faces = qhull3d( [ (self.HAVOK_SCALE * n_vert.x, self.HAVOK_SCALE * n_vert.y, self.HAVOK_SCALE * n_vert.z) for n_vert in bhkshape.vertices ]) b_obj = mesh_from_data("convexpoly", verts, faces) b_obj.show_wire = True b_obj.draw_type = 'WIRE' b_obj.draw_bounds_type = 'BOX' b_obj.game.use_collision_bounds = True b_obj.game.collision_bounds_type = 'CONVEX_HULL' # radius: quick estimate b_obj.game.radius = bhkshape.radius b_obj.nifcollision.havok_material = NifFormat.HavokMaterial._enumkeys[bhkshape.material] return [ b_obj ]