Displacement Map Visualizer update (#35952)
Update Displacement Map Visualizer.lua
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user