Beispiel #1
0
 private void createSpinTG() {
   spin = new TransformGroup();
   spin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
   spin.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
   spin.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
   spin.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
   spin.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
 }
  /** @see boogiepants.model.Displayable#display() */
  public Node display() {
    Appearance a = new Appearance();
    Group shape = new Sphere(.15f, a);
    a.setColoringAttributes(new ColoringAttributes(.5f, .5f, 1f, ColoringAttributes.NICEST));
    a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, .3f));
    Transform3D t = new Transform3D();
    if (loPoint == null) {
      loPoint = new Point3d(0d, 0d, 0d);
    }
    t.set(new Vector3d(loPoint.x, loPoint.y, loPoint.z));
    transformGroupLo = new TransformGroup();
    transformGroupLo.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroupLo.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transformGroupLo.setTransform(t);
    transformGroupLo.addChild(shape);
    loEndpoint = endpoint(loPoint, transformGroupLo);
    Shape3D geom = (Shape3D) shape.getChild(0);
    geom.setUserData(loEndpoint);

    a = new Appearance();
    shape = new Sphere(.15f, a);
    a.setColoringAttributes(new ColoringAttributes(1f, .5f, .5f, ColoringAttributes.NICEST));
    a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, .3f));
    t = new Transform3D();
    if (hiPoint == null) {
      hiPoint = new Point3d(0d, 0d, 0d);
    }
    t.set(new Vector3d(hiPoint.x, hiPoint.y, hiPoint.z));
    transformGroupHi = new TransformGroup();
    transformGroupHi.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroupHi.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transformGroupHi.setTransform(t);
    transformGroupHi.addChild(shape);
    hiEndpoint = endpoint(hiPoint, transformGroupHi);
    geom = (Shape3D) shape.getChild(0);
    geom.setUserData(hiEndpoint);

    container = new BranchGroup();
    container.setCapability(BranchGroup.ALLOW_DETACH);
    container.addChild(transformGroupHi);
    container.addChild(transformGroupLo);
    stickGroup = BoogiepantsDisplayWindow.getInstance().getStickGroup();

    behavior = new ScaleInstrumentBehavior(oscaddress, loPoint, hiPoint, stickGroup);
    container.addChild(behavior);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    behavior.setSchedulingBounds(bounds);

    editGroup = new BranchGroup();
    editGroup.setCapability(BranchGroup.ALLOW_DETACH);
    editGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    editGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    container.addChild(editGroup);

    behavior.computeLineLen();

    return container;
  }
Beispiel #3
0
  public ObjectViewer(URL url) {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    add("Center", canvas3D);

    BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000);
    BranchGroup root = new BranchGroup();
    BranchGroup scene = createSceneGraph(url);
    scene.setBoundsAutoCompute(true);
    System.out.println(scene.getBounds());
    BoundingSphere sceneBounds = new BoundingSphere(scene.getBounds());

    SimpleUniverse univ = new SimpleUniverse(canvas3D);
    ViewingPlatform view = univ.getViewingPlatform();
    view.setNominalViewingTransform();

    Transform3D t = new Transform3D();
    TransformGroup viewTransform = view.getViewPlatformTransform();

    t.set(new Vector3d(0, 0, 3 * sceneBounds.getRadius()));
    viewTransform.setTransform(t);

    BranchGroup lights = new BranchGroup();
    Light light = new AmbientLight();
    light.setInfluencingBounds(bounds);
    lights.addChild(light);
    light = new DirectionalLight();
    light.setInfluencingBounds(bounds);
    lights.addChild(light);
    root.addChild(lights);

    TransformGroup tg = new TransformGroup();
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg.addChild(scene);

    root.addChild(tg);

    MouseRotate mouse = new MouseRotate();
    mouse.setTransformGroup(tg);
    mouse.setSchedulingBounds(bounds);
    root.addChild(mouse);

    MouseZoom mousezoom = new MouseZoom();
    mousezoom.setTransformGroup(tg);
    mousezoom.setSchedulingBounds(bounds);
    root.addChild(mousezoom);

    Background background = new Background(1, 1, 1);
    background.setApplicationBounds(bounds);
    root.addChild(background);

    root.compile();

    univ.addBranchGraph(root);
  }
