public static TextureAtlas Create(params FreeType.Glyph[] glyphs) { var builder = new TextureAtlasBuilder(); foreach (var glyph in glyphs) { builder.AddImage(new ImageHandle(glyph)); } return(builder.Create()); }
public static TextureAtlas Create(Dictionary <uint, Bitmap> images) { var builder = new TextureAtlasBuilder(); foreach (var image in images) { builder.AddImage(new ImageHandle(image.Key, image.Value)); } return(builder.Create()); }
private void LoadTextures() { Console.WriteLine("[Client] Loading textures..."); using (var builder = new TextureAtlasBuilder <GLTexture>(textureFactory)) { var files = Directory.GetFiles("./Textures/Blocks"); foreach (var file in files) { var name = Path.GetFileNameWithoutExtension(file); builder.AddImage(name, new Bitmap(file)); } blockTextureAtlas = builder.Build(); } Console.WriteLine("[Client] Loaded textures"); }
protected override void OnBeforeInitalizers(object sender, EventArgs e) { var assets = _resource.GetAssets().Where(asset => asset.Type == AssetType.Texture && asset.NamedIdentifier.Name.StartsWith("block/") && asset.NamedIdentifier.Name.EndsWith(".png")); var textureBuilder = new TextureAtlasBuilder(); var i = 0; foreach (var asset in assets) { using var stream = asset.OpenRead(); Logger.GetLogger <MainWindow>().Info(asset.NamedIdentifier.FullName); var bImg = new Image(stream); var isSingle = bImg.FrameCount == 1; var q = 0; foreach (var image in bImg) { textureBuilder.Add(isSingle ? asset.NamedIdentifier.FullName : $"{asset.NamedIdentifier.FullName}{{{q}}}", image); i++; q++; if (i == 4096) { break; } } if (i == 4096) { break; } } _atlases = textureBuilder.Build(); GL.ClearColor(Color4.CornflowerBlue); GL.Enable(EnableCap.DepthTest); GL.LineWidth(2F); base.OnBeforeInitalizers(sender, e); }
protected override void OnContainerInitalized(object sender, EventArgs e) { var assets = _resource.GetAssets().Where(asset => asset.Type == AssetType.Texture && (asset.NamedIdentifier.Name.StartsWith("block/") //|| asset.NamedIdentifier.Name.StartsWith("font/") ) && asset.NamedIdentifier.Name.EndsWith(".png")); _textureBuilder = new TextureAtlasBuilder(); var i = 0; foreach (var asset in assets) { using var stream = asset.OpenRead(); Logger.GetLogger <MainWindow>().Info(asset.NamedIdentifier.FullName); var bImg = new Image(stream); _textureBuilder.Add(asset.NamedIdentifier.FullName, bImg); //var isSingle = bImg.FrameCount == 1; //var q = 0; //foreach (var image in bImg) //{ // _textureBuilder.Add(isSingle ? asset.NamedIdentifier.FullName : $"{asset.NamedIdentifier.FullName}{{{q}}}", image); // i++; // q++; // if (i == 4096) // break; //} if (i == 4096) { break; } } base.OnContainerStarted(sender, e); }
/// <summary> /// Performs a fully standalone in-place location layout. /// This method is used only by editor layouts, not by streaming world. /// </summary> private void LayoutLocation(ref DFLocation location) { #if SHOW_LAYOUT_TIMES // Start timing System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); long startTime = stopwatch.ElapsedMilliseconds; #endif // Get city dimensions int width = location.Exterior.ExteriorData.Width; int height = location.Exterior.ExteriorData.Height; // Create billboard batch game objects for this location TextureAtlasBuilder miscBillboardAtlas = null; summary.NatureBillboardBatch = null; DaggerfallBillboardBatch lightsBillboardBatch = null; DaggerfallBillboardBatch animalsBillboardBatch = null; DaggerfallBillboardBatch miscBillboardBatch = null; if (dfUnity.Option_BatchBillboards) { miscBillboardAtlas = dfUnity.MaterialReader.MiscBillboardAtlas; int natureArchive = ClimateSwaps.GetNatureArchive(CurrentNatureSet, CurrentSeason); summary.NatureBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(natureArchive, transform); lightsBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(TextureReader.LightsTextureArchive, transform); animalsBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(TextureReader.AnimalsTextureArchive, transform); miscBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(miscBillboardAtlas.AtlasMaterial, transform); } // Import blocks for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (dfUnity.Option_BatchBillboards) { // Set block origin for billboard batches // This causes next additions to be offset by this position Vector3 blockOrigin = new Vector3((x * RMBLayout.RMBSide), 0, (y * RMBLayout.RMBSide)); summary.NatureBillboardBatch.BlockOrigin = blockOrigin; lightsBillboardBatch.BlockOrigin = blockOrigin; animalsBillboardBatch.BlockOrigin = blockOrigin; miscBillboardBatch.BlockOrigin = blockOrigin; } string blockName = dfUnity.ContentReader.BlockFileReader.CheckName(dfUnity.ContentReader.MapFileReader.GetRmbBlockName(ref location, x, y)); GameObject go = GameObjectHelper.CreateRMBBlockGameObject( blockName, x, y, dfUnity.Option_RMBGroundPlane, dfUnity.Option_CityBlockPrefab, summary.NatureBillboardBatch, lightsBillboardBatch, animalsBillboardBatch, miscBillboardAtlas, miscBillboardBatch, CurrentNatureSet, CurrentSeason); go.transform.parent = this.transform; go.transform.position = new Vector3((x * RMBLayout.RMBSide), 0, (y * RMBLayout.RMBSide)); } } // Apply batches if (summary.NatureBillboardBatch) { summary.NatureBillboardBatch.Apply(); } if (lightsBillboardBatch) { lightsBillboardBatch.Apply(); } if (animalsBillboardBatch) { animalsBillboardBatch.Apply(); } if (miscBillboardBatch) { miscBillboardBatch.Apply(); } // Enumerate start marker game objects EnumerateStartMarkers(); #if SHOW_LAYOUT_TIMES // Show timer long totalTime = stopwatch.ElapsedMilliseconds - startTime; DaggerfallUnity.LogMessage(string.Format("Time to layout location: {0}ms", totalTime), true); #endif }
private IEnumerator UpdateLocation(int index, bool allowYield) { int key = TerrainHelper.MakeTerrainKey(terrainArray[index].mapPixelX, terrainArray[index].mapPixelY); int playerKey = TerrainHelper.MakeTerrainKey(MapPixelX, MapPixelY); bool isPlayerTerrain = (key == playerKey); if (terrainArray[index].active && terrainArray[index].hasLocation && terrainArray[index].updateLocation) { // Disable update flag terrainArray[index].updateLocation = false; // Create location object DFLocation location; GameObject locationObject = CreateLocationGameObject(index, out location); if (locationObject) { // Add location object to dictionary LocationDesc locationDesc = new LocationDesc(); locationDesc.locationObject = locationObject; locationDesc.mapPixelX = terrainArray[index].mapPixelX; locationDesc.mapPixelY = terrainArray[index].mapPixelY; locationList.Add(locationDesc); // Create billboard batch game objects for this location // Streaming world always batches for performance, regardless of options int natureArchive = ClimateSwaps.GetNatureArchive(LocalPlayerGPS.ClimateSettings.NatureSet, dfUnity.WorldTime.Now.SeasonValue); TextureAtlasBuilder miscBillboardAtlas = dfUnity.MaterialReader.MiscBillboardAtlas; DaggerfallBillboardBatch natureBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(natureArchive, locationObject.transform); DaggerfallBillboardBatch lightsBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(TextureReader.LightsTextureArchive, locationObject.transform); DaggerfallBillboardBatch animalsBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(TextureReader.AnimalsTextureArchive, locationObject.transform); DaggerfallBillboardBatch miscBillboardBatch = GameObjectHelper.CreateBillboardBatchGameObject(miscBillboardAtlas.AtlasMaterial, locationObject.transform); // Set hide flags natureBillboardBatch.hideFlags = HideFlags.HideAndDontSave; lightsBillboardBatch.hideFlags = HideFlags.HideAndDontSave; animalsBillboardBatch.hideFlags = HideFlags.HideAndDontSave; miscBillboardBatch.hideFlags = HideFlags.HideAndDontSave; // RMB blocks are laid out in centre of terrain to align with ground int width = location.Exterior.ExteriorData.Width; int height = location.Exterior.ExteriorData.Height; float offsetX = ((8 * RMBLayout.RMBSide) - (width * RMBLayout.RMBSide)) / 2; float offsetZ = ((8 * RMBLayout.RMBSide) - (height * RMBLayout.RMBSide)) / 2; Vector3 origin = new Vector3(offsetX, 2.0f * MeshReader.GlobalScale, offsetZ); // Get location data DaggerfallLocation dfLocation = locationObject.GetComponent <DaggerfallLocation>(); // Perform layout and yield after each block is placed for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Set block origin for billboard batches // This causes next additions to be offset by this position Vector3 blockOrigin = origin + new Vector3((x * RMBLayout.RMBSide), 0, (y * RMBLayout.RMBSide)); natureBillboardBatch.BlockOrigin = blockOrigin; lightsBillboardBatch.BlockOrigin = blockOrigin; animalsBillboardBatch.BlockOrigin = blockOrigin; miscBillboardBatch.BlockOrigin = blockOrigin; // Add block and yield string blockName = dfUnity.ContentReader.BlockFileReader.CheckName(dfUnity.ContentReader.MapFileReader.GetRmbBlockName(ref location, x, y)); GameObject go = GameObjectHelper.CreateRMBBlockGameObject( blockName, false, dfUnity.Option_CityBlockPrefab, natureBillboardBatch, lightsBillboardBatch, animalsBillboardBatch, miscBillboardAtlas, miscBillboardBatch); go.hideFlags = HideFlags.HideAndDontSave; go.transform.parent = locationObject.transform; go.transform.localPosition = blockOrigin; dfLocation.ApplyClimateSettings(); if (allowYield) { yield return(new WaitForEndOfFrame()); } } } // If this is the player terrain we may need to reposition player if (isPlayerTerrain && repositionPlayer) { // Position to location and use start marker for large cities bool useStartMarker = (dfLocation.Summary.LocationType == DFRegion.LocationTypes.TownCity); PositionPlayerToLocation(MapPixelX, MapPixelY, dfLocation, origin, width, height, useStartMarker); repositionPlayer = false; } // Apply billboard batches natureBillboardBatch.Apply(); lightsBillboardBatch.Apply(); animalsBillboardBatch.Apply(); miscBillboardBatch.Apply(); } } else if (terrainArray[index].active) { if (playerKey == key && repositionPlayer) { PositionPlayerToTerrain(MapPixelX, MapPixelY, Vector3.zero); repositionPlayer = false; } } }