three.js引入obj模型使用 rotation 自转。轴心不在物体中心点,如何解决

loverfh2 2019-03-09 10:22:43
主要代码。如下,不加 .geometry.center() 自转。轴心不在物体中心点 ,加上geometry.center() 可以正常自转。但物体位置改变了。轮子脱离了汽车。前面设置的position也无效。求大神指点。
在3dmax 软件中调整轮子轴心后再导出也是无效。
 /** 加入模型 */
function createModel() {
// model
var onProgress = function ( xhr ) {

if ( xhr.lengthComputable ) {

var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round( percentComplete, 2 ) + '% downloaded' );

}

};
var onError = function () { };
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
//加载模型

new THREE.OBJLoader()
.setPath( 'models/obj/bentley_motors/' )
.load('qc10.obj', function ( object ) {//加载模型
object.position.y =-180;
object.position.x =-350;
object.position.z =200;

object.scale.x = 0.04;
object.scale.y = 0.04;
object.scale.z = 0.04;
left_front_wheel = new THREE.Object3D;
left_front_wheel.position.y =-180;
left_front_wheel.position.x =-350;
left_front_wheel.position.z =200;

left_front_wheel.scale.x = 0.04;
left_front_wheel.scale.y = 0.04;
left_front_wheel.scale.z = 0.04;

var left_front_1,left_front_2 ;
object.traverse(function(child) {

if(child instanceof THREE.Mesh) {
if(child.name=="left_front_wheel"){
left_front_2= child;
}
console.log("元素——"+child.name)
console.log(child)

}
})

left_front_wheel.add(left_front_2);

//left_front_wheel.children[0].geometry.center()
scene.add( left_front_wheel );
ready=true;
return object;
}, onProgress, onError );
}
//轮子自转 动画
function updateWheel(){
left_front_wheel.rotation.x-=speed;
}
...全文
2559 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
金梦入凡尘 2021-03-26
  • 打赏
  • 举报
回复
问题解决了吗?
qq_19640709 2019-10-03
  • 打赏
  • 举报
回复
我也遇到这个问题。我先让它回归坐标原点,然后其他组件按照它的位置来摆放。
exit8878 2019-06-06
  • 打赏
  • 举报
回复
// 先获取geometey的中心点位置并留存 let center = new THREE.Vector3(); geometry.computeBoundingBox(); geometry.boundingBox.getCenter(center); let x = center.x; let y = center.y; let z = center.z; // 把对象放到坐标原点 geometry.center(); // 绕轴旋转 geometry.rotateZ(0.1); // 再把对象放回原来的地方 geometry.translate(x, y, z); // 这种方式是不会刷新显示的,需要执行一下render renderer.render(scene, camera); // 需要做成动画效果的话,就是重复放到原点-旋转-放回原处-刷新显示的操作
loverfh2 2019-03-09
  • 打赏
  • 举报
回复
木有人么

10,607

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