Пример #1
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')
Пример #2
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)
Пример #3
0
    def createPlane(self):
        rb = BulletRigidBodyNode('Ground')
        rb.addShape(BulletPlaneShape(Vec3(0, 0, 1), 1))
        rb.setFriction(1.0)

        np = self.render.attachNewNode(rb)
        np.setPos(Vec3(0, 0, -100))
        np.setCollideMask(BitMask32.bit(0))

        self.world.attachRigidBody(rb)

        return np
Пример #4
0
    def createPlane(self, pos):
        rb = BulletRigidBodyNode("plane")
        rb.addShape(BulletPlaneShape(Vec3(0, 0, 1), 1))
        rb.setFriction(1.0)
        rb.setAnisotropicFriction(1.0)
        rb.setRestitution(1.0)

        np = self.render.attachNewNode(rb)
        np.setPos(pos)
        np.setCollideMask(BitMask32.bit(0))

        self.world.attachRigidBody(rb)

        return np
Пример #5
0
    def addSmiley(self, task):
        node = cd.genCollisionMeshNp(self.smiley)
        node.setMass(1.0)
        node.setName("part"+str(self.smileyCount))
        np = base.render.attachNewNode(node)
        np.setPos(random.uniform(-2, 2), random.uniform(-2, 2), 15.0+self.smileyCount*25.0)
        sm = np.attachNewNode("partrender"+str(self.smileyCount))
        self.smiley.instanceTo(sm)
        self.bltWorld.attachRigidBody(node)

        self.smileyCount += 1

        if self.smileyCount == 20:
            return task.done
        return task.again
Пример #6
0
    def addSmiley(self, task):
        node = cd.genCollisionMeshNp(self.smiley)
        node.setMass(1.0)
        node.setName("part"+str(self.smileyCount))
        np = base.render.attachNewNode(node)
        np.setPos(random.uniform(-2, 2), random.uniform(-2, 2), 15.0+self.smileyCount*25.0)
        sm = np.attachNewNode("partrender"+str(self.smileyCount))
        self.smiley.instanceTo(sm)
        self.bltWorld.attachRigidBody(node)

        self.smileyCount += 1

        if self.smileyCount == 20:
            return task.done
        return task.again
Пример #7
0
    def createLighting(self):
        light = DirectionalLight("light")
        light.setColor(VBase4(0.2, 0.2, 0.2, 1))

        np = self.render.attachNewNode(light)
        np.setPos(10, -10, 20)
        np.lookAt(0, 0, 0)

        self.render.setLight(np)

        light = AmbientLight("ambient")
        light.setColor(VBase4(0.4, 0.4, 0.4, 1))

        np = self.render.attachNewNode(light)

        self.render.setLight(np)
Пример #8
0
    def createLighting(self):
        light = DirectionalLight('light')
        light.set_color(VBase4(0.2, 0.2, 0.2, 1))

        np = self.render.attach_new_node(light)
        np.setPos(0, -200, 0)
        np.lookAt(0, 0, 0)

        self.render.set_light(np)

        light = AmbientLight('ambient')
        light.set_color(VBase4(0.4, 0.4, 0.4, 1))

        np = self.render.attachNewNode(light)

        self.render.setLight(np)
Пример #9
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
        length = 2.8
        width = 1.2
        height = 1
        axisDis = 2.1
        wheelDis = 1.4
        wheelH = 0.3
        radius = 0.25

        self.vehicles = []
        self.sensors = []

        # Adding autonomous vehicles
        for i in range(len(self.initAV)):
            self.vehicles.append(
                basicVehicle(self,
                             [self.initAV[i][0], self.initAV[i][1], -0.6],
                             self.initAV[i][2], length, width, height, axisDis,
                             wheelDis, radius, wheelH))
            self.sensors.append(basicSensor(self))  # initial sensor
            self.sensors[i].setVehicle(self.vehicles[i])
            self.vehicles[i].setSensor(self.sensors[i])
            self.vehicles[i].sensor.align()
            self.agents[i].setVehicle(self.vehicles[i])
            self.vehicles[i].setAgent(self.agents[i])
