I am making a piano song animation in cycles where in exact places (if a piano button was hit) the piano string lights up (Emission shader Strength = 5) then fades away (so go back to 0 Strength in 100 frames).
Until now I did this manually. So I checked the frame number where it should be lighten up let's say frame 2345, went back two frames (to 2343) set a keyframe (if this string was hit within 100 frames back its higher than 0) go back to original frame (2345) set the material strength to 5 and keyframe it then go forward a hundred frames (to 2445) set the Emission shader's Strength to 0 and made it keyframe. This is a really time consuming work especially now where there is 3-4 key is hit in the same time...
I need a really simple script to speed things up a little bit. My plan is to do the following workflow. I just check the frame number where the string should lighten up go to that frame in editor, select the string object what is should be lighten up, then hit "Run Script" and the script makes all this for me on the actual frame number on the selected object's material.
I want something like this:
import everything what is needed for this script
curMat = get active object's (what is actually selected in 3d editor) material
curFrame = get the current frame which is shown in the timeline editor
keyframe_insert(curMat.Strength, curFrame-2)
for (curFrame-1 to curFrame+100)
{
check for keyframes in material strength and if there is
delete_keyframes
}
set strength(curMat, value = 5, curFrame)
keyframe_insert(curMat.Strength, curFrame)
set strenght(curMat, value = 0, curFrame+100)
keyframe_insert(curMat.Strength, curFrame+100)
I hope one of you can understand what I want to achieve and help me out with a few lines of code, I would really appreciate your help!