Exemplo n.º 1
0
        public static Mesh CreateMeshFromBillboardInstance(BillboardInstance billboardInstance)
        {
            NativeArray <Vector3> verticeArray = billboardInstance.VerticeList;
            NativeArray <int>     indexArray   = billboardInstance.IndexList;
            NativeArray <Vector2> uvArray      = billboardInstance.UvList;
            NativeArray <Vector2> uv2Array     = billboardInstance.Uv2List;
            NativeArray <Vector2> uv3Array     = billboardInstance.Uv3List;
            NativeArray <Vector3> normalArray  = billboardInstance.NormalList;

            Vector3[] vertices = new Vector3[billboardInstance.VerticeList.Length];
            int[]     indices  = new int[billboardInstance.IndexList.Length];
            Vector2[] uvs      = new Vector2[billboardInstance.UvList.Length];
            Vector2[] uv2S     = new Vector2[billboardInstance.Uv2List.Length];
            Vector2[] uv3S     = new Vector2[billboardInstance.Uv3List.Length];
            Vector3[] normals  = new Vector3[billboardInstance.NormalList.Length];

            verticeArray.CopyToFast(vertices);
            indexArray.CopyToFast(indices);
            uvArray.CopyToFast(uvs);
            uv2Array.CopyToFast(uv2S);
            uv3Array.CopyToFast(uv3S);
            normalArray.CopyToFast(normals);

            var newMesh = new Mesh
            {
                hideFlags    = HideFlags.DontSave,
                subMeshCount = 1,
                indexFormat  = IndexFormat.UInt32,
                vertices     = vertices
            };

            newMesh.SetIndices(indices, MeshTopology.Triangles, 0, false);
            newMesh.uv      = uvs;
            newMesh.uv2     = uv2S;
            newMesh.uv3     = uv3S;
            newMesh.normals = normals;

            //TODO add bounds manually from billboard cell bounds
            //TODO replace with nativearray direct when unity adds interface.
            newMesh.RecalculateBounds();
            return(newMesh);
        }