Beispiel #1
0
 public static ReaderBase FindReaderForExtension(string extension)
 {
     if (((IList)FbxReader.GetExtensions()).Contains(extension))
     {
         return(new FbxReader());
     }
     if (((IList)GltfReader.GetExtensions()).Contains(extension))
     {
         return(new GltfReader());
     }
     if (((IList)ObjReader.GetExtensions()).Contains(extension))
     {
         return(new ObjReader());
     }
     if (((IList)StlReader.GetExtensions()).Contains(extension))
     {
         return(new StlReader());
     }
     if (((IList)PlyReader.GetExtensions()).Contains(extension))
     {
         return(new PlyReader());
     }
     if (((IList)ThreeMfReader.GetExtensions()).Contains(extension))
     {
         return(new ThreeMfReader());
     }
     return(null);
 }
Beispiel #2
0
        static void GltfExample()
        {
            //string pathI = @".\..\..\..\..\file_samples\gltf\Box.glb";
            //string pathO = @".\..\..\..\..\file_samples\gltf\Box_out.fbx";
            //string pathI = @".\..\..\..\..\file_samples\gltf\objects_ascii_2014-2015.glb";
            //string pathO = @".\..\..\..\..\file_samples\gltf\objects_ascii_2014-2015_out.fbx";
            //string pathI = @".\..\..\..\..\file_samples\gltf\2CylinderEngine.glb";
            //string pathO = @".\..\..\..\..\file_samples\gltf\2CylinderEngine_out.fbx";
            //string pathI = @".\..\..\..\..\file_samples\gltf\canoe.glb";
            //string pathO = @".\..\..\..\..\file_samples\gltf\canoe_out.fbx";
            string pathI = @".\..\..\..\..\file_samples\gltf\GearboxAssy.glb";
            string pathO = @".\..\..\..\..\file_samples\gltf\GearboxAssy_out.fbx";

            using (GltfReader reader = new GltfReader(pathI))
            {
                Scene scene = reader.Read();
                FbxWriter.WriteAscii(pathO, scene);
            }
        }
Beispiel #3
0
        public static GltfContainer ReadAsContainer(Stream s)
        {
            using (var r = new Reader(s))
            {
                var h = r.ReadHeader();
                if (h.Magic != 0x46546C67)               // glTF Header
                {
                    throw new NotImplementedException(); // TODO: change types
                }

                if (h.Version != 2)
                {
                    throw new NotImplementedException(); // TODO: change types
                }

                Types.Gltf   gltf   = null;
                StoredBuffer buffer = null;

                for (var i = 0; ; ++i)
                {
                    var c = r.ReadChunk();
                    if (c == null)
                    {
                        break;
                    }

                    switch (c.ChunkType)
                    {
                    case 0x4E4F534A:     // JSON
                        if (i != 0)
                        {
                            // JSON chunk must be the first chunk
                            throw new NotImplementedException("Json");     // TODO: change type
                        }

                        if (gltf != null)
                        {
                            // Duplicated
                            throw new NotImplementedException("Json");     // TODO: change type
                        }

                        using (var cs = new MemoryStream(c.ChunkData))
                        {
                            gltf = GltfReader.Read(cs);
                        }

                        break;

                    case 0x004E4942:     // BIN
                        if (i != 1)
                        {
                            // Binary buffer chunk must be the second chunk
                            throw new NotImplementedException("BinaryBuffer");     // TODO: change type
                        }

                        if (buffer != null)
                        {
                            // Duplicated
                            throw new NotImplementedException("BinaryBuffer");     // TODO: change type
                        }

                        buffer = new StoredBuffer
                        {
                            Payload = new ArraySegment <byte>(c.ChunkData),
                        };

                        break;

                    default:
                        // Ignore
                        continue;
                    }
                }

                if (gltf == null)
                {
                    throw new NotImplementedException("Json is empty"); // TODO: change type
                }

                return(new GltfContainer(gltf, buffer));
            }
        }