Animatable Layer Origin by Layer Script?(In Process..)

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
Rai López
Posts: 2294
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Animatable Layer Origin by Layer Script?(In Process..)

Post by Rai López »

HI! I don't know if you, but I (and at least one more person in this forum) always have wanted can animate Layer Origin cause I (and he/she, I suppose...) think that it could be very useful in a lot of situations that now are SO complicated or requires a lot of (innecesary) work, you know... Well, I've been thinking, yes :) and maybe one of the possible solutions could be an embedded script to link specified named SubLayers Origin to a specific named bone in the Parent Bone Layer... Could be?? I think that this script could be based in the 7feet's "bone_control/master" scripts and luckly the most part of the work could still be done! :D Well, THANKS if somebody consider it and... BYE!
Last edited by Rai López on Sun Mar 05, 2006 8:56 pm, edited 4 times in total.
User avatar
Rai López
Posts: 2294
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Hmmm... More thoughts! What about if simply a bone (possibly root and without Strengh) in a Bone Layer controls his own Layer Origin? Maybe more easy and with only one Embedded Script :) althought only limited to the Origin of the same Bone layer... Well, and about possible strange results in movement, I'm not sure and I think that would need to see it or make some tests to experiment...
Last edited by Rai López on Mon Mar 06, 2006 6:51 pm, edited 1 time in total.
User avatar
Rai López
Posts: 2294
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Hello guys! Well... I almost thought that I'd got it! And after only a few hours of scripting!!! :D But well, finally seems that there is a problem with Origin movement and X/Y/Z rotation interaction... the problem seems occurs after Translation Layer keyframes are wrote, cause the firs time you play the animation all seems right, but the second time (when keys still have been wrote) a weird and unexpected results start to occur... Anyway this is a very first idea and sure it requires more work, but well... I only put it here just in case somebody with scripting powers had any suggestion or advice to can get reliable results meantime I keep on experimenting :) ...Well, here is the 1.0.2 beta version:

Code: Select all

function LayerScript(moho)
	if (moho.frame == 0) then
		return
	end
	local skel = moho:Skeleton()
	if (skel == nil) then
		print("No skeleton found in layer:", moho.layer:Name())
		return
	end
	local matrix = LM.Matrix:new_local()
	local beforeVec = LM.Vector3:new_local()
	local afterVec = LM.Vector3:new_local()
	local origin = LM.Vector2:new_local()
	
	moho.layer:GetFullTransform(moho.frame, matrix, nil)
	matrix:Transform(beforeVec)
	
	moho.layer:GetFullTransform(moho.frame, matrix, moho.document)

	for i = 0, skel:CountBones() - 1 do
		local originBone = skel:Bone(i)
		if (originBone:Name() == "Origin") then
			originBone = originBone.fAnimPos:GetValue(moho.frame)
			moho.layer:SetOrigin(originBone)
		end
	end
	
	moho.layer:GetFullTransform(moho.frame, matrix, nil)
	matrix:Transform(afterVec)
	
	local newLayerPos = moho.layer.fTranslation.value + beforeVec - afterVec
	local v = newLayerPos - moho.layer.fTranslation.value
	if (v:Mag() > 0.000001) then
		moho.layer.fTranslation:SetValue(moho.frame, newLayerPos)
		moho:NewKeyframe(CHANNEL_LAYER_T)
	end
	moho.document:DepthSort()
	skel:UpdateBoneMatrix()
end
Well, if you want to try it, the only thing you have to take into account is have a bone called Origin inside the Bone Layer where script is embedded and nothing more, the Origin of the own bone layer will be traslated with it and so animatable along the time, very useful (if someday it works fine :) ) in many situations, I think... CIAO!
Post Reply