How to instantiate models as "clones"?
by Alessandro · in Torque 3D Professional · 10/07/2011 (3:15 am) · 3 replies
Hello,
I need to instantiate MANY objects, but they come from one single model.
So I wanted to load a model, then instancing other models without a real copy/clone, but something like a model reference (one model in PC memory, and other instances change only the position).
Now I do this:
But I think, in this way, I really create copies in memory of everything. Is it true?
For testing, I loaded a rock, then I have 1100 instances. I get about 1500 draw calls, even if the model is the same (only rotated and repositioned).
HOw can I optimize this?
Thank you!
I need to instantiate MANY objects, but they come from one single model.
So I wanted to load a model, then instancing other models without a real copy/clone, but something like a model reference (one model in PC memory, and other instances change only the position).
Now I do this:
%objName = "myCube" @ %x @ %y;
new StaticShape(%objName)
{
dataBlock = "myCubeTemplate";
position = %myPos;
rotation = %myRot;
scale = "15 15 15";
};But I think, in this way, I really create copies in memory of everything. Is it true?
For testing, I loaded a rock, then I have 1100 instances. I get about 1500 draw calls, even if the model is the same (only rotated and repositioned).
HOw can I optimize this?
Thank you!
#2
I tried to use
But seems I get no benefit (same draw calls, same fps).
So I found in other game engines that one can:
1) Load new models. They are independent models. So if you instantiate 10 models, there are 10 objects (shaders, maybe textures - some of them use texture index and do not duplicate them -, etc...)
2) Load a model. NOw other instances refer to the same model. It means I can have small amount of draw calls, not so memory used, etc... Furthermore, in this way, if I change something in the "parent" model (i.e. a Shader) all instances will change also.
I think this method is independent from hardware instancing. I think it is more a 3D game engine approach (I think...)
10/07/2011 (3:29 am)
Thank you, I red that post.I tried to use
$pref::Video::disableHardwareInstancing = 0;
But seems I get no benefit (same draw calls, same fps).
So I found in other game engines that one can:
1) Load new models. They are independent models. So if you instantiate 10 models, there are 10 objects (shaders, maybe textures - some of them use texture index and do not duplicate them -, etc...)
2) Load a model. NOw other instances refer to the same model. It means I can have small amount of draw calls, not so memory used, etc... Furthermore, in this way, if I change something in the "parent" model (i.e. a Shader) all instances will change also.
I think this method is independent from hardware instancing. I think it is more a 3D game engine approach (I think...)
#3
That being said, optimizing draw calls is mostly about batching. I know some of our members were talking about this a few months ago - I'll try to find time today to look some of the threads up and link them for you here.
10/07/2011 (7:07 am)
You must still draw the object 1100 times if you have 1100 instances - instancing doesn't make the draw free, it just saves memory.That being said, optimizing draw calls is mostly about batching. I know some of our members were talking about this a few months ago - I'll try to find time today to look some of the threads up and link them for you here.
Torque Owner Sei
Default Studio Name
Hardware Instancing