Esempio n. 1
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;
        }
      }
    }
  }