예제 #1
0
        public static HittableGeometryComponent ReadObj(FileInfo file)
        {
            var reader  = new OBJReader();
            var builder = new SimpleMeshBuilder();

            using (var text = new StreamReader(File.OpenRead(file.FullName))) {
                var result = reader.Read(text, ReadOptions.Defaults, builder);
            }



            //var reader = new StandardMeshReader();
            //var res = reader.Read(file.FullName, ReadOptions.Defaults);

            //StandardMeshReader.ReadMesh()

            var mesh = builder.Meshes[0];



            return(new HittableGeometryComponent {
                Indices = mesh.GetTriangleArray().ToImmutableArray(),
                Normals = mesh.NormalsItr().Select(n => new Vector3(n.x, n.y, n.z)).ToImmutableArray(),
                Positions = mesh.VerticesItr().Select(n => new Vector3((float)n.x, (float)n.y, (float)n.z)).ToImmutableArray(),
            });
        }
예제 #2
0
 private async Task <SimpleMeshBuilder> loadObj(string filename)
 {
     using (StreamReader reader = File.OpenText(filename))
     {
         OBJReader         objReader   = new OBJReader();
         SimpleMeshBuilder meshBuilder = new SimpleMeshBuilder();
         try
         {
             IOReadResult result = objReader.Read(reader, new ReadOptions(), meshBuilder);
         }
         catch (Exception e) when(
             e is UnauthorizedAccessException ||
             e is DirectoryNotFoundException ||
             e is FileNotFoundException ||
             e is NotSupportedException
             )
         {
             Debug.LogError("Failed to Load" + filename + " : " + e.ToString());
             meshBuilder = new SimpleMeshBuilder();
         }
         return(meshBuilder);
     }
 }