资源大湿 发表于 2020-4-14 13:38

可查看法线的脚本normals line script in unity

using System;
using UnityEngine;


public class ShowNormals : MonoBehaviour {

    public float length = 1;

    public Vector3 bias;
    public Boolean isShowDebugPoint;

    // Update is called once per frame
    private void OnValidate()
    {
      
    }
    private void OnDrawGizmos()
    {
      if (isShowDebugPoint)
      {
            // 获取网格法线
            Mesh mesh = GetComponent<MeshFilter>().sharedMesh;

            Vector3[] vertices = mesh.vertices;
            Vector3[] normals = mesh.normals;

            for (var i = 0; i < normals.Length; i++)
            {
                Vector3 pos = vertices;
                pos.x *= transform.localScale.x;
                pos.y *= transform.localScale.y;
                pos.z *= transform.localScale.z;
                pos += transform.position + bias;

                Gizmos.DrawLine
                (
                  pos,
                  pos + normals * length);
            }
      }
    }

}

xinwenhui88 发表于 2020-5-8 07:09

楼主是超人

hr1120 发表于 2020-5-8 07:47

好帖就是要顶

师叔 发表于 2020-5-8 07:34

真心顶

kacool 发表于 2020-5-8 07:53

很好哦

anoxic 发表于 2020-5-8 07:43

不错不错
页: [1]
查看完整版本: 可查看法线的脚本normals line script in unity