White Morph wrote:
> Hi,
>
> I have 2 polygons, each uses GeometryInfo to generate its indexedGeometryArray. A
>BranchGroup is created to add both Shape3D objects into it. There are some problems:
>(please see my code attached, you can try)
>
> 1. if I just add either of the 2 Shape3D objects into the BranchGroup, the bounding
>center is just the same as I add all of them into the group, so I guess the Java3D
>class calculate the bounding center using all of the vertices instead of only the
>vertices the Geometry object refers to.
>
Bug 4720938
- IndexedGeometry shouldn't consider vertex not reference by index in
computeBound
is submitted for this. Current implementation will use all vertices pass
in IndexedGeometryArray even though some of them is not actually
reference by index array.
> 2. when I just add one of the polygons into the group, the picking for this polygon
>is correct, but if I add both of them into the group, the picking for the first one
>is not correct, the second one is correct.
>
Bounds picking is used by default and both Geometry occupy by the same
bound. So it is possible for this case happen.
Add
pickCanvas.setMode(PickTool.GEOMETRY);
in the constructor of PickAllMouseBehavior should fix it.
> 3. Even when I just add one polygon into the group, if I use
>PickCanvas.setShape(PickPoint, startPoint) before I use pickAllSorted(). I got a
>Runtime exception: java.lang.RuntimeException: PointArray0
>
> Could you please try my code? Did I have sth wrong or else? Thank you very much!
>
PickPoint is not support in PickResult so RuntimeException throws.
Try to use PickRay in this case.
Thanks.
- Kelvin
------------------
Java 3D Team
Sun Microsystems Inc.
> /*
> * PickAllTest.java
> *
> * Created on July 23, 2002, 10:15 AM
> */
>
> /**
> *
> * @author
> */
> import javax.vecmath.*;
> import javax.media.j3d.*;
> import com.sun.j3d.utils.picking.PickTool;
> import com.sun.j3d.utils.universe.*;
> import com.sun.j3d.utils.geometry.*;
> import java.awt.*;
>
> public class PickAllTest extends javax.swing.JFrame {
>
> /** Creates new form PickAllTest */
> public PickAllTest() {
> initComponents();
> initGraphics();
> }
>
> /** This method is called from within the constructor to
> * initialize the form.
> * WARNING: Do NOT modify this code. The content of this method is
> * always regenerated by the Form Editor.
> */
> private void initComponents() {
>
> addWindowListener(new java.awt.event.WindowAdapter() {
> public void windowClosing(java.awt.event.WindowEvent evt) {
> exitForm(evt);
> }
> });
>
> pack();
> java.awt.Dimension screenSize =
>java.awt.Toolkit.getDefaultToolkit().getScreenSize();
> setSize(new java.awt.Dimension(640, 480));
> setLocation((screenSize.width-640)/2,(screenSize.height-480)/2);
> }
>
> /** Exit the Application */
> private void exitForm(java.awt.event.WindowEvent evt) {
> System.exit(0);
> }
>
> private void initGraphics(){
> GraphicsConfiguration config =
> SimpleUniverse.getPreferredConfiguration();
>
> canvas = new Canvas3D(config);
> u = new SimpleUniverse(canvas);
>
> imagePanel = new javax.swing.JPanel(new java.awt.BorderLayout());
> getContentPane().add(imagePanel, java.awt.BorderLayout.CENTER);
>
> imagePanel.add(canvas, java.awt.BorderLayout.CENTER);
>
> BranchGroup scene = createSceneGraph();
>
>
> ViewingPlatform viewingPlatform = u.getViewingPlatform();
> Transform3D t = new Transform3D();
> Point3d cp = new Point3d();
> bounds.getCenter(cp);
> System.out.println("The bounding center is "+cp.x+", "+cp.y+", "+cp.z);
>
> t.set(new Vector3d(cp.x, cp.y, cp.z+2.5*bounds.getRadius()));
> (viewingPlatform.getViewPlatformTransform()).setTransform(t);
>
> u.addBranchGraph(scene);
>
>
> imagePanel.updateUI();
> }
>
> private BranchGroup createSceneGraph(){
> double vertices[] = {-2,-1,0, -1,-2,0, 0,-1,0, 0,1,0, -2,1,0, 2,-1,-1,
>2,1,0};
>
> Shape3D part1 = new Shape3D();
> int []part1Index = {0, 1, 2, 3, 4};
> int []stripCounts1 = new int[1];
> int []stripCounts2 = new int[1];
>
> stripCounts1[0] = part1Index.length;
>
> GeometryInfo gi1 = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
> gi1.setCoordinates(vertices);
> gi1.setCoordinateIndices(part1Index);
> gi1.setStripCounts(stripCounts1);
>
>
> Stripifier st1 = new Stripifier();
> st1.stripify(gi1);
>
> IndexedGeometryArray ga1 = gi1.getIndexedGeometryArray();
> ga1.setUserData("left polygon");
>
> part1.setGeometry(ga1);
>
> Appearance myApp1 = new Appearance();
> ColoringAttributes colorAttr1 = new ColoringAttributes(0.5f, 0.4f, 0.0f,
>ColoringAttributes.SHADE_GOURAUD);
>
> myApp1.setColoringAttributes(colorAttr1);
> part1.setAppearance(myApp1);
> part1.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
> part1.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
> part1.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
> PickTool.setCapabilities(part1, PickTool.INTERSECT_FULL);
>
>
>
> Shape3D part2 = new Shape3D();
> int []part2Index = {2, 5, 6, 3};
>
> GeometryInfo gi2 = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
> gi2.setCoordinates(vertices);
> gi2.setCoordinateIndices(part2Index);
> stripCounts2[0] = part2Index.length;
> gi2.setStripCounts(stripCounts2);
>
>
> Stripifier st2 = new Stripifier();
> st2.stripify(gi2);
>
> IndexedGeometryArray ga2 = gi2.getIndexedGeometryArray();
> ga2.setUserData("right polygon");
> part2.setGeometry(ga2);
>
> Appearance myApp2 = new Appearance();
> ColoringAttributes colorAttr2 = new ColoringAttributes(0.2f, 0.7f, 0.0f,
>ColoringAttributes.SHADE_GOURAUD);
>
> myApp2.setColoringAttributes(colorAttr2);
> part2.setAppearance(myApp2);
> part2.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
> part2.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
> part2.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
> PickTool.setCapabilities(part2, PickTool.INTERSECT_FULL);
>
> BranchGroup group = new BranchGroup();
>
> //Here is the interesting thing, try to comment out one of them or change
>the order of them
> //group.addChild(part2);
> group.addChild(part1);
>
> bounds = new BoundingSphere(group.getBounds());
> PickAllMouseBehavior pick = new PickAllMouseBehavior(group, canvas, bounds);
> pick.setEnable(true);
> group.addChild(pick);
>
> group.compile();
>
> return group;
> }
>
>
> public static void main(String args[]) {
> new PickAllTest().show();
> }
>
>
> // Variables declaration - do not modify
> // End of variables declaration
>
> private BoundingSphere bounds;
> private SimpleUniverse u;
> private Canvas3D canvas;
> private javax.swing.JPanel imagePanel;
> }
>
>
> /*
> * PickAllMouseBehavior.java
> *
> * Created on July 23, 2002, 1:26 PM
> */
>
> /**
> *
> * @author
> * @version
> */
> import javax.vecmath.*;
> import javax.media.j3d.*;
> import com.sun.j3d.utils.picking.behaviors.PickMouseBehavior;
> import com.sun.j3d.utils.picking.PickResult;
> import com.sun.j3d.utils.picking.PickIntersection;
>
> public class PickAllMouseBehavior extends PickMouseBehavior {
>
> /** Creates new PickAllMouseBehavior */
> public PickAllMouseBehavior(BranchGroup root, Canvas3D canvas, Bounds bounds) {
> super(canvas, root, bounds);
> this.setSchedulingBounds(bounds);
> }
>
> public void updateScene(int xpos, int ypos) {
> if (!mevent.isMetaDown() && !mevent.isAltDown()){
>
> pickCanvas.setShapeLocation(xpos, ypos);
> PickResult pr = pickCanvas.pickClosest();
>
> if(pr != null ){
> GeometryArray g = pr.getGeometryArray();
> String str = (String)(g.getUserData());
> if(str != null)
> System.out.println("This is the \""+str+"\" part!");
>
> if(pr.numIntersections() > 0){
> PickIntersection pi = pr.getIntersection(0);
> if(pi != null){
> Point3d localPt = pi.getClosestVertexCoordinates();
> PickPoint pp = new PickPoint(localPt);
> pickCanvas.setShape(pp, localPt);
> }
>
> PickResult[] pra = pickCanvas.pickAllSorted();
> if(pra == null)
> return;
>
> System.out.println("The number of GeometryArrays picked is:
>"+pra.length);
>
> GeometryArray[] ga = new GeometryArray[pra.length];
>
> }
> }
> }
>
> }
>
> }
>
> ===========================================================================
> 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".