コード例 #1
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(False)

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attach_new_node(bodyA)
        bodyNP.node().add_shape(shape)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(-3, 0, 4)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyA)

        # Box B
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attach_new_node(bodyB)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(1.0)
        bodyNP.node().set_deactivation_enabled(False)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(0, 0, 0)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyB)

        # Slider
        frameA = TransformState.make_pos_hpr(LPoint3(2, 0, 0),
                                             LVector3(0, 0, 45))
        frameB = TransformState.make_pos_hpr(LPoint3(0, -3, 0),
                                             LVector3(0, 0, 0))

        slider = BulletSliderConstraint(bodyA, bodyB, frameA, frameB, True)
        slider.set_debug_draw_size(2.0)
        slider.set_lower_linear_limit(0)
        slider.set_upper_linear_limit(6)
        slider.set_lower_angular_limit(-60)
        slider.set_upper_angular_limit(60)
        self.world.attach(slider)
コード例 #2
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(False)

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attach_new_node(bodyA)
        bodyNP.node().add_shape(shape)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(-2, 0, 1)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyA)

        # Box B
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attach_new_node(bodyB)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(1.0)
        bodyNP.node().set_deactivation_enabled(False)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(2, 0, 1)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyB)

        # Hinge
        pivotA = LPoint3(2, 0, 0)
        pivotB = LPoint3(-4, 0, 0)
        axisA = LVector3(0, 0, 1)
        axisB = LVector3(0, 0, 1)

        hinge = BulletHingeConstraint(bodyA, bodyB, pivotA, pivotB, axisA,
                                      axisB, True)
        hinge.set_debug_draw_size(2.0)
        hinge.set_limit(-90, 120, softness=0.9, bias=0.3, relaxation=1.0)
        self.world.attach(hinge)
コード例 #3
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        shape = BulletPlaneShape(LVector3(0, 0, 1), 0)

        #img = PNMImage(Filename('models/elevation.png'))
        #shape = BulletHeightfieldShape(img, 1.0, ZUp)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Ground'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -1)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Box
        shape = BulletBoxShape(LVector3(1.0, 3.0, 0.3))

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Box'))
        np.node().set_mass(10.0)
        np.node().add_shape(shape)
        np.set_pos(3, 0, 4)
        np.setH(20.0)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Character
        self.crouching = False

        h = 1.75
        w = 0.4
        shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
        self.character = BulletCharacterControllerNode(shape, 0.4, 'Player')
        self.characterNP = self.worldNP.attach_new_node(self.character)
        self.characterNP.set_pos(-2, 0, 14)
        self.characterNP.set_h(45)
        self.characterNP.set_collide_mask(BitMask32.all_on())
        self.world.attach(self.character)

        self.actorNP = Actor(
            'samples/roaming-ralph/models/ralph.egg.pz', {
                'run': 'samples/roaming-ralph/models/ralph-run.egg.pz',
                'walk': 'samples/roaming-ralph/models/ralph-walk.egg.pz'
            })
        self.actorNP.reparent_to(self.characterNP)
        self.actorNP.set_scale(0.3048)  # 1ft = 0.3048m
        self.actorNP.setH(180)
        self.actorNP.set_pos(0, 0, -1)
コード例 #4
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(False)

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attach_new_node(bodyA)
        bodyNP.node().add_shape(shape)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(-2, 0, 4)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyA)

        # Box B
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attach_new_node(bodyB)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(1.0)
        bodyNP.node().set_deactivation_enabled(False)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(0, 0, 0)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyB)

        # Cone
        frameA = TransformState.make_pos_hpr(LPoint3(0, 0, -2),
                                             LVector3(0, 0, 90))
        frameB = TransformState.make_pos_hpr(LPoint3(-5, 0, 0),
                                             LVector3(0, 0, 0))

        cone = BulletConeTwistConstraint(bodyA, bodyB, frameA, frameB)
        cone.set_debug_draw_size(2.0)
        cone.set_limit(30, 45, 170, softness=1.0, bias=0.3, relaxation=8.0)
        self.world.attach(cone)
