I'm trying to implement a ray casting using PickTool object. I've got
several meshes representing parts of an object. Each mesh has been
generated with a TriangleArray structure,as follows:
triangle[n] = new TriangleArray(point[n],
(TriangleArray.COORDINATES)
| (TriangleArray.COLOR_3) );
.
.
.
triangle[n].setCoordinate(ind, new
Point3d(point.x,point.y,point.z));
triangle[n].setColor(ind, color);
ind++;
And the Capabilities of triangle has been changed to
triangle[n].setCapability(TriangleArray.ALLOW_COORDINATE_READ);
triangle[n].setCapability(TriangleArray.ALLOW_COORDINATE_WRITE);
triangle[n].setCapability(TriangleArray.ALLOW_COUNT_READ);
triangle[n].setCapability(TriangleArray.ALLOW_COUNT_WRITE);
triangle[n].setCapability(TriangleArray.ALLOW_FORMAT_READ);
triangle[n].setCapability(TriangleArray.ALLOW_COLOR_READ);
triangle[n].setCapability(TriangleArray.ALLOW_COLOR_WRITE);
to allow picking, and then for the Shape3D object:
shape[n] = new Shape3D(triangle[n]);
shape[n].setCapability(Shape3D.ALLOW_GEOMETRY_READ);
Well, after that I'm trying to get some information from the picked
object, as follows:
Line line;
Point2d imagePnt = new Point2d();
PickTool pickTool = new PickTool(objRoot);
pickTool.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
PickResult closest;
PickIntersection intersect;
Color4f color = new Color4f();
int pixel=0;
for(int i=0;i<fil;i++)
{
for(int j=0;j<col;j++)
{
imagePnt.set((double)j,(double)i);
line=cam1.getLine(imagePnt);
pickTool.setShapeRay(line.point(),line.vec());
closest=pickTool.pickClosest();
if (closest==null)
{
image[pixel] = 0;
}
else
{
if (closest.numIntersections() <1)
{
image[pixel]=0;
}
else
{
intersect =closest.getClosestIntersection(line.point());
color=intersect.getPointColor(); <----- It gets null object
System.out.println(color);
image[pixel]=(float)(color.x);
}
pixel++;
}
}
The problem I have is that I'm not able to get any color information
from the Pickesult object. It gets null object every time.
Since I'm really new in Java3d programming maybe it's a problem of
implementation. So could anyone give some advice in that?
Thanks in advance.
