Esempio n. 1
0
    def setup(self):
        OgreBites.ApplicationContext.setup(self)
        self.addInputListener(self)

        self.restart = False
        imgui_overlay = OgreOverlay.ImGuiOverlay()
        OgreOverlay.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()
        OgreOverlay.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)
Esempio n. 2
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)