adjustable layer scripts
Moderators: Víctor Paredes, Belgarath, slowtiger
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
adjustable layer scripts
Okay, this is an admittedly odd request, but I'd like to be able to choose how often (once every how many frames) a layer script is run. Basically this is just to help with some performance issues on scripts that don't neccessarily need to run each frame.
Maybe even be able to keyframe where exactly I want it to run.
Maybe even be able to keyframe where exactly I want it to run.
I have a bit of code I use that does this. I will track it down.
Basically it stores the frame number in a global variable and checks it before running the code. If the frame number hasn't changed it doesn't run the code again. If the frame number changes and doesn't match the number in the variable, then the code runs and updates the global variable.
It's very short code and works quite well.
I have to find it... it's here somewhere...
-vern
Basically it stores the frame number in a global variable and checks it before running the code. If the frame number hasn't changed it doesn't run the code again. If the frame number changes and doesn't match the number in the variable, then the code runs and updates the global variable.
It's very short code and works quite well.
I have to find it... it's here somewhere...
-vern
Found it!
Save this code and embed in a layer. It will print the frame number in the lua console ONCE per frame. You can modify it to work with almost anything.
I put the separate part for frame 0 because almost all the scripts have a different function on frame 0 and you NEED it to run more than once. It's only on frames ABOVE 0 that you want it to run once.
Don't forget... nothing will make it run again on a frame. The reason scripts run more than once is to check for updates made by the user... moving bones... points...etc. Using this code will not update the script at all. It just won't run again. So keep that in mind. If you need the frame to update from user action it won't work.
However it will work fine if you move a bone... then back up and forward. So it works when rendering.
-vern
Save this code and embed in a layer. It will print the frame number in the lua console ONCE per frame. You can modify it to work with almost anything.
Code: Select all
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
Don't forget... nothing will make it run again on a frame. The reason scripts run more than once is to check for updates made by the user... moving bones... points...etc. Using this code will not update the script at all. It just won't run again. So keep that in mind. If you need the frame to update from user action it won't work.
However it will work fine if you move a bone... then back up and forward. So it works when rendering.
-vern
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Mmm, well I need the script to update, just not so frequently. I could just embed the script where I want on the timeline and remove it to store that frame's script change. I added your code to the sort_shapes script, and it seems to have the same effect. Without being able to pick the frame alteration for the whole document.Using this code will not update the script at all. It just won't run again. So keep that in mind. If you need the frame to update from user action it won't work.

That code would only be useful (for my purpose) if I broke scenes down to like 5 or 10 frame segments.
Oh well, still looking for a workaround to sort_shape's performance issues.

My mistake. I misread the request. you want to run the script say only of frames 6 and 10, or run the script on all even frames.
This is simple. Either hard code it, or find some element that can contain the information to decide when and where it runs.
For example a special "script" bone's rotation or even it's name could be linked to which frames a script runs on. You would just need to decide how this would be transcribed to the variable and use the same code.
For instance, key a bone's rotation within a marked range. Use some math to round it to an exact whole number. Compare that number to the frame number. If it matches, run the script. Or use translation if that's easier.
You could key the bone so that it runs on specific frames.
I could whip up a code snippet for this pretty easily I think. I had something similar for a bone rotation controlling a switch layer. Actually I think translation would be the easiest to convert to key frame numbers... but rotation could be infinite for any possible length of the animation. I just had trouble creating the rotation ranges and converting them to numbers.
-vern
This is simple. Either hard code it, or find some element that can contain the information to decide when and where it runs.
For example a special "script" bone's rotation or even it's name could be linked to which frames a script runs on. You would just need to decide how this would be transcribed to the variable and use the same code.
For instance, key a bone's rotation within a marked range. Use some math to round it to an exact whole number. Compare that number to the frame number. If it matches, run the script. Or use translation if that's easier.
You could key the bone so that it runs on specific frames.
I could whip up a code snippet for this pretty easily I think. I had something similar for a bone rotation controlling a switch layer. Actually I think translation would be the easiest to convert to key frame numbers... but rotation could be infinite for any possible length of the animation. I just had trouble creating the rotation ranges and converting them to numbers.
-vern
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
How did I miss that one?!I could whip up a code snippet for this pretty easily I think. I had something similar for a bone rotation controlling a switch layer.

Actually it's funny you mention that. Thinking about it today, the only workaround to sort_shape's performance issues I could come up with was falling back on the idea of a shape order switch. I could embed meshinstance at different points of the character's rotation to capture order switches of the potentially hundreds of shapes.
The only drawback to this is needing to switch manually. I've toyed with the notion of somehow using Genete's pose_array script to control the switch with a constraint from the 3Drig control. But alas, both scripts can't run in the same layer.
I thought of your master bone script, but that's one too many high level scripts for my brain to manage at the moment.


So yeah, if you have a script to control a switch by bone rotation, that may be one solution to my troubles.
Sadly, I still don't know enough scripting to do anything with your other suggestions. I can hunt down and usually fix lua errors, but that's about it.
But yeah, if you can write a bit of code I could add in that will let me minimize how often the script runs, I'd really appreciate it.

The switch layer bone control script isn't quite ready for prime time yet. I got involved with the "real world" while working on it and haven't gotten back to it to finish it.
I got stuck on finding the "ranges" between rotations that would change the switch. It involves radians and degrees and pi... I suck at math.
The concept works I just have to tweak it.
-vern
I got stuck on finding the "ranges" between rotations that would change the switch. It involves radians and degrees and pi... I suck at math.

The concept works I just have to tweak it.
-vern
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
So let's say there are "n" layers within a switch, and a boneheyvern wrote:The switch layer bone control script isn't quite ready for prime time yet. I got involved with the "real world" while working on it and haven't gotten back to it to finish it.
I got stuck on finding the "ranges" between rotations that would change the switch. It involves radians and degrees and pi... I suck at math.
The concept works I just have to tweak it.
-vern
can rotate within "r" degrees,
you need a function
selectClosestLayer(r) = n
I might be able to help with that, but I don't know what the LUA grammar is. You could let me know relevant LUA functions and the types of vars you currently have.
Then again, maybe I'm not understanding correctly. I could give it a shot.