围绕其中心点旋转自定义几何网格 [英] Rotating a custom geometry mesh around its center point

查看:36
本文介绍了围绕其中心点旋转自定义几何网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在场景中添加一个 CustomGeometry 并定义顶点而不设置位置时,我们如何让它围绕自己的中心点旋转?

When we add a CustomGeometry to the scene with defining vertices and not setting the position, how can we get it to rotate around its own center point?

小提琴:http://jsfiddle.net/tezcancirakoglu/Ldt7z

Fiddle : http://jsfiddle.net/tezcancirakoglu/Ldt7z

在示例代码中,对象围绕场景 X 轴旋转.我需要围绕它的中心点旋转它.

In the sample code, object is rotating around Scenes X axis. I need to rotate it around its center point.

提示:红色立方体网格是旋转对象的初始中心点.我需要围绕红色立方体的 x 轴旋转它...我尝试了很多但还是失败了.

Hint: The red cube mesh is the initial centerpoint of the object which is rotating. I need to rotate it around x axis of red cube... I tried alot but failed anyway.

推荐答案

一种解决方案是平移网格几何体,并通过改变网格位置来进行补偿,如下所示:

One solution is to translate the mesh geometry, and compensate by changing the mesh position, like so:

var offset = objMesh.centroid.clone();
objMesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation( -offset.x, -offset.y, -offset.z ) );
objMesh.position.copy( objMesh.centroid );

更新小提琴:http://jsfiddle.net/Ldt7z/165/

附言你不需要在运行之前保存你的小提琴.没有理由有这么多版本.

P.S. You do not need to save your fiddle before running it. There is no reason to have so many versions.

three.js r.55

three.js r.55

这篇关于围绕其中心点旋转自定义几何网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