instancing vs multiple copies of object (for static mesh)

I have a simple code wherein i instance cube blocks into the scenegraph.
I was wondering if instancing provides me with any benefits at all if the the model loaded is a static mesh with no animation.
The code i am currently using is;

# create a node for all cubes
		worldNode = render.attachNewNode("World Node")

		mapList = MapMaker().levelParser()
		cubeCounter = 0
		# import the coord list. add a new node at the coord position. use instancing to save cpu usage.
		for i in mapList:
			placeholderNode = worldNode.attachNewNode("Placeholder Node")
			placeholderNode.setPos(i[0], i[1], -i[2])
			placeholderNode.setColor(float(i[4]), float(i[5]), float(i[6]), 0)
			cubeCounter += 1

I thought i will try to not use instancing of nodes and instead simply call the object multiple times. however, i have been unable to do this simple task. I dont want to load the model in the for loop as the read cost wwill be very high.
how do i load the model multiple times from memory without using multiple nodes?

I’m not that much into instancing, but I’d first try with simply reloading the model, since loader has caching capabilities included. AFAIK the second time you call loader.loadModel() the model will be loaded from cache (not sure if that’s always the RAM version or sometimes only the optimized bam-formatted model from HDD).

There is no performance benefit at all to using instancing in this way. You are much better off just called loader.loadModel() repeatedly, as Nemesis#13 suggests; this will be fast.

You can also use copyTo() instead of instanceTo(), which is also as fast as calling loader.loadModel(), and avoids the confusions that instancing causes.


Ah thanks. but wouldn’t calling the load model function a few hundred times be very io expensive?
@Nemesis: how do i use the caching of loaded models?

@drwr: thanks. will try copyTo.

The model caching is handled for you automatically. The first time a particular model is loaded it will be read from disk, and any subsequent time it will be read from memory so it is very fast. So really all you need to do is call loadModel many times, it will not be slow.

I have changed my code to

worldNode = render.attachNewNode("World Node")

mapList = MapMaker().levelParser()
cubeCounter = 0

for i in mapList:
	self.block = self.loader.loadModel("assets/cube.egg")
	self.block.setPos(i[0], i[1], -i[2])
	self.block.setColor(float(i[4]), float(i[5]), float(i[6]), 0)
	cubeCounter += 1

and can see no noticable performance loss.