Author Topic: Multiple entities using the same models/textures.  (Read 1299 times)

Offline lawless_c

  • int
  • **
  • Posts: 91
    • View Profile
Multiple entities using the same models/textures.
« 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Multiple entities using the same models/textures.
« Reply #1 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.

Offline lawless_c

  • int
  • **
  • Posts: 91
    • View Profile
Re: Multiple entities using the same models/textures.
« Reply #2 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.

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Multiple entities using the same models/textures.
« Reply #3 on: February 12, 2014, 02:02:14 am »
Wait, would mesh reuse improve the software renderer performance? Or is this only about memory?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Multiple entities using the same models/textures.
« Reply #4 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;
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Multiple entities using the same models/textures.
« Reply #5 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.

Offline lawless_c

  • int
  • **
  • Posts: 91
    • View Profile
Re: Multiple entities using the same models/textures.
« Reply #6 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