Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

12046 Posts in 1593 Topics- by 597 Members - Latest Member: Cydfewoot

22. May 2013, 05:57:58 am
Xith3D CommunityGeneral CategoryGeneral Discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)setting transparency on a visual object that has two colors
Pages: [1]
Print
Author Topic: setting transparency on a visual object that has two colors  (Read 733 times)
mikelizzi
Just dropped in

Offline Offline

Posts: 8


View Profile Email
« on: 04. May 2011, 04:09:52 pm »

Hi, I’m moving along converting my java3d code to xith3d.

I’m having trouble setting transparency on a visual object that has two colors.
I’m successfully setting transparency on a visual object that has one color.  I do that through the Appearance object because I set the color in the Material object.  But to give an object two colors I had to assign colors per vertex using the color array.  I’m not using the Material or Appearance object.  So, I’m trying this;

Colorf transparentGreen = new Colorf( Colorf.GREEN );
transparentGreen.setAlpha( .9f );
setFaceColor( transparentGreen );
.
.
.

public  void setFaceColor( Colorf color )
{
   for ( int j = 0; j < numFaceVertices; j++ )
   {
       this.getGeometry().setColor( j, color );
   }
}

But I’m getting the following  error
java.lang.IllegalArgumentException: mismatching color size

Can anybody help?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4403


May the 4th, be with you...


View Profile
« Reply #1 on: 04. May 2011, 05:14:39 pm »

There must be some other code of yours, that sets the vertex colors using a color without alpha prior to that code above. Once the vertex colors are set with or without alpha you cannot simply set them the other way.
Logged
mikelizzi
Just dropped in

Offline Offline

Posts: 8


View Profile Email
« Reply #2 on: 04. May 2011, 09:23:24 pm »

There must be some other code of yours, that sets the vertex colors using a color without alpha prior to that code above. Once the vertex colors are set with or without alpha you cannot simply set them the other way.

Yes indeed there is.  Thanks for the quick response.  I'm off to fix it.
Logged
mikelizzi
Just dropped in

Offline Offline

Posts: 8


View Profile Email
« Reply #3 on: 05. May 2011, 12:46:54 pm »

Hi again.  I'm still having problems. 
I reduced my code for a partially transparent 2D object to this.
I insert it into my scene and insert another object of different color behind it.
I can't see the other object at all.
I can insert a partially transparent 3D object (created using TransparencyAttributes) that works fine.
Any help identifying what I am doing wrong would be much appreciated.


public class Shape3DClockFace extends Shape3D
{
     public Shape3DClockFace( float dummy )
    {
       super( createGeometryTA() );
    }

    public static TriangleArray createGeometryTA()
    {
        GeometryConstruct gc = createGeometryConstructTA();
        TriangleArray ta = GeomFactory.createTriangleArray( gc );
        return ( ta );
    }

    public static GeometryConstruct createGeometryConstructTA()
    {
       Tuple3f[] allVertices = new Tuple3f[ 6 ];
       Vector3f[] allNormals = new Vector3f[ 6 ];
       Colorf[]    allColors = new Colorf[ 6 ];
       TexCoord2f[]   allTex = null;
       Colorf defaultColor   = new Colorf( 1f, 1f, 0f, .5f );    // Yellow 50% Transparent
       Vector3f normal       = new Vector3f( 0f, 0f, 1f );

      allVertices[ 0 ] = new Point3f( -.1f,  .1f, 0f );
      allVertices[ 1 ] = new Point3f( -.1f, -.1f, 0f );
      allVertices[ 2 ] = new Point3f(  .1f,  .1f, 0f );
      allVertices[ 3 ] = new Point3f(  .1f,  .1f, 0f );
      allVertices[ 4 ] = new Point3f( -.1f, -.1f, 0f );
      allVertices[ 5 ] = new Point3f(  .1f, -.1f, 0f );

        for ( int i = 0; i < 6; i++ )
        {
           allNormals[ i ]  = normal;
          allColors[ i ]   = defaultColor;
        }
         return new GeometryConstruct( GeometryType.TRIANGLE_ARRAY, allVertices, allNormals, allTex, allColors );
    }
}
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic