Here is my code for building a box.  I hope this helps.  It does not use
utility classes.  Its parent class, not provided, defines the appearance and
so forth.  Let me know if you need that also.


package com.xith.java3d.geometry.shape;

/**
 * Construct a box with 6 shapes and uniform texture based on texture
density as applied to longest side.
 * @author David Yazel
 * @Copyright 2000, You are free to use for any purpose providing you send
me any bug fixes you make :)
 *
 */
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class BuildingBox extends BuildingBlocks {

   public BuildingBox(BoundingBox bounds, String textureName, double
textureScale) {
      super(bounds,textureName,textureScale);
   }

   private Vector3f calcNormal( Point3f vertex, Point3f sibling1, Point3f
sibling2 ) {


  Vector3f normal = new Vector3f();
  Vector3f v1 = new Vector3f();
  Vector3f v2 = new Vector3f();


    v1.sub(sibling1, vertex);
    v2.sub(sibling2, vertex);
       normal.cross(v1, v2);
    normal.normalize();
      return normal;

   }

   /**
    * This method will define a single face of the cube.  The two points
    * specify the corners of the side, but the points must lay in the same
    * plane.
    * @param p1 The upper left coordinate of this face
    * @param p2 The bottom left cordinate of this face
    * @param p3 The top right cordinate of this face
    * @param p4 The bottom right cordinate of this face
    */

   protected GeometryArray genSide( Point3f p1, Point3f p2, Point3f p3,
Point3f p4,
                                  float textureDensity ) {

      // we need to calculate the proper texture scale in the width and
      // height of the plane.  This is because if we don't do this the
      // texture will be distorted.

      float textureScaleWidth, textureScaleHeight;

      // At this point we don't know what plane we are in, but we are
quarenteed
      // all four points are in the same plane, and we know the points are
      // specificed in triangle strip mode, so p1,p2 are in same in one dim
      // and p2,p4 are also.

      float distanceHeight = p1.distance(p2);
      float distanceWidth = p2.distance(p4);

      // scale the texture given the distance and the density

      textureScaleWidth = distanceWidth * textureDensity;
      textureScaleHeight = distanceHeight * textureDensity;

      // we will build this as a triangle strip array, with normals and
      // texture coordinates

  int perStrip[] = new int[1];
      perStrip[0] = 4;

  int numVertexPoints = 4;
  TriangleStripArray triangles = new TriangleStripArray(numVertexPoints,
   GeometryArray.COORDINATES |
   GeometryArray.NORMALS |
   GeometryArray.TEXTURE_COORDINATE_2 |
   GeometryArray.COLOR_3,
   perStrip);

  triangles.setCapability(GeometryArray.ALLOW_TEXCOORD_WRITE);
  triangles.setCapability(GeometryArray.ALLOW_TEXCOORD_READ);
  int count = 0;

      // we need to build 4 points.  At each point we need to set the
normal,
      // texture coordinates and space coordinates.

      // define the first vertex

      triangles.setCoordinate(0,p1);
      triangles.setNormal(0,calcNormal(p1,p2,p3));
      triangles.setTextureCoordinate(0,new Point2f(0.0f,0.0f));
      triangles.setColor(0,new Color3f(1f,1f,1f));

      // define the second vertex

      triangles.setCoordinate(1,p2);
      triangles.setNormal(1,calcNormal(p2,p1,p3));
      triangles.setTextureCoordinate(1,new
Point2f(0.0f,textureScaleHeight));
      triangles.setColor(1,new Color3f(1f,1f,1f));

      // define the third vertex

      triangles.setCoordinate(2,p3);
      triangles.setNormal(2,calcNormal(p3,p2,p4));
      triangles.setTextureCoordinate(2,new Point2f(textureScaleWidth,0.0f));
      triangles.setColor(2,new Color3f(1f,1f,1f));

      // define the fourth vertex

      triangles.setCoordinate(3,p4);
      triangles.setNormal(3,calcNormal(p4,p3,p2));
      triangles.setTextureCoordinate(3,new
Point2f(textureScaleWidth,textureScaleHeight));
      triangles.setColor(3,new Color3f(1f,1f,1f));

      return triangles;

   }

   /**
    * We will be creating the 6 sides as different geometries, thus allowing
    * them to be easily referenced, plus we can use multi textures to have
    * different textures on different faces
    */

   public void genGeometry( Shape3D shape, BoundingBox bounds, float
textureDensity ) {

      // variables needed by this method

      Vector3f normal;
      Point3f p1,p2,p3,p4;
      Point3d lowerd = new Point3d();
      Point3d upperd = new Point3d();

      // get the lower and upper bounds

      bounds.getLower(lowerd);
      bounds.getUpper(upperd);

      // translate them to single floating

      Point3f lower = new Point3f( (float)lowerd.x, (float)lowerd.y,
(float)lowerd.z );
      Point3f upper = new Point3f( (float)upperd.x, (float)upperd.y,
(float)upperd.z );

      // define the front facing side

      p1 = new Point3f( lower.x, upper.y, lower.z );
      p2 = new Point3f( lower.x, lower.y, lower.z );
      p3 = new Point3f( upper.x, upper.y, lower.z );
      p4 = new Point3f( upper.x, lower.y, lower.z );
      shape.addGeometry(genSide(p3,p4,p1,p2,textureDensity));

      // define the back facing side

      p1 = new Point3f( lower.x, upper.y, upper.z );
      p2 = new Point3f( lower.x, lower.y, upper.z );
      p3 = new Point3f( upper.x, upper.y, upper.z );
      p4 = new Point3f( upper.x, lower.y, upper.z );
      shape.addGeometry(genSide(p1,p2,p3,p4,textureDensity));

      // define the LEFT facing side

      p1 = new Point3f( lower.x, upper.y, lower.z );
      p2 = new Point3f( lower.x, lower.y, lower.z );
      p3 = new Point3f( lower.x, upper.y, upper.z );
      p4 = new Point3f( lower.x, lower.y, upper.z );
      shape.addGeometry(genSide(p1,p2,p3,p4,textureDensity));

      // define the RIGHT facing side

      p1 = new Point3f( upper.x, upper.y, lower.z );
      p2 = new Point3f( upper.x, lower.y, lower.z );
      p3 = new Point3f( upper.x, upper.y, upper.z );
      p4 = new Point3f( upper.x, lower.y, upper.z );
      shape.addGeometry(genSide(p3,p4,p1,p2,textureDensity));

      // define the TOP facing side

      p1 = new Point3f( lower.x, upper.y, upper.z );
      p2 = new Point3f( lower.x, upper.y, lower.z );
      p3 = new Point3f( upper.x, upper.y, upper.z );
      p4 = new Point3f( upper.x, upper.y, lower.z );
      shape.addGeometry(genSide(p3,p4,p1,p2,textureDensity));

      // define the LOWER facing side

      p1 = new Point3f( lower.x, lower.y, upper.z );
      p2 = new Point3f( lower.x, lower.y, lower.z );
      p3 = new Point3f( upper.x, lower.y, upper.z );
      p4 = new Point3f( upper.x, lower.y, lower.z );
      shape.addGeometry(genSide(p1,p2,p3,p4,textureDensity));


   }

}

