Ejemplo n.º 1
0
 def setupLights(self):    #This function sets up some default lighting
   lAttrib = LightAttrib.makeAllOff()
   ambientLight = AmbientLight( "ambientLight" )
   ambientLight.setColor( Vec4(.8, .8, .8, 1) )
   lAttrib = lAttrib.addLight( ambientLight )
   directionalLight = DirectionalLight( "directionalLight" )
   directionalLight.setDirection( Vec3( 0, 45, -45 ) )
   directionalLight.setColor( Vec4( 0.2, 0.2, 0.2, 1 ) )
   lAttrib = lAttrib.addLight( directionalLight )
   render.attachNewNode( directionalLight ) 
   render.attachNewNode( ambientLight ) 
   render.node().setAttrib( lAttrib )
Ejemplo n.º 2
0
 def setupLights(self):                    #Sets up some default lighting
   lAttrib = LightAttrib.makeAllOff()
   ambientLight = AmbientLight( "ambientLight" )
   ambientLight.setColor( Vec4(.4, .4, .35, 1) )
   lAttrib = lAttrib.addLight( ambientLight )
   directionalLight = DirectionalLight( "directionalLight" )
   directionalLight.setDirection( Vec3( 0, 8, -2.5 ) )
   directionalLight.setColor( Vec4( 0.9, 0.8, 0.9, 1 ) )
   lAttrib = lAttrib.addLight( directionalLight )
   render.attachNewNode( directionalLight ) 
   render.attachNewNode( ambientLight ) 
   render.node().setAttrib( lAttrib )
Ejemplo n.º 3
0
 def setupLights(self):
     lAttrib = LightAttrib.makeAllOff()
     ambientLight = AmbientLight("ambientLight")
     ambientLight.setColor(Vec4(.8, .8, .75, 1))
     lAttrib = lAttrib.addLight(ambientLight)
     directionalLight = DirectionalLight("directionalLight")
     directionalLight.setDirection(Vec3(0, 0, -2.5))
     directionalLight.setColor(Vec4(0.9, 0.8, 0.9, 1))
     lAttrib = lAttrib.addLight(directionalLight)
     render.attachNewNode(directionalLight)
     render.attachNewNode(ambientLight)
     render.node().setAttrib(lAttrib)
Ejemplo n.º 4
0
 def setupLights(self):
     lAttrib = LightAttrib.makeAllOff()
     ambientLight = AmbientLight("ambientLight")
     ambientLight.setColor(Vec4(0.8, 0.8, 0.75, 1))
     lAttrib = lAttrib.addLight(ambientLight)
     directionalLight = DirectionalLight("directionalLight")
     directionalLight.setDirection(Vec3(0, 0, -2.5))
     directionalLight.setColor(Vec4(0.9, 0.8, 0.9, 1))
     lAttrib = lAttrib.addLight(directionalLight)
     render.attachNewNode(directionalLight)
     render.attachNewNode(ambientLight)
     render.node().setAttrib(lAttrib)
Ejemplo n.º 5
0
 def setupLights(self):
     lAttrib = LightAttrib.makeAllOff()
     ambientLight = AmbientLight( "ambientLight" )
     ambientLight.setColor( Vec4(.4, .4, .35, 1) )
     lAttrib = lAttrib.addLight( ambientLight )
     directionalLight = DirectionalLight( "directionalLight" )
     directionalLight.setDirection( Vec3( 0, 8, -2.5 ) )
     directionalLight.setColor( Vec4( 0.9, 0.8, 0.9, 1 ) )
     lAttrib = lAttrib.addLight( directionalLight )
     #set lighting on teapot so steam doesn't get affected
     self.t.attachNewNode( directionalLight ) 
     self.t.attachNewNode( ambientLight ) 
     self.t.node().setAttrib( lAttrib )
Ejemplo n.º 6
0
 def setupLights(self):
     lAttrib = LightAttrib.makeAllOff()
     ambientLight = AmbientLight("ambientLight")
     ambientLight.setColor(Vec4(.4, .4, .35, 1))
     lAttrib = lAttrib.addLight(ambientLight)
     directionalLight = DirectionalLight("directionalLight")
     directionalLight.setDirection(Vec3(0, 8, -2.5))
     directionalLight.setColor(Vec4(0.9, 0.8, 0.9, 1))
     lAttrib = lAttrib.addLight(directionalLight)
     #set lighting on teapot so steam doesn't get affected
     self.t.attachNewNode(directionalLight)
     self.t.attachNewNode(ambientLight)
     self.t.node().setAttrib(lAttrib)
Ejemplo n.º 7
0
    def setupLights(self):
        #Create some lights and add them to the scene. By setting the lights on
        #render they affect the entire scene
        #Check out the lighting tutorial for more information on lights
        lAttrib = LightAttrib.makeAllOff()
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor(Vec4(.4, .4, .35, 1))
        lAttrib = lAttrib.addLight(ambientLight)
        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setDirection(Vec3(0, 8, -2.5))
        directionalLight.setColor(Vec4(0.9, 0.8, 0.9, 1))
        lAttrib = lAttrib.addLight(directionalLight)
        render.attachNewNode(directionalLight)
        render.attachNewNode(ambientLight)
        render.node().setAttrib(lAttrib)

        #Explicitly set the environment to not be lit
        lAttrib = LightAttrib.makeAllOff()
        self.env.node().setAttrib(lAttrib)
Ejemplo n.º 8
0
  def setupLights(self):
    #Create some lights and add them to the scene. By setting the lights on
    #render they affect the entire scene
    #Check out the lighting tutorial for more information on lights
    lAttrib = LightAttrib.makeAllOff()
    ambientLight = AmbientLight( "ambientLight" )
    ambientLight.setColor( Vec4(.4, .4, .35, 1) )
    lAttrib = lAttrib.addLight( ambientLight )
    directionalLight = DirectionalLight( "directionalLight" )
    directionalLight.setDirection( Vec3( 0, 8, -2.5 ) )
    directionalLight.setColor( Vec4( 0.9, 0.8, 0.9, 1 ) )
    lAttrib = lAttrib.addLight( directionalLight )
    render.attachNewNode( directionalLight )
    render.attachNewNode( ambientLight )
    render.node().setAttrib( lAttrib )

    #Explicitly set the environment to not be lit
    lAttrib = LightAttrib.makeAllOff()
    self.env.node().setAttrib( lAttrib )
