示例#1
0
    def setup(self):
        Bites.ApplicationContext.setup(self)
        self.addInputListener(self)

        root = self.getRoot()
        scn_mgr = root.createSceneManager()

        shadergen = RTShader.ShaderGenerator.getSingleton()
        shadergen.addSceneManager(
            scn_mgr)  # must be done before we do anything with the scene

        # overlay/ trays
        scn_mgr.addRenderQueueListener(self.getOverlaySystem())
        self.trays.showFrameStats(Bites.TL_TOPRIGHT)
        self.trays.refreshCursor()

        # enable per pixel lighting
        rs = shadergen.getRenderState(
            RTShader.cvar.ShaderGenerator_DEFAULT_SCHEME_NAME)
        rs.addTemplateSubRenderState(
            shadergen.createSubRenderState(
                RTShader.cvar.PerPixelLighting_Type))

        scn_mgr.setAmbientLight(Ogre.ColourValue(.1, .1, .1))

        light = scn_mgr.createLight("MainLight")
        lightnode = scn_mgr.getRootSceneNode().createChildSceneNode()
        lightnode.setPosition(0, 10, 15)
        lightnode.attachObject(light)

        cam = scn_mgr.createCamera("myCam")
        cam.setNearClipDistance(5)
        cam.setAutoAspectRatio(True)
        camnode = scn_mgr.getRootSceneNode().createChildSceneNode()
        camnode.attachObject(cam)

        self.camman = Bites.CameraMan(camnode)
        self.camman.setStyle(Bites.CS_ORBIT)
        self.camman.setYawPitchDist(Ogre.Radian(0), Ogre.Radian(0.3), 15)
        self.addInputListener(self.camman)

        # must keep a reference to ctrls so it does not get deleted
        self.ctrls = Bites.AdvancedRenderControls(self.trays, cam)
        self.addInputListener(self.ctrls)

        vp = self.getRenderWindow().addViewport(cam)
        vp.setBackgroundColour(Ogre.ColourValue(.3, .3, .3))

        ent = scn_mgr.createEntity("Sinbad.mesh")
        node = scn_mgr.getRootSceneNode().createChildSceneNode()
        node.attachObject(ent)
示例#2
0
    def loadResources(self):
        self.enableShaderCache()

        # load essential resources for trays/ loading bar
        Ogre.ResourceGroupManager.getSingleton().initialiseResourceGroup(
            "Essential")
        self.createDummyScene()
        self.trays = Bites.TrayManager("Interface", self.getRenderWindow())
        self.addInputListener(self.trays)

        # show loading progress
        self.trays.showLoadingBar(1, 0)
        ret = Bites.ApplicationContext.loadResources(self)

        # clean up
        self.trays.hideLoadingBar()
        self.destroyDummyScene()
        return ret
