示例#1
0
        public void HandleVertices(object num)
        {
            ThreadData data  = (ThreadData)num;
            int        start = data.start;
            int        end   = data.end;

            for (int i = start; i < end; i++)
            {
                VertexTrait trait = new VertexTrait(i);
                trait.position = this.verts[i];
                trait.hashCode = GDMesh.getHashforVector3(this.verts[i]);
                trait.ID       = i;
                if (this.checkNormals)
                {
                    trait.Normal = this.normals[i];
                }
                if (this.checkTangents)
                {
                    trait.tangent = this.tangents[i];
                }
                if (this.checkColors)
                {
                    trait.color = this.colors[i];
                }
                if (this.checkUV)
                {
                    trait.uv = this.uv[i];
                }
                if (this.checkUV1)
                {
                    trait.uv1 = this.uv1[i];
                }
                if (this.checkUV2)
                {
                    trait.uv2 = this.uv2[i];
                }
                if (this.checkBones)
                {
                    trait.boneWeight = this.bones[i];
                }
                GDMesh.Vertex item = new GDMesh.Vertex();
                item.Traits = trait;
                if (!this._gdmesh.relatedVertices.ContainsKey(item.Traits.hashCode))
                {
                    lock (this.Vlocker)
                    {
                        this._gdmesh.Vertices.Add(item);
                    }
                    this.AddRelatedVertex(item, false);
                }
                else
                {
                    this.AddRelatedVertex(item, true);
                }
                this.vertices[i] = item;
            }
            this.mutex.WaitOne();
            this.finishedCount++;
            this.mutex.ReleaseMutex();
        }
示例#2
0
        public static GDMesh Build(Mesh m, GDMesh GDMesh = null)
        {
            bool flag  = false;
            bool flag2 = (m.normals != null) && (m.normals.Length == m.vertexCount);
            bool flag3 = (m.tangents != null) && (m.tangents.Length == m.vertexCount);
            bool flag4 = (m.colors != null) && (m.colors.Length == m.vertexCount);
            bool flag5 = (m.uv != null) && (m.uv.Length == m.vertexCount);

            if (m.uv2 != null)
            {
                Vector2[] vectorArray1 = m.uv2;
                int       vertexCount  = m.vertexCount;
            }
            bool flag6 = (m.uv2 != null) && (m.uv2.Length == m.vertexCount);
            bool flag7 = (m.boneWeights != null) && (m.boneWeights.Length == m.vertexCount);
            bool flag8 = (m.bindposes != null) && (m.bindposes.Length > 0);

            Vector3[]    vertices     = m.vertices;
            Vector3[]    normals      = m.normals;
            Vector4[]    tangents     = m.tangents;
            Color[]      colors       = m.colors;
            Vector2[]    uv           = m.uv;
            Vector2[]    vectorArray6 = m.uv2;
            Vector2[]    vectorArray5 = m.uv2;
            BoneWeight[] boneWeights  = m.boneWeights;
            int[]        triangles    = m.triangles;
            if (GDMesh == null)
            {
                flag   = true;
                GDMesh = new GDMesh(m);
            }
            GDMesh.vertexCount = m.vertexCount;
            GDMesh.Vertex[] collection = new GDMesh.Vertex[m.vertexCount];
            SerializableDictionary <int, IndexBuffer> relatedVertices = GDMesh.relatedVertices;
            List <GDMesh.Vertex> list = GDMesh.Vertices;

            if (flag)
            {
                int num = m.vertexCount;
                for (int i = 0; i < num; i++)
                {
                    VertexTrait trait = new VertexTrait(i);
                    trait.position = vertices[i];
                    trait.hashCode = GDMesh.getHashforVector3(m.vertices[i]);
                    trait.ID       = i;
                    if (flag2)
                    {
                        trait.Normal = normals[i];
                    }
                    if (flag3)
                    {
                        trait.tangent = tangents[i];
                    }
                    if (flag4)
                    {
                        trait.color = colors[i];
                    }
                    if (flag5)
                    {
                        trait.uv = uv[i];
                    }
                    if (flag6)
                    {
                        trait.uv2 = vectorArray5[i];
                    }
                    if (flag7)
                    {
                        trait.boneWeight = boneWeights[i];
                    }
                    GDMesh.Vertex item = new GDMesh.Vertex();
                    item.Traits = trait;
                    if (!relatedVertices.ContainsKey(trait.hashCode))
                    {
                        list.Add(item);
                        AddRelatedVertex(item, GDMesh, false);
                    }
                    else
                    {
                        AddRelatedVertex(item, GDMesh, true);
                    }
                    collection[i] = item;
                }
            }
            else
            {
                if (GDController.vertexCount > 0)
                {
                    collection = new GDMesh.Vertex[GDController.vertexCount];
                }
                int count = list.Count;
                for (int j = 0; j < count; j++)
                {
                    IndexBuffer buffer = relatedVertices[list[j].Traits.hashCode];
                    foreach (int num5 in buffer)
                    {
                        collection[num5] = list[j];
                    }
                }
            }
            if (!flag)
            {
                GDMesh.vertices = new List <GDMesh.Vertex>(collection);
                if (GDMesh.faces == null)
                {
                    GDMesh.faces = new List <GDMesh.Face>();
                }
                GDMesh.faces.Clear();
                if (GDMesh.edges == null)
                {
                    GDMesh.edges = new List <GDMesh.Edge>();
                }
                GDMesh.edges.Clear();
                if (GDMesh.elements == null)
                {
                    GDMesh.elements = new List <GDMesh.Element>();
                }
                GDMesh.elements.Clear();
            }
            if (m.subMeshCount == 0)
            {
                GDMesh.Element element = new GDMesh.Element();
                int            length  = m.triangles.Length;
                for (int k = 0; k < length; k += 3)
                {
                    FaceTrait vt = new FaceTrait(k);
                    vt.ID           = k;
                    vt.subMeshIndex = 0;
                    GDMesh.AddTriangle(vt, relatedVertices[collection[triangles[k]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[triangles[k + 1]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[triangles[k + 2]].Traits.hashCode].vert).Element = element;
                }
                element.Index = 0;
                GDMesh.Elements.Add(element);
            }
            else
            {
                int id           = 0;
                int subMeshCount = m.subMeshCount;
                for (int n = 0; n < subMeshCount; n++)
                {
                    GDMesh.Element element2  = new GDMesh.Element();
                    int[]          numArray2 = m.GetTriangles(n);
                    int            num11     = numArray2.Length;
                    for (int num12 = 0; num12 < num11; num12 += 3)
                    {
                        FaceTrait trait3 = new FaceTrait(id);
                        trait3.ID           = id;
                        trait3.subMeshIndex = n;
                        trait3.subMeshTriID = num12;
                        GDMesh.AddTriangle(trait3, relatedVertices[collection[numArray2[num12]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[numArray2[num12 + 1]].Traits.hashCode].vert, GDMesh.relatedVertices[collection[numArray2[num12 + 2]].Traits.hashCode].vert).Element = element2;
                        id++;
                    }
                    element2.Index = n;
                    GDMesh.Elements.Add(element2);
                }
            }
            if (flag8)
            {
                GDMesh.bindposes = new List <Matrix4x4>(m.bindposes);
            }
            Quadrangulate(GDMesh, 90f, 5f, 5f, true, false);
            GDMesh.isBuilt = true;
            return(GDMesh);
        }