PDA

View Full Version : Changing Color of an object over time


MunichM
11-23-2010, 05:44 AM
Hi,
maybe you can help me:

Question:
I would like to do that

a = box()
at time z animate a.wirecolor = color 255 7 0

that means I would like to change the color over time.

Since I think the variable color is not animatable that does not work.
What is the solution?

For background knowledge:
I have a box which changes the hight over time (between 0 and 1)
The color value of the box should depend on the height.
For example:
if heigth = 0 then red
if heigth = 0.5 then green
if height = 1 then blue
or so.

Thanks!

labbejason
11-23-2010, 10:50 PM
I created a float script controller on a box's Length controller. Here's was the script:

redValue = (255 * myBox.height) -- Get the color's red value based on the box's height
if (redValue > 255) then redValue = 255 -- We want the value to stay between 0 - 255, so limit it to those values
else if (redValue < 0) do redValue = 0

myColor = color redValue 0 (255-redValue) -- Use the red value as is, the blue value subtracts as the red value increases
myBox.wireColor = myColor -- Set the box's .wireColor property
10 -- The script controller is expecting a float as a return value, otherwise it will crash

When the box's height value was 0, its color would be blue. When the height value was 1, it would be red. If you wanted it to be green when the value is 0.5 then you would have to fool around with the expression a little more.

MunichM
11-24-2010, 01:26 AM
very useful, thank you!

denisT
11-24-2010, 03:16 AM
Changing Color of an object over time

why do you want to tickle the wirecolor?

MunichM
11-24-2010, 04:21 AM
I don't fully understand the question.

I would like to change the color of the box.
It is a box for a neural network.

For example:
If box.height is 0 then the input = 0 and the color is red.
If box.beight is 1 then the input = 1 and the color should be yellow.
And similar effects.

Like in the picture. How would you do that, Denis? Not in the same way like Jason?

I found the Color_RGB controller in the help.
Do you mean that would be better?

denisT
11-24-2010, 02:11 PM
I don't fully understand the question.

I would like to change the color of the box.
It is a box for a neural network.

For example:
If box.height is 0 then the input = 0 and the color is red.
If box.beight is 1 then the input = 1 and the color should be yellow.
And similar effects.

Like in the picture. How would you do that, Denis? Not in the same way like Jason?

I found the Color_RGB controller in the help.
Do you mean that would be better?



the wirecolor property of the object is not for real time changing or for animation. this property is for the displaying objects in view port with different (or unique) color. If you want to colorize objects in your scene by their size - that's OK. But the idea to animate the parameter that might be visible in just particular cases is kinda strange for me.

MunichM
11-24-2010, 07:31 PM
Yes, you are right.
I manipulate now the material.diffuse parameter with the code of Jason.
But another question.
The srupt is working - but only for one object(here myBox)

Now I want to apply this script to more than one object.

I search anything like (this) or so to get the height of the object calling the script:
But these two don't work:

fs.script(obj) = "gValue = obj.height*255.0
myColor = color 255 gvalue 0
m =standardmaterial()
m.diffuse = color 255 gvalue 0
m.opacity = obj.height * 100.0
obj.material = m
10"
pr

fs.script() = "gValue = this.height*255.0
myColor = color 255 gvalue 0
m =standardmaterial()
m.diffuse = color 255 gvalue 0
m.opacity = this.height * 100.0
this.material = m
10"



redValue = (255 * myBox.height) -- Get the color's red value based on the box's height
if (redValue > 255) then redValue = 255 -- We want the value to stay between 0 - 255, so limit it to those values
else if (redValue < 0) do redValue = 0

myColor = color redValue 0 (255-redValue) -- Use the red value as is, the blue value subtracts as the red value increases
myBox.wireColor = myColor -- Set the box's .wireColor property
10 -- The script controller is expecting a float as a return value, otherwise it will crash

denisT
11-24-2010, 08:45 PM
Yes, you are right.
I manipulate now the material.diffuse parameter with the code of Jason.


it's much easier (and will work faster) to use param wiring system (see MXS help for details):

--delete objects
(
b = box material:(Standard name:"BindHeight") width:(units.decodevalue "1m") length:(units.decodevalue "1m") height:(units.decodevalue "1m")
paramWire.connect b.baseObject[#Height] b.mat[#Shader_Basic_Parameters][#Diffuse_Color] "color (Height/(units.decodevalue \"1m\")) 0 0"
)


this sample binds R-component of material's diffuse color to Height of the objects.
it uses an expression to range the color's R from 0m to 1m of height.

if you want you can make 2-way connection (color will change height, height will change color)

MunichM
11-25-2010, 03:17 AM
Thank you, Denis, now it works.
But I don't fully understand the code. For me the documentation is very confusing.

With luck I found out the settings for changing the opacity:
tmp.mat[#Extended_Parameters][#Opacity] "0.5"

But how can I find out that in a systematic way?
Where is written that the parater Height is under the Node basicObjects?

Thank you anyways for your help.

CGTalk Moderation
11-25-2010, 03:17 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.