Hi, all
I have a Java3D Scene graph like this

                                        Locale
                                            |
                                            |
                                        rootBG
                                            |
                                            |
                                        rootTG
                                        /            \
                                      /                \
               Behavior1--- BG1             BG2 ---- Behavior2
                           \       /                        \      /
                             \   /                            \ /
                            TG1                        TG2
                               |                               |
                        Shape3D1             Shape3D2

The goal is to delete the Shape3D2 from  a PickResult object  generated
by a PickCanvas.
For this purpose I have extended  the  Behavior class.
Then I recover the SceneGraphPath from PickResult and I get  the
terminal node ?
When this one is Shape3D, I search the corresponding  BG here (BG1 or
BG2) then  remove it from the local.
The strange think occurs is that after deleting, the Shape3D remaining
can't be delete and  does not
reponse any more to my  behavior class. This is  two  classes used for
deleting.




import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.picking.*;
import com.sun.j3d.utils.picking.behaviors.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;

/** This class is made for use with the class Tools. It is used to link GUI
 *  components such as buttons and menu items to methods of the class
Tools.
 */
public class ToolsBehavior extends Behavior
{ float size=0.5f;
  private static double sphereDistance = 0.1;
  PickCanvas pickCanvas;
  PickResult[] pickResult = null;
  BranchGroup rootBranchGroup;
  javax.media.j3d.Locale locale;
  public SceneCreator creator = null;
  boolean intersectOrNot = false;
  PickResult[] intersectPickResult = null;
  private SceneGraphPath path;
  private Node node;
  private PickIntersection pi;
  private Point3d eyePos;
  private String doAction = "Delete";

  /** Constructs a ToolsBehavior object by giving it references to
Canvas3D,
   *  Locale, BranchGroup.
   *
   *  @param canvas3D The Canvas3D object used to interact with the scene.
   *  @param locale The Locale object of the scene.
   *  @param branchGroup The root of the objects to handle.
   */
 public ToolsBehavior(Canvas3D canvas3D, javax.media.j3d.Locale locale,
BranchGroup branchGroup,  SceneCreator sc)
  {
    rootBranchGroup = branchGroup;
    this.locale = locale;
    creator = sc;
    pickCanvas = new PickCanvas(canvas3D, branchGroup);
    pickCanvas.setTolerance(2.0f);
    pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
  }

  /** Initialising method.
   *
   */
  public void initialize()
  { wakeupOn (new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
  }

  /** Process Stimulus meothod.
   *
   */
  public void processStimulus (Enumeration criteria)
  { WakeupCriterion wakeup;
    AWTEvent[] event;
    int eventId;
    while (criteria.hasMoreElements())
    { wakeup = (WakeupCriterion) criteria.nextElement();
      if (wakeup instanceof WakeupOnAWTEvent)
      { event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
    for (int i= event.length; i-- > 0; )
        { eventId = event[i].getID();
      if (eventId == MouseEvent.MOUSE_PRESSED){
            if (((MouseEvent)event[i]).getModifiers() ==
MouseEvent.BUTTON3_MASK)
            {
              int x = ((MouseEvent)event[i]).getX();
              int y = ((MouseEvent)event[i]).getY();
              pickCanvas.setShapeLocation(x, y);
             eyePos = pickCanvas.getStartPosition ();
             pickResult = pickCanvas.pickAllSorted();
             if  (pickResult != null)
              System.out.println("Picked True ");
              if (doAction.equals("Delete") &&( pickResult != null))
Tools.deleteObject(pickResult);
            }
        }
     } //endfor
   }
 }//endwhile
wakeupOn (new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
}

I put to BG1 and BG2  an instance of  toolBehavior.


public class Tools {
..
.....

/** Method that deletes the object picked by user. (Class Tools)
   *
   * @param pickResult array of  PickResult objects according to the
user selection.
   */
  public static void deleteObject(PickResult[]  pickResult){
    if  (pickResult != null){   if (pickResult != null){ // Check if the
ray intersects an object.
       toolPATH = pickResult.getSceneGraphPath();
       toolNODE = toolPATH.getObject();
       if  ( toolNODE instanceof Shape3D ) {

SceneCreator.l.removeBranchGraph((BranchGroup)pickResult.getNode(pickResult.BRANCH_GROUP));

      }
   }
}

}//End Tools

SceneCreator is a class that  creates Virtual universe, locale, rootBG
and rootTG and view  branchGroup.


Is anybody can give me the best way to delete Shape3D1 or Shape3D2 or
the errors in my code.

Thanks for all.

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