Beispiel #4
0
  public void draw(DrawModel d) {
    view.detach();
    rotation.removeAllChildren();
    drawModel = d;
    if (drawModel.getPicture() == null) return;
    Integer i = 0;
    for (VisualShape v : drawModel.getPicture()) {
      TransformGroup shapeGroup = new TransformGroup();
      rotation.addChild(shapeGroup);
      BranchGroup faces = v.getFaces2(BranchGroup.class);
      BranchGroup edges = v.getEdges2(BranchGroup.class);
      BranchGroup text = v.getText2(BranchGroup.class);
      if (faces == null && edges == null) continue;
      i++;
      if (faces != null) {
        faces.detach();
        rotation.addChild(faces);
        faces.setPickable(true);
        faces.setUserData(v);
        faces.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        faces.setName(i.toString());
      }
      if (edges != null) {
        edges.detach();
        rotation.addChild(edges);
        edges.setPickable(true);
        edges.setUserData(v);
        edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        edges.setName(i.toString());
      }

      if (text != null) {
        text.detach();
        rotation.addChild(text);
        text.setPickable(false);
        if (text instanceof BranchGroup) {
          BranchGroup bg = (BranchGroup) text;
          for (int j = 0; j < bg.numChildren(); j++) {
            Node child = bg.getChild(j);
            if (child instanceof TransformGroup) {
              TransformGroup tg = (TransformGroup) child;
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              textLabels.add(tg);
            }
          }
        }

        //        		edges.setUserData(v);
        //        		edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        //         		edges.setName(i.toString());
      }
    }
    root.addChild(view);
  }
Beispiel #5
0
  public void init() {
    // initialize our SimpleUniverse -> u
    u = new SimpleUniverse(this);

    // set viewing platform (the camera)
    vp = u.getViewingPlatform();
    view = u.getViewer().getView();
    view.setScreenScalePolicy(View.SCALE_EXPLICIT);
    view.setBackClipPolicy(View.VIRTUAL_EYE);
    view.setFrontClipPolicy(View.VIRTUAL_EYE);
    view.setBackClipDistance(FARTHEST);
    view.setFrontClipDistance(CLOSEST);
    fieldOfView = view.getFieldOfView();
    view.setDepthBufferFreezeTransparent(false);
    cameraTG = vp.getViewPlatformTransform();
    cameraT3D = new Transform3D();
    cameraTG.getTransform(cameraT3D);

    // initialize root of our scene -> BranchGroup kainBG and TransformGroup kainTG
    kainBG = new BranchGroup();
    kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

    background = new Background(new Color3f(0, 0, 0));
    background.setCapability(Background.ALLOW_COLOR_READ);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    background.setCapability(Background.ALLOW_IMAGE_READ);
    background.setCapability(Background.ALLOW_IMAGE_WRITE);
    background.setApplicationBounds(new BoundingSphere(new Point3d(0, 0, 0), FARTHEST));
    background.setImageScaleMode(Background.SCALE_FIT_ALL);
    kainBG.addChild(background);

    kainTG = new TransformGroup();
    kainTG.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    kainTG.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    kainBG.addChild(kainTG);

    // branch for axis lines
    axisBG = new BranchGroup();
    axisBG.setCapability(BranchGroup.ALLOW_DETACH);
    axisLines = createAxisLines();
    axisBG.addChild(axisLines);

    // branch for ground
    groundBG = new BranchGroup();
    groundBG.setCapability(BranchGroup.ALLOW_DETACH);
    ground = createGround();
    groundBG.addChild(ground);

    kainBG.compile();
    u.addBranchGraph(kainBG);
    currentAppearance = Appearance3DChangerCookie.Appearance.WIREFRAME;
  }
  /**
   * Set the version of VRML that this node should represent. Different versions have different
   * capabilities, even within the same node.
   *
   * @param major The major version number of this scene
   * @param minor The minor version number of this scene
   * @param isStatic true if this node is under a static group and won't change after the setup is
   *     finished
   */
  public void setVersion(int major, int minor, boolean isStatic) {
    super.setVersion(major, minor, isStatic);

    if (isStatic) return;

    implGroup.setCapability(BranchGroup.ALLOW_DETACH);
    implGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    implGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

    implTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    implTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    implTG.setCapability(BranchGroup.ENABLE_PICK_REPORTING);
  }
