Beispiel #1
0
 def makeMapBorders(self, offset):
     plane1 = BulletPlaneShape(Vec3(1, 0, 0), 0)
     np = self.worldNP.attachNewNode(BulletRigidBodyNode('border1'))
     np.node().addShape(plane1)
     np.setPos(-offset, -offset, -self.height / 2.0)
     np.setCollideMask(BitMask32.allOn())
     self.world.attachRigidBody(np.node())
     plane2 = BulletPlaneShape(Vec3(0, 1, 0), 0)
     np = self.worldNP.attachNewNode(BulletRigidBodyNode('border2'))
     np.node().addShape(plane2)
     np.setPos(-offset, -offset, -self.height / 2.0)
     np.setCollideMask(BitMask32.allOn())
     self.world.attachRigidBody(np.node())
     plane3 = BulletPlaneShape(Vec3(0, -1, 0), 0)
     np = self.worldNP.attachNewNode(BulletRigidBodyNode('border3'))
     np.node().addShape(plane3)
     np.setPos(offset, offset, self.height / 2.0)
     np.setCollideMask(BitMask32.allOn())
     self.world.attachRigidBody(np.node())
     plane4 = BulletPlaneShape(Vec3(-1, 0, 0), 0)
     np = self.worldNP.attachNewNode(BulletRigidBodyNode('border4'))
     np.node().addShape(plane4)
     np.setPos(offset, offset, self.height / 2.0)
     np.setCollideMask(BitMask32.allOn())
     self.world.attachRigidBody(np.node())
Beispiel #2
0
def gen_plane_cdmesh(updirection=np.array([0, 0, 1]), offset=0, name='autogen'):
    """
    generate a plane bulletrigidbody node
    :param updirection: the normal parameter of bulletplaneshape at panda3d
    :param offset: the d parameter of bulletplaneshape at panda3d
    :param name:
    :return: bulletrigidbody
    author: weiwei
    date: 20170202, tsukuba
    """
    bulletplnode = BulletRigidBodyNode(name)
    bulletplshape = BulletPlaneShape(da.npv3_to_pdv3(updirection), offset)
    bulletplshape.setMargin(0)
    bulletplnode.addShape(bulletplshape)
    return bulletplnode
Beispiel #3
0
    def setup(self):

        # World
        self.worldNP = render.attachNewNode("World")
        self.GUI = self.worldNP.attachNewNode("GUI")
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode("Debug"))
        self.debugNP.show()
        self.debugNP.node().showWireframe(True)
        self.debugNP.node().showConstraints(True)
        self.debugNP.node().showBoundingBoxes(False)
        self.debugNP.node().showNormals(True)

        self.setDefaults()
        self.addGUI()
        self.createCurve()

        self.world = BulletWorld()
        # self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setGravity(Vec3(0, 0, 0))
        self.world.setDebugNode(self.debugNP.node())

        # Plane (static)
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        nodePath = self.worldNP.attachNewNode(BulletRigidBodyNode("Ground"))
        nodePath.node().addShape(shape)
        nodePath.setPos(0, 0, 0)
        nodePath.setCollideMask(BitMask32.allOn())
        self.world.attachRigidBody(nodePath.node())

        self.loadModel()
Beispiel #4
0
    def __init__(self):
        ShowBase.__init__(self)
        # Bullet Physics Setup
        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))

        shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
        node = BulletRigidBodyNode('Ground')
        node.addShape(shape)
        ground_np = self.render.attachNewNode(node)
        ground_np.setPos(0, 0, -60)
        # noinspection PyArgumentList
        self.world.attach(node)

        # Mouse and Camera Setup
        self.disable_mouse()
        self.camera.set_pos(20, -150, 5)
        self.follow_np = self.render.attach_new_node('Follow')

        # Instructions
        self.add_instruction('(p) to generate a Plane', 0.06)
        self.add_instruction('(b) to generate a Cuboid/Box', 0.12)
        self.add_instruction('(s) to generate a Spheroid', 0.18)
        self.add_instruction('(c) to generate a Cylinder', 0.24)
        self.add_instruction('(f1) to toggle wireframe', 0.30)
        self.add_instruction('(esc) to exit', 0.36)
        # Input
        self.accept('escape', sys.exit, [0])
        self.accept('p', self.generate_plane)
        self.accept('b', self.generate_cuboid)
        self.accept('s', self.generate_spheroid)
        self.accept('c', self.generate_cylinder)
        self.accept('f1', self.toggle_wireframe)

        self.task_mgr.add(self.update, 'update')
