Attach face colors using a factory

From JReality Wiki
Jump to: navigation, search

Source file: Cube05


Run as Java webstart


Factories can be used to set more advanced properties, e.g. colors or labels of vertices, edges and faces, or texture coordinates of vertices.


For example, modifying our final cube class as follows easily improves the appearance of our result.


This example also includes changing the geometry's appearance by setting Appearance attributes. A new SceneGraphComponent is created containing our geometry and the created Appearance which allows us to hide the cube vertices.


    ifsf.setGenerateEdgesFromFaces( false );
    
    ifsf.setFaceColors(new Color[]{
      Color.BLUE, Color.BLUE, Color.GREEN, Color.GREEN, Color.RED, Color.RED 
    });
    
    ifsf.update();
    
    SceneGraphComponent sgc = new SceneGraphComponent();
    sgc.setGeometry(ifsf.getIndexedFaceSet());
    
    Appearance app = new Appearance();
    app.setAttribute(CommonAttributes.VERTEX_DRAW, false);
    sgc.setAppearance(app);
    
    JRViewer.display(sgc);


even nicer cube

Attach customized edges

Source file: Cube06


Run as Java webstart


This example shows how to define your own edges which are not connected to the faces in the indexed face set. The relevant commands to the factory are:

    int [][] edgeIndices = new int [][] {
    		{0,1},{1,2},{2,6},{6,7},{7,4},{4,0}
    };
    
   ...
    ifsf.setEdgeCount(edgeIndices.length);
    ifsf.setEdgeIndices(edgeIndices);
   ...


Notice that the edges make a zig-zag path around the cube.


customized edge list


Previous: Use an indexed face set factory Developer Tutorial: Contents Next: Unwrap a geometry using a factory