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
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.
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:
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.
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.
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
Quote from: angieIe on October 22, 2014, 10:35:02 AM
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).
Thank you egon, it's work now :)