def make_collision_from_model(input_model, node_number, mass, world, target_pos, h_adj): # tristrip generation from static models # generic tri-strip collision generator begins geom_nodes = input_model.find_all_matches('**/+GeomNode') geom_nodes = geom_nodes.get_path(node_number).node() # print(geom_nodes) geom_target = geom_nodes.get_geom(0) # print(geom_target) output_bullet_mesh = BulletTriangleMesh() output_bullet_mesh.add_geom(geom_target) tri_shape = BulletTriangleMeshShape(output_bullet_mesh, dynamic=False) print(output_bullet_mesh) body = BulletRigidBodyNode('input_model_tri_mesh') np = self.render.attach_new_node(body) np.node().add_shape(tri_shape) np.node().set_mass(mass) np.node().set_friction(0.01) np.set_pos(target_pos) np.set_scale(1) np.set_h(h_adj) # np.set_p(180) # np.set_r(180) np.set_collide_mask(BitMask32.allOn()) world.attach_rigid_body(np.node())
def setup_world(self): self.world_node = self.render.attachNewNode('World') self.world.setGravity(Vec3(0, 0, -9.81)) # Landscape model = self.loader.loadModel("mesh/models/landscape/landscape") model.reparentTo(self.render) model.setScale(100) model.flatten_light() geom_nodes = model.findAllMatches('**/+GeomNode') geom_node = geom_nodes.getPath(0).node() geom_mesh = geom_node.getGeom(0) mesh = BulletTriangleMesh() mesh.add_geom(geom_mesh) ground_shape = BulletTriangleMeshShape(mesh, dynamic=False) ground_node = self.world_node.attachNewNode( BulletRigidBodyNode('Ground')) ground_node.node().addShape(ground_shape) ''' if self.debug_mode: debug_node_path = self.world_node.attachNewNode(BulletDebugNode('Debug')) debug_node_path.show() debug_node_path.node().showNormals(True) self.world.setDebugNode(debug_node_path.node()) ''' self.debug_node_path = self.world_node.attachNewNode( BulletDebugNode('Debug')) self.debug_node_path.hide() self.world.setDebugNode(self.debug_node_path.node()) ground_node.setPos(0, 0, 0) ground_node.setCollideMask(BitMask32.allOn()) self.world.attachRigidBody(ground_node.node()) # Character player = Player() # Other models path = 'mesh/models/bullet/pyramid' self.add_model(path, pos_x=50, pos_y=15, pos_z=370, scale=5) self.add_model(path, pos_x=30, pos_y=15, pos_z=370, scale=5) self.add_model(path, pos_x=70, pos_y=15, pos_z=390, scale=5) self.add_model(path, pos_x=50, pos_y=40, pos_z=360, scale=5) path = 'mesh/models/bullet/ball' self.add_model(path, pos_x=0, pos_y=15, pos_z=400, scale=8) self.add_model(path, pos_x=30, pos_y=40, pos_z=450, scale=8) taskMgr.add(self.update, 'updateWorld')