LoginSignup
1
1

More than 5 years have passed since last update.

unity > mesh使ってみた

Last updated at Posted at 2016-09-24
動作環境
Unity 5.3.5f1 on MacOS X El Capitan

100万個の粒子から構成される形状のビューワを作るにはどうするか。
GameObjectを100万個は出せないようだ。

パーティクルで120万個を生成している例がある。ただし、パーティクルで指定の場所に粒子を配置できるかは未消化。
http://tips.hecomi.com/entry/2016/05/08/160626

メッシュを使って、上限64Kのものをたくさん配置していることになるだろうか。

とりあえずmesh使ってみた。

参考 https://www.youtube.com/watch?v=R_kV3YiJqEw

code

using UnityEngine;
using System.Collections;

public class MeshCreateSC : MonoBehaviour {

    public float width = 50f;
    public float height = 50f;

    void Start () {
        MeshFilter mf = GetComponent<MeshFilter> ();
        Mesh mesh = new Mesh ();
        mf.mesh = mesh;

        // Vertices
        Vector3[] vertices = new Vector3[4] {
            new Vector3 (0, 0, 0), new Vector3 (width, 0, 0),
            new Vector3 (0, height, 0), new Vector3 (width, height, 0)
        };

        // Triangles
        int[] tri = new int[6];

        tri [0] = 0;
        tri [1] = 2;
        tri [2] = 1;

        tri [3] = 2;
        tri [4] = 3;
        tri [5] = 1;

        // Normals (only if you want to display object in the game).
        Vector3[] normals = new Vector3[4];

        normals [0] = -Vector3.forward;
        normals [1] = -Vector3.forward;
        normals [2] = -Vector3.forward;
        normals [3] = -Vector3.forward;

        // UVs (How textures are displayed).
        Vector2[] uv = new Vector2[4];

        uv [0] = new Vector2 (0, 0);
        uv [1] = new Vector2 (1, 0);
        uv [2] = new Vector2 (0, 1);
        uv [3] = new Vector2 (1, 1);

        // Assign Arrays
        mesh.vertices = vertices;
        mesh.triangles = tri;
        mesh.normals = normals;
        mesh.uv = uv;
    }

    // Update is called once per frame
    void Update () {

    }
}

qiita.png

qiita.png

平面を作れた。

1
1
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
1
1