Ejemplo n.º 1
0
        public static BOM Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            BOM bom = new BOM();

            bom.name = Path.GetFileNameWithoutExtension(path);

            using (BinaryReader br = new BinaryReader(fi.OpenRead()))
            {
                br.ReadBytes(18);   // Unknown
                int meshCount = br.ReadInt16();
                br.ReadBytes(28);   // Unknown

                for (int i = 0; i < meshCount; i++) { bom.offsets.Add(br.ReadInt32()); }

                for (int i = 0; i < meshCount; i++)
                {
                    br.BaseStream.Seek(bom.offsets[i], SeekOrigin.Begin);
                    var mesh = new BOMMesh();

                    br.ReadBytes(76);
                    mesh.VertCount = br.ReadInt32();
                    br.ReadBytes(4);
                    mesh.FaceCount = br.ReadInt32();
                    bom.meshes.Add(mesh);

                    br.ReadBytes(40);
                }

                br.ReadBytes(32);

                for (int i = 0; i < meshCount; i++)
                {
                    br.ReadBytes(80);
                }

                for (int i = 0; i < meshCount; i++)
                {
                    for (int j = 0; j < bom.meshes[i].FaceCount * 3; j++)
                    {
                        bom.meshes[i].IndexBuffer.Add(br.ReadUInt16());
                    }
                }

                br.BaseStream.Seek(16 - (br.BaseStream.Position % 16), SeekOrigin.Current);

                for (int i = 0; i < meshCount; i++)
                {
                    for (int j = 0; j < bom.meshes[i].VertCount; j++)
                    {
                        bom.verts.Add(
                            new BOMVertex(
                                br.ReadSingle(), br.ReadSingle(), br.ReadSingle(),
                                br.ReadSingle(), br.ReadSingle(), br.ReadSingle()
                            )
                        );
                        //Console.WriteLine("X {0} Y {1} Z {2}", br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        //Console.WriteLine("U {0} V {1}", br.ReadSingle(), br.ReadSingle());
                        //Console.WriteLine("A {0} B {1}", br.ReadInt32(), br.ReadInt32());
                        br.ReadBytes((i == 0 ? 36 : 28));
                    }

                    if (i == 0) { br.ReadBytes(12); }
                }
            }

            return bom;
        }
Ejemplo n.º 2
0
        public static BOM Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            BOM bom = new BOM {
                Name = Path.GetFileNameWithoutExtension(path)
            };

            using (BinaryReader br = new BinaryReader(fi.OpenRead()))
            {
                br.ReadBytes(18);   // Unknown
                int meshCount = br.ReadInt16();
                br.ReadBytes(28);   // Unknown

                for (int i = 0; i < meshCount; i++)
                {
                    bom.Offsets.Add(br.ReadInt32());
                }

                for (int i = 0; i < meshCount; i++)
                {
                    br.BaseStream.Seek(bom.Offsets[i], SeekOrigin.Begin);
                    BOMMesh mesh = new BOMMesh();

                    br.ReadBytes(76);
                    mesh.VertCount = br.ReadInt32();
                    br.ReadBytes(4);
                    mesh.FaceCount = br.ReadInt32();
                    bom.Meshes.Add(mesh);

                    br.ReadBytes(40);
                }

                br.ReadBytes(32);

                for (int i = 0; i < meshCount; i++)
                {
                    br.ReadBytes(80);
                }

                for (int i = 0; i < meshCount; i++)
                {
                    for (int j = 0; j < bom.Meshes[i].FaceCount * 3; j++)
                    {
                        bom.Meshes[i].IndexBuffer.Add(br.ReadUInt16());
                    }
                }

                br.BaseStream.Seek(16 - (br.BaseStream.Position % 16), SeekOrigin.Current);

                for (int i = 0; i < meshCount; i++)
                {
                    for (int j = 0; j < bom.Meshes[i].VertCount; j++)
                    {
                        bom.Verts.Add(
                            new BOMVertex(
                                br.ReadSingle(), br.ReadSingle(), br.ReadSingle(),
                                br.ReadSingle(), br.ReadSingle(), br.ReadSingle()
                                )
                            );
                        //Console.WriteLine("X {0} Y {1} Z {2}", br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        //Console.WriteLine("U {0} V {1}", br.ReadSingle(), br.ReadSingle());
                        //Console.WriteLine("A {0} B {1}", br.ReadInt32(), br.ReadInt32());
                        br.ReadBytes((i == 0 ? 36 : 28));
                    }

                    if (i == 0)
                    {
                        br.ReadBytes(12);
                    }
                }
            }

            return(bom);
        }