Пример #10
0
    def __init__(self):
        ShowBase.__init__(self)

        loadPrcFileData('', 'bullet-enable-contact-events true')
        loadPrcFileData("", "win-size 300 100")
        loadPrcFileData("", "show-buffers t")
        winProp = WindowProperties()
        winProp.setSize(300,100)
        base.win.requestProperties(winProp)
        world = BulletWorld()
        self.world = world

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

        # Plane ground
        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)

        plight = PointLight('plight')
        plnp = render.attachNewNode(plight)
        plnp.setPos(100,0,1000)
        render.setLight(plnp)
        plight2 = PointLight('plight2')
        plnp2 = render.attachNewNode(plight2)
        plnp2.setPos(-100,0,1000)
        render.setLight(plnp2)
        # Repeat every new game
        self.newGame()
        self.skip = True
        plt.ion()        
        plt.figure(figsize=(2,3))
        # Repeat tasks every frame
        taskMgr.add(self.update, 'update')
        self.texDepth = Texture()
        base.win.addRenderTexture(self.texDepth, GraphicsOutput.RTMCopyRam, GraphicsOutput.RTPDepthStencil)
Пример #11
0
    def createPlane(self, pos):
        rb = BulletRigidBodyNode("GroundPlane")
        rb.addShape(BulletPlaneShape(Vec3(0, 0, 1), 1))
        rb.setFriction(1.0)
        rb.setAnisotropicFriction(1.0)
        rb.setRestitution(1.0)

        np = self.render.attachNewNode(rb)
        np.setPos(pos)
        np.setCollideMask(BitMask32.bit(0))

        plane = self.loader.loadModel("cube")
        plane.setScale(Vec3(100, 100, 1))
        plane.setPos(Vec3(0, 0, -0.5))
        plane.setColor(VBase4(0.8, 0.8, 0.8, 1.0))
        plane.reparentTo(np)

        self.world.attachRigidBody(rb)

        return np
Пример #12
0
    def createLighting(self):
        light = DirectionalLight("light")
        light.setColor(VBase4(0.4, 0.4, 0.4, 1))
        light.setShadowCaster(True)
        light.getLens().setNearFar(100.0, 400.0)
        light.getLens().setFilmSize(400, 400)
        # light.showFrustum()

        np = self.render.attachNewNode(light)
        np.setPos(100, -100, 200)
        np.lookAt(0, 0, -100)

        self.render.setLight(np)

        light = AmbientLight("ambient")
        light.setColor(VBase4(0.2, 0.2, 0.2, 1))

        np = self.render.attachNewNode(light)

        self.render.setLight(np)
Пример #13
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)

        # 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')
Пример #14
0
    def createBox(self, mass, pos, scale, color):
        rb = BulletRigidBodyNode('box')
        rb.addShape(BulletBoxShape(scale))
        rb.setMass(mass)
        rb.setLinearDamping(0.2)
        rb.setAngularDamping(0.9)
        rb.setFriction(1.0)
        rb.setAnisotropicFriction(1.0)
        rb.setRestitution(0.0)

        self.world.attachRigidBody(rb)

        np = self.render.attachNewNode(rb)
        np.setPos(pos)
        np.setCollideMask(BitMask32.bit(1))

        cube = self.loader.loadModel('cube')
        cube.setScale(scale)
        cube.setColor(color)
        cube.reparentTo(np)

        return np
Пример #15
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())

        self.vehicles = dict()
