www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: lawless_c on February 11, 2014, 11:23:40 pm

Title: Multiple entities using the same models/textures.
Post by: lawless_c on February 11, 2014, 11:23:40 pm
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.
Title: Re: Multiple entities using the same models/textures.
Post by: EgonOlsen on February 11, 2014, 11:32:01 pm
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.
Title: Re: Multiple entities using the same models/textures.
Post by: 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.
Title: Re: Multiple entities using the same models/textures.
Post by: aZen on February 12, 2014, 02:02:14 am
Wait, would mesh reuse improve the software renderer performance? Or is this only about memory?
Title: Re: Multiple entities using the same models/textures.
Post by: EgonOlsen on February 12, 2014, 04:41:35 pm
oh, are there any examples anywhere? not sure i'll get this without seeing how it is used.
You do something like:
Code: [Select]
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;
}
Title: Re: Multiple entities using the same models/textures.
Post by: EgonOlsen on February 12, 2014, 04:42:53 pm
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.
Title: Re: Multiple entities using the same models/textures.
Post by: lawless_c on February 26, 2014, 12:05:09 pm
Sorry should have updated, your code work worked perfectly, not even something like so much as an exactly like. :D