Ejemplo n.º 9
0
    if numIterations%3==0:
      #decrease dimensions when we branch
      length=Vec3(length.getX()/2, length.getY()/2, length.getZ()/1.1)
      for i in range(numCopies):
        makeFractalTree(bodydata, nodePath,length,newPos, numIterations-1, numCopies,randomAxis(vecList))
    else:
      #just make another branch connected to this one with a small variation in direction
      makeFractalTree(bodydata, nodePath,length,newPos, numIterations-1,numCopies,smallRandomAxis(vecList))

  else:
    drawBody(nodePath,bodydata, pos, vecList, length.getX(),False)
    drawLeaf(nodePath,bodydata, pos,vecList)



alight = AmbientLight('alight')
alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)

slight = Spotlight('slight')
slight.setColor(Vec4(1, 1, 1, 1))
lens = PerspectiveLens()
slight.setLens(lens)
slnp = render.attachNewNode(slight.upcastToLensNode())
render.setLight(slnp)

slnp.setPos(0, 0,40)

#rotating light to show that normals are calculated correctly
def updateLight(task):
Ejemplo n.º 10
0
    def __init__(self):
        
        # Post the instructions.
        self.title = addTitle("Panda3D: Tutorial - Using Render-to-Texture")
        self.inst1 = addInstructions(0.95,"ESC: Quit")
        self.inst2 = addInstructions(0.90,"Up/Down: Zoom in/out on the Teapot")
        self.inst3 = addInstructions(0.85,"Left/Right: Move teapot left/right")
        self.inst4 = addInstructions(0.80,"V: View the render-to-texture results")

        #we get a handle to the default window
        mainWindow=base.win

        #we now get buffer thats going to hold the texture of our new scene   
        altBuffer=mainWindow.makeTextureBuffer("hello", 256, 256)
        
        #now we have to setup a new scene graph to make this scene
        altRender=NodePath("new render")

        #this takes care of setting up ther camera properly
        self.altCam=base.makeCamera(altBuffer)
        self.altCam.reparentTo(altRender)        
        self.altCam.setPos(0,-10,0)

        #get the teapot and rotates it for a simple animation
        self.teapot=loader.loadModel('models/teapot')
        self.teapot.reparentTo(altRender)
        self.teapot.setPos(0,0,-1)
        self.teapot.hprInterval(1.5,Point3(360,360,360)).loop()
        
        #put some lighting on the teapot
        dlight = DirectionalLight('dlight')
        alight = AmbientLight('alight')
        dlnp = altRender.attachNewNode(dlight) 
        alnp = altRender.attachNewNode(alight)
        dlight.setColor(Vec4(0.8, 0.8, 0.5, 1))
        alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        dlnp.setHpr(0, -60, 0) 
        altRender.setLight(dlnp)
        altRender.setLight(alnp)
        
        # Panda contains a built-in viewer that lets you view the results of
        # your render-to-texture operations.  This code configures the viewer.

        self.accept("v", base.bufferViewer.toggleEnable)
        self.accept("V", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        base.bufferViewer.setCardSize(1.0, 0.0)

        # Create the tv-men. Each TV-man will display the
        # offscreen-texture on his TV screen.
        self.tvMen = []
        self.makeTvMan(-5,30, 1,altBuffer.getTexture(),0.9)
        self.makeTvMan( 5,30, 1,altBuffer.getTexture(),1.4)
        self.makeTvMan( 0,23,-3,altBuffer.getTexture(),2.0)
        self.makeTvMan(-5,20,-6,altBuffer.getTexture(),1.1)
        self.makeTvMan( 5,18,-5,altBuffer.getTexture(),1.7)

        self.accept("escape", sys.exit, [0])
        self.accept("arrow_up", self.zoomIn)
        self.accept("arrow_down", self.zoomOut)
        self.accept("arrow_left", self.moveLeft)
        self.accept("arrow_right", self.moveRight)
Ejemplo n.º 11
0
    def __init__(self):
        base.disableMouse()
        base.cam.node().getLens().setNear(10.0)
        base.cam.node().getLens().setFar(200.0)
        camera.setPos(0, -50, 0)
        
        # Check video card capabilities.
        
        if (base.win.getGsg().getSupportsBasicShaders() == 0):
            addTitle("Toon Shader: Video driver reports that shaders are not supported.")
            return
        
        # Enable a 'light ramp' - this discretizes the lighting,
        # which is half of what makes a model look like a cartoon.
        # Light ramps only work if shader generation is enabled,
        # so we call 'setShaderAuto'.

        tempnode = NodePath(PandaNode("temp node"))
        tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4))
        tempnode.setShaderAuto()
        base.cam.node().setInitialState(tempnode.getState())
        
        # Use class 'CommonFilters' to enable a cartoon inking filter.
        # This can fail if the video card is not powerful enough, if so,
        # display an error and exit.
        
        self.separation = 1 # Pixels
        self.filters = CommonFilters(base.win, base.cam)
        filterok = self.filters.setCartoonInk(separation=self.separation)
        if (filterok == False):
            addTitle("Toon Shader: Video card not powerful enough to do image postprocessing")
            return
        
        # Post the instructions.
        
        self.title = addTitle("Panda3D: Tutorial - Toon Shading with Normals-Based Inking")
        self.inst1 = addInstructions(0.95,"ESC: Quit")
        self.inst2 = addInstructions(0.90,"Up/Down: Increase/Decrease Line Thickness")
        self.inst3 = addInstructions(0.85,"V: View the render-to-texture results")
        
        # Load a dragon model and animate it.
        
        self.character = Actor()
        self.character.loadModel('models/samples/cartoon/nik_dragon')
        self.character.reparentTo(render)
        self.character.loadAnims({'win': 'models/samples/cartoon/nik_dragon'})
        self.character.loop('win')
        self.character.hprInterval(15, Point3(360, 0,0)).loop()
        
        # Create a non-attenuating point light and an ambient light.
        
        plightnode = PointLight("point light")
        plightnode.setAttenuation(Vec3(1,0,0))
        plight = render.attachNewNode(plightnode)
        plight.setPos(30,-50,0)
        alightnode = AmbientLight("ambient light")
        alightnode.setColor(Vec4(0.8,0.8,0.8,1))
        alight = render.attachNewNode(alightnode)
        render.setLight(alight)
        render.setLight(plight)
        
        # Panda contains a built-in viewer that lets you view the 
        # results of all render-to-texture operations.  This lets you
        # see what class CommonFilters is doing behind the scenes.
        
        self.accept("v", base.bufferViewer.toggleEnable)
        self.accept("V", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        self.accept("s", self.filters.manager.resizeBuffers)
        
        # These allow you to change cartooning parameters in realtime
        
        self.accept("escape", sys.exit, [0])
        self.accept("arrow_up", self.increaseSeparation)
        self.accept("arrow_down", self.decreaseSeparation)
Ejemplo n.º 12
0
    def __init__(self):
        base.disableMouse()
        base.setBackgroundColor(0,0,0)
        camera.setPos(0,-50,0)
        
        # Check video card capabilities.

        if (base.win.getGsg().getSupportsBasicShaders() == 0):
            addTitle("Glow Filter: Video driver reports that shaders are not supported.")
            return

        # Use class 'CommonFilters' to enable a bloom filter.
        # The brightness of a pixel is measured using a weighted average
        # of R,G,B,A.  We put all the weight on Alpha, meaning that for
        # us, the framebuffer's alpha channel alpha controls bloom.

        self.filters = CommonFilters(base.win, base.cam)
        filterok = self.filters.setBloom(blend=(0,0,0,1), desat=-0.5, intensity=3.0, size="small")
        if (filterok == False):
            addTitle("Toon Shader: Video card not powerful enough to do image postprocessing")
            return
        self.glowSize=1

        # Post the instructions
        self.title = addTitle("Panda3D: Tutorial - Glow Filter")
        self.inst1 = addInstructions(0.95,"ESC: Quit")
        self.inst2 = addInstructions(0.90,"Space: Toggle Glow Filter Small/Med/Large/Off")
        self.inst3 = addInstructions(0.85,"Enter: Toggle Running/Spinning")
        self.inst4 = addInstructions(0.80,"V: View the render-to-texture results")

        # load our model

        self.tron=Actor()
        self.tron.loadModel("samples/glow/tron")
        self.tron.loadAnims({"running":"samples/glow/models/tron_anim"})
        self.tron.reparentTo(render)
        self.interval = self.tron.hprInterval(60,Point3(360,0,0))
        self.interval.loop()
        self.isRunning=False

        # put some lighting on the model

        dlight = DirectionalLight('dlight')
        alight = AmbientLight('alight')
        dlnp = render.attachNewNode(dlight) 
        alnp = render.attachNewNode(alight)
        dlight.setColor(Vec4(1.0, 0.7, 0.2, 1))
        alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        dlnp.setHpr(0, -60, 0) 
        render.setLight(dlnp)
        render.setLight(alnp)

        # Panda contains a built-in viewer that lets you view the results of
        # your render-to-texture operations.  This code configures the viewer.

        self.accept("v", base.bufferViewer.toggleEnable)
        self.accept("V", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        base.bufferViewer.setLayout("hline")
        #base.camLens.setFov(100)
        # event handling
        self.accept("space", self.toggleGlow)
        self.accept("enter", self.toggleDisplay)
        self.accept("escape", sys.exit, [0])
Ejemplo n.º 13
0
    def __init__(self):
        base.disableMouse()
        base.setBackgroundColor(0, 0, 0)
        camera.setPos(0, -50, 0)

        # Check video card capabilities.

        if (base.win.getGsg().getSupportsBasicShaders() == 0):
            addTitle(
                "Glow Filter: Video driver reports that shaders are not supported."
            )
            return

        # Use class 'CommonFilters' to enable a bloom filter.
        # The brightness of a pixel is measured using a weighted average
        # of R,G,B,A.  We put all the weight on Alpha, meaning that for
        # us, the framebuffer's alpha channel alpha controls bloom.

        self.filters = CommonFilters(base.win, base.cam)
        filterok = self.filters.setBloom(blend=(0, 0, 0, 1),
                                         desat=-0.5,
                                         intensity=3.0,
                                         size="small")
        if (filterok == False):
            addTitle(
                "Toon Shader: Video card not powerful enough to do image postprocessing"
            )
            return
        self.glowSize = 1

        # Post the instructions
        self.title = addTitle("Panda3D: Tutorial - Glow Filter")
        self.inst1 = addInstructions(0.95, "ESC: Quit")
        self.inst2 = addInstructions(
            0.90, "Space: Toggle Glow Filter Small/Med/Large/Off")
        self.inst3 = addInstructions(0.85, "Enter: Toggle Running/Spinning")
        self.inst4 = addInstructions(0.80,
                                     "V: View the render-to-texture results")

        # load our model

        self.tron = Actor()
        self.tron.loadModel("samples/glow/tron")
        self.tron.loadAnims({"running": "samples/glow/models/tron_anim"})
        self.tron.reparentTo(render)
        self.interval = self.tron.hprInterval(60, Point3(360, 0, 0))
        self.interval.loop()
        self.isRunning = False

        # put some lighting on the model

        dlight = DirectionalLight('dlight')
        alight = AmbientLight('alight')
        dlnp = render.attachNewNode(dlight)
        alnp = render.attachNewNode(alight)
        dlight.setColor(Vec4(1.0, 0.7, 0.2, 1))
        alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        dlnp.setHpr(0, -60, 0)
        render.setLight(dlnp)
        render.setLight(alnp)

        # Panda contains a built-in viewer that lets you view the results of
        # your render-to-texture operations.  This code configures the viewer.

        self.accept("v", base.bufferViewer.toggleEnable)
        self.accept("V", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        base.bufferViewer.setLayout("hline")
        #base.camLens.setFov(100)
        # event handling
        self.accept("space", self.toggleGlow)
        self.accept("enter", self.toggleDisplay)
        self.accept("escape", sys.exit, [0])
Ejemplo n.º 14
0
        self.bcard.setScale(0.999)
        self.bcard.setPos(0,0,0)
        self.bcard.setR(1)
        self.clickrate = 10000
        self.nextclick = 0

        
t=MotionTrails()

character=Actor()
character.loadModel('models/samples/motion_trails/dancer')
character.reparentTo(render)
character.loadAnims({'win':'models/samples/motion_trails/dancer'})
character.loop('win')
# character.hprInterval(15, Point3(360, 0,0)).loop()

#put some lighting on the model
dlight = DirectionalLight('dlight')
alight = AmbientLight('alight')
dlnp = render.attachNewNode(dlight) 
alnp = render.attachNewNode(alight)
dlight.setColor(Vec4(1.0, 0.9, 0.8, 1))
alight.setColor(Vec4(0.2, 0.3, 0.4, 1))
dlnp.setHpr(0, -60, 0) 
render.setLight(dlnp)
render.setLight(alnp)

run()


Ejemplo n.º 15
0
    def __init__(self):
        base.disableMouse()
        base.setBackgroundColor(0,0,0)
        camera.setPos(0,-50,0)
        
        # Check video card capabilities.

        if (base.win.getGsg().getSupportsBasicShaders() == 0):
            addTitle("Glow Filter: Video driver reports that shaders are not supported.")
            return

        # Post the instructions
        self.title = addTitle("Panda3D: Tutorial - Glow Filter")
        self.inst1 = addInstructions(0.95,"ESC: Quit")
        self.inst2 = addInstructions(0.90,"Space: Toggle Glow Filter On/Off")
        self.inst3 = addInstructions(0.85,"Enter: Toggle Running/Spinning")
        self.inst4 = addInstructions(0.80,"V: View the render-to-texture results")

        #create the shader that will determime what parts of the scene will glow
        glowShader=Shader.load(os.path.join(PANDA_SHADER_PATH, \
          "samples/glow/glow_shader.sha"))

        # load our model
        self.tron=Actor()
        self.tron.loadModel("models/samples/glow/tron")
        self.tron.loadAnims({"running":"models/samples/glow/tron_anim"})
        self.tron.reparentTo(render)
        self.interval = self.tron.hprInterval(60,Point3(360,0,0))
        self.interval.loop()
        self.isRunning=False

        #put some lighting on the tron model
        dlight = DirectionalLight('dlight')
        alight = AmbientLight('alight')
        dlnp = render.attachNewNode(dlight) 
        alnp = render.attachNewNode(alight)
        dlight.setColor(Vec4(1.0, 0.7, 0.2, 1))
        alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        dlnp.setHpr(0, -60, 0) 
        render.setLight(dlnp)
        render.setLight(alnp)

        # create the glow buffer. This buffer renders like a normal scene,
        # except that only the glowing materials should show up nonblack.
        glowBuffer=base.win.makeTextureBuffer("Glow scene", 512, 512)
        glowBuffer.setSort(-3)
        glowBuffer.setClearColor(Vec4(0,0,0,1))

        # We have to attach a camera to the glow buffer. The glow camera
        # must have the same frustum as the main camera. As long as the aspect
        # ratios match, the rest will take care of itself.
        glowCamera=base.makeCamera(glowBuffer, lens=base.cam.node().getLens())

        # Tell the glow camera to use the glow shader
        tempnode = NodePath(PandaNode("temp node"))
        tempnode.setShader(glowShader)
        glowCamera.node().setInitialState(tempnode.getState())

        # set up the pipeline: from glow scene to blur x to blur y to main window.
        blurXBuffer=makeFilterBuffer(glowBuffer,  "Blur X", -2, \
          os.path.join(PANDA_SHADER_PATH, "samples/glow/glow_xblur.sha"))
        blurYBuffer=makeFilterBuffer(blurXBuffer, "Blur Y", -1, \
          os.path.join(PANDA_SHADER_PATH, "samples/glow/glow_yblur.sha"))
        self.finalcard = blurYBuffer.getTextureCard()
        self.finalcard.reparentTo(render2d)
        self.finalcard.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd))
        
        # Panda contains a built-in viewer that lets you view the results of
        # your render-to-texture operations.  This code configures the viewer.

        self.accept("v", base.bufferViewer.toggleEnable)
        self.accept("V", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        base.bufferViewer.setLayout("hline")
        base.bufferViewer.setCardSize(0.652,0)

        # event handling
        self.accept("space", self.toggleGlow)
        self.accept("enter", self.toggleDisplay)
        self.accept("escape", sys.exit, [0])

        self.glowOn=True;
Ejemplo n.º 16
0
    def __init__(self):

        # Check video card capabilities.

        if (base.win.getGsg().getSupportsBasicShaders() == 0):
            addTitle("Normal Mapping: Video driver reports that shaders are not supported.")
            return

        # Post the instructions
        self.title = addTitle("Panda3D: Tutorial - Normal Mapping (aka Bump Mapping)")
        self.inst1 = addInstructions(0.95, "Press ESC to exit")
        self.inst2 = addInstructions(0.90, "Move mouse to rotate camera")
        self.inst3 = addInstructions(0.85, "Left mouse button: Move forwards")
        self.inst4 = addInstructions(0.80, "Right mouse button: Move backwards")
        self.inst5 = addInstructions(0.75, "Enter: Turn normal maps Off")

        # Load the 'abstract room' model.  This is a model of an
        # empty room containing a pillar, a pyramid, and a bunch
        # of exaggeratedly bumpy textures.

        self.room = loader.loadModel( \
          "models/samples/normal_mapping/abstractroom")
        self.room.reparentTo(render)

        # Make the mouse invisible, turn off normal mouse controls
        base.disableMouse()
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)

        # Set the current viewing target
        self.focus = Vec3(55,-55,20)
        self.heading = 180
        self.pitch = 0
        self.mousex = 0
        self.mousey = 0
        self.last = 0
        self.mousebtn = [0,0,0]

        # Start the camera control task:
        taskMgr.add(self.controlCamera, "camera-task")
        self.accept("escape", sys.exit, [0])
        self.accept("mouse1", self.setMouseBtn, [0, 1])
        self.accept("mouse1-up", self.setMouseBtn, [0, 0])
        self.accept("mouse2", self.setMouseBtn, [1, 1])
        self.accept("mouse2-up", self.setMouseBtn, [1, 0])
        self.accept("mouse3", self.setMouseBtn, [2, 1])
        self.accept("mouse3-up", self.setMouseBtn, [2, 0])
        self.accept("enter", self.toggleShader)
        self.accept("j", self.rotateLight, [-1])
        self.accept("k", self.rotateLight, [1])
        self.accept("arrow_left", self.rotateCam, [-1])
        self.accept("arrow_right", self.rotateCam, [1])

        # Add a light to the scene.
        self.lightpivot = render.attachNewNode("lightpivot")
        self.lightpivot.setPos(0,0,25)
        self.lightpivot.hprInterval(10,Point3(360,0,0)).loop()
        plight = PointLight('plight')
        plight.setColor(Vec4(1, 1, 1, 1))
        plight.setAttenuation(Vec3(0.7,0.05,0))
        plnp = self.lightpivot.attachNewNode(plight)
        plnp.setPos(45, 0, 0)
        self.room.setLight(plnp)
        self.room.setShaderInput("light", plnp)
        
        # Add an ambient light
        alight = AmbientLight('alight')
        alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        alnp = render.attachNewNode(alight)
        self.room.setLight(alnp)

        # create a sphere to denote the light
        sphere = loader.loadModel("models/samples/normal_mapping/sphere")
        sphere.reparentTo(plnp)

        # load and apply the shader.  This is using panda's
        # built-in shader generation capabilities to create the
        # shader for you.  However, if desired, you can supply
        # the shader manually.  Change this line of code to:
        #   self.room.setShader(Shader.load("bumpMapper.sha"))
        self.room.setShaderAuto()

        self.shaderenable = 1
Ejemplo n.º 17
0
  def __init__(self):
    #This code puts the standard title and instruction text on screen
    self.title = OnscreenText(text="Panda3D: Tutorial - Collision Detection",
                              style=1, fg=(1,1,1,1),
                              pos=(0.7,-0.95), scale = .07, font = font)
    self.instructions = OnscreenText(text="Mouse pointer tilts the board",
                                     pos = (-1.3, .95), fg=(1,1,1,1), font = font,
                                     align = TextNode.ALeft, scale = .05)
    
    self.accept("escape", sys.exit)        #Escape quits
    base.disableMouse()                    #Disable mouse-based camera control
    camera.setPosHpr(0, 0, 25, 0, -90, 0)  #Place the camera

    #Load the maze and place it in the scene
    self.maze = loader.loadModel("models/samples/ball_in_maze/maze")
    self.maze.reparentTo(render)

    #Most times, you want collisions to be tested against invisible geometry
    #rather than every polygon. This is because testing against every polygon
    #in the scene is usually too slow. You can have simplified or approximate
    #geometry for the solids and still get good results.
    #
    #Sometimes you'll want to create and position your own collision solids in
    #code, but it's often easier to have them built automatically. This can be
    #done by adding special tags into an egg file. Check maze.egg and ball.egg
    #and look for lines starting with <Collide>. The part is brackets tells
    #Panda exactly what to do. Polyset means to use the polygons in that group
    #as solids, while Sphere tells panda to make a collision sphere around them
    #Keep means to keep the polygons in the group as visable geometry (good
    #for the ball, not for the triggers), and descend means to make sure that
    #the settings are applied to any subgroups.
    #
    #Once we have the collision tags in the models, we can get to them using
    #NodePath's find command

    #Find the collision node named wall_collide
    self.walls = self.maze.find("**/wall_collide")

    #Collision objects are sorted using BitMasks. BitMasks are ordinary numbers
    #with extra methods for working with them as binary bits. Every collision
    #solid has both a from mask and an into mask. Before Panda tests two
    #objects, it checks to make sure that the from and into collision masks
    #have at least one bit in common. That way things that shouldn't interact
    #won't. Normal model nodes have collision masks as well. By default they
    #are set to bit 20. If you want to collide against actual visable polygons,
    #set a from collide mask to include bit 20
    #
    #For this example, we will make everything we want the ball to collide with
    #include bit 0
    self.walls.node().setIntoCollideMask(BitMask32.bit(0))
    #CollisionNodes are usually invisible but can be shown. Uncomment the next
    #line to see the collision walls
    #self.walls.show()

    #We will now find the triggers for the holes and set their masks to 0 as
    #well. We also set their names to make them easier to identify during
    #collisions
    self.loseTriggers = []
    for i in range(6):
      trigger = self.maze.find("**/hole_collide" + str(i))
      trigger.node().setIntoCollideMask(BitMask32.bit(0))
      trigger.node().setName("loseTrigger")
      self.loseTriggers.append(trigger)
      #Uncomment this line to see the triggers
      #trigger.show()

    #Ground_collide is a single polygon on the same plane as the ground in the
    #maze. We will use a ray to collide with it so that we will know exactly
    #what height to put the ball at every frame. Since this is not something
    #that we want the ball itself to collide with, it has a different
    #bitmask.
    self.mazeGround = self.maze.find("**/ground_collide")
    self.mazeGround.node().setIntoCollideMask(BitMask32.bit(1))
    
    #Load the ball and attach it to the scene
    #It is on a root dummy node so that we can rotate the ball itself without
    #rotating the ray that will be attached to it
    self.ballRoot = render.attachNewNode("ballRoot")
    self.ball = loader.loadModel("models/samples/ball_in_maze/ball")
    self.ball.reparentTo(self.ballRoot)

    #Find the collison sphere for the ball which was created in the egg file
    #Notice that it has a from collision mask of bit 0, and an into collison
    #mask of no bits. This means that the ball can only cause collisions, not
    #be collided into
    self.ballSphere = self.ball.find("**/ball")
    self.ballSphere.node().setFromCollideMask(BitMask32.bit(0))
    self.ballSphere.node().setIntoCollideMask(BitMask32.allOff())

    #No we create a ray to start above the ball and cast down. This is to
    #Determine the height the ball should be at and the angle the floor is
    #tilting. We could have used the sphere around the ball itself, but it
    #would not be as reliable
    self.ballGroundRay = CollisionRay()     #Create the ray
    self.ballGroundRay.setOrigin(0,0,10)    #Set its origin
    self.ballGroundRay.setDirection(0,0,-1) #And its direction
    #Collision solids go in CollisionNode
    self.ballGroundCol = CollisionNode('groundRay') #Create and name the node
    self.ballGroundCol.addSolid(self.ballGroundRay) #Add the ray
    self.ballGroundCol.setFromCollideMask(BitMask32.bit(1)) #Set its bitmasks
    self.ballGroundCol.setIntoCollideMask(BitMask32.allOff())
    #Attach the node to the ballRoot so that the ray is relative to the ball
    #(it will always be 10 feet over the ball and point down)
    self.ballGroundColNp = self.ballRoot.attachNewNode(self.ballGroundCol)
    #Uncomment this line to see the ray
    #self.ballGroundColNp.show()

    #Finally, we create a CollisionTraverser. CollisionTraversers are what
    #do the job of calculating collisions
    self.cTrav = CollisionTraverser()
    #Collision traverservs tell collision handlers about collisions, and then
    #the handler decides what to do with the information. We are using a
    #CollisionHandlerQueue, which simply creates a list of all of the
    #collisions in a given pass. There are more sophisticated handlers like
    #one that sends events and another that tries to keep collided objects
    #apart, but the results are often better with a simple queue
    self.cHandler = CollisionHandlerQueue()
    #Now we add the collision nodes that can create a collision to the
    #traverser. The traverser will compare these to all others nodes in the
    #scene. There is a limit of 32 CollisionNodes per traverser
    #We add the collider, and the handler to use as a pair
    self.cTrav.addCollider(self.ballSphere, self.cHandler)
    self.cTrav.addCollider(self.ballGroundColNp, self.cHandler)

    #Collision traversers have a built in tool to help visualize collisions.
    #Uncomment the next line to see it.
    #self.cTrav.showCollisions(render)
    
    #This section deals with lighting for the ball. Only the ball was lit
    #because the maze has static lighting pregenerated by the modeler
    lAttrib = LightAttrib.makeAllOff()
    ambientLight = AmbientLight( "ambientLight" )
    ambientLight.setColor( Vec4(.55, .55, .55, 1) )
    lAttrib = lAttrib.addLight( ambientLight )
    directionalLight = DirectionalLight( "directionalLight" )
    directionalLight.setDirection( Vec3( 0, 0, -1 ) )
    directionalLight.setColor( Vec4( 0.375, 0.375, 0.375, 1 ) )
    directionalLight.setSpecularColor(Vec4(1,1,1,1))
    lAttrib = lAttrib.addLight( directionalLight )
    self.ballRoot.node().setAttrib( lAttrib )
    
    #This section deals with adding a specular highlight to the ball to make
    #it look shiny
    m = Material()
    m.setSpecular(Vec4(1,1,1,1))
    m.setShininess(96)
    self.ball.setMaterial(m, 1)

    #Finally, we call start for more initialization
    self.start()
Ejemplo n.º 18
0
    def __init__(self):
        #This code puts the standard title and instruction text on screen
        self.title = OnscreenText(
            text="Panda3D: Tutorial - Collision Detection",
            style=1,
            fg=(1, 1, 1, 1),
            pos=(0.7, -0.95),
            scale=.07,
            font=font)
        self.instructions = OnscreenText(text="Mouse pointer tilts the board",
                                         pos=(-1.3, .95),
                                         fg=(1, 1, 1, 1),
                                         font=font,
                                         align=TextNode.ALeft,
                                         scale=.05)

        self.accept("escape", sys.exit)  #Escape quits
        base.disableMouse()  #Disable mouse-based camera control
        camera.setPosHpr(0, 0, 25, 0, -90, 0)  #Place the camera

        #Load the maze and place it in the scene
        self.maze = loader.loadModel("models/samples/ball_in_maze/maze")
        self.maze.reparentTo(render)

        #Most times, you want collisions to be tested against invisible geometry
        #rather than every polygon. This is because testing against every polygon
        #in the scene is usually too slow. You can have simplified or approximate
        #geometry for the solids and still get good results.
        #
        #Sometimes you'll want to create and position your own collision solids in
        #code, but it's often easier to have them built automatically. This can be
        #done by adding special tags into an egg file. Check maze.egg and ball.egg
        #and look for lines starting with <Collide>. The part is brackets tells
        #Panda exactly what to do. Polyset means to use the polygons in that group
        #as solids, while Sphere tells panda to make a collision sphere around them
        #Keep means to keep the polygons in the group as visable geometry (good
        #for the ball, not for the triggers), and descend means to make sure that
        #the settings are applied to any subgroups.
        #
        #Once we have the collision tags in the models, we can get to them using
        #NodePath's find command

        #Find the collision node named wall_collide
        self.walls = self.maze.find("**/wall_collide")

        #Collision objects are sorted using BitMasks. BitMasks are ordinary numbers
        #with extra methods for working with them as binary bits. Every collision
        #solid has both a from mask and an into mask. Before Panda tests two
        #objects, it checks to make sure that the from and into collision masks
        #have at least one bit in common. That way things that shouldn't interact
        #won't. Normal model nodes have collision masks as well. By default they
        #are set to bit 20. If you want to collide against actual visable polygons,
        #set a from collide mask to include bit 20
        #
        #For this example, we will make everything we want the ball to collide with
        #include bit 0
        self.walls.node().setIntoCollideMask(BitMask32.bit(0))
        #CollisionNodes are usually invisible but can be shown. Uncomment the next
        #line to see the collision walls
        #self.walls.show()

        #We will now find the triggers for the holes and set their masks to 0 as
        #well. We also set their names to make them easier to identify during
        #collisions
        self.loseTriggers = []
        for i in range(6):
            trigger = self.maze.find("**/hole_collide" + str(i))
            trigger.node().setIntoCollideMask(BitMask32.bit(0))
            trigger.node().setName("loseTrigger")
            self.loseTriggers.append(trigger)
            #Uncomment this line to see the triggers
            #trigger.show()

        #Ground_collide is a single polygon on the same plane as the ground in the
        #maze. We will use a ray to collide with it so that we will know exactly
        #what height to put the ball at every frame. Since this is not something
        #that we want the ball itself to collide with, it has a different
        #bitmask.
        self.mazeGround = self.maze.find("**/ground_collide")
        self.mazeGround.node().setIntoCollideMask(BitMask32.bit(1))

        #Load the ball and attach it to the scene
        #It is on a root dummy node so that we can rotate the ball itself without
        #rotating the ray that will be attached to it
        self.ballRoot = render.attachNewNode("ballRoot")
        self.ball = loader.loadModel("models/samples/ball_in_maze/ball")
        self.ball.reparentTo(self.ballRoot)

        #Find the collison sphere for the ball which was created in the egg file
        #Notice that it has a from collision mask of bit 0, and an into collison
        #mask of no bits. This means that the ball can only cause collisions, not
        #be collided into
        self.ballSphere = self.ball.find("**/ball")
        self.ballSphere.node().setFromCollideMask(BitMask32.bit(0))
        self.ballSphere.node().setIntoCollideMask(BitMask32.allOff())

        #No we create a ray to start above the ball and cast down. This is to
        #Determine the height the ball should be at and the angle the floor is
        #tilting. We could have used the sphere around the ball itself, but it
        #would not be as reliable
        self.ballGroundRay = CollisionRay()  #Create the ray
        self.ballGroundRay.setOrigin(0, 0, 10)  #Set its origin
        self.ballGroundRay.setDirection(0, 0, -1)  #And its direction
        #Collision solids go in CollisionNode
        self.ballGroundCol = CollisionNode(
            'groundRay')  #Create and name the node
        self.ballGroundCol.addSolid(self.ballGroundRay)  #Add the ray
        self.ballGroundCol.setFromCollideMask(
            BitMask32.bit(1))  #Set its bitmasks
        self.ballGroundCol.setIntoCollideMask(BitMask32.allOff())
        #Attach the node to the ballRoot so that the ray is relative to the ball
        #(it will always be 10 feet over the ball and point down)
        self.ballGroundColNp = self.ballRoot.attachNewNode(self.ballGroundCol)
        #Uncomment this line to see the ray
        #self.ballGroundColNp.show()

        #Finally, we create a CollisionTraverser. CollisionTraversers are what
        #do the job of calculating collisions
        self.cTrav = CollisionTraverser()
        #Collision traverservs tell collision handlers about collisions, and then
        #the handler decides what to do with the information. We are using a
        #CollisionHandlerQueue, which simply creates a list of all of the
        #collisions in a given pass. There are more sophisticated handlers like
        #one that sends events and another that tries to keep collided objects
        #apart, but the results are often better with a simple queue
        self.cHandler = CollisionHandlerQueue()
        #Now we add the collision nodes that can create a collision to the
        #traverser. The traverser will compare these to all others nodes in the
        #scene. There is a limit of 32 CollisionNodes per traverser
        #We add the collider, and the handler to use as a pair
        self.cTrav.addCollider(self.ballSphere, self.cHandler)
        self.cTrav.addCollider(self.ballGroundColNp, self.cHandler)

        #Collision traversers have a built in tool to help visualize collisions.
        #Uncomment the next line to see it.
        #self.cTrav.showCollisions(render)

        #This section deals with lighting for the ball. Only the ball was lit
        #because the maze has static lighting pregenerated by the modeler
        lAttrib = LightAttrib.makeAllOff()
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor(Vec4(.55, .55, .55, 1))
        lAttrib = lAttrib.addLight(ambientLight)
        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setDirection(Vec3(0, 0, -1))
        directionalLight.setColor(Vec4(0.375, 0.375, 0.375, 1))
        directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
        lAttrib = lAttrib.addLight(directionalLight)
        self.ballRoot.node().setAttrib(lAttrib)

        #This section deals with adding a specular highlight to the ball to make
        #it look shiny
        m = Material()
        m.setSpecular(Vec4(1, 1, 1, 1))
        m.setShininess(96)
        self.ball.setMaterial(m, 1)

        #Finally, we call start for more initialization
        self.start()
Ejemplo n.º 19
0
  def __init__( self ):
  #The main initialization of our class
    #This creates the on screen title that is in every tutorial
    self.title = OnscreenText(text="Panda3D: Tutorial - Lighting",
                              style=1, fg=(1,1,0,1), font = font,
                              pos=(0.87,-0.95), scale = .07)

    #Creates labels used for onscreen instructions
    self.ambientText = self.makeStatusLabel(0)
    self.directionalText = self.makeStatusLabel(1)
    self.spotlightText = self.makeStatusLabel(2)
    self.pointLightText = self.makeStatusLabel(3)
    self.spinningText = self.makeStatusLabel(4)
    self.ambientBrightnessText = self.makeStatusLabel(5)
    self.directionalBrightnessText = self.makeStatusLabel(6)
    self.spotlightBrightnessText = self.makeStatusLabel(7)
    self.spotlightExponentText = self.makeStatusLabel(8)
    self.lightingPerPixelText = self.makeStatusLabel(9)

    self.disco = loader.loadModel("models/samples/disco_lights/disco_hall")
    self.disco.reparentTo(render)
    self.disco.setPosHpr(0, 50, -4, 90, 0, 0)

    # First we create an ambient light. All objects are affected by ambient
    # light equally
    #Create and name the ambient light
    self.ambientLight = render.attachNewNode( AmbientLight( "ambientLight" ) )
    #Set the color of the ambient light
    self.ambientLight.node().setColor( Vec4( .1, .1, .1, 1 ) )
    #add the newly created light to the lightAttrib

    # Now we create a directional light. Directional lights add shading from a
    # given angle. This is good for far away sources like the sun
    self.directionalLight = render.attachNewNode( DirectionalLight(
"directionalLight" ) )
    self.directionalLight.node().setColor( Vec4( .35, .35, .35, 1 ) )
    # The direction of a directional light is set as a 3D vector
    self.directionalLight.node().setDirection( Vec3( 1, 1, -2 ) )

    # Now we create a spotlight. Spotlights light objects in a given cone
    # They are good for simulating things like flashlights
    self.spotlight = camera.attachNewNode( Spotlight( "spotlight" ) )
    self.spotlight.node().setColor( Vec4( .45, .45, .45, 1 ) )
    #The cone of a spotlight is controlled by it's lens. This creates the lens
    self.spotlight.node().setLens( PerspectiveLens() )
    #This sets the Field of View (fov) of the lens, in degrees for width and
    #height. The lower the numbers, the tighter the spotlight.
    self.spotlight.node().getLens().setFov( 16, 16 )
    # Attenuation controls how the light fades with distance. The numbers are
    # The three values represent the three constants (constant, linear, and
    # quadratic) in the internal lighting equation. The higher the numbers the
    # shorter the light goes.
    self.spotlight.node().setAttenuation( Vec3( 1, 0.0, 0.0 ) ) 
    # This exponent value sets how soft the edge of the spotlight is. 0 means a
    # hard edge. 128 means a very soft edge.
    self.spotlight.node().setExponent( 60.0 )

    # Now we create three colored Point lights. Point lights are lights that
    # radiate from a single point, like a light bulb. Like spotlights, they
    # are given position by attaching them to NodePaths in the world
    self.redHelper = loader.loadModel('models/samples/disco_lights/sphere')
    self.redHelper.setColor( Vec4( 1, 0, 0, 1 ) )
    self.redHelper.setPos( -6.5, -3.75, 0 )
    self.redHelper.setScale(.25)
    self.redPointLight = self.redHelper.attachNewNode( PointLight(
"redPointLight" ) )
    self.redPointLight.node().setColor( Vec4( .35, 0, 0, 1 ) )
    self.redPointLight.node().setAttenuation( Vec3( .1, 0.04, 0.0 ) ) 

    #The green point light and helper
    self.greenHelper = loader.loadModel('models/samples/disco_lights/sphere')
    self.greenHelper.setColor( Vec4( 0, 1, 0, 1 ) )
    self.greenHelper.setPos( 0, 7.5, 0 )
    self.greenHelper.setScale(.25)
    self.greenPointLight = self.greenHelper.attachNewNode( PointLight(
"greenPointLight" ) )
    self.greenPointLight.node().setAttenuation( Vec3( .1, .04, .0 ) ) 
    self.greenPointLight.node().setColor( Vec4( 0, .35, 0, 1 ) )

    #The blue point light and helper
    self.blueHelper = loader.loadModel('models/samples/disco_lights/sphere')
    self.blueHelper.setColor( Vec4( 0, 0, 1, 1 ) )
    self.blueHelper.setPos( 6.5, -3.75, 0 )
    self.blueHelper.setScale(.25)
    self.bluePointLight = self.blueHelper.attachNewNode( PointLight( "bluePointLight" ) )
    self.bluePointLight.node().setAttenuation( Vec3( .1, 0.04, 0.0 ) ) 
    self.bluePointLight.node().setColor( Vec4( 0, 0, .35, 1 ) )
    self.bluePointLight.node().setSpecularColor( Vec4( 1 ) )

    #Create a dummy node so the lights can be spun with one command
    self.pointLightHelper = render.attachNewNode( "pointLightHelper" )
    self.pointLightHelper.setPos(0, 50, 11)
    self.redHelper.reparentTo( self.pointLightHelper )
    self.greenHelper.reparentTo( self.pointLightHelper )
    self.blueHelper.reparentTo( self.pointLightHelper )

    #Finally we store the lights on the root of the scene graph.
    #This will cause them to affect everything in the scene.

    render.setLight( self.ambientLight )
    render.setLight( self.directionalLight )
    render.setLight( self.spotlight )
    render.setLight( self.redPointLight )
    render.setLight( self.greenPointLight )
    render.setLight( self.bluePointLight )

    # Create and start interval to spin the lights, and a variable to
    # manage them.
    self.pointLightsSpin = self.pointLightHelper.hprInterval(6, Vec3(360, 0, 0))
    self.pointLightsSpin.loop()
    self.arePointLightsSpinning = True

    # Per-pixel lighting is initially off
    self.perPixelEnabled = False

    # listen to keys for controlling the lights
    self.accept( "escape", sys.exit)
    self.accept( "a", self.toggleLights, [[self.ambientLight]] )
    self.accept( "d", self.toggleLights, [[self.directionalLight]] )
    self.accept( "s", self.toggleLights, [[self.spotlight]] )
    self.accept( "p", self.toggleLights, [[self.redPointLight,
                                           self.greenPointLight,
                                           self.bluePointLight]] )
    self.accept( "r", self.toggleSpinningPointLights )
    self.accept( "l", self.togglePerPixelLighting )
    self.accept( "z", self.addBrightness, [self.ambientLight, -.05] )
    self.accept( "x", self.addBrightness, [self.ambientLight, .05] )
    self.accept( "c", self.addBrightness, [self.directionalLight, -.05] )
    self.accept( "v", self.addBrightness, [self.directionalLight, .05] )
    self.accept( "b", self.addBrightness, [self.spotlight, -.05] )
    self.accept( "n", self.addBrightness, [self.spotlight, .05] )
    self.accept( "q", self.adjustSpotlightExponent, [self.spotlight, -1] )
    self.accept( "w", self.adjustSpotlightExponent, [self.spotlight, 1] )

    #Finally call the function that builds the instruction texts
    self.updateStatusLabel()
Ejemplo n.º 20
0
        self.fcard.hide()
        self.bcard.setColor(1, 1, 1, 1)
        self.bcard.setScale(0.999)
        self.bcard.setPos(0, 0, 0)
        self.bcard.setR(1)
        self.clickrate = 10000
        self.nextclick = 0


t = MotionTrails()

character = Actor()
character.loadModel('models/samples/motion_trails/dancer')
character.reparentTo(render)
character.loadAnims({'win': 'models/samples/motion_trails/dancer'})
character.loop('win')
# character.hprInterval(15, Point3(360, 0,0)).loop()

#put some lighting on the model
dlight = DirectionalLight('dlight')
alight = AmbientLight('alight')
dlnp = render.attachNewNode(dlight)
alnp = render.attachNewNode(alight)
dlight.setColor(Vec4(1.0, 0.9, 0.8, 1))
alight.setColor(Vec4(0.2, 0.3, 0.4, 1))
dlnp.setHpr(0, -60, 0)
render.setLight(dlnp)
render.setLight(alnp)

run()