private void setDefaultStates() { setStates(defaultStateSet(Color.LIGHT_GRAY)); } }
/** * Constructs a triangle group with specified vertex coordinates. * <p> * The (x,y,z) coordinates of vertices are packed into the specified * array xyz. The number of vertices is nv = xyz.length/3. The number * of triangles is nt = nv/3 = xyz.length/9. * <p> * The (r,g,b) components of colors are packed into the specified * array rgb. The number of colors equals the number of vertices. * <p> * Normal vectors may be computed for either vertices or triangles. * When computed for a vertex, a normal vector is the area-weighted * average of the normal vectors for all triangles with that vertex. * <p> * If no vertices have the same (x,y,z) coordinates, then vertex and * triangle normal vectors are the same vectors, but triangle normal * vectors are less costly to compute. * @param vn true, for vertex normals; false, for triangle normals. * @param xyz array[3*nv] of packed vertex coordinates. * @param rgb array[3*nv] of packed color components. */ public TriangleGroup(boolean vn, float[] xyz, float[] rgb) { int[] ijk = indexVertices(!vn,xyz); float[] uvw = computeNormals(ijk,xyz); buildTree(ijk,xyz,uvw,rgb); setDefaultStates(); }
protected void selectedChanged() { System.out.println("TriangleGroup: "+this+" selected="+isSelected()); dirtyDraw(); }
public static void go() { float[] xyz = makeSineWave(); xyz = addBulge(xyz); xyz = addTear(xyz); float[] rgb = makeColors(xyz); TriangleGroup tg = new TriangleGroup(true,xyz,rgb); System.out.println("TriangleGroup bounding sphere =\n" + tg.getBoundingSphere(true)); StateSet states = new StateSet(); ColorState cs = new ColorState(); cs.setColor(Color.CYAN); states.add(cs); LightModelState lms = new LightModelState(); lms.setTwoSide(true); states.add(lms); MaterialState ms = new MaterialState(); ms.setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ms.setSpecular(Color.WHITE); ms.setShininess(100.0f); states.add(ms); tg.setStates(states); World world = new World(); world.addChild(tg); DemoFrame frame = new DemoFrame(world); OrbitView view = frame.getOrbitView(); view.setWorldSphere(new BoundingSphere(5,5,5,5)); frame.setSize(new Dimension(800,600)); frame.setVisible(true); }
/** * Adds a triangle group with specified vertex coordinates and colors. * @param xyz array of packed vertex coordinates. * @param rgb array of packed color components. * @return the triangle group. */ public TriangleGroup addTriangles(float[] xyz, float[] rgb) { return addTriangles(new TriangleGroup(true,xyz,rgb)); }
/** * Constructs a triangle group with specified vertex coordinates * and optional corresponding normal vectors and colors. * <p> * Triangles are specified by triplets of vertex indices (i,j,k), one * triplet per triangle, packed into the specified array of integers * ijk. The number of triangles is nt = ijk.length/3. * <p> * The (x,y,z) coordinates of vertices are packed into the specified * array xyz. The number of vertices is nv = xyz.length/3. * <p> * The (u,v,w) components of normal vectors are packed into the specified * array uvw. If not null, the number of normal vectors equals the number * of vertices. * <p> * The (r,g,b) components of colors are packed into the specified array * rgb. If not null, the number of colors equals the number of vertices. * @param ijk array[3*nt] of packed vertex indices. * @param xyz array[3*nv] of packed vertex coordinates. * @param uvw array[3*nv] of packed normal vector components. * @param rgb array[3*nv] of packed color components. */ public TriangleGroup(int[] ijk, float[] xyz, float[] uvw, float[] rgb) { if (uvw==null) uvw = computeNormals(ijk,xyz); buildTree(ijk,xyz,uvw,rgb); setDefaultStates(); }
/** * Recursively builds a binary tree with leaf triangle nodes. */ private void buildTree(int[] ijk, float[] xyz, float[] uvw, float[] rgb) { float[] c = computeCenters(ijk,xyz); BoundingBoxTree bbt = new BoundingBoxTree(MIN_TRI_PER_NODE,c); buildTree(this,bbt.getRoot(),ijk,xyz,uvw,rgb); } private void buildTree(Group parent, BoundingBoxTree.Node bbtNode,
/** * Returns a new simple frame with a triangle group. * @param tg a triangle group. * @return the simple frame. */ public static SimpleFrame asTriangles(TriangleGroup tg) { SimpleFrame sf = new SimpleFrame(); sf.addTriangles(tg); sf.getOrbitView().setWorldSphere(tg.getBoundingSphere(true)); return sf; }
/** * Constructs a triangle group with specified vertex coordinates. * <p> * The (x,y,z) coordinates of vertices are packed into the specified * array xyz. The number of vertices is nv = xyz.length/3. * <p> * The (u,v,w) components of normal vectors are packed into the specified * array uvw. The number of normal vectors equals the number of vertices. * @param xyz array[3*nv] of packed vertex coordinates. * @param uvw array[3*nv] of packed normal vector components. */ public TriangleGroup(float[] xyz, float[] uvw) { this(indexVertices(true,xyz),xyz,uvw,null); }
/** * Sets the color of the triangles in this triangle group. * Note that if per-vertex colors were specified when this triangle group was * constructed, then the color specified here is not used. * @param color the color. */ public void setColor(Color color) { StateSet states = getStates(); ColorState cs = (ColorState)states.find(ColorState.class); if (cs==null) cs = new ColorState(); cs.setColor(color); }
private void buildTree(Group parent, BoundingBoxTree.Node bbtNode, int[] ijk, float[] xyz, float[] uvw, float[] rgb) { if (bbtNode.isLeaf()) { TriangleNode tn = new TriangleNode(bbtNode,ijk,xyz,uvw,rgb); parent.addChild(tn); } else { Group group = new Group(); parent.addChild(group); buildTree(group,bbtNode.getLeft(),ijk,xyz,uvw,rgb); buildTree(group,bbtNode.getRight(),ijk,xyz,uvw,rgb); } }
/** * Returns a new simple frame with a triangle group. * @param vn true, for vertex normals; false, for triangle normals. * @param sx sampling of x coordinates; may be non-uniform. * @param sy sampling of y coordinates; may be non-uniform. * @param z array[nx][ny] of z coordinates z = f(x,y). */ public static SimpleFrame asTriangles( boolean vn, Sampling sx, Sampling sy, float[][] z) { return asTriangles(new TriangleGroup(vn,sx,sy,z)); }
/** * Constructs a triangle group with specified vertex coordinates * and optional corresponding normal vectors and colors. * <p> * The (x,y,z) coordinates of vertices are packed into the specified * array xyz. The number of vertices is nv = xyz.length/3. * <p> * The (u,v,w) components of normal vectors are packed into the specified * array uvw. The number of normal vectors equals the number of vertices. * <p> * The (r,g,b) components of colors are packed into the specified array * rgb. The number of colors equals the number of vertices. * @param xyz array[3*nv] of packed vertex coordinates. * @param uvw array[3*nv] of packed normal vector components. * @param rgb array[3*nv] of packed color components. */ public TriangleGroup(float[] xyz, float[] uvw, float[] rgb) { this(indexVertices(true,xyz),xyz,uvw,rgb); }
/** * Returns a new simple frame with a triangle group. * @param vn true, for vertex normals; false, for triangle normals * @param xyz array of packed vertex coordinates. * @param rgb array of packed color coordinates. * @return the simple frame. */ public static SimpleFrame asTriangles(boolean vn, float[] xyz, float[] rgb) { return asTriangles(new TriangleGroup(vn,xyz,rgb)); }
/** * Adds a triangle group for a sampled function z = f(x,y). * @param sx sampling of x coordinates; may be non-uniform. * @param sy sampling of y coordinates; may be non-uniform. * @param z array[nx][ny] of z coordinates z = f(x,y). */ public TriangleGroup addTriangles(Sampling sx, Sampling sy, float[][] z) { return addTriangles(new TriangleGroup(true,sx,sy,z)); }
/** * Adds a triangle group with specified vertex coordinates. * @param xyz array of packed vertex coordinates. * @return the triangle group. */ public TriangleGroup addTriangles(float[] xyz) { return addTriangles(new TriangleGroup(true,xyz,null)); }
/** * Returns a new simple frame with a triangle group. * @param vn true, for vertex normals; false, for triangle normals. * @param sx sampling of x coordinates; may be non-uniform. * @param sy sampling of y coordinates; may be non-uniform. * @param z array[nx][ny] of z coordinates z = f(x,y). * @param r array[nx][ny] of red color components. * @param g array[nx][ny] of green color components. * @param b array[nx][ny] of blue color components. */ public static SimpleFrame asTriangles( boolean vn, Sampling sx, Sampling sy, float[][] z, float[][] r, float[][] g, float[][] b) { return asTriangles(new TriangleGroup(vn,sx,sy,z,r,g,b)); }