GetSegmentPercentTangent() Simulation?

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: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

GetSegmentPercentTangent() Simulation?

Post by Rai López »

Hello, I'm still a little amazed about the new curve scripting interface functions that have been added to the new AS version cause, preciselly, I was trying to develop a little embedded script to provide a good bone path following solution and, before this functions exists (specially the "GetPercentTangent()" one), get the real-time response for the bones orientation that I wanted was simply impossible...

But as I said, looking into the new API, I discovered all this new encouraging stuff:

CurveLength() --The length of a certain curve.
SegmentLength(i) --The length of a given segment.
GetPercentLocation(0-1) --Given a percentage, returns a location along the ENTIRE curve.
GetPercentTangent(0-1) --Given a percentage, get the orientation over certain point of the ENTIRE curve.
GetSegmentRange(i, ?, ?) --Not totally sure how to use the returned value yet, but sounds interesting...

And well, some of that functions simply changes all :), cause they provide the necessary to get total path following with the real-time bone orientation that I was not able to get before... BUT!

...As always, I have an intricate problem :(, cause I want to get the tangent be not based in the ENTIRE curve percentage but in the each segments percentage (that is how the translation of the bone is deliberately calculated in my tries (instead using the GetPercentLocation())), to can avoid that the path follower bone rotates inadequately when any of the points of the curve is moved (due to the length of the curve changes).

So... well, maybe I'm complicating things too much but all is for a good reason (for my POV), cause the system I propose it seems to me more practical, controllable and dynamical/adjustable (among other things). Well, now the questions:

Do you think could be a mathematical way to give to the "GetPercentTangent()" a segment percentage instead a curve one and can compensate the curve length variations (caused by NOT adjacent points movement during animation) to avoid that unwanted rotations? I mean, now it's possible to get the entire curve length and the segments length, so I'm almost sure that there must be a way to compensate/counteract this behavior that I simply can't see due to limited mathematical skills :(


PS: I'd like be wrong, but as I consider the possibility that nothing could have been understood due to the fatal combination of my english and my "maths", hmmm... I'm thinking if my only hope could be have called the Genete's attention to can treat with him/you? all this issue in plain spanglish, couldría? couldría? :roll:
...
Rudiger
Posts: 786
Joined: Sat Dec 17, 2005 5:25 pm

Post by Rudiger »

Each curve segment in AS is actually a Bezier curve segment, so it should be possible to write any extra function you need that's not included in the API.

Perhaps you could start with a detailed description of what you are trying to do. Is it just to get a bone to follow a path? Can't you do that now in AS7?
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

INCREDIBLE!!! How I've had it all the time just right under my nose! And I was not able to see it, you'll see...

Ah, HI & THANKS for your interest, BTW :) Well, the fact is that for some reason I was insistent in get the necessary tangent info be means of the position of the bone in the previous frame and the next one and, although this method worked, it didn't give me the real-time response during manipulations that I wanted, and believe me if I tell you that I proved all variables that came to my mind...

Of course, this obstinacy on do it in that way, derives from I was looking into the macton's "cc_paste_curve_to_layer_translation" code and he used that method to obtain the rotation, so I should think that was the way... and I was not able to see nothing more :x

