Exemplo n.º 1
0
def main():
    root = Ogre.Root("plugins.cfg", "ogre.cfg", "")

    cfg = Ogre.ConfigFile()
    cfg.loadDirect("resources.cfg")

    rgm = Ogre.ResourceGroupManager.getSingleton()

    for sec, settings in cfg.getSettingsBySection().items():
        for kind, loc in settings.items():
            rgm.addResourceLocation(loc, kind, sec)

    arch = cfg.getSettings("General").values()[0]
    rgm.addResourceLocation(arch + "/materials/programs/GLSL", "FileSystem",
                            "General")
    arch += "/RTShaderLib"
    rgm.addResourceLocation(arch + "/materials", "FileSystem", "General")
    rgm.addResourceLocation(arch + "/GLSL", "FileSystem", "General")

    if not root.restoreConfig():
        root.showConfigDialog(Ogre.ConfigDialog())

    win = root.initialise(True)

    OgreRTShader.ShaderGenerator.initialize()
    shadergen = OgreRTShader.ShaderGenerator.getSingleton()

    sgres = SGResolver(shadergen)
    Ogre.MaterialManager.getSingleton().addListener(sgres)

    rgm.initialiseAllResourceGroups()

    rs = shadergen.getRenderState(
        OgreRTShader.cvar.ShaderGenerator_DEFAULT_SCHEME_NAME)
    rs.addTemplateSubRenderState(
        shadergen.createSubRenderState(
            OgreRTShader.cvar.PerPixelLighting_Type))

    scn_mgr = root.createSceneManager(Ogre.ST_GENERIC)
    shadergen.addSceneManager(scn_mgr)

    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.setPosition(0, 0, 15)
    cam.setNearClipDistance(5)
    cam.lookAt(0, 0, -1)
    vp = win.addViewport(cam)
    vp.setBackgroundColour(Ogre.ColourValue(.3, .3, .3))

    ent = scn_mgr.createEntity("Sinbad.mesh")
    node = scn_mgr.getRootSceneNode().createChildSceneNode()
    node.attachObject(ent)

    root.startRendering()
Exemplo n.º 2
0
    def __init__(self, scn_mgr, moonpos, cam):
        #skybox and distance of the skybox
        #scn_mgr.setSkyDome(True,"Skyes/Night1",50,5)
        scn_mgr.setSkyBox(True, "Skyes/NightSkyBox", 100)
        #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)

        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)
        dirlight.setDirection(moonpos * -1)

        moon = scn_mgr.createBillboardSet("Moon")
        moon.setMaterialName("Skyes/Moon")
        moon.setDefaultDimensions(2000, 2000)
        #self.mBurstSet.setCullIndividually(True)
        #self.mBurstSet.setQueryFlags(0)
        moonNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        moonboard = moon.createBillboard(moonpos)
        #moonboard.setDimensions(1,1)

        moonNode.attachObject(moon)
        moonNode.setPosition(0, 1, 1)
        #lens flare
        self.lensflare = Lensflare.LensFlare(moonpos, cam, scn_mgr)
Exemplo n.º 3
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)
Exemplo n.º 4
0
    def setupScene(self):
        # Step 1: https://ogrecave.github.io/ogre/api/latest/setup.html
        sceneManager = self._root.createSceneManager()

        # In Python, whenever you see `getSingleton()` you need to call
        # `.initialize()` first. Note that here it's with a 'z', in other
        # cases its spelled with an 's'.
        OgreRTShader.ShaderGenerator.initialize()
        shaderGen = OgreRTShader.ShaderGenerator.getSingleton()
        shaderGen.addSceneManager(sceneManager)

        rootNode = sceneManager.getRootSceneNode()

        light = sceneManager.createLight('MainLight')
        lightNode = rootNode.createChildSceneNode()
        lightNode.setPosition(0, 100, 200)
        lightNode.attachObject(light)

        self.camNode = rootNode.createChildSceneNode()
        self.camNode.setPosition(0, 0, 200)
        self.camNode.lookAt(Ogre.Vector3(0, 0, -1), Ogre.Node.TS_PARENT)

        camera = sceneManager.createCamera('My Camera')
        camera.setNearClipDistance(5)
        camera.setAutoAspectRatio(True)
        self.camNode.attachObject(camera)

        viewport = self._rend.addViewport(camera)
        viewport.setBackgroundColour(Ogre.ColourValue(.1, .1, .1))

        athena = sceneManager.createEntity('athene.mesh')
        athenaNode = rootNode.createChildSceneNode()
        athenaNode.attachObject(athena)
