LibGDX 模型实例 - 无法重置缩放,在缩放时设置转换会使模型变形



有没有办法在不使用transform.set的情况下重置模型实例的比例或设置模型实例位置?我正在制作一个 3D 怪物制造商,当选择一个零件时,一组 3D 箭头移动到该零件并变得可见,允许拖动零件。我注意到,无论出于何种原因,在严重缩放时设置箭头的位置都会使箭头变形。这是一个巨大的问题,因为我需要箭头根据零件的大小而不同。不设仓位,带定位。在未缩放的模型实例(或按 1 缩放的模型实例(上使用transform.set可以正常工作。

我认为解决方案是在移动箭头之前重置箭头的大小,然后在移动后重新缩放它,但似乎没有任何方法可以做到这一点,并且使用transform.scale(-currentScale, -currentScale, -currentScale)反转箭头并增加其大小而不是减小它。

以下是我更改箭头位置的方法:arrow[j].transform.set(modelInstance[i].transform.getTranslation(new Vector3(), arrow[j].transform.getRotation(new Quaternion());

好的,我做了一些日志记录,发现缩放会改变 matrix4 中的所有值,而不仅仅是 modelInstance 的大小。我没有找到仅缩放旋转的方法,但我想出了解决此问题的方法:我创建了一个空的 Matrix4,并在缩放之前将其设置为箭头矩阵的副本。当箭头需要定位在某个零件上时,我将箭头的矩阵设置为 baseMatrix,使用 transform.set 更改箭头的位置,然后重新缩放箭头。

if(Intersector.intersectRayBoundsFast(pickRay, modelInstance[i].boundingBox)) {
modelInstance[i].transform.getTranslation(modelInstance[i].position);//get the part's position and store it
for(int j = 0 ; j < 3 ; j++) {
arrow[j].transform = arrow[j].baseTransform.cpy();//reset the arrows transform
arrow[j].transform.getRotation(arrow[j].rotation);//get the arrow's (unscaled) rotation and store it
arrow[j].transform.set(modelInstance[i].position, arrow[j].rotation);//set the arrow's position and rotation
arrow[j].changeSize('S');//rescale the arrow
}
break;
}

您可以使用 transform.scale(1f/currentScale, 1f/currentScale, 1f/currentScale( 来还原缩放或函数 ModelInstance.calculateTransforms((

最新更新