Now, I simply substract a "0.001" to the actual PointOnSegment bone position to obtain the previous point and add 0.001 to that point to obtain the next and be able to obtain the necessary tangent that the macton's formula needs to calculate the angle! Ufff... very happy about that cause I think it have save me lots of headaches, like if I have tried to deal with Beziers as you suggested cause, unfortunately, I won't know even how to start :(

Of course, the problems never leave me and now I have another kind of real-time manipulation preoblem, I mean, when I translate a point with the mouse, the bone follows the curve prefectly (:D), but the points attached to that follower bone doesn't reacts until the frame is recalculated (:(), so... as I have been applied only one embedded script over the child vector layer, the natural next step will be modificate the script to can apply it to the parent bone layer instead, and see if this takes some favorable effect in this matter, as I hope... But this will have to wait until tomorrow cause I'm exhausted :P


Again thanks & greetings!
Ramón López.


PS: Ah, what AS7 can do now is make a layer follow a path, but not any other object like, in this case, a bone; of course I still though to attach a bone to a follower layer by scripting, but... it could be a little messy with several bones/layer involved, although... maybe if finally I am not able to solve all that real-time problems... I tried it just for curiosity.
...
Rudiger
Posts: 786
Joined: Sat Dec 17, 2005 5:25 pm

Post by Rudiger »

Only too happy to help. You always make your posts entertaining, even when talking about such mundane technical issues! That's a neat little trick about calculating the tangents by the way.
Ramón López wrote: Of course, the problems never leave me and now I have another kind of real-time manipulation preoblem, I mean, when I translate a point with the mouse, the bone follows the curve prefectly (:D), but the points attached to that follower bone doesn't reacts until the frame is recalculated (:(), so... as I have been applied only one embedded script over the child vector layer, the natural next step will be modificate the script to can apply it to the parent bone layer instead, and see if this takes some favorable effect in this matter, as I hope... But this will have to wait until tomorrow cause I'm exhausted :P
I'm not sure if there is a more correct way to do this, but when all the other Update type methods fail, I sometimes put in a couple of explicit SetCurFrame commands to change to the next frame and then back again at the bottom of the layer script, to force it to update the frame. It might even work without the first SetCurFrame command, if you want it to be a bit faster. I think moving your embedded script to the parent bone layer will be problematic, as there is no easy way to access the mesh of a child vector layer like there is for accessing the skeleton of a parent bone layer.

Good luck with your experiments and hope you share the results with us.
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

Eyyy... THANKS! For the kind/useful words :), ufff... You have made incredible scripts & you seem to have that math knowledges which I couldn't even dream, so... you don't know how happy makes me that you be there and even you like read this kind of non senses that so much times I wonder if won't only worry to me :roll:

Well! I've not had too much time along weekend as I wanted to continue with the idea of transform the script into a bone layer applicable one, but that I've tried and I've not able to make it works is the SetCurFrame() function into the script cause, no matter were I put it, reports a "attempt to call a number value" error and I'm not sure why, cause I remember to have used this function much many other times with no problems... of course I have been placing some the UpdateCurFrame() functions here and there without any result too, as well as I have done with the UpdateBoneMatrix() one without any success... So I really hope, more then ever, that the "apply the script to bone layer" works in some or other way...

And, talking about that... yeah, it can be a "little" more difficult due to the lack of a specific function, but I suppose it will be possible, isn't? I mean, with the new way of AS scripts & layers management and improved info access/interchange without the limitations of the past, if I have understand it well... And although, surely, this intricate "priorities" issue which I've stumbled will be more complicated than it seems and probably all the consequent effort will be in vain... I still think it'll worth the try just in case.

And well, the script state is very rough at the moment and I have only the essential code, without all the bones name and point groups conventions and all that stuff that I want to add to make it more powerful and as friendly as possible, but surely an example always can help to help, so I'll post it here as soon as I be able to test some aspects about the new "variant" I have in mind.


Of course, again, thanks for be there and greetings! :)
...
Rudiger
Posts: 786
Joined: Sat Dec 17, 2005 5:25 pm

Post by Rudiger »

The difficulty is in the way you have to use moho.Mesh() to get access to a layer's mesh object. This means that that layer has to be selected first using moho.SetSelLayer(). It's doable, but I've found that having the primary layer being switched on you by a layer script causes problems when using AS.

When you got that error with moho.SetCurFrame(), did you give it a frame number? I'm expecting that you would have to use something like this:

local frame = moho.frame

moho.SetCurFrame(frame+1)
moho.SetCurFrame(frame)

although it may work without the first SetCurFrame.

**Updated: Edits shown in RED
Post Reply