Author Topic: remove an Object from the World  (Read 6146 times)

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
remove an Object from the World
« on: April 30, 2006, 03:58:36 am »
How can I remove an object from its world without calling to World.removeObject ();

Object3D have a build method to be built without a world calling it from thee World, now I need something similar but to remove it. How can I do it. SUposse I have no acces to the World, only to the object3D and I need it to be removed.
Nada por ahora

Offline Remo

  • int
  • **
  • Posts: 64
    • View Profile
    • http://www.opsdirector.com/3dart
remove an Object from the World
« Reply #1 on: April 30, 2006, 11:13:19 am »
You need access to the world! get the id of the object and get rid of it.

You do build the object by itself but removing is the contrary of addtoworld() not to build().

What I am doing to remove objects is send them to a pool of unused object (somewhat like in the car demo with the bullets) and when I need an object I get it from that pool.

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
remove an Object from the World
« Reply #2 on: May 01, 2006, 02:18:55 pm »
An alternative to removing the object is to simply hide it using setVisibility() on that object. This can be done without referencing the world.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
remove an Object from the World
« Reply #3 on: May 01, 2006, 04:58:08 pm »
but it will keep it on memory and that is resource consuming.
Nada por ahora

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
remove an Object from the World
« Reply #4 on: May 02, 2006, 02:52:54 am »
it depends of what you need. If there are some object that will be frequently reused. I think it is better to keep it in memory instead of having to reload it (which is a very CPU consuming process if your object is complex).

I never tested the following proposition but i was thinking about it... Is the cost of cloning an object in term of CPU similar to the fact of creating a new one using the Loader class? I think cloning should be far more efficient but i never tested it. If so, you could create a set of frequently created objects (those object would not be linked to the world and would only be used to create cloned models that could be linked to the world). The CPU usage would be reduced but it would cost you some space in memory. Everything is a question of balance :P

I suppose if your Object3D is created without being linked to anything and you do not use it for a certain period, the garbage collector should destroy it... But maybe there is some kind of list in the JPCT architecture where all objects are referenced once they are created (which could explain the NO_OBJECT field)... I suppose only Egon can answer to this question.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
remove an Object from the World
« Reply #5 on: May 02, 2006, 04:58:00 pm »
Quote from: "manumoi"
But maybe there is some kind of list in the JPCT architecture where all objects are referenced once they are created (which could explain the NO_OBJECT field)... I suppose only Egon can answer to this question.
No, there is no such thing. As long as you don't add it to the world, the object isn't referenced from inside of jPCT.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
remove an Object from the World
« Reply #6 on: May 02, 2006, 07:45:35 pm »
Well, My object is inside a World but I need to remove it from a method in another class where the World cant be referenced. Thats my problem, in anyway, I will continue with the rest of my game and let this topic to the end.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
remove an Object from the World
« Reply #7 on: May 02, 2006, 11:16:31 pm »
Then make the Object3D carry it's own world. Either by extending Object3D and keeping the reference in your extended class or by using the setUserObject() in Object3D.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
remove an Object from the World
« Reply #8 on: May 02, 2006, 11:21:17 pm »
ok, I will pass the World as a parameter but I didnt wanted to because I must change some other code. Its a suggestion to implement a Object3D.remove () method. Thanks in anyway.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
remove an Object from the World
« Reply #9 on: May 02, 2006, 11:26:04 pm »
Quote from: "Melssj5"
Its a suggestion to implement a Object3D.remove () method. Thanks in anyway.
You can easily add this by making the derived YourObject3D class know an object's world (as mentioned above) and implementing the remove()-method.