Author Topic: Creating 3D-Objects "on the fly" ...  (Read 2006 times)

Offline tom3001

  • byte
  • *
  • Posts: 9
    • View Profile
Creating 3D-Objects "on the fly" ...
« on: August 28, 2011, 11:21:16 pm »
Hi.

Here's my problem:

I have a big, empty flat world I can walk around in. So far, everything works fine.

Now I want to put some trees in that world. I have three different "types" of trees. Oak, Fir, and Beech. The placing of all the trees in that world is determined by a fractal algorithm. Therefore, I never know how many trees (or how much of one type) are standing in my current environment, while I'm walking through that world. My visible range in every direction is ~ 1 mile.

Because of the Garbage collector, it seems not efficient to create the trees during runtime.

So, I thought about loading my meshes for Oak, Fir, and Beech on startup into three static 3D-Objects, which are cloned dynamically on runtime as the need arises. Because the clones are references, the memory usage would stay small, right?

The problem is, if I walk from a forest of Oaks into a forest of Firs, what shall I do with all the Oaks? How can I delete the clone objects in order to free some memory? Or is there a way to reassign the mesh-reference of a clone object? And how can I add a new clone object on the fly into the world anyway?

Or would it be better to create three big arrays of trees at startup? For Example:

Oaks[100]; Firs[100]; Beeches[100];

Placing all of them "down under" at startup, and making them visible via xyz-transformation during runtime????

Well ... I think there's a more elegant solution for my problem than that, isn't there?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Creating 3D-Objects "on the fly" ...
« Reply #1 on: August 28, 2011, 11:30:24 pm »
For desktop Java, i wouldn't worry too much about the garbage collector. It's usually not a problem. On Android, it's another story...

Offline tom3001

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Creating 3D-Objects "on the fly" ...
« Reply #2 on: August 29, 2011, 01:21:15 am »
I got the solution:

it was: world.removeObject(...);

Thanks anyway.
« Last Edit: August 29, 2011, 03:09:12 am by tom3001 »