Beispiel #5
0
    def reset(self):
        namelist = [
            'Ground', 'Conveyor', 'Finger', 'Block', 'Scrambled Block',
            'Not Rewardable', 'Teleport Me'
        ]
        for child in render.getChildren():
            for test in namelist:
                if child.node().name == test:
                    self.world.remove(child.node())
                    child.removeNode()
                    break

        # Plane
        self.plane_shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
        self.plane_node = BulletRigidBodyNode('Ground')
        self.plane_node.addShape(self.plane_shape)
        self.plane_np = self.render.attachNewNode(self.plane_node)
        self.plane_np.setPos(0.0, 0.0, -1.0)
        self.world.attachRigidBody(self.plane_node)

        # Conveyor
        self.conv_node = BulletRigidBodyNode('Conveyor')
        self.conv_node.setFriction(1.0)
        self.conv_np = self.render.attachNewNode(self.conv_node)
        self.conv_shape = BulletBoxShape(Vec3(100.0, 1.0, 0.05))
        self.conv_node.setMass(1000.0)
        self.conv_np.setPos(-95.0, 0.0, 0.1)
        self.conv_node.addShape(self.conv_shape)
        self.world.attachRigidBody(self.conv_node)
        self.model = loader.loadModel('assets/conv.egg')
        self.model.flattenLight()
        self.model.reparentTo(self.conv_np)

        # Finger
        self.finger_node = BulletRigidBodyNode('Finger')
        self.finger_node.setFriction(1.0)
        self.finger_np = self.render.attachNewNode(self.finger_node)
        self.finger_shape = BulletCylinderShape(0.1, 0.25, ZUp)
        self.finger_node.setMass(0)
        self.finger_np.setPos(1.8, 0.0, 0.24 + 0.0254 * 3.5)
        self.finger_node.addShape(self.finger_shape)
        self.world.attachRigidBody(self.finger_node)
        self.model = loader.loadModel('assets/finger.egg')
        self.model.flattenLight()
        self.model.reparentTo(self.finger_np)

        self.blocks = []
        for block_num in range(15):
            new_block = self.spawn_block(Vec3(18, 0, (0.2 * block_num) + 2.0))
            self.blocks.append(new_block)

        self.have_scramble = False
        self.penalty_applied = False
        self.spawnned = False
        self.score = 10
        self.teleport_cooled_down = True
        self.fps = 20
        self.framecount = 0

        return self.step(1)[0]
Beispiel #6
0
    def _setup(self):
        if hasattr(self, '_model_path'):
            # Collidable objects
            visNP = loader.loadModel(self._model_path)
            visNP.clearModelNodes()
            visNP.reparentTo(render)
            pos = (0., 0., 0.)
            visNP.setPos(pos[0], pos[1], pos[2])

            bodyNPs = BulletHelper.fromCollisionSolids(visNP, True)
            for bodyNP in bodyNPs:
                bodyNP.reparentTo(render)
                bodyNP.setPos(pos[0], pos[1], pos[2])

                if isinstance(bodyNP.node(), BulletRigidBodyNode):
                    bodyNP.node().setMass(0.0)
                    bodyNP.node().setKinematic(True)
                    bodyNP.setCollideMask(BitMask32.allOn())
                    self._world.attachRigidBody(bodyNP.node())
        else:
            ground = self._worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
            shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
            ground.node().addShape(shape)
            ground.setCollideMask(BitMask32.allOn())
            self._world.attachRigidBody(ground.node())
        self._place_vehicle()
        self._setup_light()
        self._setup_restart_pos()
