Lee's Lessons
Interpolators! Part 2
2000-05-26
AAAAA! Like I said in the news, this was a complete pain in the butt! I have been
working on this for 2 days. There is NO documentation out there to describe how
to use these things. This was all trial, error and sweat. Anyway, it's done.
It's not done completely because I haven't delved very deeply into them, I was just
trying to get them to work! I will go into more depth on all the interpolators at
some time in the future. The commonality between the two was that YOU MUST SET
APPROPRIATE APPEARANCE OBJECTS TO HAVE WRITE CAPABILITY! I go more into this with
each section below. It makes sense though. Rotation, Position, and Scale Interpolators
all deal with geometry while Color and Transparency Interpolators deal with Appearances.
I already had the TransformGroup WRITE capabilities on from the previous lessons. That
is why the geometric Interpolators worked right off the bat.
ColorInterpolator
BasicColInterpolator.java
This gave me a LOT of trouble! This does not appear to be well documented so you can
benefit from my misery. I'm still having problems but I got a very basic one up. All
it does is change from black to white. I had trouble working with other colors. Also,
it has to mess with the Material object in the Appearance so I had to find this out the
hard way. It was impossible to find how to do this so here is the code:
ColorInterpolator colInterp = new ColorInterpolator (
rotationTime,
shape.getAppearance().getMaterial(),
new Color3f (0.0f, 0.0f, 0.0f), // start color
new Color3f (1.0f, 1.0f, 1.0f)); // stop color
This is the constructor. I wanted this to be a basic constructor like the rest to
demonstrate a basic ColorInterpolator but this was not possible. Notice the line
shape.getAppearance().getMaterial(). This gives the ColorInterpolator
the Material for the Appearance that was attached to the Geometry Box with the
createAppearance() method. This appears to be necessary. Using a new Material()
did not appear to work. Then, here's more of the tricky part, when you create the
Appearance object set the Material object this way:
Material material = new Material ( white, green, white, green, 1.0f );
material.setCapability ( Material.ALLOW_COMPONENT_WRITE );
app.setMaterial ( material );
I create a material as in the other examples but YOU MUST SET THE WRITE CAPABILITY!!
This makes sense when you think about it, but I didn't see it in the documentation.
This was very frustrating.
Summary: For the ColorInterpolator keep an eye on that Material object for the
Appearances in your Transform group!!
TransparencyInterpolator
BasicTraInterpolator.java
This was the worst of all! I stopped working on this one first. Then I came to
ColorInterpolator and the horror started all over. Once I finished Color I came
back to this. Didn't help much. I got an error that said I must set the capability
to write but that meant nothing. Which capability? I left all the commented out code
to show you what I went through. It is this reason that I now understand to set WRITE
bits and also which WRITE bits to set. The TransparencyInterpolator does just what it
says also. It uses an Appearance object just like ColorInterpolator.
ColorInterpolator uses the Material object in the Appearance object while the
TransparencyInterpolator uses the TransparencyAttributes object of the Appearance
object. This is what gave me so much trouble. I had to use the TransparencyAttributes
of the Appearance object. You may be saying DUH! Think of this. I didn't even know
Appearance HAD a TransparencyAttributes object. I didn't know about the Materials object
either. The documentation says NOTHING about getting these objects from the Appearance
object. They make it sound like its just to be created for the sole purpose of existing
as a parameter in the Interpolator's constructor. As with ColorInterpolator, I had trouble
using colored objects. I set the cube to be green but it just kept going from white and
fading out. Oh well. I'll look into this more later. The key code is:
TransparencyInterpolator transparency = new TransparencyInterpolator (
time, shape.getAppearance ( ).getTransparencyAttributes ( ), 0.0f, 1.0f );
This creates the Interpolator with the Alpha object, time, the TransparencyAttributes
(which are part of Appearance like I said),
shape.getAppearance ( ).getTransparencyAttributes ( )I, and the next 2 values are the
beginning and ending transparency values.
TransparencyAttributes trAp
= new TransparencyAttributes ( TransparencyAttributes.NICEST, 0.1f );
// trAp.setCapability ( TransparencyAttributes.ALLOW_MODE_WRITE );
// trAp.setCapability ( TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE );
trAp.setCapability ( TransparencyAttributes.ALLOW_VALUE_WRITE );
// trAp.setCapability ( TransparencyAttributes.ALLOW_MODE_READ );
app.setMaterial ( new Material ( white, green, white, green, 1.0f ) );
app.setTransparencyAttributes ( trAp );
// app.setCapability ( Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE );
// app.setCapability ( Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ );
Look at all the commented out code! Blech! I left this in for a reason.
There are a lot of cababilities to read and write. Sometimes ya just gotta
play around with it. On the constructor for TransparencyAttributes I chose to
use the NICEST mode with a 0.1f transparency value. Neither of these really
appear to have much of an affect. I then set that TransparencyAttributes object
capabilities to VALUE_WRITE which allows the transparency value to be writeable.
I then set the Appearance TransparencyAttributes object to the one I just created
with app.setTransparencyAttributes(trAp).
Conclusion
If you are going to use an Appearance Interpolator, set the WRITE capability bit
for the Appearance aspect object you wish to set. By aspect I mean the aspect of
the Appearance you are working with. For example, with ColorInterpolator it is the
Material object, of the Appearance object, whose WRITE capability bit you must set.
With the TransparencyInterpolator it is the TransparencyAttributes. More specifically
its VALUE_WRITE attributes.
As you can see, the cube gets darker or lighter depending upon which Interpolator
you run. Both look the same. They start off white and end up black. Color turns
from white to black while on the Transparency the color is always white, it just
becomes more transparent so you can see the black background.
|