Example #1
0
        public static MaterialTexture Read(Reader reader)
        {
            MapLoader.Loader.print("reading material texture");
            MaterialTexture mt = new MaterialTexture();

            mt.textureFilteringMode = reader.ReadByte();
            mt.textureFiltering     = (FilterMode)mt.textureFilteringMode;
            mt.addressingMode       = reader.ReadByte();
            mt.wrapModeU            = (AddressingMode)(mt.addressingMode & 0x0F);
            mt.wrapModeV            = (AddressingMode)((mt.addressingMode & 0xF0) << 4);
            mt.useMipLevels         = (reader.ReadUInt16() & 0x1) != 0;
            return(mt);
        }
Example #2
0
        private VisualMaterial ConvertMaterialSection(Section s)
        {
            VisualMaterial vm = new VisualMaterial(null);
            Material       m  = (Material)s[0]["material"];

            vm.ambientCoef  = m.color * m.ambient;
            vm.diffuseCoef  = new Color(m.diffuse, m.diffuse, m.diffuse);
            vm.specularCoef = new Color(m.specular, m.specular, m.specular);
            vm.num_textures = 1;
            if (m.isTextured)
            {
                MaterialTexture       mt        = (MaterialTexture)s[1][0]["texture"];
                byte[]                texName   = s[1][1].data;
                byte[]                alphaName = s[1][2].data;
                VisualMaterialTexture vmt       = new VisualMaterialTexture();

                /*foreach (TextureDictionary txd in txds) {
                 *      Texture2D tex = txd.Lookup(texName, TextureDictionary.Type.Texture);
                 *      if (tex != null) {
                 *              vmt.texture = new TextureInfo(null) {
                 *                      width = (ushort)tex.width,
                 *                      height = (ushort)tex.height,
                 *                      Texture = tex
                 *              };
                 *              break;
                 *      }
                 * }*/
                vm.textures.Add(vmt);
            }
            else
            {
                vm.textures.Add(new VisualMaterialTexture()
                {
                    texture = new TextureInfo(null)
                    {
                        width   = 1,
                        height  = 1,
                        Texture = Util.CreateDummyTexture()
                    }
                });
            }

            return(vm);
        }
