예제 #1
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();

    SphereGenerator generator = new SphereGenerator(vfRadius, 32);
    GeometryData data = new GeometryData();

    data.geometryType = GeometryData.TRIANGLE_STRIPS;
    data.geometryComponents = GeometryData.NORMAL_DATA | GeometryData.TEXTURE_2D_DATA;

    generator.generate(data);

    impl = new TriangleStripArray(false, VertexGeometry.VBO_HINT_STATIC);
    impl.setVertices(TriangleStripArray.COORDINATE_3, data.coordinates, data.vertexCount);
    impl.setStripCount(data.stripCounts, data.numStrips);
    impl.setNormals(data.normals);

    // Make an array of objects for the texture setting
    float[][] textures = {data.textureCoordinates};
    int[] tex_type = {TriangleStripArray.TEXTURE_COORDINATE_2};
    impl.setTextureCoordinates(tex_type, textures, 1);

    // Setup 4 texture units
    int[] tex_maps = new int[4];

    for (int i = 0; i < 4; i++) tex_maps[i] = 0;

    impl.setTextureSetMap(tex_maps, 4);

    OGLUserData u_data = new OGLUserData();
    u_data.geometryData = data;

    impl.setUserData(u_data);
  }
예제 #2
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();
  }
예제 #3
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;
        }
      }
    }
  }
예제 #4
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);
  }
예제 #5
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);
  }