Image Sequencer (Bone Controlled)

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
dkwroot
Posts: 680
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Image Sequencer (Bone Controlled)

Post 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
Last edited by dkwroot on Sat Oct 02, 2021 1:46 pm, edited 1 time in total.
dkwroot
Posts: 680
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Re: Image Sequencer (Bone Controlled)

Post 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.
User avatar
negroclarito
Posts: 135
Joined: Sun Feb 28, 2010 6:38 am

Re: Image Sequencer (Bone Controlled)

Post by negroclarito »

I will look forward the next version. :D
User avatar
cartoonmonkey
Posts: 91
Joined: Thu Feb 12, 2009 2:06 pm
Location: Portland, Oregon
Contact:

Re: Image Sequencer (Bone Controlled)

Post by cartoonmonkey »

Thank you for this script! So useful for imported lip sync mouth shapes!
User avatar
dougm
Posts: 1
Joined: Thu Jul 10, 2014 11:27 pm

Re: Image Sequencer (Bone Controlled)

Post 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!
Post Reply