コード例 #1
0
  /** Clear the child node list of all children - both VRML and OpenGL. */
  protected void clearChildren() {

    int size = vfChildren.size();
    for (int i = 0; i < size; i++) {
      OGLVRMLNode node = (OGLVRMLNode) vfChildren.get(i);
      Node ogl_node = (Node) oglChildMap.get(node);
      removedChildren.add(ogl_node);
      oglChildMap.remove(node);
    }

    if (!inSetup) {
      if (implGroup.isLive()) {
        implGroup.boundsChanged(this);
      } else {
        removedChildren.clear();
        implGroup.removeAllChildren();
      }
    }

    if (sensorList != null) sensorList.clear();

    OGLUserData data = (OGLUserData) implGroup.getUserData();

    if (data != null) {
      data.sensors = null;
    }

    super.clearChildren();
  }
コード例 #2
0
  /**
   * Add a single child node to the list of available children. This auto matically deals with
   * DEF/USE and adds links and branchgroups where appropriate. When nodes are null, we do not add
   * them to the GL representation, only to the vfChildren list.
   *
   * @param node The node to view
   * @throws InvalidFieldValueException This is a bindable node shared
   */
  protected void addChildNode(VRMLNodeType node) throws InvalidFieldValueException {

    super.addChildNode(node);

    OGLVRMLNode n = (OGLVRMLNode) node;

    if (!inSetup) {
      Node ogl_node = (Node) n.getSceneGraphObject();
      oglChildMap.put(node, ogl_node);

      if (implGroup.isLive()) {
        addedChildren.add(ogl_node);
        implGroup.boundsChanged(this);
      } else implGroup.addChild(ogl_node);
    }

    // Finally check for sensors that we need to deal with.
    VRMLPointingDeviceSensorNodeType sensor = null;

    if (node instanceof VRMLPointingDeviceSensorNodeType)
      sensor = (VRMLPointingDeviceSensorNodeType) node;
    else if (node instanceof VRMLProtoInstance) {
      Object impl = ((VRMLProtoInstance) node).getImplementationNode();

      if (impl instanceof VRMLPointingDeviceSensorNodeType)
        sensor = (VRMLPointingDeviceSensorNodeType) impl;
    }

    if (sensor != null) {
      // So we have a valid sensor. Let's now add it to the
      // system. We only add the sensor itself, even if wrapped in a
      // proto. This is so that the processing of sensors doesn't need
      // to stuff around with the details of protos. As far as the proto
      // node is concerned it just wants the full events, not the
      // restricted view the outside of the proto would give.
      if (inSetup) sensorList.add(sensor);
      else {
        OGLUserData data = (OGLUserData) implGroup.getUserData();

        if (data == null) {
          data = new OGLUserData();
          implGroup.setUserData(data);
        }

        if (data.sensors == null) {
          data.sensors = new VRMLPointingDeviceSensorNodeType[1];
          data.sensors[0] = sensor;
        } else {
          int size = data.sensors.length;
          VRMLPointingDeviceSensorNodeType[] tmp = new VRMLPointingDeviceSensorNodeType[size + 1];

          System.arraycopy(data.sensors, 0, tmp, 0, size);
          tmp[size] = sensor;
          data.sensors = tmp;
        }
      }
    }
  }
コード例 #3
0
  /**
   * Notification that the rendering of the event model is complete and that rendering is about to
   * begin. Used to update the transformation matrix only once per frame.
   */
  public void allEventsComplete() {
    if (implGroup.isLive()) {
      implGroup.boundsChanged(this);
    } else {
      updateNodeBoundsChanges(implGroup);
    }

    super.allEventsComplete();
  }
コード例 #4
0
  /**
   * Set the visible field. Renderer specific impl.
   *
   * @param value The new value.
   */
  protected void setVisible(boolean[] value, int numValid) {
    super.setVisible(value, numValid);

    if (inSetup) return;

    maskChanged = true;

    if (implGroup.isLive()) implGroup.boundsChanged(this);
    else updateNodeBoundsChanges(implGroup);
  }
コード例 #5
0
  /**
   * Remove the given node from this grouping node. If the node is not a child of this node, the
   * request is silently ignored.
   *
   * @param node The node to remove
   */
  protected void removeChildNode(VRMLNodeType node) {
    if (!oglChildMap.containsKey(node)) return;

    if (!inSetup) {
      Node ogl_node = (Node) oglChildMap.get(node);
      oglChildMap.remove(node);

      if (implGroup.isLive()) {
        removedChildren.add(ogl_node);
        implGroup.boundsChanged(this);
      } else implGroup.removeChild(ogl_node);
    }

    // Check to see if it is a sensor node and in therefore needs to be
    // removed from the current list.

    VRMLPointingDeviceSensorNodeType sensor = null;

    if (node instanceof VRMLPointingDeviceSensorNodeType)
      sensor = (VRMLPointingDeviceSensorNodeType) node;
    else if (node instanceof VRMLProtoInstance) {
      Object impl = ((VRMLProtoInstance) node).getImplementationNode();

      if (impl instanceof VRMLPointingDeviceSensorNodeType)
        sensor = (VRMLPointingDeviceSensorNodeType) impl;
    }

    if (sensor != null) {
      OGLUserData data = (OGLUserData) oglImplGroup.getUserData();

      int size = data.sensors.length;

      if (size == 1) {
        data.sensors = null;
      } else {
        int i;

        for (i = 0; i < size; i++) {
          if (data.sensors[i] == sensor) break;
        }

        for (; i < size - 1; i++) data.sensors[i] = data.sensors[i + 1];

        // now resize the array to suit
        VRMLPointingDeviceSensorNodeType[] tmp = new VRMLPointingDeviceSensorNodeType[size - 1];

        System.arraycopy(data.sensors, 0, tmp, 0, size - 1);
        data.sensors = tmp;
      }
    }

    super.removeChildNode(node);
  }
コード例 #6
0
  /**
   * Notification that the construction phase of this node has finished. If the node would like to
   * do any internal processing, such as setting up geometry, then go for it now.
   */
  public void setupFinished() {
    if (!inSetup) return;

    super.setupFinished();

    if (isStatic && shareCount == 0) {
      oglImplGroup = implGroup;
    } else {
      oglImplGroup = new SharedGroup();
      oglImplGroup.addChild(implGroup);
    }

    // Check what sensors we have available and register those with the
    // user data information.
    if (!isStatic && (sensorList.size() != 0)) {
      OGLUserData data = new OGLUserData();
      implGroup.setUserData(data);

      data.sensors = new VRMLPointingDeviceSensorNodeType[sensorList.size()];

      sensorList.toArray(data.sensors);
    }

    sensorList = null;

    oglChildMap = new HashMap();
    oglChildList = new LinkedList();

    for (int i = 0; i < childCount; i++) {
      OGLVRMLNode node = (OGLVRMLNode) vfChildren.get(i);

      Node ogl_node = (Node) node.getSceneGraphObject();
      implGroup.addChild(ogl_node);

      oglChildList.add(ogl_node);
      oglChildMap.put(node, ogl_node);
    }

    if (!isStatic) {
      removedChildren = new LinkedList();
      addedChildren = new LinkedList();
    }

    // Need to fix this, not handling the list being different size to th
    // real values.
    System.out.println("OGLCADLayer not handling numVisible correctly");
    implGroup.setMask(vfVisible);
  }