From e6180da35c347120b7fb9eada4ae947341082f52 Mon Sep 17 00:00:00 2001 From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Sat, 5 Apr 2025 15:51:59 +0300 Subject: [PATCH] Displacement Map Visualizer update (#35952) Update Displacement Map Visualizer.lua --- .../Displacement Map Visualizer.lua | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Tools/SS14 Aseprite Plugins/Displacement Map Visualizer.lua b/Tools/SS14 Aseprite Plugins/Displacement Map Visualizer.lua index 468636c07d..49824acbed 100644 --- a/Tools/SS14 Aseprite Plugins/Displacement Map Visualizer.lua +++ b/Tools/SS14 Aseprite Plugins/Displacement Map Visualizer.lua @@ -73,6 +73,33 @@ local findLayer = function(sprite, name) return nil end +local applyOffset = function(dx, dy) + local cel = app.cel + local image = cel.image:clone() + local sprite = app.editor.sprite + local selection = sprite.selection + + for x = selection.bounds.x, selection.bounds.x + selection.bounds.width - 1 do + for y = selection.bounds.y, selection.bounds.y + selection.bounds.height - 1 do + local xImg = x - cel.position.x + local yImg = y - cel.position.y + if xImg >= 0 and xImg < image.width and yImg >= 0 and yImg < image.height then + local pixelValue = image:getPixel(xImg, yImg) + local color = Color(pixelValue) + + -- Offset R and G channel + color.red = math.min(255, math.max(0, color.red + dx)) + color.green = math.min(255, math.max(0, color.green + dy)) + + image:drawPixel(xImg, yImg, app.pixelColor.rgba(color.red, color.green, color.blue, color.alpha)) + end + end + end + + cel.image = image + dialog:repaint() +end + dialog = Dialog{ title = "Displacement map preview", onclose = function(ev) @@ -160,7 +187,7 @@ dialog:combobox{ dialog:slider{ id = "size", label = "displacement size", - min = 1, + min = 127, --We dont support non 127 atm max = 127, value = 127, onchange = function(ev) @@ -168,4 +195,36 @@ dialog:slider{ end } +dialog:button{ + id = "moveDown", + text = "Down", + onclick = function(ev) + applyOffset(0, -1) + end +} + +dialog:button{ + id = "moveUp", + text = "Up", + onclick = function(ev) + applyOffset(0, 1) + end +} + +dialog:button{ + id = "moveLeft", + text = "Left", + onclick = function(ev) + applyOffset(1, 0) + end +} + +dialog:button{ + id = "moveRight", + text = "Right", + onclick = function(ev) + applyOffset(-1, 0) + end +} + dialog:show{wait = false} -- 2.51.2