Hi all !
 
I have a problem with assigning colors per vertex to an IndexedGeometryArray.
I load the geometry with the SUN loader (it's plane vanilla VRML IFS with material color information but _NO_ color per vertex at this point).
Then I calculate some weight for every vertex and map that into a color range.
Now I wanted to assign these colors to the vertices already loaded geometry, so I made a new instance of IndexedTriangleArray with the correct vertex format (means including ITA.COLOR_3)
and then the problems begin.
How should I set up the color array ? The number of colors does not correspond to the vertex count neither should it 'cause it's an indexed format, right ?
Currently I use this code :
 
        ita.setCoordinates(0,coords);
        ita.setCoordinateIndices(0,coordIndices);
        ita.setColors(0,colors);
        ita.setColorIndices(0,colorIndices);
 
where the colors and color indices are set with default values and later changed in a loop by :
 
            Color3f nc3 = new Color3f(1.f, 1.f-(float)weights[currentWeight], 0.f);
            ita.setColor(currentWeight, nc3);
            Color3f c3 = new Color3f();
            ita.getColor(ita.getColorIndex(v1), c3);
            if ( 1.f-(float)weights[currentWeight] < c3.y ) {
                ita.setColorIndex(ita.getColorIndex(v1), currentWeight); 
            }
My code throws this exception at runtime :
 
java.lang.ArrayIndexOutOfBoundsException: GeometryArray: has no colors
        at javax.media.j3d.GeometryArray.getColors(GeometryArray.java:2677)
        at cutnglue.CutNGlue.init(CutNGlue.java:112)
        at com.sun.j3d.utils.applet.MainFrame.run(MainFrame.java:294)
        at java.lang.Thread.run(Thread.java:484)
It's caused by this line in the main class:
 
colorization.getIndexedTriangleArray().getColors(0, colors);
 
I know my method returns an IGA, I checked with getClass().getName()
 
So is this a bug or am I missing something here ?
 
Where can I find more info about this subject ? ( the javadoc isn't that clear on these things )
 
I attached the complete source for the colorization class which handles the construction of the new ITA with colors per vertex
 
btw. If I comment out the line, I get drawn a completely white shape, even without shading...
Just a white blob in a black window. How can that be ?
I create a Shape3D using the constructed geometry like this :
 
    public static Appearance createAppearance(float r, float g, float b) {
        Material material = new Material();
        material.setDiffuseColor(r, g, b);
        //material.setEmissiveColor(.3f, .3f, .4f);
        ColoringAttributes ca = new ColoringAttributes();
        Appearance appearance = new Appearance();
        appearance.setMaterial(material);
        appearance.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE , 0.f));
        appearance.setColoringAttributes(ca);
        return appearance;
    }
 
    public static Shape3D buildShape3D(IndexedTriangleArray ita) {
        Shape3D shape3d = new Shape3D(ita, createAppearance());
        return shape3d;
       
    }
 
Thanks to all who cared enough to read this to the end...maybe it's just a simple glitch of me
Norbert Schoepke
 

Attachment: Colorization.java
Description: Binary data

Reply via email to