Vertex colors don't work!
Posted: 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:
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:
But then in the call color[j].getComponents(c); (line 335), inside that method it throws the exception because of this condition (line 153):
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:
Please fix that problem.
Thanks,
Fausto
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);
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];
Code: Select all
if (dest != null && dest.length != 4)
throw new IllegalArgumentException
("wrong dimension of color array " + dest.length);
In line 332 of AbstractPointSetFactory.toDoubleArray(Color[] color) just change the code to:
Code: Select all
float [] c = new float[4];
Thanks,
Fausto