Exemplo n.º 5
0
def main():
    app = OgreBites.ApplicationContext("PySample")
    app.initApp()
    
    root = app.getRoot()
    scn_mgr = root.createSceneManager()
    
    shadergen = OgreRTShader.ShaderGenerator.getSingleton()
    shadergen.addSceneManager(scn_mgr);
    
    ## [numpy_image]
    arr = np.zeros((256, 256, 3), dtype=np.uint8)
    arr[:,:,1] = np.mgrid[0:256,0:256][1]
    ## [numpy_image]
    
    ## [np_to_ogre]
    mem = OgreNumpy.AsDataStream(arr)
    ogre_img = Ogre.Image()
    ogre_img.loadDynamicImage(mem.getPtr(), 256, 256, Ogre.PF_BYTE_RGB)
    
    Ogre.TextureManager.getSingleton().loadImage("gradient", "General", ogre_img)
    ## [np_to_ogre]

    ## [apply_to_rect]
    mat = Ogre.MaterialManager.getSingleton().create("gradient_mat", "General")
    rpass = mat.getTechniques()[0].getPasses()[0]
    rpass.setLightingEnabled(False)
    rpass.createTextureUnitState("gradient")

    rect = Ogre.Rectangle2D(True)
    rect.setCorners(-0.5, 0.5, 0.5, -0.5) # in normalized screen space
    rect.setMaterial(mat)
    rect.setBoundingBox(Ogre.AxisAlignedBox(Ogre.AxisAlignedBox.BOX_INFINITE))

    scn_mgr.getRootSceneNode().createChildSceneNode().attachObject(rect)
    ## [apply_to_rect]
    
    cam = scn_mgr.createCamera("myCam")
    win = app.getRenderWindow()
    vp = win.addViewport(cam)
    
    ## [py_to_primitive]
    gray = (0.3, 0.3, 0.3)
    vp.setBackgroundColour(Ogre.ColourValue(*gray))
    ## [py_to_primitive]

    root.startRendering()
    
    ## [allocate_with_ogre]
    mem = Ogre.MemoryDataStream(win.getWidth() * win.getHeight() * 3)
    pb = Ogre.PixelBox(win.getWidth(), win.getHeight(), 1, Ogre.PF_BYTE_RGB, mem.getPtr())
    win.copyContentsToMemory(pb, pb)
    ## [allocate_with_ogre]
    
    ## [zero_copy_view]
    pyplot.imsave("screenshot.png", OgreNumpy.view(pb))
    ## [zero_copy_view]

    app.closeApp()
