コード例 #1
0
        public void AddUVs()
        {
            Vector2 uv1 = new Vector2(0, 1);
            Vector2 uv2 = new Vector2(0.5f, 0.1328f);
            Vector2 uv3 = new Vector2(1, 1);

            for (int i = 0; i < indices.Length; i += 3)
            {
                MeshAttr.SetUV(ref mesh.vertices[i], ref uv1);
                MeshAttr.SetUV(ref mesh.vertices[i + 1], ref uv2);
                MeshAttr.SetUV(ref mesh.vertices[i + 2], ref uv3);
            }
        }
コード例 #2
0
        public void AddTriangle2 <AltVertex>(ref List <AltVertex> newVerts, ref List <uint> newIndices, int v1index, ref Vector3 v2, ref Vector3 v3)
            where AltVertex : struct, IVertex
        {
            AltVertex[] triVerts = new AltVertex[3];
            triVerts.Initialize();

            Vector3 v1Pos = MeshAttr.GetPosition(ref mesh.vertices[v1index]);

            MeshAttr.SetPosition(ref triVerts[0], ref v1Pos);
            MeshAttr.SetPosition(ref triVerts[1], ref v2);
            MeshAttr.SetPosition(ref triVerts[2], ref v3);

            v1Pos.Normalize();
            for (int i = 0; i < 3; i++)
            {
                MeshAttr.SetNormal(ref triVerts[i], ref v1Pos);
            }

            Vector2 uv0 = new Vector2(0.5f, 1);
            Vector2 uv1 = new Vector2(0, 0);
            Vector2 uv2 = new Vector2(1, 0);

            MeshAttr.SetUV(ref triVerts[0], ref uv0);
            MeshAttr.SetUV(ref triVerts[1], ref uv1);
            MeshAttr.SetUV(ref triVerts[2], ref uv2);

            Vector4 c0 = MeshAttr.GetColor(ref mesh.vertices[v1index]);
            Vector4 c1 = MeshAttr.GetColor(ref mesh.vertices[v1index]);
            Vector4 c2 = MeshAttr.GetColor(ref mesh.vertices[v1index]);

            MeshAttr.SetColor(ref triVerts[0], ref c0);
            MeshAttr.SetColor(ref triVerts[1], ref c1);
            MeshAttr.SetColor(ref triVerts[2], ref c2);

            newVerts[v1index] = triVerts[0];
            int index = newVerts.Count;

            newVerts.Add(triVerts[1]);
            newVerts.Add(triVerts[2]);

            newIndices.Add((uint)v1index);
            newIndices.Add((uint)index++);
            newIndices.Add((uint)index++);
        }
コード例 #3
0
        public void AddTriangle <AltVertex>(ref List <AltVertex> newVerts, ref List <uint> newIndices, ref Vector3 v1, ref Vector3 v2, ref Vector3 v3, bool isAnticlockwise)
            where AltVertex : struct, IVertex
        {
            AltVertex[] triVerts = new AltVertex[3];
            triVerts.Initialize();
            MeshAttr.SetPosition(ref triVerts[0], ref v1);
            MeshAttr.SetPosition(ref triVerts[1], ref v2);
            MeshAttr.SetPosition(ref triVerts[2], ref v3);
            Vector3 v1N = v1;

            v1N.Normalize();
            for (int i = 0; i < 3; i++)
            {
                MeshAttr.SetNormal(ref triVerts[i], ref v1N);
            }

            Vector2 uv0 = new Vector2(0.5f, 1);
            Vector2 uv1 = new Vector2(0, 0);
            Vector2 uv2 = new Vector2(1, 0);

            MeshAttr.SetUV(ref triVerts[0], ref uv0);
            MeshAttr.SetUV(ref triVerts[1], ref uv1);
            MeshAttr.SetUV(ref triVerts[2], ref uv2);
            int index = newVerts.Count;

            for (int i = 0; i < 3; i++)
            {
                newVerts.Add(triVerts[i]);
            }

            if (isAnticlockwise)
            {
                newIndices.Add((uint)index);
                newIndices.Add((uint)index + 1);
                newIndices.Add((uint)index + 2);
            }
            else
            {
                newIndices.Add((uint)index);
                newIndices.Add((uint)index + 2);
                newIndices.Add((uint)index + 1);
            }
        }