예제 #1
0
        public MT7Node(BinaryReader reader, MT7Node parent)
        {
            Parent = parent;

            Offset = (uint)reader.BaseStream.Position;
            ID     = reader.ReadUInt32();

            Position = new Vector3
            {
                X = reader.ReadSingle(),
                Y = reader.ReadSingle(),
                Z = reader.ReadSingle()
            };

            Rotation = new Vector3
            {
                X = 360.0f * reader.ReadInt32() / 0xffff,
                Y = 360.0f * reader.ReadInt32() / 0xffff,
                Z = 360.0f * reader.ReadInt32() / 0xffff
            };

            Scale = new Vector3
            {
                X = reader.ReadSingle(),
                Y = reader.ReadSingle(),
                Z = reader.ReadSingle()
            };

            XB01Offset    = reader.ReadUInt32();
            ChildOffset   = reader.ReadUInt32();
            SiblingOffset = reader.ReadUInt32();
            ParentOffset  = reader.ReadUInt32();

            reader.BaseStream.Seek(8, SeekOrigin.Current);

            //Check for sub nodes
            uint subNodeIdentifier = reader.ReadUInt32();

            reader.BaseStream.Seek(-4, SeekOrigin.Current);
            if (MDCX.IsValid(subNodeIdentifier))
            {
                SubNode = new MDCX(reader);
            }
            else if (MDPX.IsValid(subNodeIdentifier))
            {
                SubNode = new MDPX(reader);
            }
            else if (MDOX.IsValid(subNodeIdentifier))
            {
                new NotImplementedException("Never seen this, please report.");
            }
            else if (MDLX.IsValid(subNodeIdentifier))
            {
                new NotImplementedException("Never seen this, please report.");
            }

            //Read XB01 mesh data
            long offset = reader.BaseStream.Position;

            if (XB01Offset != 0)
            {
                HasMesh = true;
                reader.BaseStream.Seek(XB01Offset, SeekOrigin.Begin);
                XB01 = new XB01(reader, this);
            }

            //Construct node tree recursively
            if (ChildOffset != 0)
            {
                reader.BaseStream.Seek(ChildOffset, SeekOrigin.Begin);
                Child = new MT7Node(reader, this);
            }
            if (SiblingOffset != 0)
            {
                reader.BaseStream.Seek(SiblingOffset, SeekOrigin.Begin);
                Sibling = new MT7Node(reader, (MT7Node)Parent);
            }
            reader.BaseStream.Seek(offset, SeekOrigin.Begin);
        }
예제 #2
0
        protected override void _Read(BinaryReader reader)
        {
            Offset = (uint)reader.BaseStream.Position;

            Identifier = reader.ReadUInt32();
            if (!IsValid(Identifier))
            {
                return;
            }

            Size            = reader.ReadUInt32();
            FirstNodeOffset = reader.ReadUInt32();
            TextureCount    = reader.ReadUInt32();

            //Read texture entries if there are any
            for (uint i = 0; i < TextureCount; i++)
            {
                TextureEntries.Add(new TextureEntry(reader));
            }
            foreach (TextureEntry entry in TextureEntries)
            {
                entry.ReadTextureID(reader);
            }

            //If we are not at the first node yet, we still have an node offset table to read
            if (reader.BaseStream.Position != FirstNodeOffset)
            {
                NodeOffsetTableSize = reader.ReadUInt32();
                for (int i = 0; i < NodeOffsetTableSize; i++)
                {
                    NodeOffsetTable.Add(reader.ReadUInt32());
                }
            }

            //Read first node and as an result create the whole node tree structure
            reader.BaseStream.Seek(Offset + FirstNodeOffset, SeekOrigin.Begin);
            RootNode = new MT7Node(reader, null);


            //Search for optional extra sections until EOF
            while (reader.BaseStream.Position < reader.BaseStream.Length - 4)
            {
                uint identifier = reader.ReadUInt32();
                if (FACE.IsValid(identifier))
                {
                    reader.BaseStream.Seek(-4, SeekOrigin.Current);
                    FACE = new FACE(reader);
                }
                else if (CLSG.IsValid(identifier))
                {
                    reader.BaseStream.Seek(-4, SeekOrigin.Current);
                    CLSG = new CLSG(reader);
                }
                else if (TXT7.IsValid(identifier))
                {
                    reader.BaseStream.Seek(-4, SeekOrigin.Current);
                    TXT7 = new TXT7(reader);
                }
            }

            //Filling the texture entries with the actual textures
            if (TXT7 != null)
            {
                foreach (TextureEntry entry in TextureEntries)
                {
                    entry.Texture = TXT7.GetTexture(entry.TextureID);
                }
            }

            if (SearchTexturesOneDirUp)
            {
                FileStream fileStream = (FileStream)reader.BaseStream;
                string     dir        = Path.GetDirectoryName(Path.GetDirectoryName(fileStream.Name));
                TextureDatabase.SearchDirectory(dir);
            }

            if (MT7.UseTextureDatabase)
            {
                foreach (TextureEntry entry in TextureEntries)
                {
                    if (entry.Texture != null)
                    {
                        continue;
                    }

                    TEXN texture = TextureDatabase.FindTexture(entry.TextureID.Data);
                    if (texture == null)
                    {
                        Console.WriteLine("Couldn't find texture: {0}", entry.TextureID.Name);
                        continue;
                    }
                    entry.Texture           = new Texture();
                    entry.Texture.TextureID = new TextureID(texture.TextureID);
                    entry.Texture.Image     = texture.Texture;
                }
            }


            //Populate base class textures
            foreach (TextureEntry entry in TextureEntries)
            {
                if (entry.Texture == null)
                {
                    entry.Texture           = new Texture();
                    entry.Texture.TextureID = entry.TextureID;
                }
                Textures.Add(entry.Texture);
            }

            //Resolve the textures in the faces
            RootNode.ResolveFaceTextures(Textures);
        }