threejs collada model location

2019-09-02 17:31发布

I have been working on THREEJS framework to render *.dae models. There are several dae models. I have a problem with the location of the models. When I render them, each model has a different location. I set their location dae.position.set(0,0,0); but unfortunately, it doesn't work perfectly.

For example, for one model I have to set the location as dae.position.set(-2, -31, 6.5); and then model is on the location(0,0,0). I check it with AXES axes.position.set(0,0,0);.

Do you have any idea, why is the model not on the zero location for x,y,z.

Thank you for helping. I am totally new to three.js. I hope I explained myself clearly :)

1条回答
走好不送
2楼-- · 2019-09-02 18:00

The vertices of the model are offset from the origin, so you are compensating by setting the dae.position.

You can automatically adjust the dae position by recentering the model like so:

var box = new THREE.Box3().setFromObject( dae ); // compute the bounding box of the model
box.getCenter( dae.position ); // set dae.position to be the center of the bounding box
dae.position.multiplyScalar( - 1 ); // negate the dae.position coordinates

three.js r.87

查看更多
登录 后发表回答