示例#1
0
  /**
   * Notification that the script has completed the setup and should go about its own internal
   * initialization.
   */
  public void initialize() {
    touchTime = (SFTime) fields.get("touchTime");

    // Listen to events on touchTime
    touchTime.addX3DEventListener(this);

    // Create nodes directly in the parent scene
    X3DScene scene = (X3DScene) browser.getExecutionContext();

    X3DShapeNode shape = (X3DShapeNode) scene.createNode("Shape");
    X3DGeometryNode box = (X3DGeometryNode) scene.createNode("Box");
    X3DNode touchSensor = scene.createNode("TouchSensor");

    shape.setGeometry(box);

    // Create a Group to hold the nodes
    X3DGroupingNode group = (X3DGroupingNode) scene.createNode("Group");

    // Add the shape and sensor to the group
    group.addChild(shape);
    group.addChild(touchSensor);

    // Add the nodes to the scene
    scene.addRootNode(group);

    // Get a handle to the toplevel execution context
    scene.addRoute(touchSensor, "touchTime", selfRef, "touchTime");
  }
示例#2
0
  public void initialize() {
    // System.out.println("Creating Fence geometry");
    int num = 0;
    int len = startField.getSize();
    float[] start = new float[3];
    float[] end = new float[3];
    float height;

    // One shape for a panel, panelTop and post, post Top
    int shape_groups = 4;

    int num_panels = len;
    int num_panels_per_shape = fencesPerShapeField.getValue();
    int num_shapes = (num_panels / num_panels_per_shape) * shape_groups;
    int num_posts_per_shape = num_panels_per_shape;

    // System.out.println("Number of posts: " + len);
    // System.out.println("Number of panels: " + num_panels);
    // System.out.println("Number of shapes: " + num_shapes);
    // System.out.println("Number of panels per shape: " + num_panels_per_shape);
    // System.out.println("Number of posts per shape: " + num_posts_per_shape);

    X3DNode[] shapes = new X3DNode[num_shapes];

    X3DExecutionContext mainScene = browser.getExecutionContext();

    // Create a common Appearance to share

    X3DNode[] appearances = new X3DNode[appearanceField.getSize()];
    appearanceField.getValue(appearances);

    X3DNode panel_appearance = appearances[panelAppearanceField.getValue()];
    X3DNode panelTop_appearance = appearances[panelTopAppearanceField.getValue()];
    X3DNode panelRail_appearance = appearances[panelRailAppearanceField.getValue()];
    X3DNode post_appearance = appearances[postAppearanceField.getValue()];
    X3DNode postTop_appearance = appearances[postTopAppearanceField.getValue()];

    int shape_idx = 0;

    // Create Panels

    X3DNode[] new_shapes =
        createSegmentGeom(
            mainScene,
            panel_appearance,
            postField,
            postGeometryField,
            panelHeightField,
            startField,
            endField,
            false,
            null,
            len,
            (num_shapes / shape_groups),
            num_posts_per_shape,
            true,
            true,
            1,
            1);

    for (int i = 0; i < new_shapes.length; i++) {
      shapes[shape_idx++] = new_shapes[i];
    }

    // Create PanelTops
    new_shapes =
        createSegmentGeom(
            mainScene,
            panelTop_appearance,
            postField,
            postGeometryField,
            panelTopHeightField,
            startField,
            endField,
            true,
            panelHeightField,
            len,
            (num_shapes / shape_groups),
            num_posts_per_shape,
            true,
            true,
            15,
            10);

    for (int i = 0; i < new_shapes.length; i++) {
      X3DNode panel_shape = mainScene.createNode("Shape");
      shapes[shape_idx++] = new_shapes[i];
    }

    // Create Posts
    new_shapes =
        createVertexGeom(
            mainScene,
            post_appearance,
            postField,
            postGeometryField,
            postSizeField,
            startField,
            endField,
            false,
            null,
            (num_shapes / shape_groups),
            num_posts_per_shape);

    for (int i = 0; i < new_shapes.length; i++) {
      X3DNode panel_shape = mainScene.createNode("Shape");
      shapes[shape_idx++] = new_shapes[i];
    }

    // Create PostTops
    new_shapes =
        createVertexGeom(
            mainScene,
            postTop_appearance,
            postTopField,
            postTopGeometryField,
            postTopSizeField,
            startField,
            endField,
            true,
            postSizeField,
            (num_shapes / shape_groups),
            num_posts_per_shape);

    for (int i = 0; i < new_shapes.length; i++) {
      shapes[shape_idx++] = new_shapes[i];
    }

    childrenField.setValue(shapes.length, shapes);

    // System.out.println("Done creating fence geometry");
  }