简体   繁体   English

围绕枢轴点旋转对象

[英]Rotate Object around Pivot Point

I am creating gizmos on all the vertices in a mesh, but when I do this, the object is straight up and down, but the gizmos are sideways. 我正在网格中的所有顶点上创建小控件,但是当我这样做时,对象是直线向上和向下的,但是小控件是侧向的。

As you can see in this image, the character is straight up and down, but the gizmos are rotated 90 degrees, so how can I either 如您在此图像中看到的那样,角色是上下笔直的,但是小控件旋转了90度,所以我该怎么办

A: Import the Mesh the correct way. 答:以正确的方式导入网格。

or 要么

B: Rotate the gizmos 90 degrees so they match the character. B:将小控件旋转90度,以使其与角色匹配。

小玩意儿

Here is what I am using to draw the gizmos: 这是我用来绘制小控件的内容:

[RequireComponent(typeof(MeshFilter))]
public class Creator : MonoBehaviour {

    public Vector3[] vertices;

    public Mesh mesh;

    void OnDrawGizmosSelected() {
        mesh = GetComponent<MeshFilter>().sharedMesh;
        if (vertices == null || vertices.Length == 0) {
            vertices = mesh.vertices;
        } else {
            mesh.vertices = vertices;
        }
        Vector3 lp = transform.position;
        foreach (Vector3 v in vertices) {
            Vector3 p = lp - v;

            Gizmos.color = Color.yellow;
            Gizmos.DrawCube(p, new Vector3(0.02f, 0.02f, 0.02f));
        }
        mesh.RecalculateBounds();
    }
}

I think its not your points that are rotated, but that the axis does not line up. 我认为不是您旋转的点,而是轴未对齐。 Try swapping the axis like this: 尝试像这样交换轴:

foreach (Vector3 v in vertices) {
            Vector3 p = lp - v;

            Gizmos.color = Color.yellow;
            Gizmos.DrawCube(new Vector3(p.x, p.z, p.y), new Vector3(0.02f, 0.02f, 0.02f));
        }

Note: I swapped the y and z axis. 注意:我交换了y和z轴。 If that is not the right one to swap try a different combo. 如果那不是正确的选择,请尝试其他组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM