I created the line shapes using some geometry arrays.
PickIntersection class (java3d 1.2  beta2) works OK for LineArray
and IndexedLineArray.  I've got some problem trying to
intersect a shape based on LineStripArray or IndexedLineStripArray :
null value of
PickIntersection object.
There is a case:

//******************************************************
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import com.sun.j3d.utils.applet.MainFrame;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.utils.picking.PickCanvas;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.picking.PickIntersection;
import com.sun.j3d.utils.picking.PickTool;

public class PickDemo extends Applet implements MouseListener,
ActionListener {
  JRadioButton rbLine;
  JRadioButton rbIndexedLine;
  JRadioButton rbStripLine;
  JRadioButton rbIndexedStripLine;

  BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
1000.0);
  PickCanvas pickCanvas;
  Appearance appHighlight;
  Appearance appOrig;
  Shape3D [] shapes;
  BranchGroup objRoot; BranchGroup scene;
  public PickDemo() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    add("Center", c);
    c.addMouseListener(this);
    rbLine = new JRadioButton("LineArray");
    rbIndexedLine = new JRadioButton("IndexedLineArray");
    rbStripLine = new JRadioButton("LineStripArray");
    rbIndexedStripLine = new JRadioButton("IndexedLineStripArray");
    rbLine.addActionListener (this);
    rbIndexedLine.addActionListener (this);
    rbStripLine.addActionListener (this);
    rbIndexedStripLine.addActionListener (this);
    JPanel radioPanel = new JPanel(new GridLayout(1,4));
    radioPanel.add(rbLine);
    radioPanel.add(rbIndexedLine);
    radioPanel.add(rbStripLine);
    radioPanel.add(rbIndexedStripLine);
    add("North", radioPanel);
    ButtonGroup rbGroup = new ButtonGroup();
    rbGroup.add(rbLine);
    rbGroup.add(rbIndexedLine);
    rbGroup.add(rbStripLine);
    rbGroup.add(rbIndexedStripLine);
    appOrig = new Appearance ();
    PolygonAttributes pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    appOrig.setPolygonAttributes(pa);
    appHighlight = new Appearance ();
    Color3f color2 = new Color3f (0.0f, 0.9f, 0f);
    Material mat2 = new Material (color2, color2, color2, color2, 0f);
    mat2.setLightingEnable(true);
    appHighlight.setMaterial( mat2 );
    Color3f color1 = new Color3f (0.9f, 0f, 0f);
    Material mat1 = new Material (color1, color1, color1, color1, 0f);
    appOrig.setMaterial( mat1 );
    objRoot = new BranchGroup ();
    objRoot.setCapability (Group.ALLOW_CHILDREN_WRITE);
    objRoot.setCapability (Group.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability (Group.ALLOW_CHILDREN_READ);
    objRoot.setCapability (BranchGroup.ALLOW_DETACH);
    scene = new BranchGroup ();
    scene.setCapability (Group.ALLOW_CHILDREN_WRITE);
    scene.setCapability (Group.ALLOW_CHILDREN_EXTEND);
    scene.addChild(objRoot);
    SimpleUniverse u = new SimpleUniverse(c);
    TransformGroup vpTrans =
u.getViewingPlatform().getViewPlatformTransform();
    KeyNavigatorBehavior keybehavior = new KeyNavigatorBehavior
(vpTrans);
    keybehavior.setSchedulingBounds (bounds);
    scene.addChild (keybehavior);
    u.addBranchGraph(scene);
    pickCanvas = new PickCanvas(c, scene);
    pickCanvas.setTolerance(4.0f);
    shapes = new Shape3D [SHAPECOUNT];

  }


  public void actionPerformed(ActionEvent evt) {
    Transform3D t3 = new Transform3D ();
    if (objRoot.numChildren() > 0) {
      objRoot.detach();
      objRoot = new BranchGroup ();
      objRoot.setCapability (Group.ALLOW_CHILDREN_EXTEND);
      objRoot.setCapability (Group.ALLOW_CHILDREN_READ);
      objRoot.setCapability (BranchGroup.ALLOW_DETACH);
      scene.addChild(objRoot);
    }
    if (evt.getSource() == rbLine) {
      System.out.println ("LineArray");
      for (int i = 0; i < shapes.length; i++) {
        t3.setTranslation (new Vector3d(0.0, i*1.0, -(i + 10.)*3.0));
        TransformGroup objTrans = new TransformGroup(t3);
        BranchGroup objBGroup = new BranchGroup ();
        objBGroup.setCapability(BranchGroup.ALLOW_DETACH);
        Shape3D shape = new Line ();
        shape.setAppearance(appOrig);
        shapes [i] = shape;
        objTrans.addChild(shape);
        objBGroup.addChild (objTrans);
        objRoot.addChild(objBGroup);
      }
    }
    else if (evt.getSource() == rbIndexedLine) {
      System.out.println ("IndexedLineArray");
      for (int i = 0; i < shapes.length; i++) {
        t3.setTranslation (new Vector3d(0.0, i*1.0, -(i + 10.)*3.0));
        TransformGroup objTrans = new TransformGroup(t3);
        BranchGroup objBGroup = new BranchGroup ();
        objBGroup.setCapability(BranchGroup.ALLOW_DETACH);
        Shape3D shape = new IndexedLine ();
        shape.setAppearance(appOrig);
        shapes [i] = shape;
        objTrans.addChild(shape);
        objBGroup.addChild (objTrans);
        objRoot.addChild(objBGroup);
      }
    }
    else if (evt.getSource() == rbStripLine) {
      System.out.println ("LineStripArray");
      for (int i = 0; i < shapes.length; i++) {
        t3.setTranslation (new Vector3d(0.0, i*1.0, -(i + 10.)*3.0));
        TransformGroup objTrans = new TransformGroup(t3);
        BranchGroup objBGroup = new BranchGroup ();
        objBGroup.setCapability(BranchGroup.ALLOW_DETACH);
        Shape3D shape = new StripLine ();
        shape.setAppearance(appOrig);
        shapes [i] = shape;
        objTrans.addChild(shape);
        objBGroup.addChild (objTrans);
        objRoot.addChild(objBGroup);
      }
    }
    else if (evt.getSource() == rbIndexedStripLine) {
      System.out.println ("IndexedLineStripArray");
      for (int i = 0; i < shapes.length; i++) {
        t3.setTranslation (new Vector3d(0.0, i*1.0, -(i + 10.)*3.0));
        TransformGroup objTrans = new TransformGroup(t3);
        BranchGroup objBGroup = new BranchGroup ();
        objBGroup.setCapability(BranchGroup.ALLOW_DETACH);
        Shape3D shape = new IndexedStripLine ();
        shape.setAppearance(appOrig);
        shapes [i] = shape;
        objTrans.addChild(shape);
        objBGroup.addChild (objTrans);
        objRoot.addChild(objBGroup);
      }
    }
  }

  public void mouseClicked (MouseEvent evt) {

  }

  public void mouseEntered (MouseEvent evt) {
  }

  public void mouseExited (MouseEvent evt) {

  }

  public void mousePressed (MouseEvent evt) {
    Point3d eyePos = pickCanvas.getStartPosition ();
    pickCanvas.setShapeLocation(evt);
    PickResult[] results = pickCanvas.pickAllSorted();
    eyePos = pickCanvas.getStartPosition ();
    if (results != null) {
      int n = results.length;
      for (int k = 0; k < n; k++) {
        Shape3D pickedShape = (Shape3D)results[k].getObject();
        Geometry curGeom = pickedShape.getGeometry();
        System.out.println (curGeom.toString());
        PickIntersection pi = results [k].getClosestIntersection
(eyePos);
        if (pi != null) {
          double dist = pi.getDistance();
          System.out.println ("dist=" + dist);
          pickedShape.setAppearance(appHighlight);
        }
        else System.out.println ("PickIntersection object is null");
      }
    }
    else System.out.println ("results == null");
  }

  public void mouseReleased (MouseEvent evt) {
    for (int i=0; i < SHAPECOUNT; i++) {
      shapes [i].setAppearance(appOrig);

    }
  }

  public static void main(String[] args) {
    String s = "\nPickIntersection Test:\n";
    s += "Select the type of array and pick with the mouse over the
line\n";
    System.out.println (s);
    new MainFrame(new PickDemo (), 640, 640);
  }

  public class Line extends Shape3D {
    public Line () {
     LineArray mesh;
     Point3f[] coordinates = new Point3f[2];
     coordinates [0] = new Point3f (-1f, 1f, 0f);
     coordinates [1] = new Point3f (1f, 1f, 0f);
     mesh = new LineArray (2, GeometryArray.COORDINATES |
GeometryArray.NORMALS);
     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
     mesh.setCapability(GeometryArray.ALLOW_COUNT_READ);
     mesh.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

     mesh.setCoordinates(0, coordinates);
     this.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
     this.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
     this.setGeometry(mesh);
    }
  }

  public class IndexedStripLine extends Shape3D {
    public IndexedStripLine () {

     Point3f[] coordinates = new Point3f[2];
     coordinates [0] = new Point3f (-1f, 1f, 0f);
     coordinates [1] = new Point3f (1f, 1f, 0f);

     int[] indices = { 0, 1};

     int[] lineStripCounts = {2};

     IndexedLineStripArray mesh = new IndexedLineStripArray(
      coordinates.length, GeometryArray.COORDINATES |
GeometryArray.NORMALS, indices.length, lineStripCounts);
     mesh.setCoordinates(0, coordinates);
     mesh.setCoordinateIndices(0, indices);

     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
     mesh.setCapability(GeometryArray.ALLOW_COUNT_READ);

mesh.setCapability(IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ);
     mesh.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

     mesh.setCoordinates(0, coordinates);
     this.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
     this.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
     this.setGeometry(mesh);
    }
  }

  public class IndexedLine extends Shape3D {
    public IndexedLine () {

     Point3f[] coordinates = new Point3f[2];
     coordinates [0] = new Point3f (-1f, 1f, 0f);
     coordinates [1] = new Point3f (1f, 1f, 0f);

     int[] indices = { 0, 1};

     IndexedLineArray mesh = new IndexedLineArray(
      coordinates.length, GeometryArray.COORDINATES |
GeometryArray.NORMALS, indices.length);
     mesh.setCoordinates(0, coordinates);
     mesh.setCoordinateIndices(0, indices);

     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
     mesh.setCapability(GeometryArray.ALLOW_COUNT_READ);

mesh.setCapability(IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ);
     mesh.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

     mesh.setCoordinates(0, coordinates);
     this.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
     this.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
     this.setGeometry(mesh);
    }
  }

  public class StripLine extends Shape3D {
    public StripLine () {

     Point3f[] coordinates = new Point3f[2];
     coordinates [0] = new Point3f (-1f, 1f, 0f);
     coordinates [1] = new Point3f (1f, 1f, 0f);
     int[] lineStripCounts = {2};

     LineStripArray mesh = new LineStripArray(
      coordinates.length, GeometryArray.COORDINATES |
GeometryArray.NORMALS, lineStripCounts);

     mesh.setCoordinates(0, coordinates);
     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
     mesh.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
     mesh.setCapability(GeometryArray.ALLOW_COUNT_READ);
     mesh.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

     mesh.setCoordinates(0, coordinates);
     this.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
     this.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
     this.setGeometry(mesh);
    }
  }

  static final int SHAPECOUNT = 4;
}

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