Пример #16
0
    def generate_environment(self):
        f = create_plane()
        np = NodePath(f)
        np.reparentTo(self.scenery)
        np.setPos(0,0,-1)

        slight = PointLight('slight')
        slight.setColor(VBase4(1, 1, 1, 1))
        slight.setAttenuation(Point3(0, 0, 0.001))
        lens = PerspectiveLens()
        slight.setLens(lens)
        np = NodePath(slight)
        np.setPos(0, 0, 50)
        render.setLight(np)


        alight = AmbientLight('alight')
        alnp = render.attachNewNode(alight)
        alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        render.setLight(alnp)
        self.scenery.reparentTo(render)

        base.cam.setPos(0, -60, 60)
        base.cam.lookAt(0, 0, 1)
Пример #17
0
import basis.data_adapter as da
import copy

base = wd.World(cam_pos=np.array([1000, 0, 3000]), lookat_pos=np.array([0, 0, 0]), toggle_debug=True)
# World
# world = BulletWorld()
# world.setGravity(Vec3(0, 0, -9810))
# gm.gen_frame().attach_to(base)

# Plane
shape = BulletBoxShape(Vec3(500, 500, 100))
# shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
node = BulletRigidBodyNode('Ground')
node.addShape(shape)
np = base.render.attachNewNode(node)
np.setPos(0, 0, 0)
base.physicsworld.attachRigidBody(node)

# Box
# shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
# shape = BulletSphereShape(radius=.1)
# radius = 0.5
# height = 1.4
# shape = BulletCylinderShape(radius, height, ZUp)
# radius = 0.5
# height = 1.0
# shape = BulletCapsuleShape(radius, height, ZUp)
# radius = 0.6
# height = 1.0
# shape = BulletConeShape(radius, height, ZUp)
# shape = BulletConvexHullShape()
Пример #18
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
    length=2.8
    width=1.2
    height=1
    axisDis=2.1
    wheelDis=1.4
    wheelH=0.3
    radius=0.25
    
    self.vehicles=[]
    self.sensors=[]
    
    self.vehicles.append(basicVehicle(self,[self.initAV[0],self.initAV[1],-0.6],self.initAV[2],length,width,height,axisDis,wheelDis,radius,wheelH)) # [10,0.1,0.5] is vehicle start position
    self.sensors.append(basicSensor(self))  # initial sensor
    self.sensors[0].setVehicle(self.vehicles[0])
    self.vehicles[0].setSensor(self.sensors[0])
    self.vehicles[0].sensor.align()
    self.agents[0].setVehicle(self.vehicles[0])
    self.vehicles[0].setAgent(self.agents[0])

    #Adding laneKeeping vehicles
    for i in range(len(self.initSV)):
        self.vehicles.append(surroundingVehicle(self,[self.initSV[i][0],self.initSV[i][1],-0.6],self.initSV[i][2],length,width,height,axisDis,wheelDis,radius,wheelH)) # [10,0.1,0.5] is vehicle start position
        self.sensors.append(basicSensor(self))  # initial sensor
        self.sensors[i+1].setVehicle(self.vehicles[i+1])
        self.vehicles[i+1].setSensor(self.sensors[i+1])
        self.vehicles[i+1].sensor.align()
        self.agents[i+1].setVehicle(self.vehicles[i+1])
        self.vehicles[i+1].setAgent(self.agents[i+1])    
    
    '''self.vehicles.append(basicVehicle(self,[50,-6,-0.6],30)) # [10,0.1,0.5] is vehicle start position
    sensor1=basicSensor(self)  # initial sensor
    sensor1.setVehicle(self.vehicles[1])
    self.vehicles[1].setSensor(sensor1)
    self.vehicles[1].sensor.align()
    #agent1=planningAgent(20,5,40,0,1)   # initial agent
    agent1=laneKeepingAgent(20,20,30,1)
    agent1.setVehicle(self.vehicles[1])
    self.vehicles[1].setAgent(agent1)'''
    
    #Surrounding vehicles' speed
    v1=25
    v2=25
    v3=25
    v4=25
    
    '''self.vehicles.append(basicVehicle(self,[60,-6.1,-0.6],v1))