----- Original Message -----
From: Desiree Hilbring <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, September 01, 2000 9:36 AM
Subject: [JAVA3D] Stripcounts


Hi,
I tried to build a box with the GeometryInfo classes the following way:

        // Coordinates
        // needs to be counter clockwise
        Point3f[] coords = new Point3f[4*6];
        // front side
        coords[0]=new Point3f(eastValue-w,heightValue-c,northValue+l);
        coords[1]=new Point3f(eastValue+w,heightValue-c,northValue+l);
        coords[2]=new Point3f(eastValue+w,heightValue+c,northValue+l);
        coords[3]=new Point3f(eastValue-w,heightValue+c,northValue+l);
        // right side
        coords[4]=new Point3f(eastValue+w,heightValue-c,northValue+l);
        coords[5]=new Point3f(eastValue+w,heightValue-c,northValue-l);
        coords[6]=new Point3f(eastValue+w,heightValue+c,northValue-l);
        coords[7]=new Point3f(eastValue+w,heightValue+c,northValue+l);
        // top side
        coords[8]=new Point3f(eastValue-w,heightValue+c,northValue+l);
        coords[9]=new Point3f(eastValue+w,heightValue+c,northValue+l);
        coords[10]=new Point3f(eastValue+w,heightValue+c,northValue-l);
        coords[11]=new Point3f(eastValue-w,heightValue+c,northValue-l);
        // back side
        coords[12]=new Point3f(eastValue+w,heightValue-c,northValue-l);
        coords[13]=new Point3f(eastValue-w,heightValue-c,northValue-l);
        coords[14]=new Point3f(eastValue-w,heightValue+c,northValue-l);
        coords[15]=new Point3f(eastValue+w,heightValue+c,northValue-l);
        // left side
        coords[16]=new Point3f(eastValue-w,heightValue-c,northValue-l);
        coords[17]=new Point3f(eastValue-w,heightValue-c,northValue+l);
        coords[18]=new Point3f(eastValue-w,heightValue+c,northValue+l);
        coords[19]=new Point3f(eastValue-w,heightValue+c,northValue-l);
        // down side
        coords[20]=new Point3f(eastValue-w,heightValue-c,northValue+l);
        coords[21]=new Point3f(eastValue+w,heightValue-c,northValue+l);
        coords[22]=new Point3f(eastValue+w,heightValue-c,northValue-l);
        coords[23]=new Point3f(eastValue-w,heightValue-c,northValue-l);

        GeometryInfo gInfo = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
        int[] stripCounts = {4,4,4,4,4,4};
        gInfo.setCoordinates(coords);
        gInfo.setStripCounts(stripCounts);

        shape3d.setGeometry(gInfo.getGeometryArray());
        shape3d.setAppearance(createAppearance());

I think the box consists of 6 side with 4 coordinates for one side.

But unfortunately I get the following error:

Exception occurred during event dispatching:
java.lang.IllegalArgumentException: StripCounts inconsistent with
primitive
        at
com.sun.j3d.utils.geometry.GeometryInfo.checkForBadData(GeometryInfo.
java:1301)
        at
com.sun.j3d.utils.geometry.GeometryInfo.getGeometryArray(GeometryInfo
.java:1546)
        at app.gwvis.ConstructionSite.makeSite(ConstructionSite.java:138)
        at app.gwvis.ConstructionSite.<init>(ConstructionSite.java:55)
        at

...

What is wrong or what has to be in Stripcounts when not the number of the
vertices for each shape?

I am lost.

Thanks for your help in advance

Thanks Desiree

PS: I do not want to use the utility box class.

o------------------------------------------------------------------------o
| Desiree Hilbring      Institut fuer Photogrammetrie und Fernerkundung  |
|                       Universitaet Karlsruhe, Germany                  |
|                                                                        |
|                       email: [EMAIL PROTECTED]             |
|                       # 0721 6083676                                   |
o------------------------------------------------------------------------o

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to