Skip to content

Commit

Permalink
Add option to crop layers to visible region
Browse files Browse the repository at this point in the history
  • Loading branch information
2shady4u authored Aug 2, 2024
2 parents b9b018d + a617dde commit 035ddf9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions demo/addons/godot-krita-importer/krita_import_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var presets : Array[Dictionary] = [
"default_value": CanvasItem.TEXTURE_FILTER_PARENT_NODE,
"property_hint": PROPERTY_HINT_ENUM,
"hint_string": ",".join(range(0, CanvasItem.TEXTURE_FILTER_MAX))
},{
"name": "crop_to_visible",
"default_value": true
},
]

Expand Down Expand Up @@ -126,6 +129,12 @@ static func import_paint_layer(layer_data : Dictionary, options: Dictionary) ->

#create_from_data(width: int, height: int, use_mipmaps: bool, format: Format, data: PoolByteArray)
var image = Image.create_from_data(layer_data.width, layer_data.height, false, layer_data.format, layer_data.data)

if options.get("crop_to_visible", true):
var visible_region = image.get_used_rect()
image = image.get_region(visible_region)
sprite.position += Vector2(visible_region.position)

var texture = ImageTexture.create_from_image(image)

sprite.texture_filter = options.get("texture_filter", CanvasItem.TEXTURE_FILTER_PARENT_NODE)
Expand Down

0 comments on commit 035ddf9

Please sign in to comment.