Don’t worry I got it working now I did this:
p = self.perlin.noise(x+self.offsetx,y+self.offsety)
if p >= 0:
p*=127.5
self.n.setRedVal(x,y,p)
self.n.setGreenVal(x,y,p)
self.n.setBlueVal(x,y,p)
I’m not sure if that’s the right way but it works ok.
By the way, if anyone wants to make connecting terrain chunks with the panda3d perlin noise, here is some of my code for doing it (it may not be the best way though )
class FPS(object,DirectObject):
name = -1
chunkposx = 0
chunkposy = 0
chunksize = 1025
chunks = []
chunks1 = []
offsetx = 0
offsety = 0
perlin = PerlinNoise2(500,500)
This is my function to make a chunk:
def makeChunk(self):
self.n = PNMImage(self.chunksize,self.chunksize)
self.offsety -=self.chunksize
for y in xrange(self.chunksize):
for x in xrange(self.chunksize):
p = self.perlin.noise(x+self.offsetx,y+self.offsety)
if p >= 0:
p*=127.5
self.n.setRedVal(x,y,p)
self.n.setGreenVal(x,y,p)
self.n.setBlueVal(x,y,p)
self.n.makeGrayscale()
self.name+=1
name1 = str(self.name)
self.n.write(name1+".png")
#GeoMipTerrain Stuff
terrain = GeoMipTerrain(name1)
terrain.setHeightfield(self.n)
terrain.setBlockSize(128)
terrain.setNear(256)
terrain.setFar(512)
terrain.setMinLevel(2)
terrain.setFocalPoint(base.camera)
root = terrain.getRoot()
root.reparentTo(render)
root.setSz(100)
self.scaleZ = root.getSz()
terrain.setAutoFlatten(GeoMipTerrain.AFMStrong)
terrain.generate()
ts = TextureStage("ts0")
root.setTexture(ts,loader.loadTexture("test.png"))
root.setLight(self.plnp)
root.setShaderInput("light", self.plnp)
root.setLight(self.alnp)
root.setShaderAuto()
root.setPos(self.chunkposx,self.chunkposy,0)
self.chunks.append(terrain)
self.chunks1.append(root)
To calculate when a new chunk is needed, I have not quite finished (at the moment it works in one direction)
I check to see if the player’s position is greater than half the length of the chunk and make a new if that is true.
Hope that helps, I found the sources on perlin noise pretty confusing so hopefully someone will find this ^ useful.
EDIT: just remembered for some reason it should be chunks instead of self.chunks. (make them global in def init(self) because:
for i in self.chunks:
gives an error saying self is not defined. The same with self.chunks1