سؤال

i have little problem with object positioning in java 3d engine. I trying to place my 3d model in center of coordinate using the center of the object on basis of its. That mean, that center of object is located at the base of the object, but not in the middle of its height, as is done in java3d. Here is how java3d doing it: ...
I haven't reputation 10... I can post only 2 urls... So there is url horizont view And there what i need to be: ...
object placed in 0,0,0 by the center of it's base

How can i do this?

I uses this code:

 TransformGroup tg = this.olib.get_model(model); // Taking my model from lib
 Transform3D transform = new Transform3D();
//p.x =0; p.y=0; p.z=0; (center)
 Vector3d vector = new Vector3d(p.x, p.y, p.z); // p is a class x,y,z,yAxis(rotation), scale
 transform.setScale(p.scale);
 Transform3D rotate1 = new Transform3D();
 rotate1.rotY(p.yAxis);
 transform.mul(rotate1);
 transform.setTranslation(vector);
 tg.setTransform(transform);
 objRoot.addChild(tg);
هل كانت مفيدة؟

المحلول

My problem was in incorrect loader. That's how i loaded my object to 3d Scene:

TransformGroup obj = new TransformGroup();
Scene s = null;
ObjectFile f = new ObjectFile ();
f.setFlags (ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY);
try{ s = f.load (obj_path+model+"\\"+model+".obj"); }catch(Exception ex) { ex.printStackTrace(); }
obj.addChild(s.getSceneGroup());
obj.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

The problem is in that row:

f.setFlags (ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY);

Flag ObjectFile.RESIZE mean that object loaded from file placed in the middle of it's height to the center of coordinate and decrease or increase size of object from it's original to range x:[-1,1]; y:[-1,1]; z:[-1,1].

But there no way to know current size of object, like width or height... Well, or i could not find in google.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top