예제 #1
0
        public static BoneMap LoadFromStream(Stream stream)
        {
            if (stream == null)
            {
                return(null);
            }

            BinaryReader binaryReader = new BinaryReader(stream);

            BoneMap boneMap = new BoneMap();

            boneMap.Unknown0    = binaryReader.ReadUInt32();
            boneMap.BoneStart   = binaryReader.ReadUInt32();
            boneMap.BoneCount   = binaryReader.ReadUInt32();
            boneMap.Delta       = binaryReader.ReadUInt32();
            boneMap.Unknown1    = binaryReader.ReadUInt32();
            boneMap.BoneEnd     = binaryReader.ReadUInt32();
            boneMap.VertexCount = binaryReader.ReadUInt32();
            boneMap.Unknown2    = binaryReader.ReadUInt32();
            boneMap.IndexCount  = binaryReader.ReadUInt32();

            return(boneMap);
        }
예제 #2
0
        public bool Deserialize(BinaryStream stream, AssetManager assetManager)
        {
            // Header
            string magic = stream.ReadString(4);

            Assert.AreEqual(MAGIC, magic, "Model File header does not match magic value!");

            Version = stream.ReadUInt32();

            if (!Enum.IsDefined(typeof(ModelType), (int)Version))
            {
                Debug.LogWarning("Could not decode model " + Name + ". Unknown DME version " + Version);
                return(false);
            }

            ModelType = (ModelType)Version;

            ModelHeaderOffset = stream.ReadUInt32();

            // DMA
            Dma.LoadFromStream(stream, TextureStrings, Materials);

            // Bounding Box
            Min = stream.ReadVector3();
            Max = stream.ReadVector3();

            // Meshes
            uint meshCount = stream.ReadUInt32();

            for (int i = 0; i < meshCount; ++i)
            {
                Mesh mesh = Mesh.LoadFromStream(stream, Materials);

                if (mesh == null)
                {
                    continue;
                }

                Material material = Materials[(int)mesh.MaterialIndex];
                foreach (Material.Parameter parameter in material.Parameters)
                {
                    LookupTextures(mesh, parameter, TextureStrings);

                    if (mesh.BaseDiffuse != null && mesh.BumpMap != null && mesh.SpecMap != null)
                    {
                        break;
                    }
                }

                Meshes.Add(mesh);
            }

            // Bone Maps
            uint boneMapCount = stream.ReadUInt32();

            for (int i = 0; i < boneMapCount; ++i)
            {
                BoneMap boneMap = BoneMap.LoadFromStream(stream);

                if (boneMap != null)
                {
                    BoneMaps.Add(boneMap);
                }
            }

            // Bone Map Entries
            uint boneMapEntryCount = stream.ReadUInt32();

            for (int i = 0; i < boneMapEntryCount; ++i)
            {
                BoneMapEntry boneMapEntry = BoneMapEntry.LoadFromStream(stream);

                if (boneMapEntry != null)
                {
                    BoneMapEntries.Add(boneMapEntry);
                }
            }

            return(true);
        }