/// <summary> /// Adds RMB scenery flats to block node. /// </summary> /// <param name="block">DFBlock</param> /// <param name="blockNode">BlockNode.</param> /// <param name="sceneryArchive">Scenery texture archive index.</param> private void AddRMBSceneryFlats(ref DFBlock block, BlockNode blockNode, int sceneryArchive) { // Flags TextureManager.TextureCreateFlags flags = TextureManager.TextureCreateFlags.Dilate | TextureManager.TextureCreateFlags.PreMultiplyAlpha; if (Core.GraphicsProfile == GraphicsProfile.HiDef) { flags |= TextureManager.TextureCreateFlags.MipMaps; } // Add block scenery for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x++) { // Get scenery item DFBlock.RmbGroundScenery scenery = block.RmbBlock.FldHeader.GroundData.GroundScenery[x, y]; // Ignore 0 as this appears to be a marker/waypoint of some kind if (scenery.TextureRecord > 0) { // Load flat int textureKey; Vector2 startSize; Vector2 finalSize; if (true == LoadDaggerfallFlat( sceneryArchive, scenery.TextureRecord, flags, out textureKey, out startSize, out finalSize)) { // Calcuate position Vector3 position = new Vector3( x * tileSide, (finalSize.Y / 2) - 4, -rmbSide + y * tileSide); // Create billboard node BillboardNode billboardNode = new BillboardNode( BillboardNode.BillboardType.ClimateScenery, textureKey, finalSize); billboardNode.Position = position; blockNode.Add(billboardNode); } } } } }
/// <summary> /// Adds miscellaneous RMB flats to block node. /// </summary> /// <param name="block">DFBlock</param> /// <param name="blockNode">BlockNode.</param> private void AddRMBMiscFlats(ref DFBlock block, BlockNode blockNode) { // Iterate through all misc flat records foreach (DFBlock.RmbBlockFlatObjectRecord obj in block.RmbBlock.MiscFlatObjectRecords) { // Get flat type BillboardNode.BillboardType billboardType = GetFlatType(obj.TextureArchive); // Flags TextureManager.TextureCreateFlags flags = TextureManager.TextureCreateFlags.Dilate | TextureManager.TextureCreateFlags.PreMultiplyAlpha; if (Core.GraphicsProfile == GraphicsProfile.HiDef) { flags |= TextureManager.TextureCreateFlags.MipMaps; } // Load flat int textureKey; Vector2 startSize; Vector2 finalSize; if (true == LoadDaggerfallFlat( obj.TextureArchive, obj.TextureRecord, flags, out textureKey, out startSize, out finalSize)) { // Calcuate position Vector3 position = new Vector3( obj.XPos, -obj.YPos + (finalSize.Y / 2) - 4, -rmbSide + -obj.ZPos); // Create billboard node BillboardNode billboardNode = new BillboardNode( billboardType, textureKey, finalSize); billboardNode.Position = position; blockNode.Add(billboardNode); // Add point light node if (billboardType == BillboardNode.BillboardType.Light) { AddPointLight(position, PointLightNode.ExteriorRadius, blockNode); } } } }
/// <summary> /// Loads a Daggerfall flat (billboard). /// </summary> /// <param name="textureArchive">Texture archive index.</param> /// <param name="textureRecord">Texture record index.</param> /// <param name="textureFlags">Texture create flags.</param> /// <param name="textureKey">Texture key.</param> /// <param name="startSize">Start size before scaling.</param> /// <param name="finalSize">Final size after scaling.</param> /// <returns>True if successful.</returns> private bool LoadDaggerfallFlat( int textureArchive, int textureRecord, TextureManager.TextureCreateFlags textureFlags, out int textureKey, out Vector2 startSize, out Vector2 finalSize) { try { // Get path to texture file string path = Path.Combine( textureManager.Arena2Path, TextureFile.IndexToFileName(textureArchive)); // Get size and scale of this texture System.Drawing.Size size = TextureFile.QuickSize(path, textureRecord); System.Drawing.Size scale = TextureFile.QuickScale(path, textureRecord); // Set start size startSize.X = size.Width; startSize.Y = size.Height; // Apply scale int xChange = (int)(size.Width * (scale.Width / scaleDivisor)); int yChange = (int)(size.Height * (scale.Height / scaleDivisor)); finalSize.X = size.Width + xChange; finalSize.Y = size.Height + yChange; // Load texture textureKey = textureManager.LoadTexture( textureArchive, textureRecord, textureFlags); } catch (Exception e) { Console.WriteLine(e.Message); textureKey = -1; startSize.X = 0; startSize.Y = 0; finalSize.X = 0; finalSize.Y = 0; return(false); } return(true); }
/// <summary> /// Loads a Daggerfall model and any textures required. /// Will use whatever climate is currently set in texture manager. /// </summary> /// <param name="id">ID of model.</param> /// <param name="model">ModelManager.ModelData.</param> /// <returns>True if successful.</returns> private bool LoadDaggerfallModel(uint id, out ModelManager.ModelData model) { try { // Load model and textures model = modelManager.GetModelData(id); for (int i = 0; i < model.SubMeshes.Length; i++) { // Set flags TextureManager.TextureCreateFlags flags = TextureManager.TextureCreateFlags.ApplyClimate | TextureManager.TextureCreateFlags.MipMaps | TextureManager.TextureCreateFlags.PowerOfTwo; // Set HiDef flags if (Core.GraphicsProfile == GraphicsProfile.HiDef) { flags |= TextureManager.TextureCreateFlags.ExtendedAlpha; } // Load texture model.SubMeshes[i].TextureKey = textureManager.LoadTexture( model.DFMesh.SubMeshes[i].TextureArchive, model.DFMesh.SubMeshes[i].TextureRecord, flags); } } catch (Exception e) { Console.WriteLine(e.Message); model = null; return(false); } return(true); }