tags:

views:

17

answers:

0

Hello,

I developed an O3D application using the plugin version of O3D. With this application I can display cubes, shere and other primitive shapes in a 3d space. Now I want to extend this application to support external scenes (o3dtgz), but I have problems with the scaling and the translation of these scenes.

Here is my code:

var objectTransform = o3dData.pack.createObject('Transform');
var scaleTransform = o3dData.pack.createObject('Transform');
scaleTransform.parent = objectTransform;

var file = 'http://www.example.com/car.o3dtgz';

// load the scene file in the scale transform and when its loaded call the callback function
o3djs.scene.loadScene(g_client, g_client.createPack(), scaleTransform, file, callback);

objectTransform.translate(50,50,50);

var callback = function(pack, parent, exception) {

  if (exception) {
    alert('Error ' + exception);
    return;
  }

  // generate draw elements and setup material draw lists
  o3djs.pack.preparePack(pack, g_render);

  // get the aa bounding box to determine the size of the scene
  var boundingBox = o3djs.util.getBoundingBoxOfTree(parent);       

  // the size in world coodinates
  var size = o3djs.math.subVector(boundingBox.maxExtent,boundingBox.minExtent);

  // determine the midpoint of the scene in world coordinates
  var position = o3djs.math.addVector(boundingBox.maxExtent,boundingBox.minExtent);
  position = o3djs.math.divVectorScalar(position,2);

  // resize scene to the desired size
  var width='100';
  var height='100';
  var depth ='100';

  var ratioX = width / size[0];
  var ratioY = height / size[1];
  var ratioZ = depth / size[2];

  parent.scale(ratioX, ratioY, ratioZ);  // this somehow also translates the object

}

When I scale the scene, it moves in the world (although I only scale the scaleTransform). How can I avoid this?

When I draw the bounding box of the shape on screen, it appears much bigger than the shape itself. Why is that?

I can imagine this is because the scenes are not put into the origin of the model coordinate system, when they are originally modelled in the 3d modelling application. Does this make sense? How can I change the model coordinates of the scene then? I just want to position and scale them like any other transform.

Any comment is appreciated!