public override bool Load() { using (var strm = FileManager.Instance.Provider.OpenFile(mFileName)) { var reader = new BinaryReader(strm); mHeader = reader.Read <M2Header>(); if ((mHeader.GlobalFlags & 0x08) != 0) { mRemapBlend = true; var nBlendMaps = reader.Read <int>(); var ofsBlendMaps = reader.Read <int>(); strm.Position = ofsBlendMaps; mBlendMap = reader.ReadArray <ushort>(nBlendMaps); } BoundingBox = new BoundingBox(mHeader.BoundingBoxMin, mHeader.BoundingBoxMax); BoundingSphere = new BoundingSphere(Vector3.Zero, mHeader.BoundingRadius); strm.Position = mHeader.OfsName; if (mHeader.LenName > 0) { mModelName = Encoding.ASCII.GetString(reader.ReadBytes(mHeader.LenName - 1)); } GlobalSequences = ReadArrayOf <uint>(reader, mHeader.OfsGlobalSequences, mHeader.NGlobalSequences); Vertices = ReadArrayOf <M2Vertex>(reader, mHeader.OfsVertices, mHeader.NVertices); var textures = ReadArrayOf <M2Texture>(reader, mHeader.OfsTextures, mHeader.NTextures); mTextures = new Graphics.Texture[textures.Length]; for (var i = 0; i < textures.Length; ++i) { var tex = textures[i]; if (tex.type == 0 && tex.lenName > 0) { var texName = Encoding.ASCII.GetString(ReadArrayOf <byte>(reader, tex.ofsName, tex.lenName - 1)).Trim(); mTextures[i] = Scene.Texture.TextureManager.Instance.GetTexture(texName); } else { mTextures[i] = Scene.Texture.TextureManager.Instance.GetTexture("default_texture"); } } LoadSkins(reader); LoadAnimations(reader); } return(true); }
public override bool Load() { using (var strm = FileManager.Instance.Provider.OpenFile(mFileName)) { var reader = new BinaryReader(strm); mHeader = reader.Read <M2Header>(); BoundingRadius = mHeader.VertexRadius; if ((mHeader.GlobalFlags & 0x08) != 0) { mRemapBlend = true; var nBlendMaps = reader.Read <int>(); var ofsBlendMaps = reader.Read <int>(); strm.Position = ofsBlendMaps; mBlendMap = reader.ReadArray <ushort>(nBlendMaps); } BoundingBox = new BoundingBox(mHeader.VertexBoxMin, mHeader.VertexBoxMax); LoadCreatureVariations(); strm.Position = mHeader.OfsName; if (mHeader.LenName > 0) { mModelName = Encoding.ASCII.GetString(reader.ReadBytes(mHeader.LenName - 1)); } GlobalSequences = ReadArrayOf <uint>(reader, mHeader.OfsGlobalSequences, mHeader.NGlobalSequences); Vertices = ReadArrayOf <M2Vertex>(reader, mHeader.OfsVertices, mHeader.NVertices); var textures = ReadArrayOf <M2Texture>(reader, mHeader.OfsTextures, mHeader.NTextures); mTextures = new Graphics.Texture[textures.Length]; TextureInfos = new TextureInfo[textures.Length]; for (var i = 0; i < textures.Length; ++i) { var tex = textures[i]; if (tex.type == 0 && tex.lenName > 0) { var texName = Encoding.ASCII.GetString(ReadArrayOf <byte>(reader, tex.ofsName, tex.lenName - 1)).Trim(); mTextures[i] = Scene.Texture.TextureManager.Instance.GetTexture(texName); } else { switch ((TextureType)tex.type) { case TextureType.MonsterSkin1: if (DisplayOptions.TextureVariationFiles.Count > DisplayOptions.TextureVariation) { if (!string.IsNullOrEmpty(DisplayOptions.TextureVariationFiles[DisplayOptions.TextureVariation].Item1)) { mTextures[i] = Scene.Texture.TextureManager.Instance.GetTexture(DisplayOptions.TextureVariationFiles[DisplayOptions.TextureVariation].Item1); } } break; case TextureType.MonsterSkin2: if (DisplayOptions.TextureVariationFiles.Count > DisplayOptions.TextureVariation) { if (!string.IsNullOrEmpty(DisplayOptions.TextureVariationFiles[DisplayOptions.TextureVariation].Item2)) { mTextures[i] = Scene.Texture.TextureManager.Instance.GetTexture(DisplayOptions.TextureVariationFiles[DisplayOptions.TextureVariation].Item2); } } break; case TextureType.MonsterSkin3: if (DisplayOptions.TextureVariationFiles.Count > DisplayOptions.TextureVariation) { if (!string.IsNullOrEmpty(DisplayOptions.TextureVariationFiles[DisplayOptions.TextureVariation].Item3)) { mTextures[i] = Scene.Texture.TextureManager.Instance.GetTexture(DisplayOptions.TextureVariationFiles[DisplayOptions.TextureVariation].Item3); } } break; default: mTextures[i] = Scene.Texture.TextureManager.Instance.GetTexture("default_texture"); break; } } Graphics.Texture.SamplerFlagType samplerFlags; if (tex.flags == 3) { samplerFlags = Graphics.Texture.SamplerFlagType.WrapBoth; } else if (tex.flags == 2) { samplerFlags = Graphics.Texture.SamplerFlagType.WrapV; } else if (tex.flags == 1) { samplerFlags = Graphics.Texture.SamplerFlagType.WrapU; } else { samplerFlags = Graphics.Texture.SamplerFlagType.ClampBoth; } TextureInfos[i] = new TextureInfo { Texture = mTextures[i], TextureType = (TextureType)tex.type, SamplerFlags = samplerFlags }; } LoadSkins(reader); LoadAnimations(reader); } return(true); }