Beispiel #7
0
  public void createSceneGraph(DrawModel drawing) {
    // Branch group which can be deattached for changing scene;
    view = new BranchGroup();
    view.setCapability(BranchGroup.ALLOW_DETACH);
    // BranchGroup for rotation
    rotation = new TransformGroup();
    rotation.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    rotation.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    view.addChild(rotation);
    bounds = new BoundingSphere();
    DirectionalLight lightD = new DirectionalLight();
    lightD.setDirection(new Vector3f(0.0f, 0.0f, -0.7f));
    lightD.setInfluencingBounds(bounds);
    view.addChild(lightD);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(bounds);
    view.addChild(lightA);

    Background background = new Background();
    background.setColor(1.0f, 1.0f, 1.0f);
    background.setApplicationBounds(bounds);
    view.addChild(background);

    //		MouseRotate myMouseRotate = new MouseRotate();
    //        myMouseRotate.setTransformGroup(rotation);
    //        myMouseRotate.setSchedulingBounds(bounds);
    //        root.addChild(myMouseRotate);
    //
    //        MouseTranslate myMouseTranslate = new MouseTranslate();
    //        myMouseTranslate.setTransformGroup(rotation);
    //        myMouseTranslate.setSchedulingBounds(new BoundingSphere());
    //        root.addChild(myMouseTranslate);

    //        MouseZoom myMouseZoom = new MouseZoom();
    //        myMouseZoom.setTransformGroup(rotation);
    //        myMouseZoom.setSchedulingBounds(new BoundingSphere());
    //        root.addChild(myMouseZoom);
    //
    PickMouse pick = new PickMouse(this, view, bounds);
    view.addChild(pick);

    addKeyListener(new KeyListener());

    angleV = (float) Math.PI / 4;
    angleH = (float) Math.PI / 5;

    draw(drawing);
    zoomAll();
  }
Beispiel #8
0
  private void createLoaderSceneGraph() {
    loaderBranchGroup = new BranchGroup();
    loaderBranchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    loaderTransformGroup = new TransformGroup();
    loaderTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    addLights(loaderBranchGroup);
    Appearance loaderAppearance = new Appearance();
    Color3f loaderColor = new Color3f(0.5f, 0.5f, 0.5f);
    Material loaderMaterial =
        new Material(loaderColor, new Color3f(), loaderColor, loaderColor, 10);
    loaderMaterial.setLightingEnable(true);
    loaderAppearance.setMaterial(loaderMaterial);
    for (int i = 0; i < 20; i++) {
      Transform3D translate3d = new Transform3D();
      translate3d.setTranslation(new Vector3f(0f, 0f, 0.9f));
      TransformGroup translate = new TransformGroup(translate3d);

      Transform3D rotationY3d = new Transform3D();
      rotationY3d.rotY((Math.PI * 2 * i) / 20);
      TransformGroup rotateY = new TransformGroup(rotationY3d);
      rotateY.addChild(translate);

      Box box = new Box(0.1f, 0.1f, 0.1f, loaderAppearance);
      translate.addChild(box);
      loaderTransformGroup.addChild(rotateY);
    }
    loaderBranchGroup.addChild(loaderTransformGroup);
    sceneBranchGroup.addChild(loaderBranchGroup);
  }
Beispiel #9
0
  public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create the TransformGroup node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at run time. Add it to
    // the root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);

    // Create a simple Shape3D node; add it to the scene graph.
    objTrans.addChild(new ColorCube(0.4));

    // Create a new Behavior object that will perform the
    // desired operation on the specified transform and add
    // it into the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, 4000);

    RotationInterpolator rotator =
        new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 1.0f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);
    objRoot.addChild(rotator);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
  }
Beispiel #10
0
  private void prepareGeometry() {

    displayedMenuItems.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    displayedMenuItems.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    displayedMenuItems.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    displayedMenuItems.setCapability(BranchGroup.ALLOW_DETACH);

    menuItemsGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    menuItemsGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    menuItemsGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);

    menuItemsGroup.addChild(displayedMenuItems);
    menuItemsPosition.rotX(Math.PI / 2);
    menuItemsPosition.setTranslation(new Vector3d(0, 0, 0.025));
    menuItemsGroup.setTransform(menuItemsPosition);
    addChild(menuItemsGroup);
  }
Beispiel #11
0
  public CameraView(boolean close) {
    PhysicalBody physBody = new PhysicalBody();
    PhysicalEnvironment physEnv = new PhysicalEnvironment();
    view = new View();

    ViewPlatform viewPlatform = new ViewPlatform();

    view.setPhysicalBody(physBody);
    view.setPhysicalEnvironment(physEnv);
    view.attachViewPlatform(viewPlatform);
    // Modify front clip distance if seeing close objects
    if (close) view.setFrontClipDistance(0.0005);

    TransformGroup vpTG = new TransformGroup();
    vpTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    vpTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    vpTG.addChild(viewPlatform);

    rootBG = new BranchGroup();
    rootBG.setCapability(BranchGroup.ALLOW_DETACH);
    rootBG.addChild(vpTG);
  }
