Skip to main content

Set Alpha Color of a PointArray

4 replies [Last post]
Drikcc
Offline
Joined: 2012-05-30
Points: 0

Hi everyone,

I'm unable to fix a problem which seems to be very easy, but after trying several things, asking Google a lot of time and searching on java.net forum, I didn't found the solution.

Here is my problem. I want to represent a set of points using PointArray :

float[] coords = new float[size * 3];
float[] colors = new float[size * 4];

// I fill the coordinates and color arrays
// The color array is filled like this :
// colors[i * 4] = rValue;
// colors[i * 4 + 1] = gValue;
// colors[i * 4 + 2] = bValue;
// To test if the alpha parameter is efficient I set it to 0
// colors[i * 4 + 3] = 0.0f;

// Assign the coordinates and the color to a pointarray

PointArray ptArray = new PointArray(size, GeometryArray.COORDINATES |
GeometryArray.COLOR_4 | GeometryArray.BY_REFERENCE);

ptArray.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
ptArray.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
ptArray.setCoordRefFloat(coords);
ptArray.setColorRefFloat(colors);

The coordinates are OK, the colors are OK instead of the alpha parameter which is absolutely not considered (whatever the given value).

The aim of this code is to make points disappear dynamically. If I use a TransparencyAttributes, it will be applied to all points.

Have you any idea where the problem is ? It's weird that the color of each point in my PointArray is correct instead of the alpha parameter.

Thank you.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
interactivemesh
Offline
Joined: 2006-06-07
Points: 0

My test program runs fine according to your requirements if I use following Appearance. All points have their individual transparency/alpha value. The 'trick' is : the TransparencyAttributes' transparency value has to be equal to 0.0f.

August

PointAttributes p = new PointAttributes();
p.setPointSize(8);

TransparencyAttributes t = new TransparencyAttributes();
t.setTransparencyMode(TransparencyAttributes.NICEST);

Appearance a = new Appearance();
a.setPointAttributes(p);
a.setTransparencyAttributes(t);

Shape3D sh = new Shape3D(ptArray, a);
Drikcc
Offline
Joined: 2012-05-30
Points: 0

Hi August,

My code is relatively similar as yours :

PointArray ptArray = new PointArray(size, GeometryArray.COORDINATES |
GeometryArray.COLOR_4 | GeometryArray.BY_REFERENCE);
ptArray.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
ptArray.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
ptArray.setCoordRefFloat(coords);
ptArray.setColorRefFloat(colors);

pointAttributes = new PointAttributes();
pointAttributes.setPointSize(2.83f);
pointAttributes.setCapability(PointAttributes.ALLOW_SIZE_WRITE);

TransparencyAttributes ta = new TransparencyAttributes();
ta.setCapability(TransparencyAttributes.NICEST);
ta.setTransparency(0.0f); // set to 0.0f as you said

Appearance a = new Appearance();
a.setPointAttributes(pointAttributes);
a.setTransparencyAttributes(ta);

// I inherit from Shape3D
setGeometry(ptArray);
setAppearance(a);

I tried to not apply my color and geometry by reference but the result is the same.
Can you show me more from your code ? Have you set some specials Capabilities ?

Thank you for your help.

interactivemesh
Offline
Joined: 2006-06-07
Points: 0

Please, replace
- ta.setCapability(TransparencyAttributes.NICEST);
with
- ta.setTransparencyMode(TransparencyAttributes.NICEST);

The default transparency mode is NONE, so no transparency was applied. August

Drikcc
Offline
Joined: 2012-05-30
Points: 0

It works !
Thank you very much.