Notifications
Clear all

[Closed] Changing Color of an object over time

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!

8 Replies

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.

very useful, thank you!

Changing Color of an object over time

why do you want to tickle the wirecolor?

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.

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
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

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)

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.