I made the changes that Suri suggested.  He is correct that I didn't have
the
correct number of texture coordinates specified.  However, this still did
not correct
the problem because there are no texture coordinates to change.  I don't
believe it is possible to add texture coordinates on the fly.  Here's the
error message again:

> java.lang.ArrayIndexOutOfBoundsException: GeometryArray: has no texture
> coordinates



 Recall that when a geometry array is made, a variable number of arrays are
created
depending on the parameters passed.  In the following we have COORDINATES
which is always present and TEXTURE_COORDINATE_2 which is optional-so
a total of two vectors go with the quads object.  I don't think the second
array
can be added once quads is instantiated.

e.g.   QuadArray quads = new QuadArray(npoints*4, QuadArray.COORDINATES |
                              QuadArray.TEXTURE_COORDINATE_2);
--each quad is specified by 4 points.


--

So I tried copying the coordinates into a new GeometryArray that had the
TEXTURE_
COORDINATE_2 designation.  Unforetunately, I don't know what all of the
geometry types are going to be--(i.e. QuadArray, TriangleArray)--so I have
to
guess--the QuadArray is close becuase my # of virtices in this case divides
by
4.  Is there a way to see what we have without knowing in advance?

Do custom loaders have a trick for this problem?

Thanks--

Alex

> Hi Alex,
>
> Your texture coordinates array needs to have 2*npoints values (since you
are
> TEXTURE_COORDINATE_2). So you'd need to change your code like this:
>
>
>         float[] texCoords = new float[2*npoints];
>         texCoords[0] = texCoords[1] = 0.0f;
>         texCoords[2*npoints-2] = texCoords[2*npoints-1] = 1.0f;
>
>         for(int i = 1; i < 2*npoints-2; i++) {
>                 texCoords[i] = (float) i/npoints;
>                 texCoords[i+1] = (float) i/npoints;
>                 i++;
>         }
>
> That should solve your problem.

----- Original Message -----
From: "Alex Terrazas" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 11, 2001 5:05 PM
Subject: [JAVA3D] Adding texture coordinates to existing geometry


> Hi-
>
> I am using the NCSA Portfolio classes to load a .dxf file.
>
> Once I get the file, it is pretty easy to get the BranchGroup
> using the Scene.getSceneGroup() and the Shape3D's using
>
>
>          BranchGroup test = s.getSceneGroup();
>          Shape3D testShape = (Shape3D) test.getChild(1);
>
>   Now I want to add some texture coordinates and put the textures on the
> different Shape3D's.  I use the following:
>
>
>                 GeometryArray geo = (GeometryArray)
testShape.getGeometry();
>                 geo.setCapability(GeometryArray.ALLOW_TEXCOORD_WRITE);
>                 geo.setCapability(GeometryArray.ALLOW_TEXCOORD_READ);
>
>                 testShape.setAppearance(app);
>                     System.out.println("vertex: " +
geo.getValidVertexCount());
>                 int npoints = geo.getValidVertexCount();
>
>                 float[] texCoords = new float[npoints];
>                 float[] coords = new float[npoints];
>                 geo.getCoordinate(0, coords);
>
>                 texCoords[0] = 0.f;
>                 texCoords[npoints-1]=1.f;
>                 for (int ii=1; ii<npoints-1; ii++)
>
>                     texCoords[ii] = (float) (ii/npoints);
>                 }
>
> Finally, I try to set the texture coordinates.  This is where the error
> occurs:
>
>                 geo.setCapability(GeometryArray.TEXTURE_COORDINATE_2);
>                 geo.setTextureCoordinate(0,0,texCoords);
>
> The error is:
>
> vertex: 25760
> java.lang.ArrayIndexOutOfBoundsException: GeometryArray: has no texture
> coordinates
>         at
>
javax.media.j3d.GeometryArrayRetained.setTextureCoordinates(GeometryArrayRet
> ained.java:3834)
>         at
>
javax.media.j3d.GeometryArray.setTextureCoordinate(GeometryArray.java:1871)
>         at DXFLoadEx.createSceneGraph(DXFLoadEx.java:102)
>         at DXFLoadEx.<init>(DXFLoadEx.java:179)
>         at DXFLoadEx.main(DXFLoadEx.java:194)
>
> ---
>
> My question is (finally):
>
> How can I add the texture coordinates if they don't exist already on the
> GeometryArray?
>
> Thanks--
>
> Alex
>
>
===========================================================================
> 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