Beispiel #7
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

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

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

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

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, -1)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

        # initial vehicles
        self.vehicles = []
        #self.vehicles.append(basicVehicle(self,[13,2,0.5],18)) # [10,0.1,0.5] is vehicle start position
        self.vehicles.append(
            basicVehicle(self, [10, 0.1, 0.5],
                         18))  # [10,0.1,0.5] is vehicle start position
        sensor = basicSensor(self)  # initial sensor
        sensor.setVehicle(self.vehicles[0])
        self.vehicles[0].setSensor(sensor)
        self.vehicles[0].sensor.align()
        agent = basicAgent(50, 10.8, 15)  # initial agent
        agent.setVehicle(self.vehicles[0])
        self.vehicles[0].setAgent(agent)
Beispiel #8
0
    def setup(self):
        self.worldNP = self.render.attachNewNode('World')
        self.world = PGPhysicsWorld()
        self.physics_world = self.world

        # World
        if self.debug:
            self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
            self.debugNP.show()
            self.debugNP.node().showWireframe(True)
            self.debugNP.node().showConstraints(True)
            self.debugNP.node().showBoundingBoxes(True)
            self.debugNP.node().showNormals(True)

            self.debugNP.showTightBounds()
            self.debugNP.showBounds()
            self.world.dynamic_world.setDebugNode(self.debugNP.node())

        # Ground (static)
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        self.groundNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        self.groundNP.node().addShape(shape)
        self.groundNP.setPos(0, 0, 0)
        self.groundNP.setCollideMask(BitMask32.allOn())
        self.world.dynamic_world.attachRigidBody(self.groundNP.node())
Beispiel #9
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

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

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

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

        # collision
        visNP = loader.loadModel('../models/coryf2.egg')
        visNP.clearModelNodes()
        visNP.reparentTo(render)
        pos = (7., 60.0, 3.8)
        visNP.setPos(pos[0], pos[1], pos[2])

        bodyNPs = BulletHelper.fromCollisionSolids(visNP, True)
        for bodyNP in bodyNPs:
            bodyNP.reparentTo(render)
            bodyNP.setPos(pos[0], pos[1], pos[2])

            if isinstance(bodyNP.node(), BulletRigidBodyNode):
                bodyNP.node().setMass(0.0)
                bodyNP.node().setKinematic(True)
                bodyNP.setCollideMask(BitMask32.allOn())
                self.world.attachRigidBody(bodyNP.node())
Beispiel #10
0
  def setup(self):
    self.worldNP = render.attachNewNode('World')

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

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

    # Ground
    shape = BulletPlaneShape(Vec3(0, 0, 1), -1)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
    np.node().addShape(shape)
    np.setPos(0, 0, -1)
    np.setCollideMask(BitMask32.bit(0))

    self.world.attachRigidBody(np.node())

    # Boxes
    self.boxes = [None,]*6

    for i in range(6):
      shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

      np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-1'))
      np.node().setMass(1.0)
      np.node().addShape(shape)

      self.world.attachRigidBody(np.node())

      self.boxes[i] = np

      visualNP = loader.loadModel('models/box.egg')
      visualNP.reparentTo(np)

    self.boxes[0].setPos(-3, -3, 0)
    self.boxes[1].setPos( 0, -3, 0)
    self.boxes[2].setPos( 3, -3, 0)
    self.boxes[3].setPos(-3,  3, 0)
    self.boxes[4].setPos( 0,  3, 0)
    self.boxes[5].setPos( 3,  3, 0)

    self.boxes[0].setCollideMask(BitMask32.bit(1))
    self.boxes[1].setCollideMask(BitMask32.bit(2))
    self.boxes[2].setCollideMask(BitMask32.bit(3))
    self.boxes[3].setCollideMask(BitMask32.bit(1))
    self.boxes[4].setCollideMask(BitMask32.bit(2))
    self.boxes[5].setCollideMask(BitMask32.bit(3))

    self.boxNP = self.boxes[0]

    self.world.setGroupCollisionFlag(0, 1, True)
    self.world.setGroupCollisionFlag(0, 2, True)
    self.world.setGroupCollisionFlag(0, 3, True)

    self.world.setGroupCollisionFlag(1, 1, False)
    self.world.setGroupCollisionFlag(1, 2, True)
