Multiple entities using the same models/textures.

Started by lawless_c, February 11, 2014, 11:23:40 PM

Previous topic - Next topic

lawless_c

Is there a correct way to have multiple copies of objects in jPCT game?

I want to spawn multiple identical entities that would have the same 3d models and textures. If i was handling the graphics myself i would just spawn the one object and repeat the draw command for the object in each location where there is an instance of the entity.

But since jPCT handles that aspect of it im not sure how to proceed.

EgonOlsen

Yes, there is. You can create clones of Object3Ds by using the constructor that takes another Object3D as input. If they should share geometry data in the vm memory, use that one with the boolean reuseMesh-flag and set it to true.
If it's jPCT-AE or jPCT with compiled objects, you can make such objects share the same data on the GPU too by calling shareCompiledData(...). If textures and coordinates are also the same, you can use shareTextureData(..) in addition.

lawless_c

oh, are there any examples anywhere? not sure i'll get this without seeing how it is used.

aZen

Wait, would mesh reuse improve the software renderer performance? Or is this only about memory?

EgonOlsen

Quote from: lawless_c on February 12, 2014, 12:39:13 AM
oh, are there any examples anywhere? not sure i'll get this without seeing how it is used.
You do something like:

Object3D bluePrint=...; // Some object of yours

//...setup and build() your object...

public Object3D copy() {
Object3D copy=new Object3D(bluePrint, true);
copy.shareCompiledData(bluePrint);
copy.shareTextureData(bluePrint);
return copy;
}

EgonOlsen

Quote from: aZen on February 12, 2014, 02:02:14 AM
Wait, would mesh reuse improve the software renderer performance? Or is this only about memory?
No, it's memory only in case of the software renderer. In case of the hardware renderer, there should be a slight advantage due to a better cache hit rate...but to be honest, i never saw one.

lawless_c

Sorry should have updated, your code work worked perfectly, not even something like so much as an exactly like. :D