示例#3
0
    def setup(self):
        OgreBites.ApplicationContext.setup(self)
        self.addInputListener(self)

        self.restart = False
        imgui_overlay = ImGuiOverlay()
        GetIO().IniFilename = self.getFSLayer().getWritablePath("imgui.ini")

        root = self.getRoot()
        scn_mgr = root.createSceneManager()
        scn_mgr.addRenderQueueListener(self.getOverlaySystem())
        self.scn_mgr = scn_mgr

        # set listener to deal with missing materials
        self.mat_creator = MaterialCreator()
        Ogre.MeshManager.getSingleton().setListener(self.mat_creator)

        # for picking
        self.ray_query = scn_mgr.createRayQuery(Ogre.Ray())

        #imgui_overlay.addFont("SdkTrays/Value", RGN_MESHVIEWER)
        imgui_overlay.show()
        OverlayManager.getSingleton().addOverlay(imgui_overlay)
        imgui_overlay.disown()  # owned by OverlayMgr now

        shadergen = OgreRTShader.ShaderGenerator.getSingleton()
        shadergen.addSceneManager(
            scn_mgr)  # must be done before we do anything with the scene

        scn_mgr.setAmbientLight(Ogre.ColourValue(.1, .1, .1))

        self.highlight_mat = Ogre.MaterialManager.getSingleton().create(
            "Highlight", RGN_MESHVIEWER)
        self.highlight_mat.getTechniques()[0].getPasses()[0].setEmissive(
            Ogre.ColourValue(1, 1, 0))

        self.entity = scn_mgr.createEntity(self.meshname)
        scn_mgr.getRootSceneNode().createChildSceneNode().attachObject(
            self.entity)

        diam = self.entity.getBoundingBox().getSize().length()

        axes_node = scn_mgr.getRootSceneNode().createChildSceneNode()
        axes_node.getDebugRenderable(
        )  # make sure Ogre/Debug/AxesMesh is created
        self.axes = scn_mgr.createEntity("Ogre/Debug/AxesMesh")
        axes_node.attachObject(self.axes)
        axes_node.setScale(Ogre.Vector3(diam / 4))
        self.axes.setVisible(False)
        self.axes.setQueryFlags(0)  # exclude from picking

        self.cam = scn_mgr.createCamera("myCam")
        self.cam.setNearClipDistance(diam * 0.01)
        self.cam.setAutoAspectRatio(True)
        camnode = scn_mgr.getRootSceneNode().createChildSceneNode()
        camnode.attachObject(self.cam)

        light = scn_mgr.createLight("MainLight")
        light.setType(Ogre.Light.LT_DIRECTIONAL)
        light.setSpecularColour(Ogre.ColourValue.White)
        camnode.attachObject(light)

        vp = self.getRenderWindow().addViewport(self.cam)
        vp.setBackgroundColour(Ogre.ColourValue(.3, .3, .3))

        self.camman = OgreBites.CameraMan(camnode)
        self.camman.setStyle(OgreBites.CS_ORBIT)
        self.camman.setYawPitchDist(Ogre.Radian(0), Ogre.Radian(0.3), diam)
        self.camman.setFixedYaw(False)

        self.imgui_input = OgreBites.ImGuiInputListener()
        self.input_dispatcher = OgreBites.InputListenerChain(
            [self.imgui_input, self.camman])
        self.addInputListener(self.input_dispatcher)