Example #3
0
        public static Section Read(Reader reader, SectionRead specialRead = null)
        {
            MapLoader l       = MapLoader.Loader;
            Type      type    = (Type)reader.ReadUInt32();
            uint      size    = reader.ReadUInt32();
            uint      version = reader.ReadUInt32();
            Section   sec     = new Section(type, size, version);

            if (specialRead != null)
            {
                specialRead(sec);
            }
            switch (sec.type)
            {
            case Type.String:
                sec.data      = reader.ReadBytes((int)size);
                sec["string"] = System.Text.Encoding.UTF8.GetString(sec.data).TrimEnd('\0');
                break;

            case Type.TextureDictionary:
                ushort numTextures = 0;
                sec.ReadChild(reader, (s) => {
                    numTextures      = reader.ReadUInt16();
                    s["numTextures"] = numTextures;
                    s["unk"]         = reader.ReadUInt16();
                });                         // Info Struct
                for (uint i = 0; i < numTextures; i++)
                {
                    sec.ReadChild(reader);                     // TextureNative
                }
                sec.ReadChild(reader);                         // Extension
                break;

            case Type.TextureNative:
                sec.ReadChild(reader, (s) => {
                    s["platform"]       = reader.ReadUInt32();
                    s["filterMode"]     = reader.ReadByte();
                    s["addressingMode"] = reader.ReadByte();
                    reader.ReadUInt16();    // padding
                });                         // Info Struct
                sec.ReadChild(reader);      // Texture name
                sec.ReadChild(reader);      // Alpha name
                sec.ReadChild(reader, (st) => {
                    st.ReadChild(reader, (s) => {
                        s["width"]        = reader.ReadUInt32();
                        s["height"]       = reader.ReadUInt32();
                        s["bpp"]          = reader.ReadUInt32();
                        s["rasterFormat"] = reader.ReadUInt32();
                        reader.ReadUInt32();                                 // PS2 TEX0 GS register
                        reader.ReadUInt32();                                 // PS2 TEX0 GS register
                        reader.ReadUInt32();                                 // PS2 TEX1 GS register
                        reader.ReadUInt32();                                 // PS2 TEX1 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP1 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP1 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP2 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP2 GS register
                        s["textureDataSize"]    = reader.ReadUInt32();
                        s["paletteDataSize"]    = reader.ReadUInt32();
                        s["gpuDataAlignedSize"] = reader.ReadUInt32();
                        s["skyMipmapVal"]       = reader.ReadUInt32();
                    });                     // Texture - info struct
                    st.ReadChild(reader);   // Texture - data
                });                         // Texture
                sec.ReadChild(reader, (se) => {
                    se.ReadChild(reader);   // Extension - sky mipmap val - 4 bytes unknown
                });                         // Extension
                break;

            case Type.Clump:
                uint numAtomics = 0;
                sec.ReadChild(reader, (s) => {
                    numAtomics      = reader.ReadUInt32();
                    s["numAtomics"] = numAtomics;
                });                         // Info Struct
                sec.ReadChild(reader);      // Frame list
                sec.ReadChild(reader);      // Geometry list
                for (int i = 0; i < numAtomics; i++)
                {
                    sec.ReadChild(reader);
                }
                sec.ReadChild(reader);                         // Extension
                //l.print("Clump size: " + reader.BaseStream.Position);
                break;

            case Type.FrameList:
                uint numFrames = 0;
                sec.ReadChild(reader, (s) => {
                    numFrames      = reader.ReadUInt32();
                    s["numFrames"] = numFrames;
                    Frame[] frames = new Frame[numFrames];
                    for (int i = 0; i < numFrames; i++)
                    {
                        frames[i]        = new Frame();
                        frames[i].matrix = Matrix.ReadRenderware(reader);
                        frames[i].index  = reader.ReadInt32();
                        frames[i].flags  = reader.ReadUInt32();
                    }
                    s["frames"] = frames;
                });                         // Info Struct
                for (int i = 0; i < numFrames; i++)
                {
                    sec.ReadChild(reader);                             // Extension
                }
                break;

            case Type.GeometryList:
                uint numMeshes = 0;
                sec.ReadChild(reader, (s) => {
                    numMeshes      = reader.ReadUInt32();
                    s["numMeshes"] = numMeshes;
                });                         // Info Struct
                for (int i = 0; i < numMeshes; i++)
                {
                    sec.ReadChild(reader);                             // Geometry
                }
                break;

            case Type.Geometry:
                sec.ReadChild(reader, (s) => {
                    s["geometry"] = Geometry.Read(reader);
                });                         // Info Struct
                sec.ReadChild(reader);      // Material list
                sec.ReadChild(reader, (s) => {
                    if (s.size > 0)
                    {
                        s.ReadChild(reader); // Bin Mesh
                    }
                });                          // Extension
                break;

            case Type.MaterialList:
                uint numMaterials       = 0;
                uint numUniqueMaterials = 0;
                sec.ReadChild(reader, (s) => {
                    numMaterials          = reader.ReadUInt32();
                    int[] materialIndices = new int[numMaterials];
                    for (int i = 0; i < numMaterials; i++)
                    {
                        materialIndices[i] = reader.ReadInt32();
                        if (materialIndices[i] == -1)
                        {
                            numUniqueMaterials++;
                        }
                    }
                    s["numMaterials"]       = numMaterials;
                    s["numUniqueMaterials"] = numUniqueMaterials;
                    s["materialIndices"]    = materialIndices;
                });                         // Info struct
                for (int i = 0; i < numUniqueMaterials; i++)
                {
                    sec.ReadChild(reader);                             // Material
                }
                break;

            case Type.Material:
                bool isTextured = false;
                sec.ReadChild(reader, (s) => {
                    Material mat  = Material.Read(reader);
                    s["material"] = mat;
                    isTextured    = mat.isTextured;
                });                         // Material struct
                if (isTextured)
                {
                    sec.ReadChild(reader);
                }
                sec.ReadChild(reader);                         // Extension
                if (sec.children.Last().data != null && sec.children.Last().data.Length > 0)
                {
                    l.print("Check material extension ending at " + reader.BaseStream.Position + "!");
                }
                break;

            case Type.Texture:
                sec.ReadChild(reader, (s) => {
                    s["texture"] = MaterialTexture.Read(reader);
                });                         // Info struct
                sec.ReadChild(reader);      // Texture name
                sec.ReadChild(reader);      // Alpha name
                sec.ReadChild(reader);      // Extension
                if (sec.children.Last().data != null && sec.children.Last().data.Length > 0)
                {
                    l.print("Check texturematerial extension ending at " + reader.BaseStream.Position + "!");
                }
                break;

            case Type.BinMeshPlg:
                sec["binMesh"] = BinMesh.Read(reader);
                break;

            case Type.Atomic:
                sec.ReadChild(reader, (s) => {
                    s["frameIndex"]    = reader.ReadUInt32();
                    s["geometryIndex"] = reader.ReadUInt32();
                    s["flags"]         = reader.ReadUInt32();
                    s["unused"]        = reader.ReadUInt32();
                });                         // Struct
                sec.ReadChild(reader);      // Extension
                break;

            default:
                if (specialRead == null)
                {
                    sec.data = reader.ReadBytes((int)size);
                }
                break;
            }

            return(sec);
        }