Coordinated terrain texturing

Hi guys,

(It’s my first post so a bit of boring introduction =P)
Tough I met Panda3D some long time ago, I never really started a project with it. But now I did and as all newbies, I’m encountering some design problems.

Short, what I want to create is a game with elements from the civilization series and the stronghold series.
I started with creating the part where the game-map is created. Like in civ, this map consists of hexagonal tiles. First I’ve created a script that returns a python dictionary which represent the randomized map with all the tiles and their ’ tile-data ’ ( such as appearance: desert, grass,…). The other script is the panda-script which takes this dictionary, loops trough it while loading the correct models according to the tiledata.

#### Map Creation ####
#--------------------#
import random
#from sys import exc_clear
# Initial map #

class MMap():
    
    def newWorld(self):
        print 'creating new map'
        self.world = {}
        self.wsizex = input("World size x : ")
        self.wsizey = input("World size y : ")
        self.wsize = self.wsizex*self.wsizey
        print self.wsize
        self.tiles = []        
        k = 0
        while k < self.wsize:
            self.tiles.append(k)
            k = k + 1
        print self.tiles
        for k in self.tiles:
            self.world[self.tiles[k]] = ["TileData", "More TileData","Even More TileData"]
    
# Definition of the 'brush'-functions #
    def circle(self,tile):
        targettiles = []
        targettiles.append(tile - self.wsizex)
        targettiles.append(tile - self.wsizex + 1 )
        targettiles.append(tile - 1)
        targettiles.append(tile)
        targettiles.append(tile + 1)        
        targettiles.append(tile + self.wsizex)
        targettiles.append(tile + self.wsizex + 1)
        print targettiles
        for k in targettiles[:]:
            if int(k+0) < 0:
                print k
                targettiles.remove(k)
                continue
            if int(k+0) >= self.wsize:
                print k
                targettiles.remove(k)
                continue
        return targettiles
        
# Tile Randomisation #
#---------------------------------------------------------------------------------------------
#Dataformat:[  0   /   1  ,   0    /    1   /     2     /    3   ,  0 /    1   ,   0  /   1  ]
#          [ water / land , desert / plains / grassland / tundra , no / forest , flat / hill ]
#---------------------------------------------------------------------------------------------
    def tilerandom(self):
        print 'customising tiles'
        self.landtiles = self.tiles
#        targettile = self.landtiles[random.randint(0,len(self.landtiles))]
        colorlist = [self.deserttiles,self.plaintiles,self.grasstiles,self.tundratiles]
        while len(self.landtiles) != 0:
            targettile = random.choice(self.landtiles)
            color = random.choice(colorlist)
            affectedtiles = color(targettile)
            for k in affectedtiles:
                try:
                    self.landtiles.remove(k)
                except ValueError:
                    pass
#            print self.landtiles
        
    def deserttiles(self,deserttile):
        print 'creating desert tiles'
        deserttiles = self.circle(deserttile)
        print deserttiles
        for k in deserttiles:
            datalist = self.world[k]
            datalist[1] = 0
            datalist[2] = 0
        return deserttiles

    def plaintiles(self,plaintile):
        print 'creating plain tiles'
        forestchance = [0,0,1]
        plaintiles = self.circle(plaintile)
        print plaintiles
        for k in plaintiles:
            datalist = self.world[k]
            datalist[1] = 1
            datalist[2] = random.choice(forestchance)
        return plaintiles

    def grasstiles(self,grasstile):
        print 'creating grass tiles'
        forestchance = [0,1]
        grasstiles = self.circle(grasstile)
        print grasstiles
        for k in grasstiles:
            datalist = self.world[k]
            datalist[1] = 2
            datalist[2] = random.choice(forestchance)
        return grasstiles

    def tundratiles(self,tundratile):
        print 'creating tundra tiles'
        forestchance = [0,0,0,1]
        tundratiles = self.circle(tundratile)
        print tundratiles
        for k in tundratiles:
            datalist = self.world[k]
            datalist[1] = 3
            datalist[2] = random.choice(forestchance)
        return tundratiles

# Executions #

#Map = MMap()
#Map.newWorld()
#Map.tilerandom()

import direct.directbase.DirectStart
from direct.showbase import DirectObject
import World

#base.disableMouse()
#base.camera.setPos(0,-10,4.80421)
#base.camera.setHpr(90,0,0)
#base.useDrive()

Map = World.MMap()
Map.newWorld()
Map.tilerandom()
print Map.world

colors = [["Models/deserttile.x"],["Models/plaintile.x","Models/plaintile-forest.x"],
          ["Models/grasstile.x","Models/grasstile-forest.x"],["Models/tundratile.x",
                                                              "Models/tundratile-forest.x"]]

tiles = []

for k in Map.world:
    print k
    print Map.world[k]
    tiles.append(k)
    datalist = Map.world[k]
    color = datalist[1]
    modellist = colors
    color = datalist[2]
    model = modellist
    tiles[k] = loader.loadModel(model)
    tiles[k].reparentTo(render)
    tiles[k].setPos(0,0-2*int(k/Map.wsizex),0)
    tiles[k].setX(2*k+(tiles[k].getY()*Map.wsizex))
    rowchecker = (int(k / Map.wsizex)) % 2 == 0
    tiles[k].setX(tiles[k].getX()+int(rowchecker)*1)
    print tiles[k].getPos()

run()

This code gives me the randomized map I wanted. But now I want to move on to the next step: graphically enhance the world map. In Civ 5 all the tiles’ textures blend a bit into each other… the grass from a grasstiles continues a bit over to the next tiles… I hope you understand what I mean. (http://www.thetanooki.com/wp-content/gallery/civilization-v/civilization_v_screen7.jpg)

I don’t really know how to do this. If I just give each tile a separate model and texture, I don’t think I can make the tiles blend. So what do I do? Take a large plane, cover all the tiles and ‘paint’ the plane with the different textures according to the tile coordinates ?

Ps.: Do you want me to somehow post the tile-models I use to represent the different tiles?

As i probabbly should have done before starting a new thread, i searched the forums and found this similar topic, altough i dont really know how to use shaders, as stated in the thread as a possible solution. Also the generated terrain map is totally random each time the game/script runs, so actually i’m looking for way to dynamically create a new terrain texture…

[url]Mapping textures]