Losing transforms on MergeObjects(...)

Started by tbj, December 06, 2011, 11:06:15 PM

Previous topic - Next topic

tbj

Hi all,

Newbie here - sorry if this has been asked before.

I've got a class called SceneManager. This contains an ArrayList called sceneObjects which is a list of primitives (in this case, boxes) to be drawn in the scene.

Code:

Object3D scene = new Object3D(0);

for (SceneManager.SceneObject s: sceneManager.sceneObjects)
{
System.out.println("Adding object at x:" + s.x + " y: " + s.y + " z: " + s.z);
Object3D newObject = Primitives.getBox(13.0f, 1.0f);

newObject.translate(new SimpleVector(s.x, s.y, s.z));
scene = Object3D.mergeObjects(scene, newObject);

}

world.addObject(scene);


I'm trying to get all my objects merged into one so I can generate an Octree from it.

However... after merging newObject into scene, in the code above, the object seems to lose its transforms, and all my boxes end up in the same place.

If, on the other hand, I add each newObject to the World, the transforms work as expected.

Now...

- Is this what is meant to happen?
- If so, what should I do instead?

Am I right in trying to merge all my objects into one before I generate the Octree?

Should I be doing something with addChild instead?

I have read the Javadocs but I'm not too clear on this. Perhaps someone could help a newbie in distress.

Cheers :)

EgonOlsen

#1
Yes, that's what meant to happen. If you want it to behave otherwise, you have to make the transformations permanent to the mesh before merging, i.e. do something like:


Object3D newObject = Primitives.getBox(13.0f, 1.0f);

newObject.translate(new SimpleVector(s.x, s.y, s.z));
newObject.translateMesh();
scene = Object3D.mergeObjects(scene, newObject);

tbj

Thanks Egon - that worked a treat.  :)

Love the engine by the way - so easy to use! Especially for someone like me who doesn't like maths and has been struggling with pure OpenGL for quite a while...