Skip to content

Instantly share code, notes, and snippets.

@iamevn
Created November 20, 2015 20:40
Show Gist options
  • Save iamevn/0902601561c7edcb096c to your computer and use it in GitHub Desktop.
Save iamevn/0902601561c7edcb096c to your computer and use it in GitHub Desktop.
script_name="Clip Transform Points"
script_description="first and last lines selected should have clips with the same number of points. transforms each point's position from first to last line over the selected lines (WARNING: wipes out any clip on intermediate lines"
script_author="iamevn"
script_version="0.1"
script_namespace="evn.ClipTransformPoints"
function transform(subs, sel)
--[[
so here's the plan:
A - acceleration (default 1)
N - number of lines selected
]]--
A = 1.0
S = 1
N = #sel
inverseClip = string.match(subs[sel[S]].text, "\\iclip%(.-%)") ~= nil
initialClip = string.match(subs[sel[S]].text, "\\i?clip%((.-)%)")
initialTable = {}
for s in string.gmatch(initialClip, "%S+") do
table.insert(initialTable, s)
end
finalClip = string.match(subs[sel[N]].text, "\\i?clip%((.-)%)")
finalTable = {}
for s in string.gmatch(finalClip, "%S+") do
table.insert(finalTable, s)
end
for index, line_idx in ipairs(sel) do
progress = (index - S) / (N - S)
progress = math.pow(progress, A)
lineTable = {}
for key, s in ipairs(initialTable) do
if tonumber(s) == nil then
table.insert(lineTable, s)
else
IVAL = initialTable[key]
FVAL = finalTable[key]
value = (1 - progress) * IVAL + progress * FVAL
table.insert(lineTable, value)
end
end
body = ""
for i, s in ipairs(lineTable) do
if #body == 0 then
body = body .. s
else
body = body .. " " .. s
end
end
line = subs[line_idx]
line.text = string.gsub(line.text, "\\i?clip%(.-%)", "")
if inverseClip then
line.text = string.gsub(line.text, "}", "\\iclip(" .. body .. ")}")
else
line.text = string.gsub(line.text, "}", "\\clip(" .. body .. ")}")
end
subs[line_idx] = line
end
end
--[[
validates that the first and last lines have "matching" clips
(matching in the sense that they have the same number of points
and the same sorts of lines in the same places)
]]--
function validate(subs, sel)
if #sel < 3 then
return false
end
initialClip = string.match(subs[sel[1]].text, "\\i?clip%((.-)%)")
finalClip = string.match(subs[sel[#sel]].text, "\\i?clip%((.-)%)")
if initialClip == nil or finalClip == nil then
return false
end
initialTable = {}
for s in string.gmatch(initialClip, "%S+") do
table.insert(initialTable, s)
end
finalTable = {}
for s in string.gmatch(finalClip, "%S+") do
table.insert(finalTable, s)
end
if #initialTable ~= #finalTable then
return false
end
for i = 1, #initialTable do
a = initialTable[i]
b = finalTable[i]
if tonumber(a) == nil and tonumber(b) == nil then
if a ~= b then
return false
end
elseif tonumber(a) ~= nil and tonumber(b) ~= nil then
--everything's good
else
return false
end
end
return true
end
aegisub.register_macro(script_name, script_description, transform, validate)
@iamevn
Copy link
Author

iamevn commented Nov 20, 2015

  • select a bunch of lines (first and last need to have clips that have the same number of control points of the same types)
  • run script
  • lines now have clip interpolated across them

(I should probably have it split the line(s) into frame by frame things but you can do that with other scripts just fine already.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment