Example #1
0
 public static OBJData LoadOBJ(Stream lStream)
 {
     OBJLoader.m_OBJData = new OBJData();
     OBJLoader.m_CurrentMaterial = null;
     OBJLoader.m_CurrentGroup = null;
     StreamReader streamReader = new StreamReader(lStream);
     Action<string> action = null;
     while (!streamReader.EndOfStream)
     {
         string text = streamReader.ReadLine();
         if (!StringExt.IsNullOrWhiteSpace(text) && text[0] != '#')
         {
             string[] array = text.Trim().Split(null, 2);
             if (array.Length >= 2)
             {
                 string text2 = array[0].Trim();
                 string obj = array[1].Trim();
                 action = null;
                 OBJLoader.m_ParseOBJActionDictionary.TryGetValue(text2.ToLowerInvariant(), out action);
                 if (action != null)
                 {
                     action(obj);
                 }
             }
         }
     }
     OBJData oBJData = OBJLoader.m_OBJData;
     OBJLoader.m_OBJData = null;
     return oBJData;
 }
Example #2
0
 public static OBJData EncodeOBJ(this Mesh lMesh)
 {
     OBJData oBJData = new OBJData
     {
         m_Vertices = new List<Vector3>(lMesh.vertices),
         m_UVs = new List<Vector2>(lMesh.uv),
         m_Normals = new List<Vector3>(lMesh.normals),
         m_UV2s = new List<Vector2>(lMesh.uv2),
         m_Colors = new List<Color>(lMesh.colors)
     };
     for (int i = 0; i < lMesh.subMeshCount; i++)
     {
         int[] triangles = lMesh.GetTriangles(i);
         OBJGroup oBJGroup = new OBJGroup(lMesh.name + "_" + i.ToString());
         for (int j = 0; j < triangles.Length; j += 3)
         {
             OBJFace oBJFace = new OBJFace();
             oBJFace.AddVertex(new OBJFaceVertex
             {
                 m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j] : -1,
                 m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j] : -1,
                 m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j] : -1,
                 m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j] : -1,
                 m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j] : -1
             });
             oBJFace.AddVertex(new OBJFaceVertex
             {
                 m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j + 1] : -1,
                 m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j + 1] : -1,
                 m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j + 1] : -1,
                 m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j + 1] : -1,
                 m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j + 1] : -1
             });
             oBJFace.AddVertex(new OBJFaceVertex
             {
                 m_VertexIndex = (oBJData.m_Vertices.Count > 0) ? triangles[j + 2] : -1,
                 m_UVIndex = (oBJData.m_UVs.Count > 0) ? triangles[j + 2] : -1,
                 m_NormalIndex = (oBJData.m_Normals.Count > 0) ? triangles[j + 2] : -1,
                 m_UV2Index = (oBJData.m_UV2s.Count > 0) ? triangles[j + 2] : -1,
                 m_ColorIndex = (oBJData.m_Colors.Count > 0) ? triangles[j + 2] : -1
             });
             oBJGroup.AddFace(oBJFace);
         }
         oBJData.m_Groups.Add(oBJGroup);
     }
     return oBJData;
 }
Example #3
0
 private static void PushOBJGroup(string lGroupName)
 {
     OBJLoader.m_CurrentGroup = new OBJGroup(lGroupName);
     OBJLoader.m_OBJData.m_Groups.Add(OBJLoader.m_CurrentGroup);
 }