Model Instancing

My game implements a random map generator that creates a map and loads the data into a 2D list. Hooray that works, however I am having difficulty implementing this into my main.py for the game.

Heres what should be done: For every spot in the array that is designated a floor tile, place a floor tile.

Heres the problem: It is creating a new instance of floor tile for every floor tile, therefore causing significant framerate loss when moving around a room.

I was wondering if the same floor tile could be rendered in multiple places without having to load the gpu with the same model hundreds of times. If so, could they also have different tags?

This is what I currently am working with:

				map=[]
				map = mapGen.mapGen(150).map#this works fine, makes 2d list
				for i in xrange(len(map)):
					for j in xrange(len(map[i])):
						if map[i][j]=='#' or map[i][j]=='-':
							placeholder = loader.loadModel("Media/world")#this is the tile that will be loaded dont use self
							placeholder.setPos(2*i, 2*j, 0)#sets the pos of the tile
							placeholder.setScale(.2)
							self.environment.append(placeholder)#puts the tile in the list
							
				for i in xrange(0,len(self.environment)):
							self.environment[i].reparentTo(render)#reparents the tile so it will be drawn
							self.environment[i].setTag('ground',str(i))#sets the tag for the tile, str(i) gives the tag a number used for tracking later

[size=75]Mudkiiiips![/size]
Ahem, welcome to the forums. I’ve tried something similar I suppose and would recommend reparenting the tiles under a parent node and then using FlattenStrong(). That makes it one big blob of geometry for the GPU.

You could use instanceTo(NodePath)as described here: panda3d.org/manual/index.php/Instancing. The model would be send only one time to the gpu, but rendered many. Not sure if its the best posibility but it should work. Also you have the posibility to tag the NodePath you are instancing to.

Greetz

Blaz

That instancing is not hardware instancing, its only an optimization for actor models, the one here is though: panda3d.org/blog/?p=44

I think PandaSE team made a sample with hardware instancing in their site.

It uses a shader. I never had the time to try it out myself…
etc.cmu.edu/projects/pandase/downloads.html

if you use the FlattenStrong() does it allow tagging? We need the models to be tagged. Also thank you for your suggestion, we got the FPS to jump back up around 120 consistently.