Skip to main content

Draw a Wireframe around a Box Primitive

3 replies [Last post]
ecrouse
Offline
Joined: 2007-01-29
Points: 0

Hello Everyone,
I would like to outline/hightlight the edges of a box primitive I created by simply drawing a line between vertices not including any of the side diagonals.
THanks for any help,
-Erick

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mandravinos
Offline
Joined: 2012-01-19
Points: 0

i know it's about five years after, still that can be helpful to anyone who runs into the same issue! thats a class for producing a wireframe cube without the diagonals. it has nothing to do with th Box primitive, it is implemented with an IndexedLineArray.

package visualisation;

import javax.media.j3d.*;
import javax.vecmath.*;
import org.apache.log4j.Logger;


public class Room3D extends Shape3D{
    public static final int VERTEX_COUNT=8;
    public static final int INDEX_COUNT=24;
   
    private IndexedLineArray roomLineArray;
    private Point3f[] roomPoints;
    private Color3f[] roomColors;
   
    float roomLength;
    float roomWidth;
    float roomHeight;
    float roomX;
    float roomY;
    float roomZ;
   
    Logger logger;
   
    public Room3D(int roomLength, int roomWidth, int roomHeight, int roomX, int roomY, int roomZ) {
        logger=Logger.getLogger(Site3D.class.getName());
       
        this.roomLength=(float)roomLength;
        this.roomWidth=(float)roomWidth;
        this.roomHeight=(float)roomHeight;
        this.roomX=(float)roomX;
        this.roomY=(float)roomY;
        this.roomZ=(float)roomZ;
       
        this.roomLength=this.roomLength/10;
        this.roomWidth=this.roomWidth/10;
        this.roomHeight=this.roomHeight/10;
        this.roomX=this.roomX/10;
        this.roomY=this.roomY/10;
        this.roomZ=this.roomZ/10;
       
        logger.info(this.roomLength);
        logger.info(this.roomWidth);
       
        roomLineArray=new IndexedLineArray(Room3D.VERTEX_COUNT, GeometryArray.COORDINATES|GeometryArray.COLOR_3, Room3D.INDEX_COUNT);
        roomPoints=new Point3f[Room3D.VERTEX_COUNT];
        //siteColors=new Color3f[Site3D.VERTEX_COUNT];
       
        //creating the coordinate points for each vertex...
        roomPoints[0]=new Point3f(this.roomX, this.roomZ, this.roomY);
        roomPoints[1]=new Point3f(this.roomX+this.roomLength, this.roomZ, this.roomY);
        roomPoints[2]=new Point3f(this.roomX+this.roomLength, this.roomZ, this.roomY+this.roomWidth);
        roomPoints[3]=new Point3f(this.roomX, this.roomZ, this.roomY+this.roomWidth);
        roomPoints[4]=new Point3f(this.roomX, this.roomZ+this.roomHeight, this.roomY);
        roomPoints[5]=new Point3f(this.roomX+this.roomLength, this.roomZ+this.roomHeight, this.roomY);
        roomPoints[6]=new Point3f(this.roomX+this.roomLength, this.roomZ+this.roomHeight, this.roomY+this.roomWidth);
        roomPoints[7]=new Point3f(this.roomX, this.roomZ+this.roomHeight, this.roomY+this.roomWidth);
       
        //creating the corresponding color object for each vertex. no alpha blending for transparency.
        roomColors=new Color3f[Room3D.VERTEX_COUNT];
        for (int i=0; i<Room3D.VERTEX_COUNT; i++) {
            roomColors[i]=new Color3f(1f, 1f, 1f);
        }
       
        //setting the vertices to the array along with their corresponding colors, as cited in the IndexedLineArray constructor
        roomLineArray.setCoordinates(0, roomPoints);
        roomLineArray.setColors(0, roomColors);
       
       
        //filling the coordinate index array. each pair of this array's entries define a line segment.
        //first the lower parallelogrammon
        roomLineArray.setCoordinateIndex(0, 0);
        roomLineArray.setCoordinateIndex(1, 1);
        roomLineArray.setCoordinateIndex(2, 1);
        roomLineArray.setCoordinateIndex(3, 2);
        roomLineArray.setCoordinateIndex(4, 2);
        roomLineArray.setCoordinateIndex(5, 3);
        roomLineArray.setCoordinateIndex(6, 3);
        roomLineArray.setCoordinateIndex(7, 0);
        //then the upper parallelogrammon
        roomLineArray.setCoordinateIndex(8, 4);
        roomLineArray.setCoordinateIndex(9, 5);
        roomLineArray.setCoordinateIndex(10, 5);
        roomLineArray.setCoordinateIndex(11, 6);
        roomLineArray.setCoordinateIndex(12, 6);
        roomLineArray.setCoordinateIndex(13, 7);
        roomLineArray.setCoordinateIndex(14, 7);
        roomLineArray.setCoordinateIndex(15, 4);
        //lastly the perpendicular pilars
        roomLineArray.setCoordinateIndex(16, 0);
        roomLineArray.setCoordinateIndex(17, 4);
        roomLineArray.setCoordinateIndex(18, 1);
        roomLineArray.setCoordinateIndex(19, 5);
        roomLineArray.setCoordinateIndex(20, 2);
        roomLineArray.setCoordinateIndex(21, 6);
        roomLineArray.setCoordinateIndex(22, 3);
        roomLineArray.setCoordinateIndex(23, 7);
       
        roomLineArray.setColorIndex(0, 0);
        roomLineArray.setColorIndex(1, 1);
        roomLineArray.setColorIndex(2, 1);
        roomLineArray.setColorIndex(3, 2);
        roomLineArray.setColorIndex(4, 2);
        roomLineArray.setColorIndex(5, 3);
        roomLineArray.setColorIndex(6, 3);
        roomLineArray.setColorIndex(7, 0);
        roomLineArray.setColorIndex(8, 4);
        roomLineArray.setColorIndex(9, 5);
        roomLineArray.setColorIndex(10, 5);
        roomLineArray.setColorIndex(11, 6);
        roomLineArray.setColorIndex(12, 6);
        roomLineArray.setColorIndex(13, 7);
        roomLineArray.setColorIndex(14, 7);
        roomLineArray.setColorIndex(15, 4);
        roomLineArray.setColorIndex(16, 0);
        roomLineArray.setColorIndex(17, 4);
        roomLineArray.setColorIndex(18, 1);
        roomLineArray.setColorIndex(19, 5);
        roomLineArray.setColorIndex(20, 2);
        roomLineArray.setColorIndex(21, 6);
        roomLineArray.setColorIndex(22, 3);
        roomLineArray.setColorIndex(23, 7);
       
        this.setGeometry(roomLineArray);
    }
}
itpedersen
Offline
Joined: 2011-02-14
Points: 0

This is easy:
Make sure you disable materials of you apperance.
something like:
apperance.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);

PolygonAtribute pa = new PolygonAttributes();
pa.setPolygonMode(PolygonAttributes.PolygonLine);
apperance.setPolygonAttributes(pa);

Hope you can make it work

mandravinos
Offline
Joined: 2012-01-19
Points: 0

this does not work, actually doesn't do what ecrouse and i want. form what i understand, we both need the box rendered without ANY of the diagonals!!! and since it's supposed to be a convenience class, we are looking for an easy way to do this. i am setting the appearance from the Box constructor to be PolygonAttributes.POLYGON_LINE but all the diagonals (on all the box normals) appear, something i don't want.

is there anything that can be done in a non time consuming way??

thanks in advance!