Little Scripting Doubts and Curiosities Site :)

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

Moderators: Víctor Paredes, Belgarath, slowtiger

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

Post by Rai López »

HI! :D Hmmm... If you are looking for some info about how to work with this two usefull setup tools I'd advise you to take a look to the 3.4 "Character Setup" tutorial, there you'll find a lot of interesting info about that, or... are you only reffering when you are ussing bone Offsets in frame 0 and then you select Manipulate Bones tool on that frame? Well, the bones only adopts his final position when you select that Manipulate tool so the answer should be inside Manipulate Bones tool, although curiously I have not found any reference to Offset function inside it... or maybe we are talking about an internal Moho function (as in the Strength/bubbles case); anyway I think don't must be difficult contrarest this offsets to obtain the current position of the bones cause all this bone info is easely accesible and even I've been able to do it, well, working in other frame than zero :)

About the curvature issue... ARGh! :x It's the typical thing that seems SO easy at first... Uf, actually I'm trying to study some of the code added by macton in his INCREDIBLY usefull version of the Curvature tool (you should take a look at it if you have in mind some modification of this tool), it seems like a good place to search & find this kind of answers, although it's a very high level for me and I'm not sure about so much things...

...Well, THANK YOU (as always) for be there! Now I'll continue investigating about all this a little more, CIAO!
Last edited by Rai López on Fri Apr 28, 2006 3:42 am, edited 2 times in total.
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

I tried to make my version of LM_ManipulateBones and it is strange that only the "ScriptName" variable can select how the bones looks like. If it is LM_ManipulateBones or LM_BoneStrength or LM_OffsetBone (and maybe others?) then the bones will have bubbles around and offseted position. It seems it is hardcoded into the Moho software. Unfortunately, the access of the functions goes through the ScriptName, so I cannot make FA_ManipulateBones with ScriptName="LM_ManipulateBones". I think it would be a good compromise for LM if they check only the last characters of the name. Now I write an e-mail them. I planned to add a checkbox to switch between the two modes, but it seems impossible now.
- - - Fazek
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Fazek wrote:I planned to add a checkbox to switch between the two modes, but it seems impossible now.
...EY! It seems to me like a very good idea/solution to maintain compatibility and have as few repeated tools as possible... GOOD LUCK! :)
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

("hello world") :roll: ...Please, somebody can tell me why when I write some operation in a embedded script it is repeated three times instead only one? I mean, if I make the tipical "hello world" exercise it is printed 3 times in the Lua Console window each time and I think that in some cases it can slow things unnecessarly... Do you know if exist a way to avoid this? Some line/s of code to be sure the instruction is ejecuted only one time? THANK YOU VERY MUCH! :)

EDIT: Hmmm, I think I have it... the trick could be an "if ... then" sentence that after be executed must be in-me-dia-te-ly "broken", isn't? Well, at least it seems works now as I expected :) (for now...)
Last edited by Rai López on Sun Apr 30, 2006 3:23 pm, edited 1 time in total.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

