Пример #1
0
class MyApp(ShowBase):
	
	def __init__(self):
		ShowBase.__init__(self)
		
		
		#standard GeoMipTerrain usage
		self.terrain = GeoMipTerrain("worldTerrain")
		self.terrain.setHeightfield("mapheight.png")
		self.terrain.setColorMap("maptexture.png")
		#self.terrain.setBruteforce(True)
		#set dynamically updated terrain
		self.terrain.setBlockSize(32)
		self.terrain.setNearFar(128, 256) #distance in terrain coordinates
		self.terrain.setMinLevel(0) #low means high quality
		self.terrain.setFocalPoint(base.camera) #a NodePath
		#get root
		root = self.terrain.getRoot()
		root.reparentTo(render)
		root.setSz(100)
		self.terrain.generate()
		taskMgr.add(self.updateTask,  "update")
		
		self.camera.setPos(0, 0, 0)
		
		#add person
		self.player = Actor("girl4.x", {"girl03_03": "girl"})
		print("girl loaded")
		self.player.setPos(0, 5, -1)
		self.player.reparentTo(self.render)
		print("girl reparented")
	
	def updateTask(self, task):
		self.terrain.update()
		return task.cont
Пример #2
0
class Application(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.terrain = GeoMipTerrain("terrain")
        #doesn't use search path
        self.terrain.setHeightfield("../textures/height.png")
        self.terrain.setColorMap("../textures/grass.png")
        self.terrain.getRoot().setSz(35)
        #self.terrain.setBlockSize(16)
        #self.terrain.setNear(35)
        #self.terrain.setFar(75)
        self.terrain.getRoot().reparentTo(render)
        self.terrain.generate()

        z = self.terrain.getElevation(256, 256) * 40
        self.cam.setPos(256, 256, z)

        self.terrain.setFocalPoint(self.cam)
        self.taskMgr.add(self.updateTerrain, "update terrain")

    def updateTerrain(self, task):
        self.terrain.update()
        return task.cont
Пример #3
0
class Application(ShowBase):

    def __init__(self):

        ShowBase.__init__(self)

        self.terrain = GeoMipTerrain("terrain")
        self.terrain.setHeightfield("/e/models/height.bmp")
        self.terrain.setColorMap("/e/models/grass.jpg")
        #self.terrain.getRoot().setSz(100)
        self.terrain.getRoot().reparentTo(self.render)
        self.terrain.getRoot().setPos(0, 0, 0)
        self.terrain.hide()
        #z = self.terrain.getElevation(256, 256) * 40
        #self.cam.setPos(0, 10, 50)
        #self.cam.lookAt(5, 5, 0)

        #self.terrain.setFocalPoint(self.cam)
        self.taskMgr.add(self.updateTerrain, "updateTerrain")

    def updateTerrain(self, task):

        self.terrain.update()
        return task.cont
Пример #4
0
class Terrain():

    def __init__(self, _heightField):

    	texture = loader.loadTexture("ground_tex.png")
        self.zScale = 45

        self.terrain = GeoMipTerrain("BasicTerrain")
        self.terrain.setHeightfield(_heightField)

        # Dynamic settings?
        self.terrain.setBlockSize(16)
        self.terrain.setNear(20)
        self.terrain.setFar(100)
        self.terrain.setFocalPoint(base.camera)

        # Settings
        self.terrain.getRoot().setSz(self.zScale)
        self.terrain.getRoot().setTexture(texture)
        self.terrain.getRoot().reparentTo(render)
        self.terrain.generate()

        self.terrainSize = (self.terrain.heightfield().getReadXSize(), self.terrain.heightfield().getReadYSize())
        print "Terrain Size:", self.terrainSize
        taskMgr.add(self.terrainTask, "TerrainTask")

        self.skydome = loader.loadModel("Skydome")
        self.skydome.setDepthTest(False)
        self.skydome.setAttrib(CullBinAttrib.make("skydomeBin", 1000))
        self.skydome.reparentTo(camera)
        self.skydome.setScale(2)
        self.skydome.setPos(0, 0, -0.5)
        self.skydome.setCollideMask(BitMask32.allOff())
        taskMgr.add(self.skydomeTask, "paperplanet_skydome")

        # Add some fancy fog
        self.fog = Fog("Fog Name")
        self.fog.setColor(0.4,0.2,0.3)
        self.fog.setExpDensity(0.015)
        render.setFog(self.fog)

        # Some Test light
        dlight = DirectionalLight("dlight")
        dlight.setColor(VBase4(0.8, 0.8, 0.5, 1))
        dlnp = render.attachNewNode(dlight)
        dlnp.setHpr(0, -60, 0)
        render.setLight(dlnp)


        # Add basic blacksmith hut
        tmp = loader.loadModel("blacksmith_hut")
        tmp.reparentTo(render)
        tmp.setPos(164.054, 340.92, 11.3384)

    def skydomeTask(self, task):
        self.skydome.setHpr(render, 0,0,0)
        return task.cont

    def terrainTask(self, task):
        # tmp
        self.terrain.update()
        return task.cont
Пример #5
0
class Terrain:
    folder = os.path.dirname(os.path.abspath(__file__))
    subfolder = "/Maps/"
    file = "simple.jpg"
    filepath = folder + subfolder + file

    def __init__(self):
        fn = Filename.fromOsSpecific(self.filepath)
        self.terrain = GeoMipTerrain("mySimpleTerrain")
        self.terrain.setHeightfield("Entities/Maps/heightmap.png")
        self.terrain.getRoot().setSz(40)
        #terrain.setBruteforce(True)
        self.terrain.getRoot().reparentTo(render)

        # Set terrain properties
        self.terrain.setBlockSize(16)
        self.terrain.setNear(500)
        self.terrain.setFar(100)
        self.terrain.setFocalPoint(base.camera)

        # Store the root NodePath for convenience
        root = self.terrain.getRoot()
        root.reparentTo(render)

        # some tinkering
        """
        # tell renderer to repeat texture when reading over the edge.
        texGrass.setWrapU(Texture.WM_repeat)
        texGrass.setWrapV(Texture.WM_repeat)
        # apply mipmapping: tell renderer how to handle multiple texture pixels being rendered t a single screen pixel (makes textures 30% larger in GPU mem.)
        texGrass.setMinfilter(SamplerState.FT_linear_mipmap_linear)
        """
        self.terrain.generate()
        """
        new attempt to include blend mapping:
        """
        # determine terrain size
        self.heightmap = self.terrain.heightfield()
        if self.heightmap.getXSize() > self.heightmap.getYSize():
            self.size = self.heightmap.getXSize() - 1
        else:
            self.size = self.heightmap.getYSize() - 1
        self.xsize = self.heightmap.getXSize() - 1
        self.ysize = self.heightmap.getYSize() - 1

        # Set multi texture
        # Source http://www.panda3d.org/phpbb2/viewtopic.php?t=4536
        self.generateSurfaceTextures()

        # load a blend texture from file:
        self.blendTexture = loader.loadTexture("Entities/Maps/blendMap.png")

        self.blendTS = TextureStage('blend')
        self.blendTS.setSort(0)
        self.blendTS.setPriority(1)
        # apply textures to the terrain and connect custom shader for blend mapping:
        self.setSurfaceTextures()

        # Add a task to keep updating the terrain (for changing terrain, or synamic resolution)
        def updateTask(task):
            self.terrain.update()
            return task.cont

        taskMgr.add(updateTask, "update")

        # this is where we load the textures to be assigned to the terrain
    def generateSurfaceTextures(self):
        # Textureize
        self.grassTexture = loader.loadTexture("Entities/Maps/grassy2.png")
        self.grassTexture.setWrapU(Texture.WMRepeat)
        self.grassTexture.setWrapV(Texture.WMRepeat)
        self.grassTexture.setMinfilter(SamplerState.FT_linear_mipmap_linear)
        self.grassTexture.setAnisotropicDegree(8)
        self.grassTS = TextureStage('grass')
        self.grassTS.setSort(
            1)  # sorting order is relevent for assigning textures to the four

        self.rockTexture = loader.loadTexture("Entities/Maps/simple.jpg")
        self.rockTexture.setWrapU(Texture.WMRepeat)
        self.rockTexture.setWrapV(Texture.WMRepeat)
        self.rockTexture.setMinfilter(SamplerState.FT_linear_mipmap_linear)
        #self.grassTexture.setAnisotropicDegree(8)
        self.rockTS = TextureStage('rock')
        self.rockTS.setSort(2)
        # self.rockTS.setCombineRgb(TextureStage.CMAdd, TextureStage.CSLastSavedResult, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcColor)

        self.sandTexture = loader.loadTexture("Entities/Maps/stars.png")
        self.sandTexture.setWrapU(Texture.WMRepeat)
        self.sandTexture.setWrapV(Texture.WMRepeat)
        self.sandTexture.setMinfilter(SamplerState.FT_linear_mipmap_linear)
        #self.sandTexture.setAnisotropicDegree(8)
        self.sandTS = TextureStage('sand')
        self.sandTS.setSort(3)
        self.sandTS.setPriority(5)  # TODO: figure out what this is for...

        self.snowTexture = loader.loadTexture("Entities/Maps/grass.png")
        self.snowTexture.setWrapU(Texture.WMRepeat)
        self.snowTexture.setWrapV(Texture.WMRepeat)
        self.snowTexture.setMinfilter(SamplerState.FT_linear_mipmap_linear)
        #self.snowTexture.setAnisotropicDegree(8)
        self.snowTS = TextureStage('snow')
        self.snowTS.setSort(4)
        self.snowTS.setPriority(0)

        # a background (or rather freground?) texture that will be present independently from the blend map (consider removal)
        self.overlayTexture = loader.loadTexture("Entities/Maps/heightmap.png")
        self.overlayTexture.setWrapU(Texture.WMRepeat)
        self.overlayTexture.setWrapV(Texture.WMRepeat)
        self.overlayTexture.setMinfilter(SamplerState.FT_linear_mipmap_linear)
        #self.overlayTexture.setAnisotropicDegree(8)
        self.overlayTS = TextureStage('overlay')
        self.overlayTS.setSort(5)
        self.overlayTS.setPriority(10)

    # this is where we assign loaded textures to be blended in the shader.
    def setSurfaceTextures(self):
        self.ownerview = False
        root = self.terrain.getRoot()
        root.clearTexture()
        #self.terrain.setTextureMap()
        root.setTexture(
            self.blendTS, self.snowTexture
        )  # this texture determines where the other textures are visible

        root.setTexture(self.grassTS, self.snowTexture)
        #root.setTexScale(self.grassTS, self.size*5, self.size*5) # I try to make the texture 20 times smaller then the blend map...

        root.setTexture(self.rockTS, self.snowTexture)  #rockTexture
        #root.setTexScale(self.rockTS, self.size*5, self.size*5)

        root.setTexture(self.sandTS, self.snowTexture)  #sandTexture
        #root.setTexScale(self.sandTS, self.size*5, self.size*5)

        root.setTexture(self.snowTS, self.snowTexture)  #snowTexture
        #root.setTexScale(self.snowTS, self.size*5, self.size*5)

        #(consider removal)
        root.setTexture(self.overlayTS, self.overlayTexture)  #overlayTexture
        #root.setTexScale(self.overlayTS, self.xsize, self.ysize)

        root.setShaderInput('size', self.xsize, self.ysize, self.size,
                            self.size)
        root.setShader(loader.loadShader('Entities/Maps/terrainblender.sha'))