View Full Version : animating the material editor slots
Dmaxer 01-24-2007, 01:56 PM I have a script that animates a piano keyboard there's 97 keys in all , I'm using two slots in the material editor , slot one has the diffuse set to white and slot two is set to black for all the sharp keys , now what I would like to do is make the key or keys turn red if it or they are in the down position . I know I could do this just by changing the diffuse values but this would only work if each key object had its own material slot and I dont want to use up all the slots if I can help it. I have tried using a third material slot set to red and setting any keys in the down position to that material slot but its seems when I do this it will not record it in the animation , what I mean is , if I run the script with the material editor open you can see the red slot being assigned to the key objects but when you play back the animation the changes are not recorded .maybe I'm missing something silly ??. has anyone got a better idea on how I can do this ??
Thanks for reading
|
|
Dmaxer
01-25-2007, 10:04 AM
No ideas on how I can go about this then ? . Im goin to work on it over the weekend I will post up here if I come up with anything that works .
if you look at Moonlight Sonata (http://www.lotsofrobots.com/movies/MoonLight.mov) a A virtual player piano video from Andy murdock this is what Im trying to do , as I said before I got the animation working fine its just the textures bit I need help with .
any help or ideas would be great .
Thanks for reading
BakerCo
01-25-2007, 11:20 AM
I take it you are animating the keys by rotation?if so couldn't you animate the diffuse based on the rotation of the key. white/black being 0 or at rest and red being 1 or pressed and it would fade from white/black to red in that duration.
just a thought probably not what your looking for but none the less thread bumped.
-Baker
Dmaxer
01-25-2007, 12:31 PM
No that wont work in this case but thanks for your reply :).
BakerCo
01-25-2007, 01:20 PM
so just the material changes? no keys actually move?
Dmaxer
01-25-2007, 04:47 PM
sorry for the late reply but Im at work . The keys do rotate but my point is , I dont want to use 97 materials , I only want to use 3 if I can . one white one black and one red.
so if the key is a minor key its white . if the key is a sharp its black .this bit is fine the part of the script that makes the keyboard also adds the right colours to the keys objects. as Im only using 2 colours at this point Im only using 2 slots in the material editor. simple so far
the next bit of the script animates the rotation of the keys and that works fine
what i would like it to do is rotate and change the said key object to a material slot other then the 2 Im using ( slot 1 or 2 /black,white) . I can do this as the script itself runs but it wont save that data . so when I play back the animation my script made it all works apart from the colours changing .
I think maybe Im goin about this the wrong way , maybe I should make all the keys objects use the same material and make that material a multimaterial and then just change the Mat Ids . say ID 1 = black ID 2 white and change any rotated key to ID 3 being red .
anyway thanks for the help I will let you know how I get on :)
Im leaving work now so will post back a bit later when i get home ...
why don't you want to have 97 materials?
If you script everything script these materials, too.
Georg
BakerCo
01-25-2007, 06:11 PM
Well i did not explain that well what I mean is this:
you have three materials
mWhite=getMeditMaterial 1
mBlack=getMeditMaterial 2
mRed=getMeditMaterial 3
and your keys are assigned the black and white respectively.
on the transition of the down key a function checks to see what color the current key is and assigns mRed to it with the same diffuse as the current key it then rotates and blends from the current color "white/black" to the red color once the key is done it changes back to the original material "mWhite/mBlack" the only problem with this is that more than one key will be pressed over a given amount of time :| which means more than 3 materials would have to be used.
also I agree with the above if it is scripted what would it matter.
and if that is the case you could have a white and black material and just create a red for each key.
skywisenight
01-25-2007, 06:16 PM
How about this, don't use maps at all. Control the diffuse color on your keys by vertex color.
Have two maps: One for black keys, one for white. Put vertex color in the diffuse(+ambient) slot.
Have your script change the vertex color on the object in question based on angle, or however you are choosing to do it.
BakerCo
01-25-2007, 06:29 PM
How about this, don't use maps at all. Control the diffuse color on your keys by vertex color.
Have two maps: One for black keys, one for white. Put vertex color in the diffuse(+ambient) slot.
Have your script change the vertex color on the object in question based on angle, or however you are choosing to do it.
thats how a pro would do it :P nice idea I am gonna have to try doing this.
-Baker
Dmaxer
01-25-2007, 08:25 PM
Thanks for the replys guys i will try the idea skywisenight said and let you know how I get on.
Thanks guys :)
Dmaxer
01-25-2007, 10:55 PM
well I dont know how to get this working using the vertex color :( .
here's my bit of code Im using could someone take a look and tell me why its not setting any keys in the time line , or tell me how to change it so it will ?. keydiff = 1 if the key is down 0 if up , the black keyobjects have a # in the name so the script knows to what colour to turn back to from being Red . I do hope someone can help me with this cos its doing me head in:(
animate on
at time (execute(T2 as string + "s")) rotate theObj rot_key
if keydif == 1 then (theObj.material = meditMaterials["RedKeys"] )
if keydif == 0 then (
if (findstring $.name "#") ==undefined then (theObj.material = meditMaterials["WhiteKeys"] ) else (
theObj.material = meditMaterials["BlackKeys"]))
Thanks for reading and all the help so far guys :)
Chris
01-25-2007, 11:14 PM
You could also do it with one material, in the diffuse slot a gradient ramp set to the colours you were after (with no gradient transitions, the knots right next to each other) . Assign a UVW map to the key & scale it up so the key has only one colour on it. Then write a script to move the UVW gizmo around to change the colour.
Dmaxer
01-26-2007, 12:31 AM
yes but then the rest of the Keyobjects will also change colour ,as Ive said I got it working with the bit of code above but it wont record it too the time line ,I want only the keys or key that are selected at a given point in time to change .and the script to record the changes in the time line. thanks anyway
thats how a pro would do it :P nice idea I am gonna have to try doing this.
I tried this suggestion.
But isn't this getting realy slow?
Changing the vertexcolors for complex objects?
Georg
Dmaxer
02-04-2007, 07:47 PM
in the end I just wrote my script to make a multi Material and added 128 Materials (now using 128 Keys as midi will go up to this amount)each with there own ID and just animated what ever mat I needed to ,each key object had its own ID so as you can see it works great :) .Im writing a script that converts a midi file to a text file then reads that text file I got most of it working so now I got a midi controled animation :) . still got a few midi commands to add but Im getting there :)
http://img.photobucket.com/albums/v11/Dannymax/Keys.gif
http://img.photobucket.com/albums/v11/Dannymax/MidiMax.jpg
This looks very *cool*.
I allready noticed by your avatar that you must have found a way to get this running.
Will this be a free available script?
I am hooked by that vertex color thing.
Georg
Dmaxer
02-05-2007, 10:42 AM
yeah once its ready I will Email it out to anyone that wants it. I still got a few bits to sort out. but it should be ready soon.I also have added to the script so now you tell it how many keys you want and it makes and lays them out for you , it also makes the body ,this can be a grand piano or upright or a synthesizer type body , you can also pick if you want synthesizer type keys or piano type keys , you also have the option to use your own objects if you wish and have them animated to the midi files you put into it .Im very happy with how its coming along so far :) . let me know if you get the vertex color working .
CGTalk Moderation
02-05-2007, 10:42 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.