Creating Objects with custom attributes
We have just learned that we can easily create objects with a create function. In our example we have created a radial light. This light has an intensity of 1 and a white color - the same values as if we had added it via the object menu in Animator. What, if we want to create a light that is blue and has an intensity of 0.5? Woudn't we need a function where we also had an argument for intensity and color? But what about shadow buffer sizes, glow parameters and all other attributes of a light? We came to the conclusion that create functions that include all attributes of an object would lead to unreadable scripts. So we made create functions that only include the most common parameters of an object. The adjustment of all other attributes is done the "normal" Xpressionist way: linking the appropriate animation channel and assign a new value to it.
So, lets make our light that is blue and has an intensity of 0.5:
create_radiallight( "moon", "", vec( 10, 10, 10 ) );
moon.Intensity = 0.5;
moon.Color = vec( 0, 0, 255 );
Hit the Update Project button. If we look at what happens now in "slow motion" we will see this: Xpressionist will create a radial light with the name "moon". After this light is created it automatically adds the Intensity and the Color channel to the Active Channels list and writes the values as custom frames to the animation channels. If we close Xpressionist we will have a blue moon light with an intensity of 0.5.
This procedure creates custom frames for your moon light that sets the intensity value to 0.5 and the color to R=0, G=0 and B=255. Since you may want to use this light for animation afterwards and you don't want to create custom frames since they will overwride the keyframes you may want to set for the light we made a special function that declares your adjustments to be "setup" adjustments. This means that no custom frames will be created but an initial keyframe instead. The setup function looks like this:
setup( )
{
...
};
The setup function has no argument since it does not return any value. It tells Xpressionist that the following statements have to be treated in a special way. In this case everything between the two braces will only be evaluated on the first frame of the project (frame 0) and all values will be written as keyframes. When we erase our moon light from the project window and change the statement to this
setup( )
{
create_radiallight( "moon", "", vec( 10, 10, 10 ) );
moon.Intensity = 0.5;
moon.Color = vec( 0, 0, 255 );
};
Xpressionist will create a moonlight and will set its initial keyframe to an itensity of 0.5 and a color of blue and leave all other frames untouched.
Summary
In this section, you learned how to:
- create an object with custom attributes
- use the setup function to only set the initial keyframe of a newly created object
|