<this email is out of the list>
This is a Horrible demo I modifie.
Each polygon must have its own set of independent
coordinates (vertex), but the source I have doesnot
take care about it.
So the shared vertex coordinates currupts some
textured  faces.

Alessandro


 import com.sun.j3d.utils.universe.*;
 import com.sun.j3d.utils.geometry.*;
 import javax.media.j3d.BranchGroup;
 import com.sun.j3d.utils.applet.MainFrame;
 import javax.media.j3d.*;
 import java.awt.*;
 import javax.vecmath.*;
 import java.awt.BorderLayout;
 import javax.media.j3d.GeometryArray;
 import java.applet.Applet;

 import com.sun.j3d.utils.behaviors.vp.*;
 import com.sun.j3d.utils.behaviors.keyboard.*;
 import com.sun.j3d.utils.geometry.GeometryInfo;
 import com.sun.j3d.utils.image.TextureLoader;




 public class ThePolyhedron extends Applet
 {

 static java.net.URL texImageURL = null;
 BoundingSphere bounds =    new BoundingSphere(new
Point3d(0.0, 0.0,0.0), 100.0);


 public ThePolyhedron()

 {}

 public void init()
 {


 /*
 # dodecahedron

 g dodecahedron

 # 20 verticies
 v  0.436339    0.31701884  0.7060113
 v -0.16666667  0.51294726  0.7060113
 v -0.53934467  0.0         0.7060113
 v -0.16666667 -0.51294726  0.7060113
 v  0.436339   -0.31701884  0.7060113
 v  0.7060113   0.51294726  0.16666667
 v  0.26967233  0.82996607 -0.16666667
 v -0.26967233  0.82996607  0.16666667
 v -0.7060113   0.51294726 -0.16666667
 v -0.872678    0.0         0.16666667
 v -0.7060113  -0.51294726 -0.16666667
 v -0.26967233 -0.82996607  0.16666667
 v  0.26967233 -0.82996607 -0.16666667
 v  0.7060113  -0.51294726  0.16666667
 v  0.872678    0.0        -0.16666667
 v  0.16666667  0.51294726 -0.7060113
 v -0.436339    0.31701884 -0.7060113
 v -0.436339   -0.31701884 -0.7060113
 v  0.16666667 -0.51294726 -0.7060113
 v  0.53934467  0.0        -0.7060113

 # 12 faces

 f 1 2 3 4 5
 f 1 6 7 8 2
 f 2 8 9 10 3
 f 3 10 11 12 4
 f 4 12 13 14 5
 f 5 14 15 6 1
 f 20 19 18 17 16
 f 20 15 14 13 19
 f 19 13 12 11 18
 f 18 11 10 9 17
 f 17 9 8 7 16
 f 16 7 6 15 20
*/

 Point3f[] pts=new Point3f[20];

 try
 {

 }catch(Exception ex)
 {
         ex.printStackTrace();
 }

 pts[0]= new Point3f(  0.436339f,    0.31701884f,
0.7060113f);
 pts[1]= new Point3f( -0.16666667f,  0.51294726f,
0.7060113f);
 pts[2]= new Point3f( -0.53934467f,  0.0f,
0.7060113f);
 pts[3]= new Point3f( -0.16666667f, -0.51294726f,
0.7060113f);
 pts[4]= new Point3f(  0.436339f,   -0.31701884f,
0.7060113f);
 pts[5]= new Point3f(  0.7060113f,   0.51294726f,
0.16666667f);
 pts[6]= new Point3f(  0.26967233f,  0.82996607f,
-0.16666667f);
 pts[7]= new Point3f( -0.26967233f,  0.82996607f,
0.16666667f);
 pts[8]= new Point3f( -0.7060113f,   0.51294726f,
-0.16666667f);
 pts[9]= new Point3f( -0.872678f,    0.0f,
0.16666667f);
 pts[10]= new Point3f( -0.7060113f,  -0.51294726f,
-0.16666667f);
 pts[11]= new Point3f( -0.26967233f, -0.82996607f,
0.16666667f);
 pts[12]= new Point3f(  0.26967233f, -0.82996607f,
-0.16666667f);
 pts[13]= new Point3f(  0.7060113f,  -0.51294726f,
0.16666667f);
 pts[14]= new Point3f(  0.872678f,    0.0f,
-0.16666667f);
 pts[15]= new Point3f(  0.16666667f,  0.51294726f,
-0.7060113f);
 pts[16]= new Point3f( -0.436339f,    0.31701884f,
-0.7060113f);
 pts[17]= new Point3f( -0.436339f,   -0.31701884f,
-0.7060113f);
 pts[18]= new Point3f(  0.16666667f, -0.51294726f,
-0.7060113f);
 pts[19]= new Point3f(  0.53934467f,  0.0f,
-0.7060113f);

 // the faces
  int[] indices={0, 1, 2, 3, 4, //face 1
                 0, 5, 6, 7, 1, // face 2
                 1, 7, 8,9, 2,  // face 3
                 2,9,10,11, 3,
                 3,11,12,13, 4,
                 4,13,14, 5, 0,
                 19,18,17,16,15,
                 19,14,13,12,18,
                 18,12,11,10,17,
                 17,10,9,8,16,
                 16,8,7,6,15,
                 15,6,5,14,19
                 };

 // the number of vertices of each face
 int[] stripCounts={5,5,5,5,5,5,5,5,5,5,5,5,};

 // a tuple2f for each vertex
 // for a complete texturing there actually  5*12
TexCoord2f to assigned ..
 // but this use a economic this is just a exemple
 TexCoord2f[] texcoords1 = new TexCoord2f[20];

 texcoords1[0] = new TexCoord2f(0.50f,0.10f);
 texcoords1[1] = new TexCoord2f(0.75f,0.35f);
 texcoords1[2] = new TexCoord2f(0.65f,0.75f);
 texcoords1[3] = new TexCoord2f(0.35f,0.75f);
 texcoords1[4] = new TexCoord2f(0.25f,0.35f);

 texcoords1[5] = new TexCoord2f(0.50f,0.10f);
 texcoords1[6] = new TexCoord2f(0.75f,0.35f);
 texcoords1[7] = new TexCoord2f(0.65f,0.75f);
 texcoords1[8] = new TexCoord2f(0.35f,0.75f);
 texcoords1[9] = new TexCoord2f(0.25f,0.35f);

 texcoords1[10] = new TexCoord2f(0.50f,0.10f);
 texcoords1[11] = new TexCoord2f(0.75f,0.35f);
 texcoords1[12] = new TexCoord2f(0.65f,0.75f);
 texcoords1[13] = new TexCoord2f(0.35f,0.75f);
 texcoords1[14] = new TexCoord2f(0.25f,0.35f);

 texcoords1[15] = new TexCoord2f(0.50f,0.10f);
 texcoords1[16] = new TexCoord2f(0.75f,0.35f);
 texcoords1[17] = new TexCoord2f(0.65f,0.75f);
 texcoords1[18] = new TexCoord2f(0.35f,0.75f);
 texcoords1[19] = new TexCoord2f(0.25f,0.35f);

  // I like Geometry Info. It's easier to create
shapes ;-)
  GeometryInfo gi = new
GeometryInfo(GeometryInfo.POLYGON_ARRAY);
 // initialize the geometry info here

  gi.setUseCoordIndexOnly(true);
  gi.setCoordinateIndices(indices);
  gi.setCoordinates(pts);
  gi.setStripCounts(stripCounts);

  // one set of 2D textures
  gi.setTextureCoordinateParams(1, 2);
  // for unit 0, apply texcoords1
  gi.setTextureCoordinates(0, texcoords1);

 // gi.indexify(true);


  NormalGenerator ng = new NormalGenerator();
  ng.generateNormals(gi);
  gi.recomputeIndices();
  // stripify
  Stripifier st = new Stripifier();
  st.stripify(gi);
  gi.recomputeIndices();

  GeometryArray myPolyhedron = gi.getGeometryArray();

  Shape3D shape = new Shape3D();

  shape.setGeometry(myPolyhedron);
 /** Appearance  **/
  Appearance app = new Appearance();
  Material mat = new Material();
  PolygonAttributes polyAtt= new
  PolygonAttributes(PolygonAttributes.POLYGON_FILL,
                                 PolygonAttributes.CULL_BACK,
                                 0.0f);

  app.setMaterial(mat);
  app.setPolygonAttributes(polyAtt);



   try
    {
        if (texImageURL == null) // applet mode
         texImageURL = new
java.net.URL(getCodeBase().toString() +
"/stone.jpg");

    // if texture ok lets load it.
           Texture tex = new TextureLoader(texImageURL,
this).getTexture();
           app.setTexture(tex);
           TextureAttributes texAttr = new
TextureAttributes();

texAttr.setTextureMode(TextureAttributes.MODULATE);
       app.setTextureAttributes(texAttr);


    }
          catch (java.net.MalformedURLException ex)
            {
                System.out.println(ex.getMessage());
                }


  Texture tex = new TextureLoader(texImageURL,
this).getTexture();
  app.setTexture(tex);
  TextureAttributes texAttr = new TextureAttributes();
  texAttr.setTextureMode(TextureAttributes.MODULATE);
  app.setTextureAttributes(texAttr);

  shape.setAppearance(app);

  TransformGroup tg=new TransformGroup();
  tg.addChild(shape);

    GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(config);
    SimpleUniverse universe = new SimpleUniverse(c);

    add("Center",c);

    BranchGroup group = new BranchGroup();
    group.addChild(tg);


    Color3f  light1Color = new Color3f(0.99f, 0.99f,
0.82f);
    Vector3f light1Direction = new Vector3f(0.4f,
-0.2f, -1.0f);

    Color3f  light2Color = new Color3f(0.82f, 0.99f,
0.99f);
    Vector3f light2Direction = new Vector3f(-0.5f,
-0.5f, -0.70f);

    DirectionalLight dl = new
DirectionalLight(light1Color,light1Direction);
    dl.setInfluencingBounds(bounds);

    DirectionalLight dl2 = new
DirectionalLight(light2Color,light2Direction);
    dl2.setInfluencingBounds(bounds);



   // a blue background
    Background background = new Background(new
Color3f(0.0f,0.2f,0.5f));
    background.setApplicationBounds(bounds);

    group.addChild(background);


   // add the behaviors to the ViewingPlatform
   ViewingPlatform viewingPlatform =
universe.getViewingPlatform();

   viewingPlatform.setNominalViewingTransform();
   PlatformGeometry pg = new PlatformGeometry();
   pg.addChild(dl);
   pg.addChild(dl2);

   viewingPlatform.setPlatformGeometry(pg);


   // add orbit behavior to ViewingPlatform
   OrbitBehavior orbit = new OrbitBehavior(c,
OrbitBehavior.REVERSE_ALL |
     OrbitBehavior.STOP_ZOOM);
   orbit.setSchedulingBounds(bounds);

   viewingPlatform.setViewPlatformBehavior(orbit);

    universe.addBranchGraph(group);

 }


 static public void main(String[] args)
 {
          if (args.length > 0)
             {
                    try
                    {
                        texImageURL = new java.net.URL("file:" +
args[0]);
                    }
                    catch (java.net.MalformedURLException ex)
                    {
                       System.out.println(ex.getMessage());
                           System.exit(1);
                    }
                }
                else
                {
                    // the path to the image for an application
                    try {
                        texImageURL = new
java.net.URL("file:./earth.jpg");
                    }
                    catch (java.net.MalformedURLException ex)
                    {
                        ex.printStackTrace();
                            System.exit(1);
                    }
          }
 new MainFrame(new ThePolyhedron(),256,256);
 }

 } // end of class



______________________________________________________________________

Yahoo! GeoCities: a maneira mais fácil de criar seu web site grátis!
http://br.geocities.yahoo.com/

===========================================================================
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