コード例 #5
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(False)

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Box A
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyA = BulletRigidBodyNode('Box A')
        bodyNP = self.worldNP.attach_new_node(bodyA)
        bodyNP.node().add_shape(shape)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(-1, 0, 4)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyA)

        # Box B
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        bodyB = BulletRigidBodyNode('Box B')
        bodyNP = self.worldNP.attach_new_node(bodyB)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(1.0)
        bodyNP.node().set_deactivation_enabled(False)
        bodyNP.node().setLinearDamping(0.6)
        bodyNP.node().setAngularDamping(0.6)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(2, 0, 0)

        visNP = loader.load_model('models/box.egg')
        visNP.clear_model_nodes()
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyB)

        # Spherical Constraint
        pivotA = LPoint3(2, 0, 0)
        pivotB = LPoint3(0, 0, 4)

        joint = BulletSphericalConstraint(bodyA, bodyB, pivotA, pivotB)
        joint.set_debug_draw_size(2.0)
        self.world.attach(joint)
コード例 #6
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Plane
        shape = BulletPlaneShape(LVector3(0, 0, 1), 0)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Ground'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -1)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Box
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Box'))
        np.node().set_mass(1.0)
        np.node().add_shape(shape)
        np.node().set_deactivation_enabled(False)
        np.set_pos(2, 0, 4)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        visualNP = loader.load_model('models/box.egg')
        visualNP.reparent_to(np)

        self.box = np.node()

        # Sphere
        shape = BulletSphereShape(0.6)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Sphere'))
        np.node().set_mass(1.0)
        np.node().add_shape(shape)
        np.set_pos(-2, 0, 4)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        self.sphere = np.node()
コード例 #7
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(True)

        #self.debugNP.show_tight_bounds()
        #self.debugNP.show_bounds()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground (static)
        shape = BulletPlaneShape(LVector3(0, 0, 1), 1)

        self.groundNP = self.worldNP.attach_new_node(
            BulletRigidBodyNode('Ground'))
        self.groundNP.node().add_shape(shape)
        self.groundNP.set_pos(0, 0, -2)
        self.groundNP.set_collide_mask(BitMask32.all_on())

        self.world.attach(self.groundNP.node())

        # Box (dynamic)
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        self.boxNP = self.worldNP.attach_new_node(BulletRigidBodyNode('Box'))
        self.boxNP.node().set_mass(1.0)
        self.boxNP.node().add_shape(shape)
        self.boxNP.set_pos(0, 0, 2)
        #self.boxNP.set_scale(2, 1, 0.5)
        self.boxNP.set_collide_mask(BitMask32.all_on())
        #self.boxNP.node().set_deactivation_enabled(False)

        self.world.attach(self.boxNP.node())

        visualNP = loader.load_model('models/box.egg')
        visualNP.clear_model_nodes()
        visualNP.reparent_to(self.boxNP)
コード例 #8
0
def test_bitmask_allon():
    assert BitMask16.all_on().is_all_on()
    assert BitMask32.all_on().is_all_on()
    assert BitMask64.all_on().is_all_on()
    assert DoubleBitMaskNative.all_on().is_all_on()
    assert QuadBitMaskNative.all_on().is_all_on()

    assert DoubleBitMaskNative((1 << double_num_bits) - 1).is_all_on()
    assert QuadBitMaskNative((1 << quad_num_bits) - 1).is_all_on()
コード例 #9
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        shape = BulletPlaneShape(LVector3(0, 0, 1), 0)
        body = BulletRigidBodyNode('Ground')
        bodyNP = self.worldNP.attach_new_node(body)
        bodyNP.node().add_shape(shape)
        bodyNP.set_pos(0, 0, -1)
        bodyNP.set_collide_mask(BitMask32.all_on())
        self.world.attach(bodyNP.node())

        # Some boxes
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))

        for i in range(10):
            for j in range(10):
                x = i - 5.0
                y = 0.0
                z = j - 0.5

                body = BulletRigidBodyNode('Box-{}-{}'.format(i, j))
                bodyNP = self.worldNP.attach_new_node(body)
                bodyNP.node().add_shape(shape)
                bodyNP.node().set_mass(1.0)
                bodyNP.node().set_deactivation_enabled(False)
                bodyNP.set_pos(x, y, z)
                bodyNP.set_collide_mask(BitMask32.all_on())

                self.world.attach(bodyNP.node())

                visNP = loader.load_model('models/box.egg')
                visNP.clear_model_nodes()
                visNP.reparent_to(bodyNP)
