branch rotated + optimization
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.5 MiB After Width: | Height: | Size: 2.5 MiB |
@@ -11,7 +11,7 @@ region = Rect2(2118, 923, 371, 391)
|
||||
[node name="Sprite" type="Sprite2D" unique_id=1642167049 node_paths=PackedStringArray("root", "attaches")]
|
||||
texture = SubResource("AtlasTexture_yh7e0")
|
||||
script = ExtResource("2_a5yje")
|
||||
part_name = "LeafG2"
|
||||
part_name = "LeafG3"
|
||||
type = 1
|
||||
root = NodePath("Root")
|
||||
attaches = NodePath("Attaches")
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -4,12 +4,14 @@ class_name PlantPart
|
||||
enum PartType {BASE_PART, BRANCH_PART, LEAF_PART, FLOWER_PART}
|
||||
|
||||
@export var texture: Texture
|
||||
@export var image: Image
|
||||
@export var type: PartType
|
||||
@export var root: PlantAttach
|
||||
@export var attaches: Array[PlantAttach] # array of vec2
|
||||
|
||||
func init(textute_arg: Texture, type_arg: PartType, root_arg: PlantAttach, attaches_arg: Array[PlantAttach]) -> void:
|
||||
texture = textute_arg
|
||||
image = texture.get_image()
|
||||
type = type_arg
|
||||
root = root_arg
|
||||
attaches = attaches_arg
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Node
|
||||
|
||||
const IMAGE_WIDTH := 1024
|
||||
const IMAGE_HEIGHT := 2048
|
||||
const IMAGE_HEIGHT := 1048
|
||||
|
||||
const PLACEHOLDER_SEED_TEXTURE: Texture = preload("res://entities/plants/assets/sprites/default/seed.png")
|
||||
const PLACEHOLDER_MATURE_TEXTURE: Texture = preload("res://entities/plants/assets/sprites/default/mature.png")
|
||||
@@ -16,6 +16,8 @@ const PLACEHOLDER_GROWING_TEXTURE: Texture = preload("res://entities/plants/asse
|
||||
@export var parts_mutation_associations: Dictionary[String, PartMutationAssociation]
|
||||
|
||||
var rng := RandomNumberGenerator.new()
|
||||
var image: Image = Image.create_empty(IMAGE_WIDTH, IMAGE_HEIGHT, false, Image.FORMAT_RGBA8)
|
||||
var image_center: Vector2i = Vector2(0.5, 1) * Vector2(image.get_size())
|
||||
|
||||
func random_ind(array: Array) -> int:
|
||||
return rng.randi_range(0, array.size() - 1)
|
||||
@@ -37,9 +39,8 @@ func build_seed_texture(_random_seed: int) -> Texture:
|
||||
func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
rng.seed = plant_data.random_seed
|
||||
|
||||
|
||||
var mature_texture: Texture = PLACEHOLDER_MATURE_TEXTURE
|
||||
var mature_image: Image = Image.create_empty(IMAGE_WIDTH, IMAGE_HEIGHT, false, Image.FORMAT_RGBA8)
|
||||
var mature_image_center: Vector2i = 0.5 * mature_image.get_size()
|
||||
var base_part: PlantPart
|
||||
var base_image_coord: Vector2i
|
||||
var available_attaches: Array[PlantAttach]
|
||||
@@ -56,10 +57,10 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
# var base_part: PlantPart = pick_random(parts_archetype_associations[plant_archetype].bases)
|
||||
base_part = pick_random(bases)
|
||||
|
||||
var base_image = base_part.texture.get_image()
|
||||
var base_image := base_part.image
|
||||
var base_image_center: Vector2i = 0.5 * base_image.get_size()
|
||||
base_image_coord = mature_image_center - Vector2i(base_part.root.position)
|
||||
mature_image.blend_rect(base_image, Rect2i(Vector2i.ZERO, base_image.get_size()), base_image_coord - base_image_center)
|
||||
base_image_coord = image_center - Vector2i(base_part.root.position)
|
||||
image.blend_rect(base_image, Rect2i(Vector2i.ZERO, base_image.get_size()), base_image_coord - base_image_center)
|
||||
|
||||
if branches.size() == 0:
|
||||
printerr("No branches in archetype")
|
||||
@@ -74,7 +75,6 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
for p in association.part_amount:
|
||||
parts_to_place.append(pick_random(mutation_possible_parts))
|
||||
|
||||
|
||||
PlantData.State.GROWING:
|
||||
# print("Build growing texture")
|
||||
# var plant_archetype := plant_data.archetype
|
||||
@@ -84,10 +84,10 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
# var base_part: PlantPart = pick_random(parts_archetype_associations[plant_archetype].baby_bases)
|
||||
base_part = pick_random(baby_bases)
|
||||
|
||||
var base_image = base_part.texture.get_image()
|
||||
var base_image := base_part.image
|
||||
var base_image_center: Vector2i = 0.5 * base_image.get_size()
|
||||
base_image_coord = mature_image_center - Vector2i(base_part.root.position)
|
||||
mature_image.blend_rect(base_image, Rect2i(Vector2i.ZERO, base_image.get_size()), base_image_coord - base_image_center)
|
||||
base_image_coord = image_center - Vector2i(base_part.root.position)
|
||||
image.blend_rect(base_image, Rect2i(Vector2i.ZERO, base_image.get_size()), base_image_coord - base_image_center)
|
||||
|
||||
for m in plant_data.mutations:
|
||||
# print("mutations: ", m.id)
|
||||
@@ -114,16 +114,17 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
|
||||
var parent_image_coord: Vector2i = parent_image_coords.pop_at(ind)
|
||||
|
||||
var part_image: Image = part.texture.get_image()
|
||||
var part_image: Image = part.image
|
||||
var part_image_center: Vector2i = 0.5 * part_image.get_size()
|
||||
var part_image_coord: Vector2i = parent_image_coord + Vector2i(attach.position - part.root.position)
|
||||
mature_image.blend_rect(part_image, Rect2i(Vector2i.ZERO, part.texture.get_size()), part_image_coord - part_image_center)
|
||||
image.blend_rect(part_image, Rect2i(Vector2i.ZERO, part.image.get_size()), part_image_coord - part_image_center)
|
||||
|
||||
for sub_attach in part.attaches:
|
||||
available_attaches.append(sub_attach)
|
||||
parent_image_coords.append(part_image_coord)
|
||||
|
||||
mature_texture = ImageTexture.create_from_image(mature_image)
|
||||
mature_texture = ImageTexture.create_from_image(image)
|
||||
image.fill(Color.TRANSPARENT)
|
||||
return mature_texture
|
||||
|
||||
## returns -1 if not found
|
||||
|
||||
Reference in New Issue
Block a user