Re: Java3D shapes to visad shapes?

Hi Stephen,

We always admire creative laziness. The only problem I can
imagine that might cause incorrect vertex connections is
that "GeometryArray sphere_geom" might not be a TriangleArray,
but may instead be Indexed or something else. The next step
is to check that.

Note that the DisplayImplJ3D.makeGeometry() method does the
reverse of what you're doing, and it works fine.

Good luck,
Bill

On Fri, 4 Mar 2005, Stephen C Harris wrote:

> Being too lazy to compute vertices and normals for the kinds of shapes I'd 
> like to display,
>  I'm trying to convert Java3D shapes (for which Sun has several nice ones 
> built in, e.g. spheres)
> to VisAD shapes, and *almost* succeeding,  in that the shape (a sphere in 
> this case) is recognizable
>  but some of the vertexes are connected wrong.  It's close enough in 
> appearance that I think it might
> be a small thing to fix though - hopefully somebody can spot what's wrong 
> with this code:
>
>  /*
>  import javax.media.j3d.Appearance;
>  import javax.media.j3d.GeometryArray;
>  import com.sun.j3d.utils.geometry.Sphere;
>  */
>
>         // Get a Java3d shape
>    Sphere sphere_j3d = new Sphere(1.0f, new Appearance());
>    GeometryArray sphere_geom = 
> (GeometryArray)sphere_j3d.getShape().getGeometry();
>
>  VisADTriangleArray sphere = new VisADTriangleArray();
>  sphere.vertexCount = sphere_geom.getValidVertexCount();
>
>         float[] coords = new float[3*sphere_geom.getValidVertexCount()];
>         float[] normals = new float[3*sphere_geom.getValidVertexCount()];
>         float[] vec = new float[3];
>
>         for (int i=0; i<sphere_geom.getValidVertexCount(); ++i)
>         {
>             sphere_geom.getCoordinate(i, vec);
>             coords[3*i] = vec[0];
>             coords[3*i + 1] = vec[1];
>             coords[3*i + 2] = vec[2];
>
>             sphere_geom.getNormal(i, vec);
>             normals[3*i] = vec[0];
>             normals[3*i + 1] = vec[1];
>             normals[3*i + 2] = vec[2];
>         }
>
>         sphere.coordinates = coords;
>
>         sphere.normals = normals;
>
>  // ////////////////////////////////////////////////////////////
>  // This shorter way has the same effect
>
>         //float[] sphere_vertexes = new float[3*sphere_geom.getVertexCount()];
>         //sphere_geom.getCoordinates(0, sphere_vertexes);
>         //sphere.coordinates = sphere_vertexes;
>
>         //float[] sphere_normals = new float[3*sphere_geom.getVertexCount()];
>         //sphere_geom.getNormals(0, sphere_normals);
>         //sphere.normals = sphere_normals;
>