【问题标题】:get farthest vertice on a specified direction of a 3D model - Unity在 3D 模型的指定方向上获取最远的顶点 - Unity
【发布时间】:2013-06-30 01:37:26
【问题描述】:

在给定方向向量和模型的情况下,我需要获取模型最远顶点的位置。

例如

obj 有以下顶点:

vertice a = (0,0,1)
vertice b = (0,1,0)
vertice c = (1,0,0)
vertice d = (0,0,0)

所以

GetPoint(obj, Vector3.up);

将返回顶点 b

提前致谢

【问题讨论】:

  • 您需要一个距离概念来计算最远点,而不仅仅是一个方向。如果您有一个方向 + 一个参考点,您可以构建一条线,您可以沿着该线搜索距参考最远的点或构建一个平面,并且您只能在平面的一侧搜索,除非您的方向用于定义特殊度量或测量。

标签: 3d unity3d vertices


【解决方案1】:

下面的代码将给出最远的点,但仅适用于没有子网格的网格,您可以稍微更改代码以针对子网格执行此操作..

Vector3 GetFarPoint (Transform obj, Vector3 direction) {

        Vector3[] vertices;
        Vector3 farthestPoint;
        float farDistance;

        vertices = obj.GetComponent<MeshFilter>().mesh.vertices;
        farDistance=0f;

        foreach(Vector3 vert in vertices)
        {
            float temp = Vector3.Dot(direction,vert);
            if(temp>farDistance)
            {
                farDistance = temp;
                farthestPoint = vert;
            }
        }
        return farthestPoint;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 2011-09-05
    相关资源
    最近更新 更多