コード例 #10
0
ファイル: definitions.py プロジェクト: TurBoss/PyAuthServer
    def ray_test(self, target, source=None, distance=None, ignore_self=True, mask=None):
        """Perform a ray trace to a target

        :param target: target to trace towards
        :param source: optional origin of trace, otherwise object position
        :param distance: distance to use instead of vector length
        :rtype: :py:class:`game_system.physics.RayTestResult`
        """
        if source is None:
            source = Vector(self._nodepath.getPos(base.render))

        # Move target to appropriate position, if explicit distance
        if distance:
            direction = target - source
            direction.length = distance

            target = source + direction

        if mask is None:
            collision_mask = BitMask32.all_on()

        else:
            collision_mask = BitMask32()
            collision_mask.set_word(mask)

        world = self._node.get_python_tag("world")

        query_result = world.rayTestAll(tuple(source), tuple(target), collision_mask)
        sorted_hits = sorted(query_result.get_hits(), key=lambda h: h.get_hit_fraction())

        for hit_result in sorted_hits:
            hit_node = hit_result.get_node()

            hit_entity = entity_from_nodepath(hit_node)

            if ignore_self and hit_entity is self._entity:
                continue

            hit_position = Vector(hit_result.get_hit_pos())
            hit_distance = (hit_position - source).length
            hit_normal = Vector(hit_result.get_hit_normal())

            return RayTestResult(hit_position, hit_normal, hit_entity, hit_distance)
コード例 #11
0
    def ray_test(self, target, source=None, distance=None, ignore_self=True, mask=None):
        """Perform a ray trace to a target

        :param target: target to trace towards
        :param source: optional origin of trace, otherwise object position
        :param distance: distance to use instead of vector length
        :rtype: :py:class:`game_system.physics.RayTestResult`
        """
        if source is None:
            source = Vector(self._nodepath.getPos(base.render))

        # Move target to appropriate position, if explicit distance
        if distance:
            direction = target - source
            direction.length = distance

            target = source + direction

        if mask is None:
            collision_mask = BitMask32.all_on()

        else:
            collision_mask = BitMask32()
            collision_mask.set_word(mask)

        world = self._node.get_python_tag("world")

        query_result = world.rayTestAll(tuple(source), tuple(target), collision_mask)
        sorted_hits = sorted(query_result.get_hits(), key=get_hit_fraction)

        for hit_result in sorted_hits:
            hit_node = hit_result.get_node()

            hit_entity = entity_from_nodepath(hit_node)

            if ignore_self and hit_entity is self._entity:
                continue

            hit_position = Vector(hit_result.get_hit_pos())
            hit_distance = (hit_position - source).length
            hit_normal = Vector(hit_result.get_hit_normal())

            return RayTestResult(hit_position, hit_normal, hit_entity, hit_distance)
コード例 #12
0
    def do_shoot(self):
        # Get from/to points from mouse click
        pMouse = base.mouseWatcherNode.get_mouse()
        pFrom = LPoint3()
        pTo = LPoint3()
        base.camLens.extrude(pMouse, pFrom, pTo)

        pFrom = render.get_relative_point(base.cam, pFrom)
        pTo = render.get_relative_point(base.cam, pTo)

        # Calculate initial velocity
        v = pTo - pFrom
        v.normalize()
        v *= 100.0

        # Create bullet
        shape = BulletSphereShape(0.3)
        body = BulletRigidBodyNode('Bullet')
        bodyNP = self.worldNP.attach_new_node(body)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(1.0)
        bodyNP.node().set_linear_velocity(v)
        bodyNP.node().set_ccd_motion_threshold(1e-7)
        bodyNP.node().set_ccd_swept_sphere_radius(0.50)
        bodyNP.set_collide_mask(BitMask32.all_on())
        bodyNP.set_pos(pFrom)

        visNP = loader.load_model('models/ball.egg')
        visNP.set_scale(0.8)
        visNP.reparent_to(bodyNP)

        self.world.attach(bodyNP.node())

        # Remove the bullet again after 2 seconds
        taskMgr.do_method_later(2,
                                self.do_remove,
                                'doRemove',
                                extraArgs=[bodyNP],
                                appendTask=True)
