I suggest you to do a method that return the shape3D ....
For example
Class Polyhedron
{
.
.
.
Shape3D getPolyedron()
{
shape.setGeometry(myPolyhedron);
return shape;
}
}
So, in the second class you must use this:
Polyhedron polyhedron=new Polyhedron();
>
> BranchGroup group = new BranchGroup();
>
> group.addChild(polyhedron.getPolyedron());
>
> universe.getViewingPlatform().setNominalViewingTransform();
>
> universe.addBranchGraph(group);
Citando ������� <[EMAIL PROTECTED]>:
> I have a the following class which make a polyhedron
> -----------------------------------------
> import com.sun.j3d.utils.geometry.*;
> import javax.media.j3d.*;
> import java.awt.*;
> import javax.vecmath.*;
> import javax.media.j3d.GeometryArray;
> import java.applet.Applet;
> import com.sun.j3d.utils.geometry.GeometryInfo;
>
>
> public class Polyhedron extends Applet
> {
>
> public Polyhedron()
>
> { Point3f[] pts=new Point3f[20];
>
> pts[0]= new Point3f( 0.0f, 0.0f, 1.1547f);
> pts[1]= new Point3f( 1.0f, 0.0f, 0.57735f);
> pts[2]= new Point3f( 0.333333f, 0.942809f, 0.57735f);
> pts[3]= new Point3f( -1.0f, 0.0f, 0.57735f);
> pts[4]= new Point3f( -0.333333f, -0.942809f, 0.57735f);
> pts[5]= new Point3f( 1.0f, 0.0f, -0.57735f);
> pts[6]= new Point3f( 0.666667f, -0.942809f, 0.0f);
> pts[7]= new Point3f( -0.666667f, 0.942809f, 0.0f);
> pts[8]= new Point3f( 0.333333f, 0.942809f, -0.57735f);
> pts[9]= new Point3f( -1.0f, 0.0f, -0.57735f);
> pts[10]= new Point3f( -0.333333f, -0.942809f, -0.57735f);
> pts[11]= new Point3f( 0.0f, 0.0f, -1.1547f);
>
>
> // the faces
> int[] indices={2, 1, 0,
> 0, 3, 4,
> 1, 6, 5,
> 2,8,7,
> 3,7,9,
> 4,10,6,
> 5,11,8,
> 9,11,10,
> 0,2,7,3,
> 0,4,6,1,
> 1,5,8,2,
> 3,9,10,4,
> 5,6,10,11,
> 7,8,11,9
>
> };
>
> // the number of vertices of each face
> int[] stripCounts={3,3,3,3,3,3,3,3,4,4,4,4,4,4};
>
>
> // I like Geometry Info. It's easier to create shapes ;-)
> GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
> // initialize the geometry info here
>
> gi.setCoordinateIndices(indices);
> gi.setCoordinates(pts);
> gi.setStripCounts(stripCounts);
> gi.recomputeIndices();
>
>
> 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 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);
>
> shape.setAppearance(app);
>
> TransformGroup tg=new TransformGroup();
> tg.addChild(shape);
> }
>
> }//end class
>
> -----------------------------------------
>
> I also have another class that calls the previous one as below
>
> -------------------------------------------
> import com.sun.j3d.utils.universe.*;
> import javax.media.j3d.BranchGroup;
> import com.sun.j3d.utils.applet.MainFrame;
> import javax.media.j3d.*;
> import java.awt.*;
> import java.awt.BorderLayout;
> import com.sun.j3d.utils.applet.MainFrame;
>
> public class CallClass extends java.applet.Applet{
>
>
> public CallClass () {
>
>
> SimpleUniverse universe = new SimpleUniverse();
>
> GraphicsConfiguration config = universe.getPreferredConfiguration();
>
>
> Canvas3D c = new Canvas3D(config);
>
> Polyhedron polyhedron=new Polyhedron();
>
> BranchGroup group = new BranchGroup();
>
> group.addChild(polyhedron);
>
> universe.getViewingPlatform().setNominalViewingTransform();
>
> universe.addBranchGraph(group);
>
>
> }
>
> public static void main(String[] args) {
>
>
> new CallClass();
>
>
>
> }
> }//end class CallClass
> -------------------------------------------
>
>
> The problem is that when i am compiling the second class i recieve the
> following error
>
> D:\java\Java3d Project\tests\Hard tests\CallClass.java:26:
> addChild(javax.media.j3d.Node) in javax.media.j3d.Group cannot be applied to
> (Polyhedron)
> group.addChild(polyhedron);
> ^
> 1 error
>
>
> What is wrong?
>
>
>
>
/*********************************************
SILVANO MALFATTI
COMPUTER SCIENCE - URI University
HOME - http://www.urisan.tche.br/~smalfatti
********************************************/
-------------------------------------------------
URI - Campus de Santo Angelo-RS
http://www.urisan.tche.br
===========================================================================
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".