private void ResetTexturePreview() { if (resourceSelect.Selected == -1) { texturePreview.Texture = null; return; } var res = resourceSelect.GetItemText(resourceSelect.Selected); if (res == "") { texturePreview.Texture = null; return; } var baseTex = getTexture(res); if (subrectW.Value < 1 || subrectH.Value < 1) { texturePreview.Texture = baseTex; } else { var tex = new AtlasTexture() { Atlas = baseTex, Region = new Rect2((int)subrectX.Value, (int)subrectY.Value, (int)subrectW.Value, (int)subrectH.Value), }; texturePreview.Texture = tex; } }
public void Dispose() { if (AtlasTexture != null) { AtlasTexture.Dispose(); } }
protected override void LoadContent() { ClientDataRegistry.Settings = ClientSettings.GetSettings(); //Parses content data from file named "content.json" _contentManager.ParseContent(ClientDataRegistry.Settings.DevelopmentMode); //Global texture load Texture2D defaultTexture = new Texture2D(_graphicsDeviceManager.GraphicsDevice, 1, 1); defaultTexture.SetData(new[] { Color.White }); _contentManager.AddTexture("default", defaultTexture); AtlasTexture defaultAtlas = new AtlasTexture { Height = 1, Width = 1, Scale = 1, Texture = defaultTexture, TextureKey = "default", X = 0, Y = 0 }; _contentManager.AddAtlasTexture("default", defaultAtlas); //start first scene _sceneManager.StartScene(nameof(MainMenuScene)); }
void Awake() { int numImage = 1000; textures_BackGrounds = new Texture2D[numImage]; string[] imageNames = new string[] { "BgMenu", "BgCreditos", "BgApresentacao", "BgInstrucoes", "BgTransitFase1", "BgTransitFase2", "BgTransitFase3", "BgLogo", "BgDerrota", }; for (int i = 0; i < imageNames.Length; i++) { textures_BackGrounds[i] = (Texture2D)Resources.Load("Textures/BackGrounds/" + imageNames[i].ToString()); } globalTexture_BackGrounds = AtlasTexture.Create(this.textures_BackGrounds, out rects_BackGrounds); globalMaterial_BackGrounds = new Material((Shader)Resources.Load("Shader/Basic2D")); globalMaterial_BackGrounds.mainTexture = globalTexture_BackGrounds; }
private void fillAnimationInternal(Texture image_texture, string animation_name) { int pos = 0; if (image_texture.GetHeight() < info.tile_height) { info.tile_height = image_texture.GetHeight(); } if (image_texture.GetWidth() < info.tile_width) { info.tile_width = image_texture.GetWidth(); } for (int i = 0; i < image_texture.GetHeight() / info.tile_height; i++) { for (int j = 0; j < image_texture.GetWidth() / info.tile_width; j++) { var tile = new AtlasTexture(); tile.Atlas = image_texture; tile.Region = new Rect2(j * info.tile_width, i * info.tile_height, info.tile_width, info.tile_height); sprite.Frames.AddFrame(animation_name, tile, pos++); if (info.anim_to != -1 && pos > info.anim_to) { return; } } } }
public void Read(AssetReader reader) { m_patches = reader.ReadAssetArray <DetailPatch>(); m_detailPrototypes = reader.ReadAssetArray <DetailPrototype>(); PatchCount = reader.ReadInt32(); PatchSamples = reader.ReadInt32(); m_randomRotations = reader.ReadAssetArray <Vector3f>(); if (IsReadAtlasTexture(reader.Version)) { AtlasTexture.Read(reader); } WavingGrassTint.Read(reader); WavingGrassStrength = reader.ReadSingle(); WavingGrassAmount = reader.ReadSingle(); WavingGrassSpeed = reader.ReadSingle(); if (IsReadDetailBillboardShader(reader.Version)) { DetailBillboardShader.Read(reader); DetailMeshLitShader.Read(reader); DetailMeshGrassShader.Read(reader); } m_treeInstances = reader.ReadAssetArray <TreeInstance>(); m_treePrototypes = reader.ReadAssetArray <TreePrototype>(); if (IsReadPreloadTextureAtlasData(reader.Version)) { m_preloadTextureAtlasData = reader.ReadAssetArray <PPtr <Texture2D> >(); } }
public YAMLNode ExportYAML(IExportContainer container) { YAMLMappingNode node = new YAMLMappingNode(); node.AddSerializedVersion(ToSerializedVersion(container.ExportVersion)); node.Add(PatchesName, Patches.ExportYAML(container)); node.Add(DetailPrototypesName, DetailPrototypes.ExportYAML(container)); node.Add(PatchCountName, PatchCount); node.Add(PatchSamplesName, PatchSamples); node.Add(RandomRotationsName, RandomRotations.ExportYAML(container)); if (HasAtlasTexture(container.ExportVersion)) { node.Add(AtlasTextureName, AtlasTexture.ExportYAML(container)); } node.Add(WavingGrassTintName, WavingGrassTint.ExportYAML(container)); node.Add(WavingGrassStrengthName, WavingGrassStrength); node.Add(WavingGrassAmountName, WavingGrassAmount); node.Add(WavingGrassSpeedName, WavingGrassSpeed); if (HasDetailBillboardShader(container.ExportVersion)) { node.Add(DetailBillboardShaderName, DetailBillboardShader.ExportYAML(container)); node.Add(DetailMeshLitShaderName, DetailMeshLitShader.ExportYAML(container)); node.Add(DetailMeshGrassShaderName, DetailMeshGrassShader.ExportYAML(container)); } TreeDatabase.ExportYAML(container, node); if (!HasAtlasTexture(container.ExportVersion)) { node.Add(PreloadTextureAtlasDataName, PreloadTextureAtlasData.ExportYAML(container)); } return(node); }
void Awake() { int numImage = 1000; textures_Animation = new Texture2D[numImage]; string[] imageNames = new string[] { "1", "2", "3", "4", "5", "6", "7", }; for (int i = 0; i < imageNames.Length; i++) { textures_Animation[i] = (Texture2D)Resources.Load("Textures/Animation/" + imageNames[i].ToString()); } globalTexture_Animation = AtlasTexture.Create(this.textures_Animation, out rects_Animation); globalMaterial_Animation = new Material((Shader)Resources.Load("Shader/Basic2D")); globalMaterial_Animation.mainTexture = globalTexture_Animation; }
public void Read(AssetReader reader) { Patches = reader.ReadAssetArray <DetailPatch>(); DetailPrototypes = reader.ReadAssetArray <DetailPrototype>(); PatchCount = reader.ReadInt32(); PatchSamples = reader.ReadInt32(); RandomRotations = reader.ReadAssetArray <Vector3f>(); if (HasAtlasTexture(reader.Version)) { AtlasTexture.Read(reader); } WavingGrassTint.Read(reader); WavingGrassStrength = reader.ReadSingle(); WavingGrassAmount = reader.ReadSingle(); WavingGrassSpeed = reader.ReadSingle(); if (HasDetailBillboardShader(reader.Version)) { DetailBillboardShader.Read(reader); DetailMeshLitShader.Read(reader); DetailMeshGrassShader.Read(reader); } TreeDatabase.Read(reader); if (!HasAtlasTexture(reader.Version)) { PreloadTextureAtlasData = reader.ReadAssetArray <PPtr <Texture2D> >(); } }
public void Write(AssetWriter writer) { Patches.Write(writer); DetailPrototypes.Write(writer); writer.Write(PatchCount); writer.Write(PatchSamples); RandomRotations.Write(writer); if (HasAtlasTexture(writer.Version)) { AtlasTexture.Write(writer); } WavingGrassTint.Write(writer); writer.Write(WavingGrassStrength); writer.Write(WavingGrassAmount); writer.Write(WavingGrassSpeed); if (HasDetailBillboardShader(writer.Version)) { DetailBillboardShader.Write(writer); DetailMeshLitShader.Write(writer); DetailMeshGrassShader.Write(writer); } TreeDatabase.Write(writer); if (!HasAtlasTexture(writer.Version)) { PreloadTextureAtlasData.Write(writer); } }
protected override void _OnUpdateDisplay() // 2 { var bone = _slotData.parent; var position = new Vector2(bone.transform.x, bone.transform.y); _slotNode = _rawDisplay as Sprite; if (_slotNode == null) { return; } _textureData = _textureData ?? _currentTextureAtlasData.GetTexture(_slotNode.Name); AtlasTexture atlas = new AtlasTexture(); atlas.Atlas = (_textureData as GodotTextureData)?.Texture; var region = new Rect2(_textureData.region.x, _textureData.region.y, _textureData.region.width, _textureData.region.height); atlas.Region = region; atlas.FilterClip = true; atlas.Flags = 0; // todo: hardcode _slotNode.Texture = atlas; //(_textureData as GodotTextureData)?.Texture; _slotNode.Position = position; }
private async void LoadEnemy(string enemyDataName) { var data = Autoload.Get <Data>(); if (!data.enemyData.ContainsKey(enemyDataName)) { GD.PushError($"Enemy data for {enemyDataName} not found"); return; } enemyName = enemyDataName; Stat = data.enemyData[enemyDataName]; moveSpeed = data.GetLerpedSpeedStat(Stat.MoveSpeed, MIN_SPEED, MAX_SPEED); battleTexture = new AtlasTexture { Atlas = GD.Load <Texture>(string.Format(BattleSpritePath, enemyDataName.ToLower())) }; if (sprite == null || stateMachine == null) { await ToSignal(this, "ready"); } sprite.Texture = GD.Load <Texture>(string.Format(OverworldSpritePath, enemyDataName.ToLower())); stateMachine.behaviour = GD.Load <AI_Behaviour>(string.Format(AIResourcePath, Stat.AiType.ToLower())); EmitSignal(nameof(StatsLoaded)); }
void Awake() { int numImage = 1000; textures_Buttons = new Texture2D[numImage]; string[] imageNames = new string[] { "BtJogar1", "BtJogar2", "BtCreditos1", "BtCreditos2", "BtVoltar1", "BtVoltar2", "BtInstrucoes1", "BtInstrucoes2", "BtTentarNovamente", }; for (int i = 0; i < imageNames.Length; i++) { textures_Buttons[i] = (Texture2D)Resources.Load("Textures/Buttons/" + imageNames[i].ToString()); } globalTexture_Buttons = AtlasTexture.Create(this.textures_Buttons, out rects_Buttons); globalMaterial_Buttons = new Material((Shader)Resources.Load("Shader/Basic2D")); globalMaterial_Buttons.mainTexture = globalTexture_Buttons; }
public IEnumerable <Object> FetchDependencies(ISerializedFile file, bool isLog = false) { foreach (DetailPrototype prototype in DetailPrototypes) { foreach (Object @object in prototype.FetchDependencies(file, isLog)) { yield return(@object); } } if (IsReadAtlasTexture(file.Version)) { yield return(AtlasTexture.FetchDependency(file, isLog, () => nameof(DetailDatabase), "m_AtlasTexture")); } foreach (TreePrototype prototype in TreePrototypes) { foreach (Object @object in prototype.FetchDependencies(file, isLog)) { yield return(@object); } } foreach (PPtr <Texture2D> preloadTexture in PreloadTextureAtlasData) { yield return(preloadTexture.FetchDependency(file, isLog, () => nameof(DetailDatabase), "m_PreloadTextureAtlasData")); } }
public void Load(BinaryReader binaryReader) { Elevation = binaryReader.ReadByte(); baseTexture = (AtlasTexture)binaryReader.ReadByte(); topTexture = (AtlasTexture)binaryReader.ReadByte(); topType = (TopType)binaryReader.ReadByte(); topDirection = (Direction)binaryReader.ReadByte(); }
/// <summary> /// Set the Texture that the Graphic is using (if it is using one.) /// </summary> /// <param name="atlasTexture">The AtlasTexture to use.</param> public void SetTexture(AtlasTexture atlasTexture) { Texture = atlasTexture.Texture; AtlasRegion = atlasTexture.Region; TextureRegion.Width = atlasTexture.Width; TextureRegion.Height = atlasTexture.Height; NeedsUpdate = true; }
public override void Draw(SpriteBatch graphics, BFBContentManager content) { InventorySlot slot = ClientDataRegistry.GetInstance()?.Client?.Meta?.MouseSlot; if (slot == null) { return; } AtlasTexture atlas = content.GetAtlasTexture(slot.TextureKey); int maxHeight = RootUI.RenderAttributes.Height / 10; int scale = maxHeight / atlas.Height; int w = atlas.Width * scale; int h = atlas.Height * scale; int x = (int)Mouse.X - w / 2; int y = (int)Mouse.Y - h / 2; graphics.DrawAtlas( atlas, new Rectangle( x, y, w, h ), Color.White); if (slot.ItemType == ItemType.Wall) { graphics.DrawAtlas( atlas, new Rectangle( x, y, w, h ), new Color(0, 0, 0, 0.4f)); } SpriteFont font = content.GetFont("default"); (float width, float height) = font.MeasureString(slot.Count.ToString()) * 0.6f; graphics.DrawString( font, slot.Count.ToString(), new Vector2(Mouse.X - width + 3, Mouse.Y - height + 3), Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 1); }
public void SetBaseTexture(AtlasTexture atlasTexture) { selectedSideTexture = atlasTexture; UVData uvData = customTerrain.GetUVDataFor(selectedSideTexture); float width = uvData.uMax - uvData.uMin; float height = uvData.vMax - uvData.vMin; sideTextureRawImage.uvRect = new Rect(uvData.uMin, uvData.vMin, width, height); }
void AddQuadTexture(AtlasTexture atlasTexture) { UVData uvData = GetUVDataFor(atlasTexture); uvs.Add(new Vector2(uvData.uMin, uvData.vMin)); uvs.Add(new Vector2(uvData.uMin, uvData.vMax)); uvs.Add(new Vector2(uvData.uMax, uvData.vMax)); uvs.Add(new Vector2(uvData.uMax, uvData.vMin)); }
public void OnFinalize(AtlasConfiguration configuration) { var texture = new AtlasTexture(configuration.AtlasTextureSize.ToTextureSize(), configuration.AtlasTextureSize.ToTextureSize()); texture.Create(configuration.Textures, configuration.TextureDivision); texture.SaveAsAsset($"{configuration.DestPath}.png"); var materials = new List <AtlasMaterial>(); foreach (var(material, idx) in configuration.NewMaterials.Select((w, i) => (w, i))) { var mat = texture.CreateMaterial(material); mat.SaveAsAsset($"{configuration.DestPath}_{idx}.mat"); materials.Add(mat); } var meshes = new Dictionary <string, AtlasMesh>(); var counter = 0; foreach (var renderer in configuration.Renderers) { var mesh = new AtlasMesh(renderer, configuration.IsUseMaterialKey); if (meshes.ContainsKey(mesh.CalcMaterialKey())) { var m = meshes[mesh.CalcMaterialKey()]; m.ApplyTo(renderer); renderer.sharedMaterials = Enumerable.Range(0, m.Channels).Select(w => materials[w]).Select(w => w.Actual).ToArray(); continue; } mesh.WriteNewUVs(0, texture); var reduceTo = 0; foreach (var group in configuration.MeshLayouts.GroupBy(w => w.Channel)) { var materialSlots = mesh.GetChannels(group.ToList()); if (group.Key >= mesh.Channels) { continue; } mesh.CombineChannels(group.Key, materialSlots); reduceTo++; } mesh.ReduceSubMeshTo(reduceTo); mesh.SaveAsAsset($"{configuration.DestPath}_{counter++}.asset"); mesh.Apply(); meshes.Add(mesh.CalcMaterialKey(), mesh); renderer.sharedMaterials = Enumerable.Range(0, reduceTo).Select(w => materials[w]).Select(w => w.Actual).ToArray(); } PrefabUtility.SaveAsPrefabAsset(configuration.GameObject, $"{configuration.DestPath}.prefab"); Object.DestroyImmediate(configuration.Workspace); }
public ItemGraphicsComponent(AtlasTexture atlas) { _atlasTexture = atlas; _rotationStep = 0.01f; _yOffset = 0; _lifeTime = 0; _offsetScale = 5; _rotation = 0; }
/// <summary> Returns UVData(uMin, uMax, vMin, vMax) </summary> /// <param name="atlasTexture"></param> /// <returns></returns> public UVData GetUVDataFor(AtlasTexture atlasTexture) { Vector2 textureCoordinates = GetCoordinatesOfAtlasTexture(atlasTexture); float uMin = portionOfAtlas * textureCoordinates.x; // + textureReadOffset; float uMax = portionOfAtlas * (textureCoordinates.x + 1); // - textureReadOffset; float vMin = portionOfAtlas * textureCoordinates.y; // + textureReadOffset; float vMax = portionOfAtlas * (textureCoordinates.y + 1); // - textureReadOffset; return(new UVData(uMin, uMax, vMin, vMax)); }
public bool IsTransparentPixel(int x, int y) { var size = (Size)(AtlasUVRect.Size * (Vector2)AtlasTexture.SurfaceSize); if (x < 0 || y < 0 || x >= size.Width || y >= size.Height) { return(false); } var offset = (IntVector2)(AtlasUVRect.A * (Vector2)AtlasTexture.SurfaceSize); return(AtlasTexture.IsTransparentPixel(x + offset.X, y + offset.Y)); }
void AddTriangle(Vector3 v0, Vector3 v1, Vector3 v2, AtlasTexture atlasTexture, RelativeDirection rightAngle) { int vertexIndex = vertices.Count; vertices.Add(v0); vertices.Add(v1); vertices.Add(v2); triangles.Add(vertexIndex); triangles.Add(vertexIndex + 1); triangles.Add(vertexIndex + 2); AddTriangleTexture(atlasTexture, rightAngle); }
public TextureAtlasData LoadTextureAtlasData(string pathToJsonAtlas, string name, float scale = 1.0f) { if (pathToJsonAtlas == null) { return(null); } if (name == null) { return(null); } var content = Helper.GetTextContentByPath(pathToJsonAtlas); if (content == null) { return(null); } var jsonData = Json.Deserialize(content) as Dictionary <string, object>; var data = ParseTextureAtlasData(jsonData, null, name, scale); if (data == null) { return(null); } data.imagePath = Helper.GetPathToImageTexture(pathToJsonAtlas, data.imagePath); // "my_texture.png" => "path/to/jsonAtlas/my_texture.png" var atlasTexture = new AtlasTexture(); var textureFromPath = Helper.LoadTexture(data.imagePath); foreach (var texture in data.textures.ToList()) // set texture foreach textureData in TextureAtlasData { var key = texture.Key; var textureData = texture.Value as GodotTextureData; if (textureData == null) { continue; } textureData.Texture = textureFromPath; data.textures[key] = textureData; } atlasTexture.Atlas = textureFromPath; return(data); }
Vector2 GetCoordinatesOfAtlasTexture(AtlasTexture atlasTexture) { int atlasTextureIndex = (int)atlasTexture; if (atlasTextureIndex == 0) { return(Vector2.zero); } else { int x = atlasTextureIndex / 10; int y = atlasTextureIndex % 10; return(new Vector2(x, y)); } }
public static void DrawAtlas(this SpriteBatch graphics, AtlasTexture atlasTexture, Rectangle dimensions, Color color, float rotation = 0, Vector2?origin = null) { graphics.Draw(atlasTexture.Texture, dimensions, new Rectangle( atlasTexture.X, atlasTexture.Y, atlasTexture.Width - 2, atlasTexture.Height - 2), color, rotation, origin ?? Vector2.Zero, SpriteEffects.None, 1); }
private bool DrawImageButton(RectangleF rect, AtlasTexture texture, float imageMargin = 0, Color?color = null) { var result = DrawButtonBase(rect); if (imageMargin != 0) { rect.X += imageMargin; rect.Y += imageMargin; rect.Width -= imageMargin * 2; rect.Height -= imageMargin * 2; } Graphics.DrawImage(texture, rect, color ?? Color.White); return(result); }
public bool UpdateCharacter() { var tex = new AtlasTexture { Atlas = GD.Load <Texture>(string.Format(OverworldSpriteSheetPath, characterName.Replace(" ", "_").ToLower())) }; if (tex.Atlas == null) { return(false); } tex.Region = new Rect2(0, 0, 8, 12); characterButton.TextureNormal = tex; return(true); }
void AddTriangleTexture(AtlasTexture atlasTexture, RelativeDirection rightAngle) { UVData uvData = GetUVDataFor(atlasTexture); if (rightAngle == RelativeDirection.LL) { uvs.Add(new Vector2(uvData.uMin, uvData.vMin)); uvs.Add(new Vector2(uvData.uMin, uvData.vMax)); uvs.Add(new Vector2(uvData.uMax, uvData.vMin)); } else if (rightAngle == RelativeDirection.LR) { uvs.Add(new Vector2(uvData.uMin, uvData.vMin)); uvs.Add(new Vector2(uvData.uMax, uvData.vMax)); uvs.Add(new Vector2(uvData.uMax, uvData.vMin)); } }
/// <summary> /// Create a new Tilemap using an AtlasTexture. /// </summary> /// <param name="texture">The AtlasTexture to use.</param> /// <param name="width">The width of the Tilemap in pixels.</param> /// <param name="height">The height of the Tilemap in pixels.</param> /// <param name="tileWidth">The width of each tile in pixels.</param> /// <param name="tileHeight">The height of each tile in pixels.</param> public Tilemap(AtlasTexture texture, int width, int height, int tileWidth, int tileHeight) { SetTexture(texture); Initialize(width, height, tileWidth, tileHeight); }
/// <summary> /// Create a new Decals object using an AtlasTexture. /// </summary> /// <param name="texture"></param> public Decals(AtlasTexture texture) { SetTexture(texture); Initialize(); }
/// <summary> /// Create a new ImageSet from an AtlasTexture. /// </summary> /// <param name="texture">The AtlasTexture to use for the image sheet.</param> /// <param name="width">The width of each cell on the image sheet.</param> /// <param name="height">The height of each cell on the image sheet.</param> public ImageSet(AtlasTexture texture, int width, int height) : base(texture) { Initialize(width, height); }
/// <summary> /// Create a new set of Vertices using an AtlasTexture. /// </summary> /// <param name="texture">The AtlasTexture to use.</param> /// <param name="vertices">The Verts to use.</param> public Vertices(AtlasTexture texture, params Vert[] vertices) : this(vertices) { SetTexture(texture); Initialize(vertices); }
/// <summary> /// Create a new Particle. /// </summary> /// <param name="x">The x position.</param> /// <param name="y">The y position.</param> /// <param name="texture"></param> /// <param name="width"></param> /// <param name="height"></param> public Particle(float x, float y, AtlasTexture texture, int width = 0, int height = 0) : base(x, y) { Image = new ImageSet(texture, width, height); }
/// <summary> /// Create a new NineSlice with an AtlasTexture. /// </summary> /// <param name="texture">The AtlasTexture to use.</param> /// <param name="width">The width of the NineSlice panel.</param> /// <param name="height">The height of the NineSlice panel.</param> /// <param name="fillRect">The rectangle to determine the stretched areas.</param> public NineSlice(AtlasTexture texture, int width, int height, Rectangle? fillRect = null) : base() { SetTexture(texture); Initialize(texture.Name + ".png", width, height, fillRect); }
/// <summary> /// Creates a new Image using an AtlasTexture. /// </summary> /// <param name="texture">The AtlasTexture to use.</param> public Image(AtlasTexture texture) : base() { SetTexture(texture); Initialize(); }
/// <summary> /// Create a new Tilemap using an AtlasTexture. /// </summary> /// <param name="texture">The AtlasTexture to use.</param> /// <param name="size">The width and height of the Tilemap in pixels.</param> /// <param name="tileSize">The width and height of each tile in pixels.</param> public Tilemap(AtlasTexture texture, int size, int tileSize) : this(texture, size, size, tileSize, tileSize) { }