This example will show one way to use the hairdresser items and the new ECA object color function.
The Room consist of the Fillable bowl, three color bottles, a wig and a sink.
The sink, color bottles and wig each have a trigger sphere to detect collisions with the bowl.
Before we set up the ECA, we need to add extra metadata to some of the objects.
For each of the color bottles we add “AtBowl” and gives it a value of 0. This will be used for checking if the bowl is close enough to be filled by the bottle.
The bowl needs three new metadata fields. “RedTotal”, “GreenTotal”, and “BlueTotal”. These values are used for calculating the color of the fluid in the bowl.
To setup the color bottles in the ECA, we create a “Simulation Starts” event. in which we set the metadata for “R”, “G” and “B”. you can only use values between 0 and 1, where 0 is non of that color and 1 is fully that color. (You can see example colors in this link, https://www.tug.org/pracjourn/2007-4/walden/color.pdf)
This will set the color of the actual bottle and its particle effect, and will also be used later for filling the bowl with the correct color.
To check where the bowl is at we use collision events and triggerSpheres.
For the Color bottles we use “Collision Begins” between the bowl and a trigger sphere. Where we set the metadata “AtBowl”, of the color bottle to 1. We also use “Collisions Ends” to set the “AtBowl” value back to 0, when the bowl leave the triggerSphere.
When the Color bottle is pressed, the “Prefab button is clicked” event is called. In this event we use a conditional to check whether the bowl is at the color bottle. Inside the Conditional we set the “RedTotal”, “GreenTotal”, and “BlueTotal” of the bowl, to their own values plus the “R”, “G” and “B” value of the Color Bottle that is pressed.
We also set the “FillLevel” of the bowl, which determines how much the bowl is filled. in this example we add 0.05 for each time the color bottle is pressed. the value ranges from 0 (empty) to 1 (filled).
Lastly we use “Broadcast message” action, this is used because it can be received in the eca Event “Message is Broadcast”.
In the “Message is Broadcast” event we update the color of the liquid. This is done with “set metadata” where we set the value of “R”, “G” and “B”.
we calculate the different values by taking the total of the specific color and dividing it with combined value of the total colors. Ex. “R = RedTotal / (RedTotal + GreenTotal + BlueTotal)”
To color the hair we again uses “collision begins” between the bowl and a triggersphere. We use a conditional to make sure that the bowl is not empty.
In the conditional we set the “R”, “G” and “B” values of the wig to the “R”, “G” and “B” values of the bowl.
after this we set the color values and the fillLevel of the bowl to zero.
We have a similar event for collisions with a triggersphere at the sink. where you can clean the bowl. to try again.