Genete, et al.
Thanks for the script! Have no idea when I would need it as I just use anime studio for comic book work (kindof static images, ya know?
)
I've only owned the software a bit over a week, but like it better than anything else - very impressive stuff!
Anyway, I did modify the script a bit to fix the memory leak that was occuring and changed a couple of the "for" loops to ensure the fastest possible interpretation. I think what I've added could be used in most all of the scripts I've seen to help with those niggling and intemittent memory leaks/speed issues.
Code: Select all
--Embed this script into all the vector layers that want to copy poses from frames 1,2,3,4, ..., maxposes
--it must be under a bone type layer and the following ROOT named bones MUST exists:
-- posek (with k form 1 to maxposes)
-- bonelesector
-- Copyright 2008 Genete
-- Released for free.
-- Thanks to Selgin for that great idea.
-- It can be extended for other animated values (curvatures, widths, shape fill colors, shape outline color, etc.)
-- Also weights w[k] can be overweigthed by the pose bone legth. It would allow some sort of variable action weights...
-- Under development...
-- Modififed June 5th, 2008:
-- Tim Fischer: Added local variables to speed up looping (interpreted languages recalculate every iteration so a variable can be much faster)
-- Added garbage collection routine to free memory (Auto GC doesn't appear to work). This fixes hanging, etc
poses = {}
maxposes = 4
bone = {}
boneselector = nil
function LayerScript(moho)
local w = {}
local distance
local posk
local pos_selector
local r
local length
local k
local layer = moho.layer
local frame = moho.frame
local skel = moho:ParentSkeleton()
if (skel == nil) then
print ("No parent skeleton found in layer:".. layer:Name())
return
end
local mesh = moho:Mesh()
if (mesh==nil) then
print ("No mesh found in layer:".. layer:Name())
return
end
if (frame <=maxposes) then
-----------------------------------look for the bones
for k=1, maxposes do
bone[k] = nil
local fc1 = skel:CountBones()-1 -- added to speed up loops
for i=0, fc1 do
local bonei = skel:Bone(i)
local bonek = "pose" .. tostring(k)
if (bonei:Name() == bonek) then
bone[k]=bonei
elseif (bonei:Name() == "boneselector") then
boneselector=bonei
end
end
if (bone[k] == nil) then
print("bone "..k.." is missing")
return
end
end
if boneselector == nil then
print("boneselector is missing")
return
end
collectgarbage()
---------------------------------
--------------------------------- creates a new array for the layer
poses[layer]={}
poses[layer]["points"]={}
local fc2 = mesh:CountPoints()-1 -- added to speed up loops
for k=1, maxposes do
poses[layer]["points"][k]={}
for i=0, fc2 do
poses[layer]["points"][k][i]=mesh:Point(i).fAnimPos:GetValue(k) --store all the points/pose/positions
end
end
collectgarbage()
return
end
pos_selector = boneselector.fPos --position of the selector bone.
length = boneselector.fLength*boneselector.fAnimScale:GetValue(moho.frame) --current length of the boneselector
for k=1, maxposes do
w[k]=0
posk = bone[k].fPos
distance = posk - pos_selector
r = distance:Mag()
w[k]=weight(r, length)
end
local wtot=0.0 --total weight
for k=1, maxposes do
wtot =wtot +w[k]
end
if (wtot == 0.0) then return end
local fc3=mesh:CountPoints()-1 -- added to speed up loops
for i=0, fc3 do --- move the points.
local pi=mesh:Point(i)
local pimoved =LM.Vector2:new_local()
pimoved:Set(0,0)
for k=1, maxposes do
pimoved = pimoved + poses[layer]["points"][k][i]*w[k]/wtot
end
pi.fPos:Set(pimoved)
end
collectgarbage ()
end
function weight (r, l)
if (r <= l) then
local w =r/l-1
--print(w)
return w
else
return 0.0
end
end
Thanks again!