コード例 #13
0
    def do_shoot(self, ccd):
        # Get from/to points from mouse click
        pMouse = base.mouseWatcherNode.get_mouse()
        pFrom = LPoint3()
        pTo = LPoint3()
        base.camLens.extrude(pMouse, pFrom, pTo)

        pFrom = render.get_relative_point(base.cam, pFrom)
        pTo = render.get_relative_point(base.cam, pTo)

        # Calculate initial velocity
        v = pTo - pFrom
        v.normalize()
        v *= 10000.0

        # Create bullet
        shape = BulletBoxShape(LVector3(0.5, 0.5, 0.5))
        body = BulletRigidBodyNode('Bullet')
        bodyNP = self.worldNP.attach_new_node(body)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(2.0)
        bodyNP.node().set_linear_velocity(v)
        bodyNP.set_pos(pFrom)
        bodyNP.set_collide_mask(BitMask32.all_on())

        if ccd:
            bodyNP.node().set_ccd_motion_threshold(1e-7)
            bodyNP.node().set_ccd_swept_sphere_radius(0.50)

        self.world.attach(bodyNP.node())

        # Remove the bullet again after 1 second
        taskMgr.do_method_later(1,
                                self.do_remove,
                                'doRemove',
                                extraArgs=[bodyNP],
                                appendTask=True)
コード例 #14
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        p0 = LPoint3(-20, -20, 0)
        p1 = LPoint3(-20, 20, 0)
        p2 = LPoint3(20, -20, 0)
        p3 = LPoint3(20, 20, 0)
        mesh = BulletTriangleMesh()
        mesh.add_triangle(p0, p1, p2)
        mesh.add_triangle(p1, p2, p3)
        shape = BulletTriangleMeshShape(mesh, dynamic=False)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Mesh'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -2)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Soft body world information
        info = self.world.get_world_info()
        info.set_air_density(1.2)
        info.set_water_density(0)
        info.set_water_offset(0)
        info.set_water_normal(LVector3(0, 0, 0))

        # Softbody
        def make_SB(pos, hpr):

            #use this to construct a torus geom.
            #import torus
            #geom = torus.make_geom()

            geom = (loader.load_model('models/torus.egg').find_all_matches(
                '**/+GeomNode').get_path(0).node().modify_geom(0))

            geomNode = GeomNode('')
            geomNode.add_geom(geom)

            node = BulletSoftBodyNode.make_tri_mesh(info, geom)
            node.link_geom(geomNode.modify_geom(0))

            node.generate_bending_constraints(2)
            node.get_cfg().set_positions_solver_iterations(2)
            node.get_cfg().set_collision_flag(
                BulletSoftBodyConfig.CF_vertex_face_soft_soft, True)
            node.randomize_constraints()
            node.set_total_mass(50, True)

            softNP = self.worldNP.attach_new_node(node)
            softNP.set_pos(pos)
            softNP.set_hpr(hpr)
            self.world.attach(node)

            geomNP = softNP.attach_new_node(geomNode)

        make_SB(LPoint3(-3, 0, 4), (0, 0, 0))
        make_SB(LPoint3(0, 0, 4), (0, 90, 90))
        make_SB(LPoint3(3, 0, 4), (0, 0, 0))
