LoginSignup
3
3

More than 5 years have passed since last update.

Unity Shaderことはじめ4 NavMeshを描画

Posted at

はじめに

今回はシェーダーではなく、シェーダーに渡す頂点情報を用意してみるサンプル。

NavMeshはよく使うけど実行中に描画するオプションがなかったので、
何かに使えないかなと思ってNavMeshを参照してみた。

手順

  • NavMeshを生成
  • 頂点情報準備/描画用にEmpty GameObjectを配置
  • GameObjectにMeshFilter, MeshRendererを追加
  • GameObjectにNavMeshのMeshを用意するスクリプト追加

NavMeshからMeshを用意するスクリプト

結構シンプル

using UnityEngine;
using System.Collections;

public class NavMeshDrawer : MonoBehaviour {

    void Awake () {
        //NavMeshの三角形集合取得
        NavMeshTriangulation triangles = NavMesh.CalculateTriangulation();

        //三角形集合からMeshを生成
        Mesh mesh = new Mesh();
        mesh.vertices = triangles.vertices;
        mesh.triangles = triangles.indices;

        //MeshFilterに生成したMeshを渡す
        MeshFilter filter = GetComponent<MeshFilter>();
        filter.mesh = mesh;
    }   
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3