Beispiel #11
0
    def __init__(self):
        ShowBase.__init__(self)
        loadPrcFileData('', 'bullet-enable-contact-events true')

        world = BulletWorld()
        self.world = world
        world.setGravity(Vec3(0, 0, -9.81))
        base.cam.setPos(0,-50,1)

        # Cameras
        base.camNode.setActive(0)
        self.cam1 = base.makeCamera(base.win, displayRegion=(0,.5,0.5,1))
        self.cam2 = base.makeCamera(base.win, displayRegion=(.5,1,0.5,1))
        self.cam1.setPos(-10,-50,1)
        self.cam2.setPos(10,-50,1)
        # base.camList[0].setPos(0,-100, 1)

        # Plane
        shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
        node = BulletRigidBodyNode('Ground')
        node.addShape(shape)
        np = render.attachNewNode(node)
        np.setPos(0, 0, 0)
        self.world.attachRigidBody(node)
        scene = loader.loadModel('Ground2/Ground2')
        scene.reparentTo(render)
        self.newGame()

        taskMgr.add(self.update, 'update')
  def setup(self):
    self.worldNP = render.attachNewNode('World')

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

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

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

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

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
    np.node().addShape(shape)
    np.setPos(0, 0, -1)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

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

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
    np.node().setMass(10.0)
    np.node().addShape(shape)
    np.setPos(3, 0, 4)
    np.setH(20.0)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(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.character.setMass(1.0)
    self.characterNP = self.worldNP.attachNewNode(self.character)
    self.characterNP.setPos(-2, 0, 14)
    self.characterNP.setH(45)
    self.characterNP.setCollideMask(BitMask32.allOn())
    self.world.attachCharacter(self.character)

    self.actorNP = Actor('models/ralph/ralph.egg', {
                         'run' : 'models/ralph/ralph-run.egg',
                         'walk' : 'models/ralph/ralph-walk.egg',
                         'jump' : 'models/ralph/ralph-jump.egg'})
    self.actorNP.reparentTo(self.characterNP)
    self.actorNP.setScale(0.3048) # 1ft = 0.3048m
    self.actorNP.setH(180)
    self.actorNP.setPos(0, 0, -1)
Beispiel #13
0
 def __init__(self, world, **kwargs):
     super().__init__(**kwargs)
     self.shape = BulletPlaneShape(Vec3(0, 1, 0), 0)
     self.node = BulletRigidBodyNode('plane')
     self.node.addShape(self.shape)
     self.np = render.attachNewNode(self.node)
     self.np.setPos(0, -2, 0)
     world.attachRigidBody(self.node)
Beispiel #14
0
    def __init__(self,
                 world: BulletWorld,
                 entity: Entity,
                 mass=0,
                 rotation=[None, None, None]) -> None:

        super().__init__(world, entity, BulletPlaneShape(Vec3(0, 1, 0), 0),
                         'plane', rotation, mass)
 def setupDeathzone(self, height):
     planeShape = BulletPlaneShape(Vec3(0, 0, 1), 1)
     planeNode = BulletRigidBodyNode('DeathZone')
     planeNode.addShape(planeShape)
     planeNP = render.attachNewNode(planeNode)
     planeNP.setPos(0, 0, height)
     self.worldBullet.attachRigidBody(planeNode)
     return planeNP
Beispiel #16
0
def task_1_Bullet_Hello_World():

    strOf_FuncName = "task_1_Bullet_Hello_World"

    '''###################
        step : 1
            opening, vars
    ###################'''
    print()
    
    print ("[%s:%d] starting : %s (time=%s)" % (
                os.path.basename(os.path.basename(libs.thisfile()))
                , libs.linenum()
                , strOf_FuncName
                , libs.get_TimeLabel_Now()
                )
    )
    
    '''###################
        step : 2
    ###################'''
    base.cam.setPos(0, -10, 0)
    base.cam.lookAt(0, 0, 0)
    
    # World
    world = BulletWorld()
    world.setGravity(Vec3(0, 0, -9.81))
    
    # Plane
    shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
    node = BulletRigidBodyNode('Ground')
    node.addShape(shape)
    np = render.attachNewNode(node)
    np.setPos(0, 0, -2)
    world.attachRigidBody(node)
    
    # Box
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
    node = BulletRigidBodyNode('Box')
    node.setMass(1.0)
    node.addShape(shape)
    np = render.attachNewNode(node)
    np.setPos(0, 0, 2)
    world.attachRigidBody(node)
    model = loader.loadModel('models/box.egg')
    model.flattenLight()
    model.reparentTo(np)
    
    # Update
    def update(task):
        dt = globalClock.getDt()
        world.doPhysics(dt)
        return task.cont
    
    taskMgr.add(update, 'update')
    base.run()
    
    '''###################
Beispiel #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.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)
Beispiel #18
0
def genBulleCDPlane(updirection=Vec3(0, 0, 1), offset=0, name='autogen'):
    """
    generate a plane bulletrigidbody node

    :param updirection: the normal parameter of bulletplaneshape at panda3d
    :param offset: the d parameter of bulletplaneshape at panda3d
    :param name:
    :return: bulletrigidbody

    author: weiwei
    date: 20170202, tsukuba
    """

    bulletplnode = BulletRigidBodyNode(name)
    bulletplshape = BulletPlaneShape(updirection, offset)
    bulletplshape.setMargin(0)
    bulletplnode.addShape(bulletplshape)
    return bulletplnode
Beispiel #19
0
    def initBullet(self):
        self.world = BulletWorld()
        #self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setGravity(Vec3(0, 0, -1.62))

        groundShape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        groundNode = BulletRigidBodyNode('Ground')
        groundNode.addShape(groundShape)
        self.world.attachRigidBody(groundNode)
def genCollisionPlane(updirection = Vec3(0,0,1), offset = 0, name = 'autogen'):
    """
    generate a plane bulletrigidbody node

    :param updirection: the normal parameter of bulletplaneshape at panda3d
    :param offset: the d parameter of bulletplaneshape at panda3d
    :param name:
    :return: bulletrigidbody

    author: weiwei
    date: 20170202, tsukuba
    """

    bulletplnode = BulletRigidBodyNode(name)
    bulletplshape = BulletPlaneShape(Vec3(0, 0, 1), offset)
    bulletplshape.setMargin(0)
    bulletplnode.addShape(bulletplshape)
    return bulletplnode
Beispiel #21
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

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

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

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

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, 0)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())

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

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.setPos(0, 0, 4)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())

        self.boxNP = np
        visualNP = loader.loadModel('models/box.egg')
        visualNP.reparentTo(self.boxNP)

        # Sphere
        shape = BulletSphereShape(0.6)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Sphere'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.setPos(3, 0, 4)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())

        # Cone
        shape = BulletConeShape(0.6, 1.0)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Cone'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.setPos(6, 0, 4)
        np.setCollideMask(BitMask32(0x0f))

        self.world.attachRigidBody(np.node())
Beispiel #22
0
    def buildGroundPlane(self):
        """Build a BulletPlane"""
        shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        np = self.engine.BulletObjects["level"].attachNewNode(
            BulletRigidBodyNode('Ground_plane'))
        np.node().addShape(shape)
        np.setPos(0, 0, 0)  # This thing is usually infinite
        np.setCollideMask(BitMask32.allOn())

        self.engine.bulletWorld.attachRigidBody(np.node())
Beispiel #23
0
 def _setup_map(self):
     if hasattr(self, '_model_path'):
         # Collidable objects
         self._setup_collision_object(self._model_path)
     else:
         ground = self._worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
         shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
         ground.node().addShape(shape)
         ground.setCollideMask(BitMask32.allOn())
         self._world.attachRigidBody(ground.node())
Beispiel #24
0
    def setupWorld(self):
        def spawnChrisRoom(*args):
            args[0].reparentTo(render)
            args[0].setPos(0, 0, -0.1)
            args[0].setScale(0.4)

        def spawnChrisLaptop(*args):
            args[0].reparentTo(render)
            args[0].setPosHpr(-5.5, 1.5, 1.0, 90, 0, 0)
            args[0].setScale(0.8)

        # Load Chris's Room
        self.chrisRoom = loader.loadModel("Resources/models/ROOMS/ChrisRoom",
                                          callback=spawnChrisRoom)

        # Load his laptop onto the desk
        self.chrisLaptop = loader.loadModel("Resources/models/OBJ/ChrisLaptop",
                                            callback=spawnChrisLaptop)

        # Load AMD HQ
        self.showAmdHq()

        # TODO: Set the screen texture
        #screenTexture = loader.loadTexture("Resources/maps/skypeChat.png")
        #self.chrisLaptopScreen = self.chrisLaptop.find("**/screen")
        #self.chrisLaptopScreen.setTexture(screenTexture, 1)

        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.show()
        self.debugNP.node().showWireframe(True)
        self.debugNP.node().showConstraints(True)
        self.debugNP.node().showBoundingBoxes(True)
        self.debugNP.node().showNormals(True)

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        #self.world.setDebugNode(self.debugNP.node()) # Used to show physics

        self.terrain_np = render.attach_new_node("terrain")

        # Ground
        ground = BulletPlaneShape(Vec3(0, 0, 1), 0)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(ground)
        np.setPos(0, 0, 0)
        np.setCollideMask(BitMask32.allOn())
        self.world.attachRigidBody(np.node())

        info = self.world.getWorldInfo()
        info.setAirDensity(1.2)
        info.setWaterDensity(0)
        info.setWaterOffset(0)
        info.setWaterNormal(Vec3(0, 0, 0))
Beispiel #25
0
 def addGround(self):
     self.garden = self.loader.loadModel("models/garden/garden.egg")
     self.garden.reparentTo(self.render)
     self.garden.setScale(2, 2, 2)
     self.garden.setPos(0, 0, 0)
     shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
     floorNP = self.render.attachNewNode(BulletRigidBodyNode('Ground'))
     floorNP.node().addShape(shape)
     floorNP.setPos(0, 0, 0)
     floorNP.setCollideMask(BitMask32.allOn())
     self.world.attachRigidBody(floorNP.node())
Beispiel #26
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

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

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

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

        np = self.ground = self.worldNP.attachNewNode(
            BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, -1)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

        # collision
        self.maze = []
        for pos in [(0.0, 72.0, 0.0), (-11.0, 60.0, 0.0), (11.0, 60.0, 0.0),
                    (-11.0, 48.0, 0.0), (11.0, 48.0, 0.0), (-11.0, 36.0, 0.0),
                    (11.0, 36.0, 0.0), (-11.0, 24.0, 0.0), (11.0, 24.0, 0.0),
                    (-11.0, 12.0, 0.0), (11.0, 12.0, 0.0), (-11.0, 0.0, 0.0),
                    (11.0, 0.0, 0.0), (0.0, -12.0, 0.0), (0.5, 12.0, 1.0),
                    (-0.5, 12.0, 1.0)]:
            translate = False
            if (abs(pos[0]) == 0.5):
                translate = True
                visNP = loader.loadModel('../models/ball.egg')
            else:
                visNP = loader.loadModel('../models/maze.egg')
            visNP.clearModelNodes()
            visNP.reparentTo(self.ground)
            visNP.setPos(pos[0], pos[1], pos[2])

            bodyNPs = BulletHelper.fromCollisionSolids(visNP, True)
            for bodyNP in bodyNPs:
                bodyNP.reparentTo(render)
                if translate:
                    bodyNP.setPos(pos[0], pos[1], pos[2] - 1)
                else:
                    bodyNP.setPos(pos[0], pos[1], pos[2])

                if isinstance(bodyNP.node(), BulletRigidBodyNode):
                    bodyNP.node().setMass(0.0)
                    bodyNP.node().setKinematic(True)
                    self.maze.append(bodyNP)

        for bodyNP in self.maze:
            self.world.attachRigidBody(bodyNP.node())
Beispiel #27
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

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

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

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

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, -1)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

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

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.node().addShape(shape, TransformState.makePos(Point3(0, 1, 0)))
        np.node().setDeactivationEnabled(False)
        np.setPos(2, 0, 4)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

        visualNP = loader.loadModel('models/box.egg')
        visualNP.reparentTo(np)

        self.box = np.node()

        # Sphere
        shape = BulletSphereShape(0.6)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Sphere'))
        np.node().setMass(1.0)
        np.node().addShape(shape)
        np.node().addShape(shape, TransformState.makePos(Point3(0, 1, 0)))
        np.setPos(-2, 0, 4)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

        self.sphere = np.node()
Beispiel #28
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

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

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

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

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

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, -1)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

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

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
        np.node().setMass(50.0)
        np.node().addShape(shape)
        np.setPos(3, 0, 4)
        np.setH(0)
        np.setCollideMask(BitMask32.allOn())

        self.world.attachRigidBody(np.node())

        # Character
        h = 1.75
        w = 0.4
        shape = BulletCapsuleShape(w, h - 2 * w, ZUp)

        self.player = BulletCharacterNode(shape, 0.4, 'Player')
        self.player.setMass(20.0)
        self.player.setMaxSlope(45.0)
        self.player.setGravity(9.81)
        self.playerNP = self.worldNP.attachNewNode(self.player)
        self.playerNP.setPos(-2, 0, 10)
        self.playerNP.setH(-90)
        self.playerNP.setCollideMask(BitMask32.allOn())
        self.world.attachCharacter(self.player)
Beispiel #29
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()
Beispiel #30
0
    def addSinglePlaneRB(self,up,const,**kw):
        pup = Vec3(up[0],up[1],up[2])
        shape = BulletPlaneShape(pup,const)#nomal and constant
        name = "plane"
        if "name" in kw :
            name = kw["name"]
        inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode(name))
#        inodenp.node().setMass(1.0)
#        inodenp.node().addShape(shape)
        inodenp.node().addShape(shape)#rotation ?      ,TransformState.makePos(Point3(0, 0, 0))  
#        spherenp.setPos(-2, 0, 4)
        self.setRB(inodenp,**kw)
        inodenp.setCollideMask(BitMask32.allOn())    
        self.world.attachRigidBody(inodenp.node())
        return inodenp
Beispiel #31
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)

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

        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.set_pos(0, 0, 4)
        np.set_collide_mask(BitMask32(0x0f))

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

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

        # Trigger
        shape = BulletBoxShape(LVector3(1, 1, 2))

        np = self.worldNP.attach_new_node(BulletGhostNode('Ghost'))
        np.node().add_shape(shape)
        np.set_pos(3, 0, 0)
        np.set_collide_mask(BitMask32(0x0f))

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

        self.ghostNP = np
  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
    self.debugNP.show()
    self.debugNP.node().showWireframe(True)
    self.debugNP.node().showConstraints(True)
    self.debugNP.node().showBoundingBoxes(False)
    self.debugNP.node().showNormals(False)

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

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

    body = BulletRigidBodyNode('Ground')
    bodyNP = self.worldNP.attachNewNode(body)
    bodyNP.node().addShape(shape)
    bodyNP.setPos(0, 0, 0)
    bodyNP.setCollideMask(BitMask32.allOn())
    self.world.attachRigidBody(bodyNP.node())

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

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

    body = BulletRigidBodyNode('Bowl')
    bodyNP = self.worldNP.attachNewNode(body)
    bodyNP.node().addShape(shape)
    bodyNP.node().setMass(10.0)
    bodyNP.setPos(0, 0, 0)
    bodyNP.setCollideMask(BitMask32.allOn())
    self.world.attachRigidBody(bodyNP.node())

    visNP.reparentTo(bodyNP)

    self.bowlNP = bodyNP
    self.bowlNP.setScale(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.loadModel('models/egg.egg')

      geom = visNP.findAllMatches('**/+GeomNode').getPath(0).node().getGeom(0)
      shape = BulletConvexHullShape()
      shape.addGeom(geom)

      body = BulletRigidBodyNode('Egg-%i' % i)
      bodyNP = self.worldNP.attachNewNode(body)
      bodyNP.node().setMass(1.0)
      bodyNP.node().addShape(shape)
      bodyNP.node().setDeactivationEnabled(False)
      bodyNP.setCollideMask(BitMask32.allOn())
      bodyNP.setPosHpr(x, y, z, h, p, r)
      #bodyNP.setScale(1.5)
      self.world.attachRigidBody(bodyNP.node())

      visNP.reparentTo(bodyNP)

      self.eggNPs.append(bodyNP)
Beispiel #33
0
  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
    self.debugNP.show()
    self.debugNP.node().showWireframe(True)
    self.debugNP.node().showConstraints(True)
    self.debugNP.node().showBoundingBoxes(False)
    self.debugNP.node().showNormals(True)

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

    # Plane (static)
    shape = BulletPlaneShape(Vec3(0, 0, 1), 0)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
    np.node().addShape(shape)
    np.setPos(0, 0, -1)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

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

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(0, 0, 4)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    self.boxNP = np # For applying force & torque

    #np.node().notifyCollisions(True)
    #self.accept('bullet-contact-added', self.doAdded)
    #self.accept('bullet-contact-destroyed', self.doRemoved)

    # Sphere (dynamic)
    shape = BulletSphereShape(0.6)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Sphere'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(-4, 0, 4)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # Cone (dynamic)
    shape = BulletConeShape(0.6, 1.2, ZUp)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Cone'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(4, 0, 4)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # Capsule (dynamic)
    shape = BulletCapsuleShape(0.5, 1.0, ZUp)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Capsule'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(0, 4, 4)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # Cyliner (dynamic)
    shape = BulletCylinderShape(0.7, 1.5, ZUp)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Cylinder'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(4, 4, 4)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # Convex (dynamic)
    shape = BulletConvexHullShape()
    shape.addPoint(Point3(1, 1, 2))
    shape.addPoint(Point3(0, 0, 0))
    shape.addPoint(Point3(2, 0, 0))
    shape.addPoint(Point3(0, 2, 0))
    shape.addPoint(Point3(2, 2, 0))

    # Another way to create the convex hull shape:
    #shape = BulletConvexHullShape()
    #shape.addArray([
    #  Point3(1, 1, 2),
    #  Point3(0, 0, 0),
    #  Point3(2, 0, 0),
    #  Point3(0, 2, 0),
    #  Point3(2, 2, 0),
    #])

    # Yet another way to create the convex hull shape:
    #geom = loader.loadModel('models/box.egg')\
    #         .findAllMatches('**/+GeomNode')\
    #         .getPath(0)\
    #         .node()\
    #         .getGeom(0)
    #shape = BulletConvexHullShape()
    #shape.addGeom(geom)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Convex'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(-4, 4, 4)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # Mesh (static)
    p0 = Point3(-10, -10, 0)
    p1 = Point3(-10, 10, 0)
    p2 = Point3(10, -10, 0)
    p3 = Point3(10, 10, 0)
    mesh = BulletTriangleMesh()
    mesh.addTriangle(p0, p1, p2)
    mesh.addTriangle(p1, p2, p3)
    shape = BulletTriangleMeshShape(mesh, dynamic=False)

    # Another way to create the triangle mesh shape:
    #geom = loader.loadModel('models/box.egg')\
    #         .findAllMatches('**/+GeomNode')\
    #         .getPath(0)\
    #         .node()\
    #         .getGeom(0)
    #mesh = BulletTriangleMesh()
    #mesh.addGeom(geom)
    #shape = BulletTriangleMeshShape(mesh, dynamic=False)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Mesh'))
    np.node().addShape(shape)
    np.setPos(0, 0, 0.1)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())

    # MutiSphere
    points = [Point3(-1, 0, 0), Point3(0, 0, 0), Point3(1, 0, 0)]
    radii = [.4, .8, .6]
    shape = BulletMultiSphereShape(points, radii)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('MultiSphere'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(8, 0, 4)
    np.setCollideMask(BitMask32.allOn())

    self.world.attachRigidBody(np.node())