コード例 #15
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        p0 = LPoint3(-20, -20, 0)
        p1 = LPoint3(-20, 20, 0)
        p2 = LPoint3(20, -20, 0)
        p3 = LPoint3(20, 20, 0)
        mesh = BulletTriangleMesh()
        mesh.add_triangle(p0, p1, p2)
        mesh.add_triangle(p1, p2, p3)
        shape = BulletTriangleMeshShape(mesh, dynamic=False)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Mesh'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -4)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Soft body world information
        info = self.world.get_world_info()
        info.set_air_density(1.2)
        info.set_water_density(0)
        info.set_water_offset(0)
        info.set_water_normal(LVector3(0, 0, 0))

        ## Softbody - From points/indices
        #import cube
        #points = [LPoint3(x,y,z) * 3 for x,y,z in cube.nodes]
        #indices = sum([list(x) for x in cube.elements], [])

        #node = BulletSoftBodyNode.make_tet_mesh(info, points, indices, True)
        #node.set_volume_mass(300);
        #node.get_shape(0).set_margin(0.01)
        #node.get_material(0).set_linear_stiffness(0.8)
        #node.get_cfg().set_positions_solver_iterations(1)
        #node.get_cfg().clear_all_collision_flags()
        #node.get_cfg().set_collision_flag(
        #BulletSoftBodyConfig.CF_cluster_soft_soft, True)
        #node.get_cfg().set_collision_flag(
        #BulletSoftBodyConfig.CF_cluster_rigid_soft, True)
        #node.generate_clusters(16)

        #softNP = self.worldNP.attach_new_node(node)
        #softNP.set_pos(0, 0, 8)
        #softNP.set_hpr(0, 0, 45)
        #self.world.attach(node)

        # Softbody - From tetgen data
        ele = open('models/cube/cube.1.ele', 'r').read()
        face = open('models/cube/cube.1.face', 'r').read()
        node = open('models/cube/cube.1.node', 'r').read()

        node = BulletSoftBodyNode.make_tet_mesh(info, ele, face, node)
        node.set_name('Tetra')
        node.set_volume_mass(300)
        node.get_shape(0).set_margin(0.01)
        node.get_material(0).set_linear_stiffness(0.1)
        node.get_cfg().set_positions_solver_iterations(1)
        node.get_cfg().clear_all_collision_flags()
        node.get_cfg().set_collision_flag(
            BulletSoftBodyConfig.CF_cluster_soft_soft, True)
        node.get_cfg().setCollisionFlag(
            BulletSoftBodyConfig.CF_cluster_rigid_soft, True)
        node.generate_clusters(6)

        softNP = self.worldNP.attach_new_node(node)
        softNP.set_pos(0, 0, 8)
        softNP.set_hpr(45, 0, 0)
        self.world.attach(node)

        # Option 1:
        visNP = loader.load_model('models/cube/cube.egg')
        visNP.reparent_to(softNP)
        geom = (visNP.findAllMatches('**/+GeomNode').getPath(
            0).node().modifyGeom(0))
        node.link_geom(geom)
コード例 #16
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Plane
        shape = BulletPlaneShape(LVector3(0, 0, 1), 0)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Ground'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -1)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Chassis
        shape = BulletBoxShape(LVector3(0.6, 1.4, 0.5))
        ts = TransformState.make_pos(LPoint3(0, 0, 0.5))

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Vehicle'))
        np.node().add_shape(shape, ts)
        np.set_pos(0, 0, 1)
        np.node().set_mass(800.0)
        np.node().set_deactivation_enabled(False)

        self.world.attach(np.node())

        #np.node().set_ccd_swept_sphere_radius(1.0)
        #np.node().set_ccd_motion_threshold(1e-7) 

        # Vehicle
        self.vehicle = BulletVehicle(self.world, np.node())
        self.vehicle.set_coordinate_system(ZUp)
        self.world.attach(self.vehicle)

        self.yugoNP = loader.load_model('models/yugo/yugo.egg')
        self.yugoNP.reparent_to(np)

        # Right front wheel
        np = loader.load_model('models/yugo/yugotireR.egg')
        np.reparent_to(self.worldNP)
        self.add_wheel(LPoint3( 0.70,  1.05, 0.3), True, np)

        # Left front wheel
        np = loader.load_model('models/yugo/yugotireL.egg')
        np.reparent_to(self.worldNP)
        self.add_wheel(LPoint3(-0.70,  1.05, 0.3), True, np)

        # Right rear wheel
        np = loader.load_model('models/yugo/yugotireR.egg')
        np.reparent_to(self.worldNP)
        self.add_wheel(LPoint3( 0.70, -1.05, 0.3), False, np)

        # Left rear wheel
        np = loader.load_model('models/yugo/yugotireL.egg')
        np.reparent_to(self.worldNP)
        self.add_wheel(LPoint3(-0.70, -1.05, 0.3), False, np)

        # Steering info
        self.steering = 0.0            # degree
        self.steeringClamp = 45.0      # degree
        self.steeringIncrement = 120.0 # degree per second
