def loadFog(self): fog = Fog('distanceFog') fog.setColor(0, 0, 0) fog.setExpDensity(.07) render.setFog(fog) fog.setOverallHidden(False) return fog.getExpDensity()
def loadFog(self, fogDensity): fog = Fog('distanceFog') fog.setColor(0, 0, 0) fog.setExpDensity(fogDensity * (math.pow(10, -2))) render.setFog(fog) fog.setOverallHidden(False) #fog.getExpDensity() print(fog.getExpDensity()) print("tried to load fog") return fog
class FogDemo(ShowBase): # Macro-like function used to reduce the amount to code needed to create the # on screen instructions def genLabelText(self, i, text): return OnscreenText(text=text, parent=base.a2dTopLeft, scale=.05, pos=(0.06, -.065 * i), fg=(1, 1, 1, 1), align=TextNode.ALeft) def __init__(self): # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) # Standard initialization stuff # Standard title that's on screen in every tutorial self.title = OnscreenText(text="Panda3D: Tutorial - Fog", style=1, fg=(1, 1, 1, 1), shadow=(0, 0, 0, .5), parent=base.a2dBottomRight, align=TextNode.ARight, pos=(-0.1, 0.1), scale=.08) # Code to generate the on screen instructions self.escapeEventText = self.genLabelText(1, "ESC: Quit") self.pkeyEventText = self.genLabelText(2, "[P]: Pause") self.tkeyEventText = self.genLabelText(3, "[T]: Toggle Fog") self.dkeyEventText = self.genLabelText(4, "[D]: Make fog color black") self.sdkeyEventText = self.genLabelText(5, "[SHIFT+D]: Make background color black") self.rkeyEventText = self.genLabelText(6, "[R]: Make fog color red") self.srkeyEventText = self.genLabelText(7, "[SHIFT+R]: Make background color red") self.bkeyEventText = self.genLabelText(8, "[B]: Make fog color blue") self.sbkeyEventText = self.genLabelText(9, "[SHIFT+B]: Make background color blue") self.gkeyEventText = self.genLabelText(10, "[G]: Make fog color green") self.sgkeyEventText = self.genLabelText(11, "[SHIFT+G]: Make background color green") self.lkeyEventText = self.genLabelText(12, "[L]: Make fog color light grey") self.slkeyEventText = self.genLabelText(13, "[SHIFT+L]: Make background color light grey") self.pluskeyEventText = self.genLabelText(14, "[+]: Increase fog density") self.minuskeyEventText = self.genLabelText(15, "[-]: Decrease fog density") # disable mouse control so that we can place the camera base.disableMouse() camera.setPosHpr(0, 0, 10, 0, -90, 0) base.setBackgroundColor(0, 0, 0) # set the background color to black # World specific-code # Create an instance of fog called 'distanceFog'. #'distanceFog' is just a name for our fog, not a specific type of fog. self.fog = Fog('distanceFog') # Set the initial color of our fog to black. self.fog.setColor(0, 0, 0) # Set the density/falloff of the fog. The range is 0-1. # The higher the numer, the "bigger" the fog effect. self.fog.setExpDensity(.08) # We will set fog on render which means that everything in our scene will # be affected by fog. Alternatively, you could only set fog on a specific # object/node and only it and the nodes below it would be affected by # the fog. render.setFog(self.fog) # Define the keyboard input # Escape closes the demo self.accept('escape', sys.exit) # Handle pausing the tunnel self.accept('p', self.handlePause) # Handle turning the fog on and off self.accept('t', toggleFog, [render, self.fog]) # Sets keys to set the fog to various colors self.accept('r', self.fog.setColor, [1, 0, 0]) self.accept('g', self.fog.setColor, [0, 1, 0]) self.accept('b', self.fog.setColor, [0, 0, 1]) self.accept('l', self.fog.setColor, [.7, .7, .7]) self.accept('d', self.fog.setColor, [0, 0, 0]) # Sets keys to change the background colors self.accept('shift-r', base.setBackgroundColor, [1, 0, 0]) self.accept('shift-g', base.setBackgroundColor, [0, 1, 0]) self.accept('shift-b', base.setBackgroundColor, [0, 0, 1]) self.accept('shift-l', base.setBackgroundColor, [.7, .7, .7]) self.accept('shift-d', base.setBackgroundColor, [0, 0, 0]) # Increases the fog density when "+" key is pressed self.accept('+', self.addFogDensity, [.01]) # This is to handle the other "+" key (it's over = on the keyboard) self.accept('=', self.addFogDensity, [.01]) self.accept('shift-=', self.addFogDensity, [.01]) # Decreases the fog density when the "-" key is pressed self.accept('-', self.addFogDensity, [-.01]) # Load the tunel and start the tunnel self.initTunnel() self.contTunnel() # This function will change the fog density by the amount passed into it # This function is needed so that it can look up the current value and # change it when the key is pressed. If you wanted to bind a key to set it # at a given value you could call self.fog.setExpDensity directly def addFogDensity(self, change): # The min() statement makes sure the density is never over 1 # The max() statement makes sure the density is never below 0 self.fog.setExpDensity( min(1, max(0, self.fog.getExpDensity() + change))) # Code to initialize the tunnel def initTunnel(self): self.tunnel = [None] * 4 for x in range(4): # Load a copy of the tunnel self.tunnel[x] = loader.loadModel('models/tunnel') # The front segment needs to be attached to render if x == 0: self.tunnel[x].reparentTo(render) # The rest of the segments parent to the previous one, so that by moving # the front segement, the entire tunnel is moved else: self.tunnel[x].reparentTo(self.tunnel[x - 1]) # We have to offset each segment by its length so that they stack onto # each other. Otherwise, they would all occupy the same space. self.tunnel[x].setPos(0, 0, -TUNNEL_SEGMENT_LENGTH) # Now we have a tunnel consisting of 4 repeating segments with a # hierarchy like this: # render<-tunnel[0]<-tunnel[1]<-tunnel[2]<-tunnel[3] # This function is called to snap the front of the tunnel to the back # to simulate traveling through it def contTunnel(self): # This line uses slices to take the front of the list and put it on the # back. For more information on slices check the Python manual self.tunnel = self.tunnel[1:] + self.tunnel[0:1] # Set the front segment (which was at TUNNEL_SEGMENT_LENGTH) to 0, which # is where the previous segment started self.tunnel[0].setZ(0) # Reparent the front to render to preserve the hierarchy outlined above self.tunnel[0].reparentTo(render) # Set the scale to be apropriate (since attributes like scale are # inherited, the rest of the segments have a scale of 1) self.tunnel[0].setScale(.155, .155, .305) # Set the new back to the values that the rest of teh segments have self.tunnel[3].reparentTo(self.tunnel[2]) self.tunnel[3].setZ(-TUNNEL_SEGMENT_LENGTH) self.tunnel[3].setScale(1) # Set up the tunnel to move one segment and then call contTunnel again # to make the tunnel move infinitely self.tunnelMove = Sequence( LerpFunc(self.tunnel[0].setZ, duration=TUNNEL_TIME, fromData=0, toData=TUNNEL_SEGMENT_LENGTH * .305), Func(self.contTunnel) ) self.tunnelMove.start() # This function calls toggle interval to pause or unpause the tunnel. # Like addFogDensity, toggleInterval could not be passed directly in the # accept command since the value of self.tunnelMove changes whenever #self.contTunnel is called def handlePause(self): toggleInterval(self.tunnelMove)
class Customize(DirectObject): def __init__(self): #ShowBase.__init__(self) #self.testModel = loader.loadModel('phase_4/models/props/snowball.bam') self.loadScene() #base.disableMouse() #base.oobe() #print(self.camera.getPos()) #self.testModel.reparentTo(render) #self.camera.setPos(0,0,0) #self.testModel.setPos(self.camera.getPos()) #self.testModel.hide() #self.camera.reparentTo(self.testModel) #self.camInterval(self.camera) #self.camInterval(self.testModel) #self.testTwo = loader.loadModel('phase_4/models/char/suitA-heads.bam') #self.testTwo.reparentTo(render) #self.testCogHeadsHere() def testCogHeadsHere(self): modelArrTwo = ['phase_4/models/char/suitA-heads.bam'] for modelName in modelArrTwo: tempLoader = loader.loadModel(modelName) for node in tempLoader.nodes: print(node) print(self.testTwo.nodes) print(self.testTwo.ancestors) print(self.testTwo.children) print(self.testTwo.findAllMaterials()) print(self.testTwo.getNodes()) def annoyingTempHeadList(self): self.backstabber = loader.loadModel( 'phase_4/models/char/suitA-heads.bam').find('**/backstabber') self.bigcheese = loader.loadModel( 'phase_4/models/char/suitA-heads.bam').find('**/bigcheese') self.bigwig = loader.loadModel( 'phase_4/models/char/suitA-heads.bam').find('**/bigwig') return [self.backstabber, self.bigcheese, self.bigwig] def loadScene(self): self.loadBackground() self.getActor() self.loadFog() self.objectList = list() self.objectList.append(self.actorHead) def loadFog(self): self.fog = Fog('distanceFog') self.fog.setColor(0, 0, 0) self.fog.setExpDensity(.07) self.render.setFog(self.fog) self.fog.setOverallHidden(False) return self.fog.getExpDensity() def loadBackground(self): self.background = loader.loadModel( 'phase_4/models/minigames/treehouse_2players.bam') self.background.reparentTo(render) self.background.place() self.background.setPosHprScale(0.00, 15.00, -3.00, 0.00, 270.00, 180.00, 1.00, 1.00, 1.00) def getActor(self): # Loading our Actor self.actorBody = ActorDict.playerBody self.actorBody.reparentTo(self.background.find('**/ground')) self.actorBody.loop('neutral') #self.actorBody.setPos(0, -2, 0) self.actorBody.setScale(0.5) self.actorBody.setP(90) #self.actorBody.place() def ActorHead(): actorHead = loader.loadModel("custom/def_m.bam") actorHead.reparentTo(self.actorBody.find('**/to_head')) actorHead.setScale(0.20) actorHead.setZ(0) actorHead.setH(-180) return actorHead self.actorHead = ActorHead() return self.actorBody def camInterval(self, cam): inc = cam.getX(), cam.getY() + 10, cam.getZ() #print(inc) #maybe a list of numbers-- an array for x, y, z, a method (manX, manY, manZ) man = manipulate by +- int, ret that array which will be used #as the Point3 args. if args are NaN/0/null, just ret the xyz arr. will be used to get the last position args for after the sequence finalizes. # just realized, look at line 53 instead of array intervalOne = cam.posInterval(4.0, Point3(inc)) #print('pos during interval: ', str(cam.getPos())) camSequence = Sequence(intervalOne) camSequence.append(Func(self.loadButtons)) #print(camSequence.__len__()) camSequence.start() #cam.setPos(inc) #print ('Pos after interval: ' + str(cam.getPos())) #return cam.setPos(cam.getPos()) #so apparently with the test model it doesn't revert back to 0,0,0 #just for now, should change later. #cam.setPos(cam.getX(), cam.getY() + 10, cam.getZ()) #if i wanted to make the model change for example during the interval, i could do an event https://www.panda3d.org/manual/?title=Event_Handlers def loadButtons(self): #arrowUp = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui.bam').find('**/nextUp') #arrowDown = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui.bam').find('**/nextDown') Button_Up = loader.loadModel( 'phase_3/models/gui/quit_button.bam').find('**/QuitBtn_UP') Button_Down = loader.loadModel( 'phase_3/models/gui/quit_button.bam').find('**/QuitBtn_DN') Button_Rlvr = loader.loadModel( 'phase_3/models/gui/quit_button.bam').find('**/QuitBtn_RLVR') # https://pastebin.com/agdb8260 Arrow_Up = loader.loadModel( 'phase_3/models/gui/nameshop_gui.bam').find('**/triangleButtonUp') Arrow_Down = loader.loadModel( 'phase_3/models/gui/nameshop_gui.bam').find('**/triangleButtonDwn') Arrow_Rlvr = loader.loadModel('phase_3/models/gui/nameshop_gui.bam' ).find('**/triangleButtonRllvr') Buttons = [Button_Up, Button_Down, Button_Rlvr] numItemsVisible = 4 itemHeight = 0.11 myScrolledList = DirectScrolledList( decButton_pos=(0.35, 0, 0.54), decButton_text_scale=0.04, decButton_relief=None, decButton_image=(Arrow_Up, Arrow_Down, Arrow_Rlvr), incButton_pos=(0.35, 0, -0.01), incButton_hpr=(0, 0, 180), incButton_text_scale=0.04, incButton_relief=None, incButton_image=(Arrow_Up, Arrow_Down, Arrow_Rlvr), pos=(0.74, 0, 0.4), numItemsVisible=numItemsVisible, forceHeight=itemHeight, itemFrame_pos=(0.35, 0, 0.43)) modelArray = [ 'phase_4/models/neighborhoods/toontown_central.bam', 'phase_13/models/parties/partyGrounds.bam', 'models/world.egg.pz' ] nameArray = ['Head 1', 'Head 2', 'Head 3'] thisIsTemp = self.annoyingTempHeadList() #for each model in modelArray --> for each node in nodePath, append to array for index, name in enumerate(nameArray): l = DirectButton(text=name, image=(Buttons), extraArgs=[thisIsTemp[index]], command=self.changeHead, text_scale=0.045, text_pos=(0, -0.007, 0), relief=None) myScrolledList.addItem(l) def changeHead(self, modelName): #if spawned object already exists, we're gonna need to remove it while len(self.objectList) >= 1: for head in self.objectList: head.detachNode() self.objectList.pop(0) spawnedObject = modelName #spawnedObject = loader.loadModel(modelName) spawnedObject.reparentTo(self.actorBody.find('**/to_head')) spawnedObject.setZ(0.05) #eventually havea task to be able to rotate the head around #spawnedObject = self.scene #self.removeWorld(self.objectList.find(spawnedObject)) self.objectList.append(spawnedObject) #print("Model Name: " + repr(modelName)) #print("Spawned Object: " + repr(spawnedObject)) testobjectindex = len(self.objectList)