Vertex colors don't work!

Found a bug? Post here.
Post Reply
fausto
Posts: 5
Joined: Sun 12. Apr 2015, 21:30

Vertex colors don't work!

Post by fausto » Sun 24. Jan 2016, 21:32

Hi,

I'm modyfing the Cube06.java tutorial example so that it sets different colors to vertices, but the application fails when run. In particular I changed the code this way:

Code: Select all

 public static void main(String[] args) {
    
    IndexedFaceSetFactory ifsf = new IndexedFaceSetFactory();
    
    double [][] vertices  = new double[][] {
      {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
      {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}
    };
    ...
    ifsf.setVertexCount( vertices.length );
   
    // Start of my code
    Color[] vertexColors = new Color[]{
  	      Color.BLUE, Color.green, Color.red, 
  	      Color.gray, Color.yellow, Color.pink, 
  	      Color.cyan, Color.magenta 
  	    };
    ifsf.setVertexColors(vertexColors);
    // End of my code
    
    ifsf.setVertexCoordinates( vertices );
    ifsf.setFaceCount( faceIndices.length);
    ...
    JRViewer.display(sgc);
    
But I get this exception:

Exception in thread "main" java.lang.IllegalArgumentException: wrong dimension of color array 5
at de.jreality.shader.Color.getRGBComponents(Color.java:154)
at de.jreality.shader.Color.getComponents(Color.java:172)
at de.jreality.geometry.AbstractPointSetFactory.toDoubleArray(AbstractPointSetFactory.java:335)
at de.jreality.geometry.AbstractPointSetFactory.setVertexColors(AbstractPointSetFactory.java:149)
at de.jreality.geometry.IndexedFaceSetFactory.setVertexColors(IndexedFaceSetFactory.java:185)
at de.jreality.tutorial.geom.Cube06.main(Cube06.java:95)


I inspected the code at AbstractPointSetFactory.toDoubleArray(Color[] color) and in line 332 we have this:

Code: Select all

float [] c = new float[5];
But then in the call color[j].getComponents(c); (line 335), inside that method it throws the exception because of this condition (line 153):

Code: Select all

if (dest != null && dest.length != 4) 
			throw new IllegalArgumentException
			("wrong dimension of color array " + dest.length);
and dest.length is 5 because of the way the float array is being initialized. The solution is very simple:

In line 332 of AbstractPointSetFactory.toDoubleArray(Color[] color) just change the code to:

Code: Select all

float [] c = new float[4];
Please fix that problem.

Thanks,

Fausto

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: Vertex colors don't work!

Post by Andre » Wed 9. Mar 2016, 16:24

Thx for the bug. Its fixed within the new repository.

Post Reply