1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 20:43:14 +00:00
Pixelorama/src/Classes/GroupLayer.gd
Emmanouil Papadeas 91aea32864
Implement 3D layers (#840)
* Implement 3D layers

* Remove unneeded files

* Fix bug where a single hidden layer would ignore all of the layers on top when exporting

* Fix pxo loading

* Remove junk nodes from 3DShapeEdit

Seems like they were created when I copied from the old 3D Options.tscn panel to the new 3D Shape Edit tool.

* Make light gizmos half the size, and hide gizmos when rotating

* Fix crash when using the 3D shape edit tool on a group layer

* Remove unneeded code in Canvas.gd

* Add torus in the Cel3DObject.Type enumerator

Torus isn't currently supported in Godot 3.5, but it is in 3.6 and 4.0, so this is just future-proofing. May break compatibility with .pxo files that were exported with 3D layers before this change.

* Toggle 3D object visibility

* Change texts and some variable names

* Fill translation strings

* Fix crash on group blending, and make the code in Export.blend_layers() more general

* Fix errors when attempting to draw on a 3D cel

Can occur when multiple cels are selected, some of them 3D and some of them pixel

* Make scene properties and objects be per-cel instead of per-layer

Breaks compatibility with previous .pxo files that had 3D layers. Also introduces serialize() and deserialize() methods to BaseCel

* Use if not layer is get_script() in GroupLayer.blend_children()

* Flip the condition in GroupLayer.blend_children()

* Fix bug where locked/invisible layers could get drawn

Regression from c2f6bf0f3f

* Move gizmo code to 3DShapeEdit's draw_start(), move some undo/redo logic to 3DShapeEdit

* Move all of the undo/redo code to 3DShapeEdit, simplify code in Cel3D

* Store Cel3D image data to pxo, for easy usage by external software

This makes importing projects with 3D layers to other software, such as Godot using godot_pixelorama_importer easier.

* Make the linter happy

* Fix bug where the previously selected object would remain selected when it got removed with undo
2023-03-31 21:58:56 +03:00

74 lines
1.9 KiB
GDScript

class_name GroupLayer
extends BaseLayer
# A class for group layer properties
var expanded := true
func _init(_project, _name := "") -> void:
project = _project
name = _name
func blend_children(frame: Frame, origin := Vector2.ZERO) -> Image:
var image := Image.new()
image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
var children := get_children(false)
var blend_rect := Rect2(Vector2.ZERO, project.size)
for layer in children:
if not layer.is_visible_in_hierarchy():
continue
# Checks if layer is GroupLayer, cannot define this due to cyclic reference error
if layer is get_script():
image.blend_rect(layer.blend_children(frame, origin), blend_rect, origin)
else:
var cel: BaseCel = frame.cels[layer.index]
var cel_image := Image.new()
cel_image.copy_from(cel.get_image())
if cel.opacity < 1: # If we have cel transparency
cel_image.lock()
for xx in cel_image.get_size().x:
for yy in cel_image.get_size().y:
var pixel_color := cel_image.get_pixel(xx, yy)
var alpha: float = pixel_color.a * cel.opacity
cel_image.set_pixel(
xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha)
)
cel_image.unlock()
image.blend_rect(cel_image, blend_rect, origin)
return image
# Overridden Methods:
func serialize() -> Dictionary:
var data := .serialize()
data["type"] = get_layer_type()
data["expanded"] = expanded
return data
func deserialize(dict: Dictionary) -> void:
.deserialize(dict)
expanded = dict.expanded
func get_layer_type() -> int:
return Global.LayerTypes.GROUP
func new_empty_cel() -> BaseCel:
return GroupCel.new()
func set_name_to_default(number: int) -> void:
name = tr("Group") + " %s" % number
func accepts_child(_layer: BaseLayer) -> bool:
return true
func instantiate_layer_button() -> Node:
return Global.group_layer_button_node.instance()