コード例 #17
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().show_wireframe(True)
        self.debugNP.node().show_constraints(True)
        self.debugNP.node().show_bounding_boxes(False)
        self.debugNP.node().show_normals(False)

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        shape = BulletPlaneShape(LVector3(0, 0, 1), 0)

        body = BulletRigidBodyNode('Ground')
        bodyNP = self.worldNP.attach_new_node(body)
        bodyNP.node().add_shape(shape)
        bodyNP.set_pos(0, 0, 0)
        bodyNP.set_collide_mask(BitMask32.all_on())
        self.world.attach(bodyNP.node())

        # Bowl
        visNP = loader.load_model('models/bowl.egg')

        geom = (visNP.findAllMatches('**/+GeomNode').get_path(
            0).node().get_geom(0))
        mesh = BulletTriangleMesh()
        mesh.addGeom(geom)
        shape = BulletTriangleMeshShape(mesh, dynamic=True)

        body = BulletRigidBodyNode('Bowl')
        bodyNP = self.worldNP.attach_new_node(body)
        bodyNP.node().add_shape(shape)
        bodyNP.node().set_mass(10.0)
        bodyNP.set_pos(0, 0, 0)
        bodyNP.set_collide_mask(BitMask32.all_on())
        self.world.attach(bodyNP.node())

        visNP.reparent_to(bodyNP)

        self.bowlNP = bodyNP
        self.bowlNP.set_scale(2)

        # Eggs
        self.eggNPs = []
        for i in range(5):
            x = random.gauss(0, 0.1)
            y = random.gauss(0, 0.1)
            z = random.gauss(0, 0.1) + 1
            h = random.random() * 360
            p = random.random() * 360
            r = random.random() * 360

            visNP = loader.load_model('models/egg.egg')

            geom = (visNP.find_all_matches('**/+GeomNode').get_path(
                0).node().get_geom(0))
            shape = BulletConvexHullShape()
            shape.addGeom(geom)

            body = BulletRigidBodyNode('Egg-%i' % i)
            bodyNP = self.worldNP.attach_new_node(body)
            bodyNP.node().set_mass(1.0)
            bodyNP.node().add_shape(shape)
            bodyNP.node().set_deactivation_enabled(False)
            bodyNP.set_collide_mask(BitMask32.all_on())
            bodyNP.set_pos_hpr(x, y, z, h, p, r)
            #bodyNP.set_scale(1.5)
            self.world.attach(bodyNP.node())

            visNP.reparent_to(bodyNP)

            self.eggNPs.append(bodyNP)