示例#4
0
    def setup(self):
        # SETUP es la primera función a la que se llama
        # Primero llamamos a la base y ponemos el listener
        OgreBites.ApplicationContext.setup(self)
        #Ahora se llama a locate resources
        self.addInputListener(self)
        #imgui_overlay = ImGuiOverlay()

        self.restart = False

        imgui_overlay = OgreOverlay.ImGuiOverlay()
        OgreOverlay.GetIO().IniFilename = self.getFSLayer().getWritablePath(
            "imgui.ini")

        #Inicializamos ogre u hacemos un puntero a Root
        root = self.getRoot()

        #Creamos el scene manager
        scn_mgr = root.createSceneManager()
        scn_mgr.addRenderQueueListener(self.getOverlaySystem())
        self.scn_mgr = scn_mgr

        imgui_overlay.show()
        OgreOverlay.OverlayManager.getSingleton().addOverlay(imgui_overlay)
        imgui_overlay.disown()  # owned by OverlayMgr now

        # Creamos el Shader y definimos las sombras
        shadergen = OgreRTShader.ShaderGenerator.getSingleton()
        shadergen.addSceneManager(scn_mgr)
        scn_mgr.setShadowTechnique(Ogre.Ogre.SHADOWTYPE_TEXTURE_MODULATIVE)
        #scn_mgr.setShadowTechnique(Ogre.Ogre.SHADOWTYPE_TEXTURE_ADDITIVE)
        #scn_mgr.setShadowTechnique(Ogre.Ogre.SHADOWTYPE_STENCIL_MODULATIVE)
        scn_mgr.setShadowDirLightTextureOffset(1)
        scn_mgr.setShadowFarDistance(200)
        #para que los objetos emitan shadow sobre si mismos
        scn_mgr.setShadowTextureSelfShadow(True)

        #skybox and distance of the skybox
        #scn_mgr.setSkyBox(True,"Skyes/Night1",100)
        scn_mgr.setSkyDome(True, "Skyes/Night1", 50, 5)
        #scn_mgr.setSkyDome(True,"Examples/SpaceSkyPlane",5,8)

        #lets set a fog
        #Fadecolor=Ogre.ColourValue(0,0,0)
        #vp.setBackgroundColour(Fadecolor)
        #scn_mgr.setFog(Ogre.Ogre.FOG_LINEAR,Fadecolor,0,600,900)

        #Creamos el mapa
        #mapa=Ogretmxmap.tmxmap("Maps/cathedral.tmx")
        mapa = Ogretmxmap.tmxmap("resources/tiled/cathedral.tmx")
        mannode = scn_mgr.getRootSceneNode().createChildSceneNode()
        mannode.setPosition(0, 0, 0)
        mapa.createmap(scn_mgr)

        # Vamos a crear el nodo perteneciente al personaje
        Playernode = scn_mgr.getRootSceneNode().createChildSceneNode()
        #Playernode.setPosition(self.pos)
        self.Playernode = Playernode
        # Creo el player y lo fusiono con su nodo
        self.Player = Player.Player(Playernode)
        self.Player.mapa = mapa
        self.Player.setpos(10, 10, 0)

        # Creamos la camara y la posicionamos en el personaje
        camNode = Playernode.createChildSceneNode()
        camNode.setPosition(0, 1.5, 0)
        self.cam = scn_mgr.createCamera("MainCam")
        #camNode.setPosition(0, 0, 80)
        camNode.lookAt(Ogre.Vector3(300, 1.5, 0), Ogre.Node.TS_WORLD)
        self.cam.setNearClipDistance(.2)
        camNode.attachObject(self.cam)
        vp = self.getRenderWindow().addViewport(self.cam)
        vp.setBackgroundColour(Ogre.ColourValue(0, 0, 0))
        self.cam.setAspectRatio((vp.getActualWidth()) / (vp.getActualHeight()))

        self.camNode = camNode

        # Setup the scene
        #night light
        scn_mgr.setAmbientLight(Ogre.ColourValue(.1, .1, .1))

        dirlight = scn_mgr.createLight("MoonLight1")
        dirlight.setType(Ogre.Light.LT_DIRECTIONAL)
        dirlight.setDiffuseColour(Ogre.ColourValue(0, .1, .7))
        dirlight.setSpecularColour(Ogre.ColourValue(0, 0, .5))
        dirlight.setDirection(-0.5, -0.5, -0.3)

        #        spotlight=scn_mgr.createLight("MoonLight2")
        #        spotlight.setType(Ogre.Light.LT_SPOTLIGHT);
        #        spotlight.setDiffuseColour(Ogre.ColourValue(.02, .2, .9));
        #        spotlight.setSpecularColour(Ogre.ColourValue(0, 0, .5))
        #        spotlight.setSpotlightInnerAngle(Ogre.Radian(0.09))
        #        spotlight.setSpotlightOuterAngle(Ogre.Radian(3))
        #        spotlight.setSpotlightFalloff(.0)
        #        spotLightNode = Playernode.createChildSceneNode()
        #        spotLightNode.setPosition(Ogre.Vector3(3, 3, 3))
        #        spotlight.setDirection(0, -1, -0.7)
        #        spotLightNode.attachObject(spotlight)
        #spotlight.setCastShadows(True)

        pointLight = scn_mgr.createLight("PointLight")
        pointLight.setType(Ogre.Light.LT_POINT)
        pointLight.setDiffuseColour(1, 1, 1)
        pointLight.setSpecularColour(1, 1, 1)
        pointLightNode = Playernode.createChildSceneNode()
        pointLightNode.attachObject(pointLight)
        pointLightNode.setPosition(0, 1.5, 0)
        pointLight.setAttenuation(100, 1, 0.045, 0.0075)

        #Daylight, esta tecnica de sombreado queda mucho mejor
        #        scn_mgr.setShadowTechnique(Ogre.Ogre.SHADOWTYPE_TEXTURE_ADDITIVE)
        #        scn_mgr.setAmbientLight(Ogre.ColourValue(.2, .2, .2))
        #        light=scn_mgr.createLight("MainLight")
        #        light.setType(Ogre.Light.LT_DIRECTIONAL);
        #        light.setDiffuseColour(Ogre.ColourValue(.6, .6, 1));
        #        light.setSpecularColour(Ogre.ColourValue(.6, .6, 1))
        #        light.setDirection(1, -0.5, 0.5)

        #        lightNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        #        lightNode.attachObject(light)
        #        lightNode.setPosition(0, 3, 0)

        self.mapa = mapa

        self.cam.getViewport().setOverlaysEnabled(True)
        #self.mtraymanager=OgreBites.TrayManager("Interface",self.getRenderWindow())
        #self.mtraymanager.createLabel(OgreBites.TL_TOP,"TInfo","",350)

        self.imgui_input = OgreBites.ImGuiInputListener()
        self.input_dispatcher = OgreBites.InputListenerChain(
            [self.imgui_input])
        self.addInputListener(self.input_dispatcher)