INSTRUCTIONS:
1. Make sure that your image sequences are named with an underscore between the image name and it's numbers. The number of zeros that go in front of your image number doesn't matter, just make sure you have an underscore. Example: Apples_01 , Grapes_00003 , Cherry_2 , Oranges_0000000000000000010
2. When you load in your image, make certain that the bone controller and the image layer are named the same.
DOWNLOAD FILE:
IDEA:
I think one improvement that could be made here is the inclusion of some sort of event listener. I need a listener to watch for one particular bone and update only when that bone is altered.
Question: Is a global variable declared from an embedded script kept around in memory after the layer containing the script is deleted? In other words, how does the program handle garbage collection?
Code: Select all
function LayerScript(moho)
function Exists(filepath)
local f = io.open(filepath, "r")
if( f ~= nil ) then
f:close()
return true;
else
return false;
end
end
local parent_skeleton=moho:ParentSkeleton()
local layer = moho.layer
if (parent_skeleton == nil) then
return
end
--------
if (DR_ImageSequencer == nil) then
DR_ImageSequencer = {}
DR_ImageSequencer.imgLayer = moho:LayerAsImage(layer)
end
local s = DR_ImageSequencer.imgLayer:SourceImage()
local layername = DR_ImageSequencer.imgLayer:Name()
-------- BONE CONTROL
for j=0, parent_skeleton:CountBones()-1 do
local parent_bone=parent_skeleton:Bone(j)
if (parent_bone:Name() == layername) then
local locval = tostring(math.floor(math.deg(parent_bone.fAngle)/20))
if(curVal ~= locval)then
-------- Format String
curVal = locval
revSource = string.reverse(s)
local dotpos, scorepos = string.find(revSource,"%.",1), string.find(revSource,"_",1)
local ftype,fnum,fpath = string.sub(s,-dotpos),string.sub(s,-scorepos+1,-dotpos-1),string.sub(s,1,-scorepos)
for i=1, string.len(fnum)-string.len(tonumber(fnum)) do
curVal = "0" .. curVal
end
local imgpath = fpath .. curVal .. ftype
---- Check for valid filepath and apply image source change
if (Exists(imgpath)) then
DR_ImageSequencer.imgLayer:SetSourceImage(imgpath)
end
end
end
end
end