protected virtual void ReadModel(ref Model model) { // Starts the whole ModelData by the magiccode "TKMD" // If the serializer don't find the TKMD, It will throw an // exception that will be catched by Load method. BeginChunk(ModelData.MagicCode); // Writes the version int version = Reader.ReadInt32(); if (version != ModelData.Version) { throw new NotSupportedException(string.Format("EffectData version [0x{0:X}] is not supported. Expecting [0x{1:X}]", version, ModelData.Version)); } // Allocated the shared memory used to load this Model AllocateSharedMemory(Reader.ReadInt32()); // Textures / preload embedded textures BeginChunk("TEXS"); int textureCount = Reader.ReadInt32(); for (int i = 0; i < textureCount; i++) { byte[] textureData = null; Serialize(ref textureData); EmbeddedTextures.Add(Texture.Load(GraphicsDevice, new MemoryStream(textureData))); } EndChunk(); // Material section BeginChunk("MATL"); ReadMaterials(ref model.Materials); EndChunk(); // Bones section BeginChunk("BONE"); ReadBones(ref model.Bones); EndChunk(); //// DISABLE_SKINNED_BONES //// Skinned Bones section //BeginChunk("SKIN"); //ReadBones(ref model.SkinnedBones); //EndChunk(); // Mesh section BeginChunk("MESH"); ReadMeshes(ref model.Meshes); EndChunk(); // Serialize attributes ReadProperties(ref model.Properties); // Close TKMD section EndChunk(); }
/// <summary> /// Loads a Cube texture from a stream. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="stream">The stream to load the texture from.</param> /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param> /// <param name="usage">Usage of the resource. Default is <see cref="ResourceUsage.Immutable"/> </param> /// <exception cref="ArgumentException">If the texture is not of type Cube</exception> /// <returns>A texture</returns> public static new TextureCube Load(GraphicsDevice device, Stream stream, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) { var texture = Texture.Load(device, stream, flags | TextureFlags.ShaderResource, usage); if (!(texture is TextureCube)) { throw new ArgumentException(string.Format("Texture is not type of [TextureCube] but [{0}]", texture.GetType().Name)); } return((TextureCube)texture); }