Exemplo n.º 6
0
    def setup(self):
        OgreBites.ApplicationContext.setup(self)
        self.addInputListener(self)

        OgreImgui.ImguiManager.createSingleton()

        root = self.getRoot()
        scn_mgr = root.createSceneManager()
        OgreImgui.ImguiManager.getSingleton().init(scn_mgr)
        self.addInputListener(
            OgreImgui.ImguiManager.getSingleton().getInputListener())

        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))

        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.setPosition(0, 0, 15)

        camnode.lookAt(Ogre.Vector3(0, 0, -1), Ogre.Node.TS_PARENT)
        camnode.attachObject(cam)

        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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
    def setup(self):
        print("setup")
        #Primero llamamos a la base y ponemos el listener
        OgreBites.ApplicationContext.setup(self)
        self.addInputListener(self)

        self.restart = False

        #get a pointer to the already created root
        #create the scene manager
        root = self.getRoot()
        scn_mgr = root.createSceneManager()
        scn_mgr.addRenderQueueListener(self.getOverlaySystem())
        self.scn_mgr = scn_mgr

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

        # -- tutorial section start --
        # Creamos la camara y la posicionamos en la escena
        camNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        cam = scn_mgr.createCamera("myCam")
        mTerrainPos = Ogre.Vector3(1000, 0, 5000)

        camNode.setPosition(mTerrainPos + Ogre.Vector3(1683, 50, 2116))
        camNode.lookAt(Ogre.Vector3(1963, 50, 1660), Ogre.Node.TS_PARENT)
        cam.setNearClipDistance(40)  # tight near plane important for shadows

        if root.getRenderSystem().getCapabilities().hasCapability(
                Ogre.RSC_INFINITE_FAR_PLANE):
            print("ponemos far clip distance a infinito")
            cam.setFarClipDistance(
                0)  # enable infinite far clip distance if we can
        else:
            cam.setFarClipDistance(50000)

        camNode.attachObject(cam)
        vp = self.getRenderWindow().addViewport(cam)
        vp.setBackgroundColour(Ogre.ColourValue(0, 0, 0))

        #Ponemos las luces
        l = scn_mgr.createLight("tstLight")
        l.setType(Ogre.Light.LT_DIRECTIONAL)
        l.setDiffuseColour(Ogre.ColourValue.White)
        l.setSpecularColour(Ogre.ColourValue(0.4, 0.4, 0.4))
        ln = scn_mgr.getRootSceneNode().createChildSceneNode()
        ln.setDirection(Ogre.Vector3(0.55, -0.3, 0.75).normalisedCopy())
        ln.attachObject(l)

        #Terreno
        TERRAIN_SIZE = 513
        TERRAIN_WORLD_SIZE = 12000
        #scn_mgr.setWorldGeometry("terrain.cfg")
        self.mTerrainGlobals = ogreterrain.TerrainGlobalOptions()
        mTerrainGroup = ogreterrain.TerrainGroup(scn_mgr,
                                                 ogreterrain.Terrain.ALIGN_X_Z,
                                                 TERRAIN_SIZE,
                                                 TERRAIN_WORLD_SIZE)
        self.mTerrainGroup = mTerrainGroup
        mTerrainGroup.setFilenameConvention("BasicTutorial3Terrain", "dat")
        mTerrainGroup.setOrigin(mTerrainPos)

        self.configureTerrainDefaults(l)

        self.defineTerrain(0, 0)
        for x in range(TERRAIN_PAGE_MIN_X, TERRAIN_PAGE_MAX_X):
            for y in range(TERRAIN_PAGE_MIN_Y, TERRAIN_PAGE_MAX_Y):
                self.defineTerrain(x, y)

        # sync load since we want everything in place when we start
        mTerrainGroup.loadAllTerrains(True)

        if (self.mTerrainsImported):
            for t in mTerrainGroup.getTerrainIterator():
                self.initBlendMaps(t.instance())

        mTerrainGroup.freeTemporaryResources()
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def setup(self):
        print("setup")
        #Primero llamamos a la base y ponemos el listener
        OgreBites.ApplicationContext.setup(self)
        self.addInputListener(self)

        mesh = Ogre.MeshManager.getSingleton().getByName("ogrehead.mesh")

        self.restart = False

        #get a pointer to the already created root
        #create the scene manager
        root = self.getRoot()
        scn_mgr = root.createSceneManager()
        scn_mgr.addRenderQueueListener(self.getOverlaySystem())
        self.scn_mgr = scn_mgr

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

        # Ponemos las luces
        scn_mgr.setAmbientLight(Ogre.ColourValue(0.5, 0.5, 0.5))
        light = scn_mgr.createLight("MainLight")
        lightNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        lightNode.attachObject(light)
        lightNode.setPosition(20, 80, 50)

        #Ponemos la camara
        camNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        cam = scn_mgr.createCamera("myCam")
        cam.setNearClipDistance(5)  # specific to this sample
        cam.setAutoAspectRatio(True)
        camNode.attachObject(cam)
        camNode.setPosition(0, 0, 140)

        #and tell it to render into the main window
        self.getRenderWindow().addViewport(cam)

        #ponemos la entidad 1
        ogreEntity = scn_mgr.createEntity("ogrehead.mesh")
        ogreNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        ogreNode.attachObject(ogreEntity)

        #CAmera movement
        camNode.setPosition(0, 47, 222)

        #Second entity
        ogreEntity2 = scn_mgr.createEntity("ogrehead.mesh")
        ogreNode2 = scn_mgr.getRootSceneNode().createChildSceneNode(
            Ogre.Vector3(84, 48, 0))
        ogreNode2.attachObject(ogreEntity2)

        #Third entity
        ogreEntity3 = scn_mgr.createEntity("ogrehead.mesh")
        ogreNode3 = scn_mgr.getRootSceneNode().createChildSceneNode()
        ogreNode3.setPosition(0, 104, 0)
        ogreNode3.setScale(2, 1.2, 1)
        ogreNode3.attachObject(ogreEntity3)

        #Fourth entity
        ogreEntity4 = scn_mgr.createEntity("ogrehead.mesh")
        ogreNode4 = scn_mgr.getRootSceneNode().createChildSceneNode()
        ogreNode4.setPosition(-84, 48, 0)
        #ogreNode4.roll(Ogre.Degree(-90))
        ogreNode4.roll(Ogre.Radian(-1.5508))
        ogreNode4.attachObject(ogreEntity4)
