Author Topic: Object 3D Loading alternatives  (Read 2289 times)

Kearnan

  • Guest
Object 3D Loading alternatives
« on: April 09, 2008, 04:48:18 am »
When I’m using “Object3D[] myNewObject = load3DS(URL, “my3DSModel.3ds”, scale)”,  I can assign, using setName(“my3DSModel.3ds”), all of the new objects a consistent name no matter how many times I load it in the same manner.  I load it, do the usual transforms and add it to the world.  I can do that 40 times, and add it to the world and each time it gives the same answer to myNewObject(1-40).getName() as “my3DSModel.3ds”, which is what I want.  Loading a 3ds model from a URL obviously doesn’t keep track if I’ve loaded it before since loading the model 40 times takes 40 times longer than loading it once.

Yet, if I clone the object or make a new Object3D from it, which takes very little time, I get default object names like “object43” and cannot assign it the name “my3DSModel.3ds” via “setName()” or I’ll get a “- ERROR: Object with name ‘my3DSModel.3ds’ already exists!” error.

I am trying to enable loading multiple copies of a model without accessing a URL repeatedly as it’s time consuming.

The default JPCT method of assigning “new Object3D(oldObject3D)” or “oldObject3D.clone()” a logical name makes sense programmatically yet is it consistent?  Why can my URL loaded models all have the same name and cloned or duplicated models cannot?

I can make a work around for this but all-n-all, it didn’t make sense.  Like myObject3D.setTexture(“myTexture.jpg”) sets an already loaded texture shouldn’t there be a method to do myObject3D = Loader.load3DS(existingObject3D);?

Or am I missing something?
 

« Last Edit: April 10, 2008, 05:59:33 pm by Kearnan »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Object 3D Loading alternatives
« Reply #1 on: April 09, 2008, 08:44:24 am »
I don't get the problem. Do you have a test case for this? The loader code for loading from a file or an url is EXACTLY the same except for the loading of the binary data itself, which uses a FileInputStream in the first case and <URL>.openStream() in the second. The rest is the same. The names that are assigned to the object are taken from the model itself and enhanced by +"_jPCT" + obj.getID(), which ensures that they are unique. I don't see you they can all be named the same (which would be a bug, they have to be unique...hence the error) and they can't be named like the file, because the filename is used for loading them only. It's not used afterwards and should in no way get assigned to the loaded object!
There's no different treatment for either of the loaders...there's caching for text files, but not for binary files (which 3ds file are).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Object 3D Loading alternatives
« Reply #2 on: April 09, 2008, 04:40:51 pm »
I see...the "problem" is, that the name has to be (read: is supposed to be) unique within a world's context. There's an ugly internal dependency between an object and its world, which is why you can't assign an object to two worlds. The objects themselves don't know from each other, only their world does. When calling setName(<String>) on an unassigned object (i.e. after loading it), there's no check for the name, because there is no world to ask. Once you've assigned that object and try to change the name, the world will be asked, if it knows of an object with this name. If you really want to name them all the same (may i ask why?), make a copy after loading that doesn't get assigned to a world, clone that one and set the name before adding it to a world. That should work, but you'll break the method that tries to get an object by name from a world with this.
The correct fix would be not to allow the same names, but to avoid them on a VM wide base. However, i'm not going to fix this, because it might break legacy code for no real gain.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Object 3D Loading alternatives
« Reply #3 on: April 10, 2008, 06:11:41 pm »
Object3D has a user object (http://www.jpct.net/doc/com/threed/jpct/Object3D.html#setUserObject(java.lang.Object)). Maybe you can use that to store the name!?
« Last Edit: April 10, 2008, 11:43:21 pm by EgonOlsen »