...EY! Another thing... I'd want that a Embedded Script only be active when the container layer is currently selected in Layers window, I've find this "fLayer" variable that I think could be the key, but I've not obtaining the expected results adding to the "if ... then" line of code... I've proved almost all the the possibilities (I think) like: "if (moho:fLayer() == true) then", "if (moho:fLayer(moho.layer) == true) then", "if (moho:fLayer() == moho.layer) then" and many others but nothing :( ... any (PLEASE) clue? THANKS!

EDIT1: No results too with: (moho.document:fLayer()) variant... :(
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

Now I see better how the bones are calculated since I created my Reparent Bone tool. My previous samples simulated more-or-less the calculation of the bone's own matrices. So the simplest way to calculate the bone positions is:

Code: Select all

function xDrawAllBones(moho,view)
	local bone,skel

	if (moho.layer:LayerType() == MOHO.LT_BONE) then
		skel= moho:Skeleton()
	else
		skel= moho:ParentSkeleton()
	end

	if (skel == nil) then return end

	local gfx= view:Graphics()
	local vec1= LM.Vector2:new_local()
	local vec2= LM.Vector2:new_local()

	gfx:SetSmoothing(true)
	gfx:SetColor(255,0,0)

	local m= LM.Matrix:new_local()
	moho.layer:GetFullTransform(moho.frame,m,moho.document)
	gfx:Push()
	gfx:ApplyMatrix(m)

	for i= 0,skel:CountBones() - 1 do
		bone= skel:Bone(i)
		vec1:Set(0,0)
		vec2:Set(bone.fLength,0)

		if (moho.frame == 0) then
			bone.fRestMatrix:Transform(vec1)
			bone.fRestMatrix:Transform(vec2)
		else
			bone.fMovedMatrix:Transform(vec1)
			bone.fMovedMatrix:Transform(vec2)
		end

		gfx:DrawLine(vec1.x,vec1.y,vec2.x,vec2.y)
	end

	gfx:Pop()
	gfx:SetSmoothing(false)
	view:Refresh()
end
Pretty nice, isn't it?
- - - Fazek
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

...HELLO!!! Another thing... Somebody would know how could I search into a Layer for a certain named group of points to get any control over them by embedded script? Basically I'd want make some point groups with the different parts of a body calling them something like "Head_Center", "Body_Center", "Eye_Center" or anything to can then get/calculate the center of that named groups like a variable, BTW, for very important reasons... Any clue/help? (PLEEEASE :))
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

You can find an example code how to parse through the layers in this topic:
http://www.lostmarble.com/forum/viewtopic.php?t=4575
- - - Fazek
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Ey! THANK YOU very much Fazek (and HI! :)), it still seemed to me interesting when you posted it but now I'm going to study it, anyway at the first sight it seems like your code is usefull to search layers and I'm treating to search groups of points in the same layer where the Embeded Script is inserted... Well, now I've no time to explain me better, but, right off the bat... Do you think I should use something like this?

Code: Select all

local name = mesh:Group(i):Name()
mesh:SelectGroup(name)
...THANKS AGAIN! :D
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Hmmm... I think I still have asked for this in the past, but... Well, I'm trying to make that a embedded script (or part of it) only be active when certain layer (normaly the same that contain the script) be selected in the Layers Window, for some rason it seems more dificult that it can seem and I'd be very grateful for any clue or help, THANKS!!!
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

Hello, I'm now trying to get someting like "Flexi-Bind Bones" by Layer Scripting, you know, to get the same movement that bones causes over Flexi-Bind Points/Layers but applied to certain bones

After study all the Scripting Reference I have found that "fPtMatrix" in the M_Bone section but I didn't be able to take advantage of it and I don't know if it's really possible calculate the Matrix "dEfoRmaTiOn" caused by bones in any coordenate to can then apply it to the .fPos of certain bones or other objects by Embedded Script.

Well, if that not be possible, maybe the only one solution could be follow my actual line of work, translate the movement of certain Flexi-Bind points (or even Flexi-Bind Layers) in the mesh to the desired bones to became it "Flexi-Binded", it's only that it results like a very desperate/complicated idea and probably difficult/slow to calculate so, well, I'd prefer be totally sure (if possible) that the other easy solution is really not possible...

Hummm... Of course I think this could be very usefull in some situations and specially to get that Super Squishy results that I always have loved so much :) ...THANK YOU if/for any help!!!
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

EY! Please, this is quick, I've been looking for answers in the Lua Manual but it seems that I'm missing something, now I must go and I've thought that it must be SO easy for you that could be better to ask for...

Well, do you know how can I maintain a numerical value betwen two quotation marks in Lua? I mean, in example, if I stablish a local value like this local i = 123 and then I want to apply that value to a SwitchValue (in example), I must write it in this way --> dataLayer:SwitchValues():SetValue(frame, "i"), isn't? So, as i must be between quotation marks for Moho take it into account I'm really introducing the letter i instead his value that is 123

...Hmmm, well I don't know if I've been clear with this issue cause I'm really half asleep... But (if possible) it must be a very basic thing... Anyway it seems to me that I could be missing something (or several somethings :roll:) and in that case I think I'll delete this potencially stupid post when I return... SO LONG!

PS: ...oOoHh! My *fAvOuRiTe* thread :roll:
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Code: Select all

local i = 123
local s = tostring(i)
print (type(s), s)
run this on the command line in Lua and you'll get:

Code: Select all

string  123
This is basic Lua coding, Rámon. Perhaps you should brush up on your Lua. Programming in Lua is a good tutorial.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

I knew, I knew :oops: ...I knew it should be SO basic that someone tell off for that... :roll:

...Well! Now it seems clear (of course, that "tostring" and "tonumber" functions) I was searching in a wrong way, I don't know why, I started thinking in something like double quotation marks, or doble single quotation marks or "/" or another weird combination of all that simbols... what I was "thinking" :roll: ...Well, anyway it works! And now I know another thing about Lua that I won't forget...

...THAAAAANKS FOR YOUR HELP! (and to go deep into my thread :))

PS: BTW, all of this is still related with that "Animating shape stack ordering" aspiration about you are discussing there, so I will write there about it if I get (I hope so!) something interesting... SEE YOU THERE!
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

A little one now... Somebody knows how can I convert a 'LM_Point' object into a LM_Vector2' object? It seems that both can manage the same info (X and Y coordinates in my case) but for some reason I can't use them indistinctively... hmmm... THANK YOU in advance!

EDIT: Well, I have found another solution and it seems that I can live without know how do it, hmmm, for this time at least, let's see in the future...
...
Post Reply