Exemplo n.º 11
0
    def setup(self):
        print("setup")
        #Primero llamamos a la base y ponemos el listener
        OgreBites.ApplicationContext.setup(self)
        self.addInputListener(self)

        self.restart = False

        #get a pointer to the already created root
        #create the scene manager
        root = self.getRoot()
        scn_mgr = root.createSceneManager()
        scn_mgr.addRenderQueueListener(self.getOverlaySystem())
        self.scn_mgr = scn_mgr

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

        # -- tutorial section start --
        # Creamos la camara y la posicionamos en la escena
        camNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        cam = scn_mgr.createCamera("myCam")
        camNode.setPosition(200, 300, 400)
        camNode.lookAt(Ogre.Vector3(0, 0, 0), Ogre.Node.TS_WORLD)
        cam.setNearClipDistance(5)
        camNode.attachObject(cam)
        vp = self.getRenderWindow().addViewport(cam)
        vp.setBackgroundColour(Ogre.ColourValue(0, 0, 0))
        #cam.setAspectRatio(Ogre.Real(vp.getActualWidth()) / Ogre.Real(vp.getActualHeight()))
        cam.setAspectRatio((vp.getActualWidth()) / (vp.getActualHeight()))

        #Put entities
        ninjaEntity = scn_mgr.createEntity("ninja.mesh")
        ninjaEntity.setCastShadows(True)
        scn_mgr.getRootSceneNode().createChildSceneNode().attachObject(
            ninjaEntity)

        #make a plane
        plane = Ogre.Ogre.Plane()
        n = plane.normal
        n.x, n.y, n.z = 0, 1, 0
        #plane.d=5000
        #plane=Ogre.Ogre.Plane(Ogre.Vector3(0,1,0))
        #Plane plane(Vector3::UNIT_Y, 0);
        Ogre.MeshManager.getSingleton().createPlane("ground",
                                                    Ogre.Ogre.RGN_DEFAULT,
                                                    plane, 1500, 1500, 20, 20,
                                                    True, 1, 5, 5,
                                                    Ogre.Vector3(0, 0, 1))

        groundEntity = scn_mgr.createEntity("ground")
        scn_mgr.getRootSceneNode().createChildSceneNode().attachObject(
            groundEntity)
        groundEntity.setCastShadows(False)
        groundEntity.setMaterialName("Examples/Rockwall")

        scn_mgr.setAmbientLight(Ogre.ColourValue(0, 0, 0))
        scn_mgr.setShadowTechnique(Ogre.Ogre.SHADOWTYPE_STENCIL_MODULATIVE)

        spotLight = scn_mgr.createLight("SpotLight")

        spotLight.setDiffuseColour(0, 0, 1.0)
        spotLight.setSpecularColour(0, 0, 1.0)
        spotLight.setType(Ogre.Ogre.Light.LT_SPOTLIGHT)

        spotLightNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        spotLightNode.attachObject(spotLight)
        spotLightNode.setDirection(-1, -1, 0)
        spotLightNode.setPosition(Ogre.Vector3(200, 200, 0))
        #spotLight.setSpotlightRange(Ogre.Degree(35), Ogre.Degree(50));
        spotLight.setSpotlightRange(Ogre.Radian(0.61), Ogre.Radian(0.8727))

        directionalLight = scn_mgr.createLight("DirectionalLight")
        directionalLight.setType(Ogre.Light.LT_DIRECTIONAL)
        directionalLight.setDiffuseColour(Ogre.ColourValue(0.4, 0, 0))
        directionalLight.setSpecularColour(Ogre.ColourValue(0.4, 0, 0))
        directionalLightNode = scn_mgr.getRootSceneNode().createChildSceneNode(
        )
        directionalLightNode.attachObject(directionalLight)
        directionalLightNode.setDirection(Ogre.Vector3(0, -1, 1))

        pointLight = scn_mgr.createLight("PointLight")
        pointLight.setType(Ogre.Light.LT_POINT)

        pointLight.setDiffuseColour(0.3, 0.3, 0.3)
        pointLight.setSpecularColour(0.3, 0.3, 0.3)
        pointLightNode = scn_mgr.getRootSceneNode().createChildSceneNode()
        pointLightNode.attachObject(pointLight)
        pointLightNode.setPosition(Ogre.Vector3(0, 150, 250))