Esempio n. 1
0
        static void SetTriangle(Mesh mesh, fbxImporter.UPolygons polygons,
                                fbxImporter.UMaterialIndex matList)
        {
            if (polygons.polygon == null || polygons.polygon.Count == 0)
            {
                return;
            }

            List <int> matindexList;

            if (matList != null)
            {
                matindexList = matList.indexList;
            }
            else
            {
                matindexList = new List <int>();
            }

            if (matindexList.Count != polygons.polygon.Count)
            {
                matindexList = new List <int>();
                for (int i = 0; i < polygons.polygon.Count; ++i)
                {
                    matindexList.Add(0);
                }
            }

            var dicTriangle = new Dictionary <int, List <int> >();
            int baseIndex   = 0;

            for (int i = 0; i < polygons.polygon.Count; ++i)
            {
                List <int> indexlist = null;
                if (!dicTriangle.TryGetValue(matindexList[i], out indexlist))
                {
                    indexlist = new List <int>();
                    dicTriangle.Add(matindexList[i], indexlist);
                }
                int n = polygons.polygon[i].coordinates.Count;
                GenIndex(baseIndex, n, indexlist);
                baseIndex += n;
            }

            mesh.subMeshCount = dicTriangle.Keys.Count;

            var list = new List <KeyValuePair <int, List <int> > >(dicTriangle);

            list.Sort(delegate(KeyValuePair <int, List <int> > a, KeyValuePair <int, List <int> > b)
            {
                return(a.Key.CompareTo(b.Key));
            }
                      );


            for (int i = 0; i < list.Count; ++i)
            {
                mesh.SetTriangles(list[i].Value, i);
            }
        }
Esempio n. 2
0
        static List <Vector3> GetAllVertexs(fbxImporter.UPolygons polygons, fbxImporter.UGeometricTransform geo, out int vertexCount)
        {
            List <Vector3> vertexs = new List <Vector3>();

            vertexCount = 0;
            if (polygons.polygon != null && polygons.polygon.Count > 0)
            {
                for (int i = 0; i < polygons.polygon.Count; ++i)
                {
                    for (int j = 0; j < polygons.polygon[i].coordinates.Count; ++j)
                    {
                        Vector3 pos = FbxVector3ToVector3(polygons.polygon[i].coordinates[j]);
                        pos.x *= geo.scaling.x;
                        pos.y *= geo.scaling.y;
                        pos.z *= geo.scaling.z;
                        //pos = pos + Quaternion.Euler(FbxVector3ToVector3(geo.rotation)) * pos;
                        pos  += FbxVector3ToVector3(geo.translation);
                        pos.x = -pos.x;
                        vertexs.Add(pos);
                        ++vertexCount;
                    }
                }
            }

            //Debug.Log("GetAllVertexs   " + count);
            return(vertexs);
        }
Esempio n. 3
0
        static List <Vector2> GetAllUVs(fbxImporter.UPolygons polygons)
        {
            List <Vector2> vertexs = new List <Vector2>();

            if (polygons.polygon != null && polygons.polygon.Count > 0)
            {
                for (int i = 0; i < polygons.polygon.Count; ++i)
                {
                    for (int j = 0; j < polygons.polygon[i].texUV.Count; ++j)
                    {
                        vertexs.Add(FbxVector2ToVector2(polygons.polygon[i].texUV[j]));
                    }
                }
            }
            return(vertexs);
        }
Esempio n. 4
0
 static int[] GetTriangle(fbxImporter.UPolygons polygons)
 {
     if (polygons.polygon != null && polygons.polygon.Count > 0)
     {
         List <int> indexList = new List <int>();
         int        baseIndex = 0;
         for (int i = 0; i < polygons.polygon.Count; ++i)
         {
             int n = polygons.polygon[i].coordinates.Count;
             GenIndex(baseIndex, n, indexList);
             baseIndex += n;
         }
         //indexList.Reverse();
         return(indexList.ToArray());
     }
     return(null);
 }
Esempio n. 5
0
        static List <Vector3> GetAllNormals(fbxImporter.UPolygons polygons, fbxImporter.UGeometricTransform geo)
        {
            List <Vector3> vertexs = new List <Vector3>();

            if (polygons.polygon != null && polygons.polygon.Count > 0)
            {
                for (int i = 0; i < polygons.polygon.Count; ++i)
                {
                    for (int j = 0; j < polygons.polygon[i].normal.Count; ++j)
                    {
                        Vector3 pos = FbxVector3ToVector3(polygons.polygon[i].normal[j]);
                        //pos = Quaternion.Euler(FbxVector3ToVector3(geo.rotation)) * pos;
                        pos.x = -pos.x;
                        vertexs.Add(pos.normalized);
                    }
                }
            }
            return(vertexs);
        }