コード例 #18
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        #self.debugNP.show_tight_bounds()
        #self.debugNP.show_bounds()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        p0 = LPoint3(-20, -20, 0)
        p1 = LPoint3(-20, 20, 0)
        p2 = LPoint3(20, -20, 0)
        p3 = LPoint3(20, 20, 0)
        mesh = BulletTriangleMesh()
        mesh.add_triangle(p0, p1, p2)
        mesh.add_triangle(p1, p2, p3)
        shape = BulletTriangleMeshShape(mesh, dynamic=False)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Mesh'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -2)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Stair
        origin = LPoint3(0, 0, 0)
        size = LVector3(2, 10, 1)
        shape = BulletBoxShape(size * 0.5)
        for i in range(10):
            pos = origin + size * i
            pos.setY(0)

            np = self.worldNP.attach_new_node(
                BulletRigidBodyNode('Stair{}'.format(i)))
            np.node().add_shape(shape)
            np.set_pos(pos)
            np.set_collide_mask(BitMask32.all_on())

            npV = loader.load_model('models/box.egg')
            npV.reparent_to(np)
            npV.set_scale(size)

            self.world.attach(np.node())

        # Soft body world information
        info = self.world.get_world_info()
        info.set_air_density(1.2)
        info.set_water_density(0)
        info.set_water_offset(0)
        info.set_water_normal(LVector3(0, 0, 0))

        # Softbody
        center = LPoint3(0, 0, 0)
        radius = LVector3(1, 1, 1) * 1.5
        node = BulletSoftBodyNode.make_ellipsoid(info, center, radius, 128)
        node.set_name('Ellipsoid')
        node.get_material(0).set_linear_stiffness(0.1)
        node.get_cfg().set_dynamic_friction_coefficient(1)
        node.get_cfg().set_damping_coefficient(0.001)
        node.get_cfg().set_pressure_coefficient(1500)
        node.set_total_mass(30, True)
        node.set_pose(True, False)

        np = self.worldNP.attach_new_node(node)
        np.set_pos(15, 0, 12)
        #np.setH(90.0)
        #np.show_bounds()
        #np.show_tight_bounds()
        self.world.attach(np.node())

        geom = BulletHelper.make_geom_from_faces(node)
        node.link_geom(geom)
        nodeV = GeomNode('EllipsoidVisual')
        nodeV.add_geom(geom)
        npV = np.attach_new_node(nodeV)
コード例 #19
0
    def setup(self):
        self.worldNP = render.attach_new_node('World')

        # World
        self.debugNP = self.worldNP.attach_new_node(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.set_gravity(LVector3(0, 0, -9.81))
        self.world.set_debug_node(self.debugNP.node())

        # Ground
        p0 = LPoint3(-20, -20, 0)
        p1 = LPoint3(-20, 20, 0)
        p2 = LPoint3(20, -20, 0)
        p3 = LPoint3(20, 20, 0)
        mesh = BulletTriangleMesh()
        mesh.add_triangle(p0, p1, p2)
        mesh.add_triangle(p1, p2, p3)
        shape = BulletTriangleMeshShape(mesh, dynamic=False)

        np = self.worldNP.attach_new_node(BulletRigidBodyNode('Mesh'))
        np.node().add_shape(shape)
        np.set_pos(0, 0, -2)
        np.set_collide_mask(BitMask32.all_on())

        self.world.attach(np.node())

        # Soft body world information
        info = self.world.get_world_info()
        info.set_air_density(1.2)
        info.set_water_density(0)
        info.set_water_offset(0)
        info.set_water_normal(LVector3(0, 0, 0))

        # Softbody
        for i in range(50):
            p00 = LPoint3(-2, -2, 0)
            p10 = LPoint3(2, -2, 0)
            p01 = LPoint3(-2, 2, 0)
            p11 = LPoint3(2, 2, 0)
            node = BulletSoftBodyNode.make_patch(info, p00, p10, p01, p11, 6,
                                                 6, 0, True)
            node.generate_bending_constraints(2)
            node.get_cfg().set_lift_coefficient(0.004)
            node.get_cfg().set_dynamic_friction_coefficient(0.0003)
            node.get_cfg().set_aero_model(
                BulletSoftBodyConfig.AM_vertex_two_sided)
            node.set_total_mass(0.1)
            node.add_force(LVector3(0, 2, 0), 0)

            np = self.worldNP.attach_new_node(node)
            np.set_pos(self.LVector3_rand() * 10 + LVector3(0, 0, 20))
            np.set_hpr(self.LVector3_rand() * 16)
            self.world.attach(node)

            fmt = GeomVertexFormat.get_v3n3t2()
            geom = BulletHelper.make_geom_from_faces(node, fmt, True)
            node.link_geom(geom)
            nodeV = GeomNode('')
            nodeV.add_geom(geom)
            npV = np.attach_new_node(nodeV)

            tex = loader.load_texture('models/panda.jpg')
            npV.set_texture(tex)
            BulletHelper.make_texcoords_for_patch(geom, 6, 6)