def makeTvMan(self,x,y,z,tex,playrate): man = Actor() man.loadModel('models/samples/teapot_on_tv/mechman_idle') man.setPos(x,y,z) man.reparentTo(render) fp = man.find("**/faceplate") fp.setTexture(tex,1) man.setPlayRate(playrate, "mechman_anim") man.loop("mechman_anim") self.tvMen.append(man)
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)
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
def __init__(self): #This code puts the standard title and instruction text on screen self.title = OnscreenText( text="Panda3D: Tutorial - Joint Manipulation", style=1, fg=(1, 1, 1, 1), font=font, pos=(0.7, -0.95), scale=.07) self.onekeyText = genLabelText("ESC: Quit", 0) self.onekeyText = genLabelText("[1]: Teapot", 1) self.twokeyText = genLabelText("[2]: Candy cane", 2) self.threekeyText = genLabelText("[3]: Banana", 3) self.fourkeyText = genLabelText("[4]: Sword", 4) #setup key input self.accept('escape', sys.exit) self.accept('1', self.setObject, [0]) self.accept('2', self.setObject, [1]) self.accept('3', self.setObject, [2]) self.accept('4', self.setObject, [3]) base.disableMouse() #Disable mouse-based camera-control camera.setPos(0, -15, 2) #Position the camera self.eve = Actor( "models/samples/looking_and_gripping/eve", #Load our animated charachter {'walk': "models/samples/looking_and_gripping/eve_walk"}) self.eve.reparentTo(render) #Put it in the scene #Now we use controlJoint to get a NodePath that's in control of her neck #This must be done before any animations are played self.eveNeck = self.eve.controlJoint(None, 'modelRoot', 'Neck') #We now play an animation. An animation must be played, or at least posed #for the nodepath we just got from controlJoint to actually effect the model self.eve.actorInterval("walk", playRate=2).loop() #Now we add a task that will take care of turning the head taskMgr.add(self.turnHead, "turnHead") #Now we will expose the joint the hand joint. ExposeJoint allows us to #get the position of a joint while it is animating. This is different than #controlJonit which stops that joint from animating but lets us move it. #This is particularly usefull for putting an object (like a weapon) in an #actor's hand self.rightHand = self.eve.exposeJoint(None, 'modelRoot', 'RightHand') #This is a table with models, positions, rotations, and scales of objects to #be attached to our exposed joint. These are stock models and so they needed #to be repositioned to look right. positions = [("models/samples/looking_and_gripping/teapot", \ (0,-.66,-.95), (90,0,90), .4), ("models/samples/looking_and_gripping/candycane", \ (.15,-.99,-.22), (90,0,90), 1), ("models/samples/looking_and_gripping/banana", \ (.08,-.1,.09), (0,-90,0), 1.75), ("models/samples/looking_and_gripping/sword", \ (.11,.19,.06), (0,0,90), 1)] self.models = [] #A list that will store our models objects for row in positions: np = loader.loadModel(row[0]) #Load the model np.setPos(row[1][0], row[1][1], row[1][2]) #Position it np.setHpr(row[2][0], row[2][1], row[2][2]) #Rotate it np.setScale(row[3]) #Scale it #Reparent the model to the exposed joint. That way when the joint moves, #the model we just loaded will move with it. np.reparentTo(self.rightHand) self.models.append(np) #Add it to our models list self.setObject(0) #Make object 0 the first shown self.setupLights() #Put in some default lighting
def __init__(self): base.disableMouse() 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 # 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, "Left/Right: Decrease/Increase Line Darkness") self.inst4 = addInstructions(0.80, "V: View the render-to-texture results") # This shader's job is to render the model with discrete lighting # levels. The lighting calculations built into the shader assume # a single nonattenuating point light. tempnode = NodePath(PandaNode("temp node")) tempnode.setShader(Shader.load(os.path.join(PANDA_SHADER_PATH, \ "samples/cartoon/cartoon_lighting.sha"))) base.cam.node().setInitialState(tempnode.getState()) # This is the object that represents the single "light", as far # the shader is concerned. It's not a real Panda3D LightNode, but # the shader doesn't care about that. light = render.attachNewNode("light") light.setPos(30, -50, 0) # this call puts the light's nodepath into the render state. # this enables the shader to access this light by name. render.setShaderInput("light", light) # The "normals buffer" will contain a picture of the model colorized # so that the color of the model is a representation of the model's # normal at that point. normalsBuffer = base.win.makeTextureBuffer("normalsBuffer", 0, 0) normalsBuffer.setClearColor(Vec4(0.5, 0.5, 0.5, 1)) self.normalsBuffer = normalsBuffer normalsCamera = base.makeCamera(normalsBuffer, lens=base.cam.node().getLens()) normalsCamera.node().setScene(render) tempnode = NodePath(PandaNode("temp node")) tempnode.setShader(Shader.load(os.path.join(PANDA_SHADER_PATH, \ "samples/cartoon/cartoon_normal.sha"))) normalsCamera.node().setInitialState(tempnode.getState()) #what we actually do to put edges on screen is apply them as a texture to #a transparent screen-fitted card drawnScene = normalsBuffer.getTextureCard() drawnScene.setTransparency(1) drawnScene.setColor(1, 1, 1, 0) drawnScene.reparentTo(render2d) self.drawnScene = drawnScene # this shader accepts, as input, the picture from the normals buffer. # it compares each adjacent pixel, looking for discontinuities. # wherever a discontinuity exists, it emits black ink. self.separation = 0.001 self.cutoff = 0.3 inkGen=Shader.load(os.path.join(PANDA_SHADER_PATH, \ "samples/cartoon/cartoon_ink.sha")) drawnScene.setShader(inkGen) drawnScene.setShaderInput("separation", Vec4(self.separation, 0, self.separation, 0)) drawnScene.setShaderInput( "cutoff", Vec4(self.cutoff, self.cutoff, self.cutoff, self.cutoff)) # 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") # 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() # 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) self.accept("arrow_left", self.increaseCutoff) self.accept("arrow_right", self.decreaseCutoff)
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])
def __init__(self): self.keyMap = { "left": 0, "right": 0, "forward": 0, "cam-left": 0, "cam-right": 0 } base.win.setClearColor(Vec4(0, 0, 0, 1)) # Post the instructions self.title = addTitle( "Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)") self.inst1 = addInstructions(0.95, "[ESC]: Quit") self.inst2 = addInstructions(0.90, "[Left Arrow]: Rotate Ralph Left") self.inst3 = addInstructions(0.85, "[Right Arrow]: Rotate Ralph Right") self.inst4 = addInstructions(0.80, "[Up Arrow]: Run Ralph Forward") self.inst6 = addInstructions(0.70, "[A]: Rotate Camera Left") self.inst7 = addInstructions(0.65, "[S]: Rotate Camera Right") # Set up the environment # # This environment model contains collision meshes. If you look # in the egg file, you will see the following: # # <Collide> { Polyset keep descend } # # This tag causes the following mesh to be converted to a collision # mesh -- a mesh which is optimized for collision, not rendering. # It also keeps the original mesh, so there are now two copies --- # one optimized for rendering, one for collisions. self.environ = loader.loadModel("models/samples/roaming_ralph/world") self.environ.reparentTo(render) self.environ.setPos(0, 0, 0) # Create the main character, Ralph ralphStartPos = self.environ.find("**/start_point").getPos() self.ralph = Actor( "models/samples/roaming_ralph/ralph", { "run": "models/samples/roaming_ralph/ralph_run", "walk": "models/samples/roaming_ralph/ralph_walk" }) self.ralph.reparentTo(render) self.ralph.setScale(.2) self.ralph.setPos(ralphStartPos) # Create a floater object. We use the "floater" as a temporary # variable in a variety of calculations. self.floater = NodePath(PandaNode("floater")) self.floater.reparentTo(render) # Accept the control keys for movement and rotation self.accept("escape", sys.exit) self.accept("arrow_left", self.setKey, ["left", 1]) self.accept("arrow_right", self.setKey, ["right", 1]) self.accept("arrow_up", self.setKey, ["forward", 1]) self.accept("a", self.setKey, ["cam-left", 1]) self.accept("s", self.setKey, ["cam-right", 1]) self.accept("arrow_left-up", self.setKey, ["left", 0]) self.accept("arrow_right-up", self.setKey, ["right", 0]) self.accept("arrow_up-up", self.setKey, ["forward", 0]) self.accept("a-up", self.setKey, ["cam-left", 0]) self.accept("s-up", self.setKey, ["cam-right", 0]) taskMgr.add(self.move, "moveTask") # Game state variables self.isMoving = False # Set up the camera base.disableMouse() base.camera.setPos(self.ralph.getX(), self.ralph.getY() + 10, 2) # We will detect the height of the terrain by creating a collision # ray and casting it downward toward the terrain. One ray will # start above ralph's head, and the other will start above the camera. # A ray may hit the terrain, or it may hit a rock or a tree. If it # hits the terrain, we can detect the height. If it hits anything # else, we rule that the move is illegal. self.cTrav = CollisionTraverser() self.ralphGroundRay = CollisionRay() self.ralphGroundRay.setOrigin(0, 0, 1000) self.ralphGroundRay.setDirection(0, 0, -1) self.ralphGroundCol = CollisionNode('ralphRay') self.ralphGroundCol.addSolid(self.ralphGroundRay) self.ralphGroundCol.setFromCollideMask(BitMask32.bit(0)) self.ralphGroundCol.setIntoCollideMask(BitMask32.allOff()) self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol) self.ralphGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler) self.camGroundRay = CollisionRay() self.camGroundRay.setOrigin(0, 0, 1000) self.camGroundRay.setDirection(0, 0, -1) self.camGroundCol = CollisionNode('camRay') self.camGroundCol.addSolid(self.camGroundRay) self.camGroundCol.setFromCollideMask(BitMask32.bit(0)) self.camGroundCol.setIntoCollideMask(BitMask32.allOff()) self.camGroundColNp = base.camera.attachNewNode(self.camGroundCol) self.camGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler)
def chooseEffectWhirlpool(self): base.setBackgroundColor(0, 0, 0, 1) self.bcard.show() 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)