Beispiel #12
0
  public ViewNode(ElementWrapper params) {
    float x = params.getChildFloat("x");
    float y = params.getChildFloat("y");
    float z = params.getChildFloat("z");

    Transform3D rPos = new Transform3D();
    rPos.setTranslation(new Vector3f(x, y, z));
    //		Transform3D rRot = new Transform3D();
    //		rRot.rotY(-Math.PI/2);
    //		rPos.mul(rRot);
    TransformGroup tg = new TransformGroup();
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg.setTransform(rPos);

    CameraView cv = new CameraView(false);
    view = cv.getView();
    tg.addChild(cv.getRootBG());

    // Add the transform group to the world branch group
    this.addChild(tg);
  }
Beispiel #13
0
  /**
   * Adds a SMRotationInterpolator Behavior to the SMGroup
   *
   * @param duration
   * @param start
   * @param rotXAxis Angle about x in which the axis of rotation is going to be rotated
   * @param rotYAxis Angle about y in which the axis of rotation is going to be rotated
   * @param rotZAxis Angle about z in which the axis of rotation is going to be rotated
   * @param startAngle
   * @param finsishAngle
   */
  public void addRotationAnim(
      long duration,
      long start,
      double rotXAxis,
      double rotYAxis,
      double rotZAxis,
      float startAngle,
      float finishAngle) {
    // Creates a necessary TransformGroup for the SMRotationInterpolator
    TransformGroup tg = new TransformGroup();

    // Adds the animation between the child and it Parent
    Group parent = (Group) _child.getParent();
    parent.removeChild(_child);
    tg.addChild(_child);
    parent.addChild(tg);

    // Allows writing on TransfomGroup
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Creates an Alpha function
    Alpha rotationAlpha = new Alpha(1, duration);
    rotationAlpha.setStartTime(System.currentTimeMillis() + start);

    // Calculates the axis of rotation
    Transform3D rX = new Transform3D();
    Transform3D rY = new Transform3D();
    Transform3D rZ = new Transform3D();
    rX.rotX(rotXAxis);
    rY.rotY(rotYAxis);
    rZ.rotZ(rotZAxis);
    rY.mul(rZ);
    rX.mul(rY);

    // Creates the SMRotationInterpolator
    SMRotationInterpolator rotator =
        new SMRotationInterpolator(rotationAlpha, tg, rX, startAngle, finishAngle, start);

    // Sets the area to render
    rotator.setSchedulingBounds(_bounds);

    // Adds the rotation animation to the TransformGroup
    tg.addChild(rotator);
  }
Beispiel #14
0
  public MoonSphere() {
    Color3f eColor = new Color3f(1.0f, 1.0f, 1.0f);

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(0, -100, 0));
    pos.setTransform(t3d);
    addChild(pos);

    // Create a Sphere object, generate one copy of the sphere,
    // and add it into the scene graph.
    Material m = new Material(new Color3f(), eColor, new Color3f(), new Color3f(), 1.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Sphere sph = new Sphere(2.0f, Primitive.GENERATE_NORMALS, 80, a);
    pos.addChild(sph);

    pos.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  }
