www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: gamenewer on October 22, 2014, 04:40:56 am

Title: How to caculate the 3d model size ?
Post by: gamenewer on October 22, 2014, 04:40:56 am
Hello Egon,  I load the 3D car model by jpct , I want to get the car width  height and length , int other way, how to get the car's boundingBox? How can I do this?  Thanks very much
Title: Re: How to caculate the 3d model size ?
Post by: EgonOlsen on October 22, 2014, 07:41:57 am
Get the Mesh instance from an Object3D and then call http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Mesh.html#getBoundingBox() (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Mesh.html#getBoundingBox()). You can calculate the actual size based on the data in the returned array.
Title: Beware of parents
Post by: Darai on October 22, 2014, 09:16:10 am
And!

As I tried to point out in some older posts, beware of parenting, because to scale a parent means to scale all its children, so I am using this to calculate the real size of the object:
Code: [Select]
public static SimpleVector getSize(Object3D object){
float[] bbox = object.getMesh().getBoundingBox();
Log.i("Util","getSize-bbox:"+Util.floatArrayToString(bbox));
float s = object.getScale();
Log.i("Util","getSize-scale:"+object.getScale());
Object3D[] par;
par = object.getParents();
while(par.length>0){
s = s*par[0].getScale();
Log.i("Util","getSize-parent:"+par[0].getScale());
par = par[0].getParents();
}
SimpleVector out = new SimpleVector((bbox[1]-bbox[0])*s,(bbox[3]-bbox[2])*s,(bbox[5]-bbox[4])*s);
Log.i("Util", "getSize:"+out.toString());
return out;
}
Enjoy,
Darai.
Title: Re: How to caculate the 3d model size ?
Post by: angieIe on October 22, 2014, 10:35:02 am
hai ,  i have 3d model that if i select image in gridview the model show up, but 3D model come with diffrent size..some show too  much bigger,some show too little.
Code: [Select]
  cube=Primitives.getBox(15,3);
      cube.calcBoundingBox();
      float[] bb=cube.getMesh().getBoundingBox();
      float xDiff=bb[1]-bb[0];
      float yDiff=bb[3]-bb[2];
      float zDiff=bb[5]-bb[4];
      float scale_cube=cube.getScale();
    obj=Loader.load3DS(new FileInputStream(f),30f)[0];
    getSize(obj).x=xDiff;
    getSize(obj).y=yDiff;
    getSize(obj).z=zDiff;
    obj.setScale(scale_cube);
    obj.strip();
obj.build();
}

  public static SimpleVector getSize(Object3D object){
float[] bbox = object.getMesh().getBoundingBox();
float s = object.getScale();
Log.i("Util","getSize-scale:"+object.getScale());
Object3D[] par;
par = object.getParents();
while(par.length>0){
s = s*par[0].getScale();
Log.i("Util","getSize-parent:"+par[0].getScale());
par = par[0].getParents();
}
SimpleVector out = new SimpleVector((bbox[1]-bbox[0])*s,(bbox[3]-bbox[2])*s,(bbox[5]-bbox[4])*s);
Log.i("Util", "getSize:"+out.toString());
return out;
}
But my code not working..can you help me..thanks
Title: Re: How to caculate the 3d model size ?
Post by: EgonOlsen on October 22, 2014, 05:11:56 pm
But my code not working..can you help me..thanks
That code makes no sense... ;) The getSize()-method that you are using returns a SimpleVector instance. You are calling it multiple times, set the xyz component of the returned vector (which is a different one for each call) to some delta value and then do nothing with any of them.
That getSize() method returns a vector with the dimensions in xyz-direction. You have to calculate the maximum value (=maxSize) of these (or maybe just of two of them, that depends on your scene) and use that to calculate the (re-)size value. If you know for example, that an object with the size 100 has the right size at scale 1, just do something like setScale(100/maxSize).
Title: Re: How to caculate the 3d model size ?
Post by: angieIe on October 23, 2014, 05:23:02 am
Thank you egon, it's work now  :)