function LayerScript(moho)
if (moho.frame == 0) then
return
end
local skel = moho:Skeleton()
if (skel == nil) then
return
end
local origin = LM.Vector2:new_local()
local tip = LM.Vector2:new_local()
for i = 0, skel:CountBones() - 1 do
local bone = skel:Bone(i)
origin:Set(0, 0)
bone.fMovedMatrix:Transform(origin)
tip:Set(0.1, 0)
bone.fMovedMatrix:Transform(tip)
local angle = math.atan2(tip.y - origin.y, tip.x - origin.x)
print("bone: "..i.." angle = "..angle)
end
skel:UpdateBoneMatrix()
end
Do what Genete says! Less code, less looping. Probably works much more efficiently.
I had this funny thought in my head that I should be using that crazy "matrix" thing but I am... frightened by matrices... even though I just checked and I AM using the bones transform matrix in my bone groups script... but I'm using it to change the matrix orientation of the graphics matrix to draw the bone shapes. I never made the connection until just now. I hate matrix math... yikes. I need to study more.
There is also some of that funky "mathy" type stuff in there that always gives me trouble as well. What's this doing:
local angle = math.atan2(tip.y - origin.y, tip.x - origin.x)
I think I know the answer but I could never have figured it out on my own. This stuff always makes my head spin. I always think "atan" is what you get when you stay out in the sun too long... or in my case "aburn".
p.s. I think we both get "points". My version still works even if it is... uh... a bit "wordy".
Thanks Genete. I had a feeling you might show up and show some matrix-y stuff. I was looking at this script last night and hoping I could glean something from it. I've got to say, I still can't.
What exactly is being calculated? It seems like it's just setting the bone to point right...
Anyway, I got the angles just fine, it's the positions that are the problem. Vern's script does basically the same mine does now, and they are both messed up. On my skeleton there's the "tail1" bone that's parented to the "cog" (root) bone - tail1 is nearly the same spot but pointing a different direction. Both of those seem to work, but then I get to the "tail2" bone and the values are whack. X is like -.1 or something when it should be -.52-something or other.
The position is just origin.x and y - got it. Hey thanks a lot for helping me out with this. Using this script is quite a bit simpler. I appreciate it.
Ok, everything is looking great. Our programmer Mike made a visualization app and the values are coming through ok! One problem left: I'm using a regular script - as in not embedded - based on the Crashcore script, and the values aren't getting updated for the following frames. It's just frame 1 values over and over. What can I do to update? Right now I'm using this at the end of my frame for loop:
Shouldn't that do it? I thought I shouldn't have that, but it wasn't working so I added it since Genete's example has it, but then it's still not working. Yeah, I think I just need a way to actually advance the timeline or something, don't I? So my fMovedMatrix gives me the value for the next frame...
Last edited by torncanvas on Wed Jan 09, 2008 10:48 pm, edited 1 time in total.
The updatebonematrix thingy is just to update the bones when you CHANGE something. All you're doing is printing the values. Nothing changes so the update isn't needed.
In the script sample I did it was retrieving the frame with "moho.frame". That is the current frame. You need to be ON a different frame for "moho.frame" to work. You are using this as a menu script? Are you running it for each frame?
torncanvas wrote:Yeah, that's what I read in the API docs, so I didn't think I needed that, but I was confused that Genete's example had it. Anyway, I'll take it out.
I'm using a menu script, but I need to actually advance the timeline to get the next frame's value.
Well, simply using "moho.frame = j" does change moho.frame, but all my values are still the same. Does anyone know what actually happens when you click on the timeline? I made a version of this as an embedded script, but I have to have all the bones in a frame instead of all the frames in a bone, and the latter is much easier for importing. Also, when I use it as an embedded script, the frames are duplicated so I have 3 frames in a row for every frame.
I'd rather use a menu script for this, but when I used fMovedMatrix:Transform, the value is always the same, even when moho.frame changes...
I don't think you can change moho.frame via scripting. It isn't like Flash where you can jump to another frame of the movie. I wish you could. That would be VERY cool.
I think rather than going to each frame to get the info, you need to just get all the keys and values based on the length of the animation. I have not done this before with scripting but it should be possible, the code is there and the old user "Macton" did it with all of those copy/save/load layer scripts.
Did you say that you found those Macton/Crashcore scripts? I think the one to look at is the "cc_save_layer_animation.lua". It seems to have all the components to print out layer animation to an external file.
All of the links for the user Macton to those crashcore.com scripts are long gone now. Even the web site is history. If you need to see that script I can post it.
Yeah, I took your advice from a while ago and found the CC script - I based mine off of save_layer_animation. The problem with that script is that Macton used GetValue, which is available for AnimVecs and AnimVals, but not for Matrices.
Assigning a value to moho.layer does work, at least I print it before and after assigning and it seems to work.
Also, I really need to fix that triplication bug for my embedded script. Would you be able to let me know what you did for that? That would be soooo awesome.
This is a very simple layer script that prints the frame number ONCE on each frame but NOT on frame 0.
I've commented the line inside the last if/then structure where you put your code to do something once on each frame.
You would need to either place ALL of your code inside that if/then structure. Or make your code another function and call it from inside the if/then structure, that is what I do when I use this.
There is just one global variable called "oldframe" that makes this work.
function LayerScript(moho)
if (moho.frame == 0) then
oldframe = 0
end
if (moho.frame > 0) then
if (oldframe ~= moho.frame) then
print(moho.frame) -- put your stuff to do here instead of the "print" function.
end
oldframe = moho.frame
end
end
Sweet, I guess I figured globals wouldn't be persistent like that. It's good to know they are, because I was writing the frame to a file and using dofile() to pull it back in. This is much cleaner and doesn't require a file.
HUGE thanks for your help guys! I still can't use a menu script, but this is good enough for what we need. This would have cost me a couple more days of work if it wasn't for you guys - thanks!