示例#1
0
        public void ProcessMesh(object obj)
        {
            ThreadData data = (ThreadData)obj;

            GDMesh.Element custom = data.custom as GDMesh.Element;
            GDMesh         mesh   = data._gdmesh as GDMesh;

            int[] numArray = data.custom2 as int[];
            int   num      = (int)data.custom3;
            int   num2     = (int)data.custom4;
            int   start    = data.start;
            int   end      = data.end;

            try
            {
                for (int i = start; i < end; i += 3)
                {
                    if ((i + 2) < numArray.Length)
                    {
                        FaceTrait vt = new FaceTrait(num2 + (i / 3));
                        vt.ID           = num2 + (i / 3);
                        vt.subMeshIndex = num;
                        vt.subMeshTriID = i;
                        mesh.AddTriangle(vt, this.vertices[numArray[i]], this.vertices[numArray[i + 1]], this.vertices[numArray[i + 2]]).Element = custom;
                    }
                }
                this.mutex.WaitOne();
                this.finishedCount++;
                this.mutex.ReleaseMutex();
            }
            catch (Exception exception)
            {
                this.ex            = exception;
                this.finishedCount = -1;
            }
        }
示例#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);
        }