Pathfinding.ObjImporter.ImportFile C# (CSharp) Method

ImportFile() public static method

public static ImportFile ( string filePath ) : Mesh
filePath string
return UnityEngine.Mesh
	    public static Mesh ImportFile (string filePath) {
			
			if (!File.Exists (filePath)) {
				Debug.LogError ("No file was found at '"+filePath+"'");
				return null;
			}
			
	        meshStruct newMesh = createMeshStruct(filePath);
	        populateMeshStruct(ref newMesh);
	
	        Vector3[] newVerts = new Vector3[newMesh.faceData.Length];
	        Vector2[] newUVs = new Vector2[newMesh.faceData.Length];
	        Vector3[] newNormals = new Vector3[newMesh.faceData.Length];
	        int i = 0;
	        /* The following foreach loops through the facedata and assigns the appropriate vertex, uv, or normal
	         * for the appropriate Unity mesh array.
	         */
	        foreach (Vector3 v in newMesh.faceData)            
	        {
	            newVerts[i] = newMesh.vertices[(int)v.x - 1];
	            if (v.y >= 1)
	                newUVs[i] = newMesh.uv[(int)v.y - 1];
	            
	            if (v.z >= 1)
	                newNormals[i] = newMesh.normals[(int)v.z - 1];
	            i++;
	        }
	        
	        Mesh mesh = new Mesh();
	
	        mesh.vertices = newVerts;     
	        mesh.uv = newUVs;        
	        mesh.normals = newNormals;
	        mesh.triangles = newMesh.triangles;
	
	        mesh.RecalculateBounds();
	        //mesh.Optimize();
	        
	        return mesh;
	    }
	

Usage Example

Ejemplo n.º 1
0
 public void ScanInternal(string objMeshPath)
 {
     Mesh x = ObjImporter.ImportFile(objMeshPath);
     if (x == null)
     {
         Debug.LogError("Couldn't read .obj file at '" + objMeshPath + "'");
         return;
     }
     this.sourceMesh = x;
     base.ScanInternal();
 }
All Usage Examples Of Pathfinding.ObjImporter::ImportFile