【发布时间】:2019-12-10 04:32:03
【问题描述】:
在 Three.js 中似乎有很多我个人觉得不太直观的旋转方式。参见例如例子
http://cloud.engineering-bear.com/apps/robot/robot.html
当我对多个对象应用旋转时,我得到了非常奇怪的意外效果。例如。当我旋转已相互添加的对象并开始旋转父对象时,各个对象将突然之间相对于彼此以不同的方式放置,然后它们原来的位置。我现在正在尝试分组,并希望避免同样的效果。
查看http://pi-q-robot.bitplan.com/example/robot?robot=/models/thing3088064.json 了解当前状态,https://github.com/BITPlan/PI-Q-Robot 了解源代码。
所以我根据不同的 API 选项搜索了合适的示例:
轮换
function renderScene() {
stats.update();
//side1.rotation.z += 0.02;
pivot.rotation.z += 0.02;
rotateOnAxis
- three.js rotate Object3d around Y axis at it center
- How to rotate a 3D object on axis three.js?
- ThreeJS - rotation around object's own axis
rotateAroundWorldAxis
object.rotateAroundWorldAxis(p, ax, r * Math.PI * 2 / frames);
- How to rotate a object on axis world three.js?
- https://stackoverflow.com/a/32038265/1497139
- https://jsfiddle.net/b4wqxkjn/7/
- THREE.js Update rotation property of object after rotateOnWorldAxis
rotateOnWorldAxis
object.rotateOnWorldAxis( axis, angle );
rotateAboutPoint
setRotationFromAxisAngle
setEulerFromQuaternion
quaternion = new THREE.Quaternion().setFromAxisAngle( axisOfRotation, angleOfRotation );
object.rotation.setEulerFromQuaternion( quaternion );
应用矩阵
this.mesh.updateMatrixWorld(); // important !
childPart.mesh.applyMatrix(new THREE.Matrix4().getInverse(this.mesh.matrixWorld))
我喜欢jsFiddle 换成https://stackoverflow.com/a/56427636/1497139
var pivot = new THREE.Object3D();
pivot.add( cube );
scene.add( pivot );
我还发现了以下讨论 disourcee.three.js.org 中的枢轴问题
- https://discourse.threejs.org/t/rotate-group-around-pivot/3656
- https://discourse.threejs.org/t/how-to-rotate-an-object-around-a-pivot-point/6838
- https://discourse.threejs.org/t/set-dynamically-generated-groups-pivot-position-to-the-center-of-its-children-objects-position/6349
- https://discourse.threejs.org/t/my-3d-model-is-not-rotating-around-its-origin/3339/3
- https://discourse.threejs.org/t/rotate-object-at-end-point/2190
问题 上述信息都不够清楚,无法指出要解决的问题。与提案中的解决方案相比,上面的图表更清楚地说明了问题。
a) 即使圆柱体被移动,我也想使用圆柱体作为轴。我希望最简单的方法是使用 rotateAroundWorldAxis - 是最新版本的three.js还是我必须从例如添加它https://stackoverflow.com/a/32038265/1497139?
b) 我想得到一个要旋转的对象链,以便以后应用逆运动学,如
虽然我查看了该解决方案的源代码,但我无法真正找到父子定位和旋转发生的地方。 有哪些相关的代码行/API 函数可以围绕关节链进行适当的旋转? 我已经查看了 Three.js 的 Bone/Skeleton API,但在那里遇到了同样的问题 - 很多代码行,但没有明确的点在哪里发生子和父之间的旋转/定位。
【问题讨论】:
-
stackoverflow.com/a/26413121/1497139 是迄今为止我找到的最有帮助的答案
-
查看discourse.threejs.org/t/robot-simulation-rotation-issues/9065 了解更详细的讨论和示例项目
标签: three.js rotation inverse-kinematics