Page 1 of 1

Image Sequencer (Bone Controlled)

Posted: Sun Jun 22, 2014 6:11 am
by dkwroot
Special Thanks to HeyVern who's awesome idea for an image sequencer inspired this script.



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

Re: Image Sequencer (Bone Controlled)

Posted: Thu Jun 26, 2014 5:45 am
by dkwroot
You know, it just hit me today that this script would work much better as a button. I should have just made two buttons, one that arrows to the right and one to the left. I'd have to find a way to keyframe the change though...

I'll start making the adjustments and update this thread with the next version.

Re: Image Sequencer (Bone Controlled)

Posted: Wed Jul 02, 2014 3:20 am
by negroclarito
I will look forward the next version. :D

Re: Image Sequencer (Bone Controlled)

Posted: Sat Jul 05, 2014 6:30 pm
by cartoonmonkey
Thank you for this script! So useful for imported lip sync mouth shapes!

Re: Image Sequencer (Bone Controlled)

Posted: Thu Jul 10, 2014 5:20 pm
by dougm
wow, great script! Thank you for creating it.

I tried it out and it worked well with one set of images. To get a second set of images to work I had to rename the script and change the code so that every time it said 'DR_ImageSequencer' - I changed it to 'DR_ImageSequencer2' - so the script had a unique name within it. That worked to get two sequences to work at the same time.

This worked in preview mode only - but when I animated the two series, only one of the image series would animate.

Also, when I exported the animation, neither image series animated. I did a test with just one image series and it would not animate either.

So, this could be a great alternative to switch layers...if those bugs were resolved.

Thanks!