Beispiel #15
0
  protected void createViewBranch() {
    TransformGroup viewTG = new TransformGroup();
    viewTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    ViewPlatform viewPlatform = new ViewPlatform();
    view = new View();
    view.setBackClipDistance(30000);
    view.addCanvas3D(canvas);
    view.setPhysicalBody(new PhysicalBody());
    view.setPhysicalEnvironment(new PhysicalEnvironment());
    view.attachViewPlatform(viewPlatform);

    float halfRadius = (float) (getBoundingSphere(sceneBranchGroup).getRadius() / 2f);
    Point3d center = new Point3d();
    getBoundingSphere(sceneBranchGroup).getCenter(center);

    BoundingSphere globalBounds = new BoundingSphere();
    globalBounds.setRadius(Double.MAX_VALUE);

    orbitBehaviorInterim =
        new OrbitBehaviorInterim(
            canvas,
            viewTG,
            OrbitBehaviorInterim.REVERSE_ROTATE | OrbitBehaviorInterim.REVERSE_TRANSLATE);

    orbitBehaviorInterim.setRotationCenter(center);
    orbitBehaviorInterim.setViewingTransform(
        new Point3d(
            halfRadius, getViewPlatformDistance(sceneBranchGroup, canvas, view), halfRadius),
        center,
        new Vector3d(0, -1, 0),
        true);
    orbitBehaviorInterim.setVpView(view);
    orbitBehaviorInterim.setTransFactors(3.0, 3.0);
    orbitBehaviorInterim.setSchedulingBounds(globalBounds);

    viewTG.addChild(viewPlatform);
    viewTG.addChild(orbitBehaviorInterim);

    viewBranchGroup.addChild(viewTG);
  }
  public SceneGraphTransformChangeBehavior(
      J3dNiAVObject source, NBKinematicRigidBody destination, NiToJ3dData niToJ3dData) {
    this.destination = destination;

    J3dNiAVObject current = source;
    while (current != null) {
      NifTransformGroup nmtg = current.getTransformGroup();

      if (!nmtg.isNoImpact()) {
        allTransformGroups.add(nmtg);
      }
      current = niToJ3dData.get(current.getNiAVObject().parent);
    }

    ArrayList<WakeupOnTransformChange> criteria = new ArrayList<WakeupOnTransformChange>();

    for (TransformGroup tg : allTransformGroups) {
      tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
      criteria.add(new WakeupOnTransformChange(tg));
    }
    wakeUp = new WakeupOr(criteria.toArray(new WakeupOnTransformChange[criteria.size()]));
  }
 /**
  * Creates Java3d behaviors given the stored envelope data. The Behavior created is a
  * LightIntensityPathInterpolator
  */
 void createJava3dBehaviors(Object target) {
   if (numFrames <= 1) behaviors = null;
   else {
     long alphaAtOne = 0;
     int loopCount;
     if (loop) loopCount = -1;
     else loopCount = 1;
     // Note: hardcoded to always loop...
     loopCount = -1;
     debugOutputLn(VALUES, "totalTime = " + totalTime);
     debugOutputLn(VALUES, "loopCount = " + loopCount);
     float animTime =
         1000.0f * totalTime * (float) (frames[numFrames - 1].getFrameNum() / (float) totalFrames);
     debugOutputLn(VALUES, " anim time: " + animTime);
     debugOutputLn(VALUES, " totalFrames = " + totalFrames);
     debugOutputLn(VALUES, " lastFrame = " + frames[numFrames - 1].getFrameNum());
     if (!loop) alphaAtOne = (long) (1000.0 * totalTime - animTime);
     Alpha theAlpha =
         new Alpha(
             loopCount, Alpha.INCREASING_ENABLE, 0, 0, (long) animTime, 0, alphaAtOne, 0, 0, 0);
     float knots[] = new float[numFrames];
     float values[] = new float[numFrames];
     for (int i = 0; i < numFrames; ++i) {
       values[i] = (float) frames[i].getValue();
       knots[i] =
           (float) (frames[i].getFrameNum()) / (float) (frames[numFrames - 1].getFrameNum());
       debugOutputLn(VALUES, "value, knot = " + values[i] + ", " + knots[i]);
     }
     LightIntensityPathInterpolator l =
         new LightIntensityPathInterpolator(theAlpha, knots, values, target);
     if (l != null) {
       behaviors = l;
       BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000000.0);
       behaviors.setSchedulingBounds(bounds);
       ((TransformGroup) target).setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
       ((TransformGroup) target).addChild(behaviors);
     }
   }
 }
  // Directional light rotating around the scene and some ambient light.
  public void addLight(SimpleUniverse su) {

    BranchGroup bgLight = new BranchGroup();

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.MAX_VALUE);

    // Directional light (to be rotated).
    Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lightDir = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight light = new DirectionalLight(lightColour, lightDir);
    light.setInfluencingBounds(bounds);

    // The transformation group for the directional light and its rotation.
    TransformGroup tfmLight = new TransformGroup();
    tfmLight.addChild(light);

    // The Alpha for the rotation.
    Alpha alphaLight = new Alpha(-1, 4000);
    // The rotation
    RotationInterpolator rot =
        new RotationInterpolator(
            alphaLight, tfmLight, new Transform3D(), 0.0f, (float) Math.PI * 2);
    rot.setSchedulingBounds(bounds);

    tfmLight.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tfmLight.addChild(rot);

    bgLight.addChild(tfmLight);

    // Ambient light.
    Color3f ambientLightColour = new Color3f(0.5f, 0.5f, 0.5f);
    AmbientLight ambLight = new AmbientLight(ambientLightColour);
    ambLight.setInfluencingBounds(bounds);
    bgLight.addChild(ambLight);

    su.addBranchGraph(bgLight);
  }
 /** Creates the objects on the scene, adds behavior effects and so on. */
 public void addChildren() {
   BranchGroup group = new BranchGroup(); // Root group of the applet.
   Appearance ap = new Appearance(); // Configurate a material for the branch.
   Material mat = new Material();
   mat.setAmbientColor(new Color3f(43 / 255f, 23 / 255f, 5 / 255f)); // Brown.
   ap.setMaterial(mat);
   TransformGroup tg =
       new TransformGroup(); // This will actually store all leaf nodes because we want them to
   // rotate with mouse movements.
   tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
   tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
   BranchShape bs =
       new BranchShape(
           new Branch(
               6,
               0f,
               -0f,
               0.9f,
               new Random(1253312432),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   bs =
       new BranchShape(
           new Branch(
               6,
               0.0f,
               -0.0f,
               0.9f,
               new Random(125462432),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   bs =
       new BranchShape(
           new Branch(
               6,
               0.0f,
               -0.0f,
               0.9f,
               new Random(3755678),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   bs =
       new BranchShape(
           new Branch(
               6,
               0.0f,
               -0.0f,
               0.9f,
               new Random(8765683),
               6,
               0.1f,
               new Point3f(0, -2, 0),
               new Vector3f(0, 1, 0),
               0),
           ap,
           0,
           10);
   bs.addChildren(10, 0.5f, 0.2f, 0.3f, 0.3f, 0.5f, 4, -0.3f, 0.3f, 0.1f, 1.2f, ap);
   tg.addChild(bs);
   // Four branches initialized by three different roots for Random.
   MouseRotate mr = new MouseRotate(tg);
   mr.setSchedulingBounds(new BoundingSphere(new Point3d(), 100));
   mr.setFactor(0.005, 0.001); // Slow rotation.
   tg.addChild(mr);
   group.addChild(tg);
   Color3f light1Color =
       new Color3f(1f, 1f, 1f); // Just to see the model, as a temporary solution.
   BoundingSphere bounds = new BoundingSphere(new Point3d(), 100);
   AmbientLight light1 = new AmbientLight(light1Color);
   light1.setInfluencingBounds(bounds); // Some more j3d magic.
   group.addChild(light1);
   universe.addBranchGraph(group);
 }
Beispiel #20
0
  BranchGroup createSceneGraph() {
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(0.0f, 0.0f, 1.0f);
    Color3f alColor = new Color3f(1.0f, 1.0f, 1.0f);

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a transform group to scale the
    // whole scene
    TransformGroup scaleGroup = new TransformGroup();
    Transform3D scaleXform = new Transform3D();
    double scale = 1;
    scaleXform.setScale(scale);
    scaleGroup.setTransform(scaleXform);
    objRoot.addChild(scaleGroup);

    // Create the static ordered group
    OrderedGroup scaleOGroup = new OrderedGroup();
    scaleGroup.addChild(scaleOGroup);

    // Create the static annotation group
    staticBackAnnotationSwitch = new Switch();
    staticBackAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    staticBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    staticBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    staticBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scaleOGroup.addChild(staticBackAnnotationSwitch);

    // Create the static attachment group
    staticAttachGroup = new Group();
    staticAttachGroup.setCapability(Group.ALLOW_CHILDREN_READ);
    staticAttachGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    staticAttachGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scaleOGroup.addChild(staticAttachGroup);

    // Create a TG at the origin
    objectGroup = new TransformGroup();

    // Enable the TRANSFORM_WRITE capability
    // so that our behavior code
    // can modify it at runtime. Add it to the
    // root of the subgraph.
    //
    objectGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objectGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    scaleOGroup.addChild(objectGroup);

    // Create the static annotation group
    staticFrontAnnotationSwitch = new Switch();
    staticFrontAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    staticFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    staticFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    staticFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scaleOGroup.addChild(staticFrontAnnotationSwitch);
    // added after objectGroup so it shows up
    // in front

    // Create the transform group node and
    // initialize it center the
    // object around the origin
    centerGroup = new TransformGroup();
    updateCenter(new Point3d(0.0, 0.0, 0.0), new Point3d(1.0, 1.0, 1.0));
    centerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objectGroup.addChild(centerGroup);

    // Set up the annotation/volume/annotation
    // sandwitch
    OrderedGroup centerOGroup = new OrderedGroup();
    centerGroup.addChild(centerOGroup);

    // create the back dynamic annotation
    // point
    dynamicBackAnnotationSwitch = new Switch(Switch.CHILD_ALL);
    dynamicBackAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    dynamicBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    dynamicBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    dynamicBackAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    centerOGroup.addChild(dynamicBackAnnotationSwitch);

    // create the dynamic attachment point
    dynamicAttachGroup = new Group();
    dynamicAttachGroup.setCapability(Group.ALLOW_CHILDREN_READ);
    dynamicAttachGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    dynamicAttachGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    centerOGroup.addChild(dynamicAttachGroup);

    // create the front dynamic annotation
    // point
    dynamicFrontAnnotationSwitch = new Switch(Switch.CHILD_ALL);
    dynamicFrontAnnotationSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    dynamicFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_READ);
    dynamicFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
    dynamicFrontAnnotationSwitch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    centerOGroup.addChild(dynamicFrontAnnotationSwitch);

    // Create the annotations
    Annotations annotations = new Annotations(view, context, volume);
    annotations.attachBack(dynamicBackAnnotationSwitch, staticBackAnnotationSwitch);
    annotations.attach(dynamicFrontAnnotationSwitch, staticFrontAnnotationSwitch);

    coordSwitch = new Switch(Switch.CHILD_ALL);
    coordSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    coordSwitch.addChild(new CoordSys(0.2, new Vector3d(-0.1, -0.1, -0.1)));
    centerGroup.addChild(coordSwitch);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10000000.0);

    FirstFramesBehavior ff = new FirstFramesBehavior(this);
    ff.setSchedulingBounds(bounds);
    objRoot.addChild(ff);

    updateBehavior = new UpdateBehavior();
    updateBehavior.setSchedulingBounds(bounds);
    objRoot.addChild(updateBehavior);

    // ExitKeyBehavior eb = new
    // ExitKeyBehavior();
    // eb.setSchedulingBounds(bounds);
    // objRoot.addChild(eb);

    BranchGroup trueRoot = new BranchGroup();
    TransformGroup trueTransform = new TransformGroup();

    trueTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trueTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    trueRoot.addChild(trueTransform);
    trueTransform.addChild(objRoot);

    // MouseTranslate mt = new
    // MouseTranslate();
    // mt.setupCallback(this);
    // mt.setTransformGroup(trueTransform);
    // mt.setSchedulingBounds(bounds);
    // trueRoot.addChild(mt);

    MouseZoom mz = new MouseZoom();
    mz.setupCallback(this);
    mz.setTransformGroup(trueTransform);
    mz.setSchedulingBounds(bounds);
    trueRoot.addChild(mz);

    MouseRotate mr = new MouseRotate();
    mr.setupCallback(this);
    mr.setTransformGroup(trueTransform);
    mr.setSchedulingBounds(bounds);
    mr.setFactor(0.007);
    trueRoot.addChild(mr);

    // trueTransform.addChild(objRoot);
    // trueRoot.addChild(trueTransform);
    return trueRoot;
  }
Beispiel #21
0
  public WireNode(double len, double rad) {
    //		super(2);
    //
    //		setGeometry(0,Cylinder.makeGeometry(24,rad,len).getIndexedGeometryArray(),0);
    super();
    Shape3D wire = new Shape3D();
    initShape(wire);
    wire.setGeometry(Cylinder.makeGeometry(24, rad, len).getIndexedGeometryArray());
    Appearance app = Node3D.makeAppearance(new Color3f(new Color(154, 105, 0)), .8f, 0.5f, false);
    TransparencyAttributes ta =
        new TransparencyAttributes(
            TransparencyAttributes.NICEST, 0.5f); // app.getTransparencyAttributes();
    // ta.setTransparency(0.5f);
    app.setTransparencyAttributes(ta);
    wire.setAppearance(app);

    mContents.addChild(wire);

    //////////////////////////////////////////////////////////////////////
    /*
    txt = new Text2D("This is a Text2D!!", new Color3f(0.f,0.f,0.f),"SansSerif",70,Font.PLAIN);
    txt.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    txt.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    txt.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    txt.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    Appearance a = txt.getAppearance();
    a.setCapability(Appearance.ALLOW_TEXTURE_READ);
    a.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    txt.setAppearance(a);
    TransformGroup bbtg = new TransformGroup();
    bbtg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D t = new Transform3D();
    t.setScale(50.);
    bbtg.setTransform(t);
    bbtg.addChild(txt);
    Billboard bb = new Billboard(bbtg,Billboard.ROTATE_ABOUT_POINT,new Point3f(0.f,0.f,0.f));
    bb.setSchedulingBounds(new BoundingSphere(new Point3d(0.,0.,0.), 100.));
    bbtg.addChild(bb);
    mContents.addChild(bbtg);
    */
    ///////////////////////////////////////////////////////////////////////

    Shape3D line = new Shape3D();
    initShape(line);
    // line.setGeometry(sLine);
    Geometry stem =
        teal.render.j3d.geometry.Cylinder.makeGeometry(20, 0.05, 1, 0.5)
            .getIndexedGeometryArray(true);
    line.setGeometry(stem);

    Cone fatcone = new Cone(0.2f, 0.25f);
    Shape3D cone = new Shape3D();
    initShape(cone);
    cone.setGeometry(fatcone.getShape(Cone.BODY).getGeometry());
    cone.addGeometry(fatcone.getShape(Cone.CAP).getGeometry());

    TransformGroup translated_cone = new TransformGroup();
    Transform3D tran = new Transform3D();
    // tran.set( new Vector3f(0.f,0.95f,0.f));
    tran.set(new Vector3f(0.f, 1.f, 0.f));
    translated_cone.addChild(cone);
    translated_cone.setTransform(tran);

    arrow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    arrow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // arrow.addChild(line);
    // arrow.addChild(translated_cone);
    Appearance arrowAppearance =
        Node3D.makeAppearance(new Color3f(new Color(154, 105, 0)), 0.f, 0.f, false);
    line.setAppearance(arrowAppearance);
    cone.setAppearance(arrowAppearance);
    arrow.addChild(line);
    arrow.addChild(translated_cone);

    Transform3D tran2 = new Transform3D();
    // tran2.set(new Vector3f(0.f,-0.5f,0.f));
    tran2.setScale(4.);
    arrow.setTransform(tran2);
    mContents.addChild(arrow);
  }
Beispiel #22
0
  /**
   * principal method used to configure the java3D model of the sky.
   *
   * @return a BranchGroup with the model contents.
   */
  protected BranchGroup createSceneGraph() {
    // ##### Transform Groups ################
    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so tha
    // our behavior code can modify it at runtime.
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);

    // #### Grid ########################################
    if (this.showGrid) {
      gridGroup = new BranchGroup();
      gridGroup.setCapability(BranchGroup.ALLOW_DETACH);
      Group3DSphere sphereRaster = new Group3DSphere(12, 24);
      Appearance sphereRasterApp = new Appearance();
      ColoringAttributes sphereRasterColor = new ColoringAttributes();
      sphereRasterColor.setColor(0.0f, 0.41176f, 0.80f); // royal blue
      sphereRasterApp.setColoringAttributes(sphereRasterColor);
      sphereRaster.setAppearance(sphereRasterApp);
      gridGroup = new BranchGroup();
      gridGroup.addChild(sphereRaster);
      objTrans.addChild(gridGroup);
    }
    // ##### Equator ########################
    equatorGroup = new BranchGroup();
    equatorGroup.setCapability(BranchGroup.ALLOW_DETACH);

    Group3DCircle equator = new Group3DCircle(EQUATOR_RADIUS, EQUATOR_RES);
    Appearance equatorApp = equator.getAppearance();

    ColoringAttributes equatorColor = new ColoringAttributes();
    equatorColor.setColor(new Color3f(java.awt.Color.YELLOW));
    equatorApp.setColoringAttributes(equatorColor);

    LineAttributes eqLine = new LineAttributes();
    eqLine.setLineWidth(3.0f);
    equatorApp.setLineAttributes(eqLine);

    equator.setAppearance(equatorApp);
    equatorGroup.addChild(equator);
    objTrans.addChild(equatorGroup);
    // ######################################

    // ##### Axis ###########################
    axisGroup = new Group3DAxis();
    axisGroup.setCapability(BranchGroup.ALLOW_DETACH);
    objTrans.addChild(axisGroup);
    // ######################################

    objScale = new TransformGroup();
    objScale.addChild(objTrans);

    // ##### root of the branch graph #######
    BranchGroup objRoot = new BranchGroup();
    objRoot.setCapability(BranchGroup.ALLOW_DETACH);
    objRoot.addChild(objScale);
    // ######################################

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), BOUNDINGSPHERE_RADIUS);

    // ##### Background #####
    Background bgNode = new Background(new Color3f(java.awt.Color.BLACK));
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);
    // ######################################

    // ##### Lighting #######################
    // Set up the ambient ligh
    AmbientLight ambientLightNode = new AmbientLight();
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);
    // ######################################
    // ##### Behaviour ######################
    // Create the rotate behavior node
    // MouseRotateY behavior = new MouseRotateY();
    MouseRotate behavior = new MouseRotate();
    behavior.setTransformGroup(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    zoom = new MouseZoom();
    zoom.setTransformGroup(objTrans);
    objTrans.addChild(zoom);
    zoom.setSchedulingBounds(bounds);

    // Create the translate behavior node
    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(objTrans);
    objTrans.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

    // Auto rotator
    Transform3D axis = new Transform3D();
    axis.set(new AxisAngle4f(0, 0, 1, 2)); // theta,x,y,z.
    Alpha mover = new Alpha(0, ALPHA_INC_DURATION); // loop count, period
    rotator = new RotationInterpolator(mover, objTrans);
    rotator.setTransformAxis(axis);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    return objRoot;
  }
Beispiel #23
0
 public static ViewingPlatform createVWorldPlatform() {
   ViewingPlatform viewingPlatform = new ViewingPlatform();
   TransformGroup viewTransGroup = viewingPlatform.getViewPlatformTransform();
   viewTransGroup.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
   return viewingPlatform;
 }