示例#1
0
文件: remOps.cs 项目: kkdevs/sb3u
        public static remMaterial FindMaterial(remMATCsection mats, remId textureId)
        {
            foreach (remMaterial mat in mats)
            {
                if (mat.texture == textureId)
                {
                    return(mat);
                }
            }

            return(null);
        }
示例#2
0
文件: remOps.cs 项目: kkdevs/sb3u
        public static remMaterial FindMaterial(remId materialId, remMATCsection mats)
        {
            foreach (remMaterial mat in mats)
            {
                if (mat.name == materialId)
                {
                    return(mat);
                }
            }

            return(null);
        }
示例#3
0
文件: REMParser.cs 项目: kkdevs/sb3u
        public remParser(Stream stream)
        {
            try
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    string[] sectionNames = { "MATC", "BONC", "MESC", "SKIC" };
                    for (int sectionIdx = 0; sectionIdx < sectionNames.Length; sectionIdx++)
                    {
                        string sectionName = Encoding.ASCII.GetString(binaryReader.ReadBytes(4));
                        if (sectionName.Length < 4)
                        {
                            throw new Exception("file incomplete");
                        }
                        if (sectionName != sectionNames[sectionIdx])
                        {
                            Report.ReportLog("Strange section or order for " + sectionName);
                        }
                        int    sectionLength  = binaryReader.ReadInt32();
                        int    numSubSections = binaryReader.ReadInt32();
                        byte[] sectionBuffer  = binaryReader.ReadBytes((int)sectionLength);
                        switch (sectionIdx)
                        {
                        case 0: this.MATC = ReadMaterials(sectionName, sectionLength, numSubSections, sectionBuffer); break;

                        case 1: this.BONC = ReadBones(sectionName, sectionLength, numSubSections, sectionBuffer); break;

                        case 2: this.MESC = ReadMeshes(sectionName, sectionLength, numSubSections, sectionBuffer); break;

                        case 3: this.SKIC = ReadSkin(sectionName, sectionLength, numSubSections, sectionBuffer); break;
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Report.ReportLog("file not found");
            }
        }
示例#4
0
文件: REMParser.cs 项目: kkdevs/sb3u
        private static remMATCsection ReadMaterials(string sectionName, int sectionLength, int numMaterials, byte[] sectionBuffer)
        {
            remMATCsection matSec    = new remMATCsection(numMaterials);
            int            secBufIdx = 0;

            for (int subSection = 0; subSection < numMaterials; subSection++)
            {
                byte[] type = new byte[4] {
                    sectionBuffer[secBufIdx + 0], sectionBuffer[secBufIdx + 1], sectionBuffer[secBufIdx + 2], sectionBuffer[secBufIdx + 3]
                };
                int length = BitConverter.ToInt32(sectionBuffer, secBufIdx + 4);

                remMaterial mat = new remMaterial();
                Trace.Assert(TypeCheck(remMaterial.ClassType, type));
                mat.name = GetIdentifier(sectionBuffer, secBufIdx + 8);

                for (int i = 0; i < mat.properties.Length; i++)
                {
                    mat[i] = BitConverter.ToSingle(sectionBuffer, secBufIdx + 8 + 256 + i * 4);
                }
                mat.specularPower = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 12 * 4);
                mat.unk_or_flag   = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 12 * 4 + 4);
                mat.unknown       = GetIdentifier(sectionBuffer, secBufIdx + 8 + 256 + 12 * 4 + 4 + 4);

                if (length >= 0x240 + 256)
                {
                    mat.texture = GetIdentifier(sectionBuffer, secBufIdx + 0x240);
                }

                matSec.AddChild(mat);

                secBufIdx += length;
            }
            if (secBufIdx != sectionLength)
            {
                Report.ReportLog("Warning! MATC section has wrong length.");
            }
            return(matSec);
        }