will try it out...how about adding some base functionality in Xith .
What i have in mind is to able to specify a convex closed ploygon on a plane and depth upto which it should be extruded.
I have wriiten a small class for it ,please give your input to improve this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| import javax.vecmath.Point3f; import com.xith3d.scenegraph.GeometryArray; import com.xith3d.scenegraph.Shape3D; import com.xith3d.scenegraph.TriangleStripArray;
public class GeometryExtruder extends Shape3D {
private float extrusonLength;
public GeometryExtruder(float length, Point3f[] coordsArray) { super(); this.extrusonLength = length; int [b]numLayers [/b]= 8; float depthShift = -this.extrusonLength/numLayers; Point3f point; Point3f[] coords = new Point3f[1+numLayers*(2*coordsArray.length+1)]; int counter = 0; for (int j = 0; j < numLayers; j++) { for (int i = 0; i < coordsArray.length; i++) { if(j==0){ point = new Point3f(coordsArray[i]); coords[counter++] = point; }else{ coords[counter++] =coords[(j-1)*(coordsArray.length*2+1)+i*2+1]; } point = new Point3f(coordsArray[i].x, coordsArray[i].y,coordsArray[i].z + depthShift); coords[counter++] = point; } coords[counter++] =coords[j*(coordsArray.length*2+1)]; for(int i=0;i<coordsArray.length;i++){ coordsArray[i].z= coordsArray[i].z+depthShift; } } coords[counter++]=coords[(numLayers-1)*(coordsArray.length*2+1)+1]; TriangleStripArray qa = null; int flags = GeometryArray.COORDINATES; qa = new TriangleStripArray(coords.length, flags, new int[] { coords.length }); qa.setCoordinates(0, coords); super.setGeometry(qa); }
} |
It takes arguments :
1.
Point3f[] coordsArray :vertices of convex polygon in XY Plane
ex: To draw a extruded pentagon Point a=(0,0,0),
Point b=(3,0,0),
Point c=(4,2,0),
Point a=(0,4,0)
2.
float length :length in Z axis upto which this pentagon should be extruded.
Variable
numlength is just variable to specify in how many layers this pentagon should be extruded.