Exemplo n.º 1
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            VertexCountOffsetOffset = reader.ReadUInt32(); //Refered to in LibS06 as `geometry_address`
            PostFaceOffset          = reader.ReadUInt32(); //Refered to in LibS06 as `mopp_code_address`
            VertexCountOffset       = reader.ReadUInt32(); //Refered to in LibS06 as `vertex_section_address`
            FaceCountOffset         = reader.ReadUInt32(); //Refered to in LibS06 as `face_section_address`
            VertexCount             = reader.ReadUInt32();

            //Vertexes
            for (int i = 0; i < VertexCount; i++)
            {
                Vertices.Add(reader.ReadVector3());
            }

            //Faces
            FaceCount = reader.ReadUInt32();
            for (int i = 0; i < FaceCount; i++)
            {
                S06CollisionFace face = new S06CollisionFace();
                face.Vertex1 = reader.ReadUInt16();
                face.Vertex2 = reader.ReadUInt16();
                face.Vertex3 = reader.ReadUInt16();
                reader.JumpAhead(2);
                face.Flags = reader.ReadUInt32();
                Faces.Add(face);
            }
        }
Exemplo n.º 2
0
        public void ImportOBJ(string filepath)
        {
            var  obj   = File.ReadAllLines(filepath);
            uint flags = 0;

            foreach (var line in obj)
            {
                if (line.StartsWith("v "))
                {
                    var     split  = line.Split(' ');
                    Vector3 vertex = new Vector3();
                    vertex.X = float.Parse(split[2]);
                    vertex.Y = float.Parse(split[3]);
                    vertex.Z = float.Parse(split[4]);
                    Vertices.Add(vertex);
                }

                if (line.StartsWith("g "))
                {
                    if (line.Contains("@"))
                    {
                        var temp = line.Substring(line.LastIndexOf('@') + 1);
                        flags = (uint)Convert.ToInt32(temp, 16);
                    }
                    else if (line.Contains("_at_"))
                    {
                        var temp = line.Substring(line.LastIndexOf("_at_") + 4);
                        flags = (uint)Convert.ToInt32(temp, 16);
                    }
                    else
                    {
                        flags = 0;
                    }
                }

                if (line.StartsWith("f "))
                {
                    S06CollisionFace face = new S06CollisionFace();
                    var split             = line.Split(' ');
                    if (split[1].Contains("/"))
                    {
                        face.Vertex1 = (ushort)(float.Parse(split[1].Substring(0, split[1].IndexOf('/'))) - 1f);
                    }
                    if (split[2].Contains("/"))
                    {
                        face.Vertex2 = (ushort)(float.Parse(split[2].Substring(0, split[2].IndexOf('/'))) - 1f);
                    }
                    if (split[3].Contains("/"))
                    {
                        face.Vertex3 = (ushort)(float.Parse(split[3].Substring(0, split[3].IndexOf('/'))) - 1f);
                    }
                    face.Flags = flags;
                    Faces.Add(face);
                }
            }
        }