Пример #1
0
 public World() {
   universe = new VirtualUniverse();
   locale = new Locale(universe);
   viewGroup = new BranchGroup();
   objGroup = new BranchGroup();
   viewGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
   objGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
 }
Пример #2
0
  /** @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;
  }
Пример #3
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);
  }
Пример #4
0
  public Java3DViewer(Window window, DrawModel drawModel) {

    super(getPreferredConfiguration(window));
    universe = new SimpleUniverse(this);
    universe.getViewingPlatform().setNominalViewingTransform();
    root = new BranchGroup();
    root.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    root.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    createSceneGraph(drawModel);
    universe.addBranchGraph(root);
  }
Пример #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;
  }
Пример #6
0
  /** set up canvas to display all faces. */
  protected void setupWholeSphere() {

    if (allView && allGroup != null) allGroup.detach();

    allGroup = new BranchGroup();
    int nfaces = 12;

    try {
      theMap = theMap.regrade(nside);
    } catch (Exception e) {
      new Exception("Regrading failed", e);
    }

    // Find map min and max
    double min = theMap.getMin();
    double max = theMap.getMax();
    System.out.println("********** #Min(0)=" + min);
    System.out.println("********** #Max(0)=" + max);
    HealpixBase index = null;
    try {
      index = new HealpixBase(theMap.nside(), Scheme.NESTED);
    } catch (Exception e) {
      e.printStackTrace();
    }
    for (int f = 0; f < nfaces; f++) {
      HealSphere face = new DataSphere(f, theMap, 0, min, max, index);
      setAppearance(face);
      allGroup.addChild(face);
    }

    allGroup.setCapability(BranchGroup.ALLOW_DETACH);
    objTrans.addChild(allGroup);
    if (!allView) allGroup.detach();
  }
Пример #7
0
 /**
  * Ad block with default size of 50cm x 50cm x 50cm
  *
  * @param material - name of material. Must be rom World._availableMaterials list.
  * @param startCoordinates - given in cells unit
  */
 public void addNewBlock(Model.Material material, Vector3d startCoordinates, Point3d blocSize) {
   BranchGroup childBG = new BranchGroup();
   TransformGroup tg = new TransformGroup();
   Transform3D transform = new Transform3D();
   Vector3d vector = new Vector3d(startCoordinates.x, startCoordinates.y, startCoordinates.z);
   transform.setTranslation(vector);
   tg.setTransform(transform);
   Appearance app = new Appearance();
   Color3f cellColor = new Color3f();
   // float transparency = 0.8f;
   cellColor = material.get_color();
   float transparency = material.get_transparency();
   ColoringAttributes coloringAttributes =
       new ColoringAttributes(cellColor, ColoringAttributes.NICEST);
   app.setColoringAttributes(coloringAttributes);
   app.setTransparencyAttributes(
       new TransparencyAttributes(TransparencyAttributes.FASTEST, transparency));
   tg.addChild(
       new Box(
           (float) (blocSize.x / 2),
           (float) (blocSize.z / 2),
           (float) (blocSize.y / 2),
           Box.ENABLE_APPEARANCE_MODIFY,
           app));
   tg.getChild(0).setCapability(Box.ENABLE_APPEARANCE_MODIFY);
   childBG.addChild(tg);
   _startsOfBlocks.add(vector);
   childBG.setCapability(BranchGroup.ALLOW_DETACH);
   _contents.addChild(childBG);
 }
Пример #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);
  }
Пример #9
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);
  }
Пример #10
0
    private Group createAtom() {
      this.app = new Appearance();
      this.app.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
      this.app.setMaterial(
          new Material(this.color, ColorConstants.black, this.color, ColorConstants.white, 120.0f));

      Sphere s = new Sphere(1f, Primitive.GENERATE_NORMALS, 50, this.app);
      try {
        s.getShape().getGeometry().setCapability(Geometry.ALLOW_INTERSECT);
      } catch (Exception e) {
      }

      s.getShape().setCapability(Node.ALLOW_BOUNDS_READ);

      Vector3d d = new Vector3d(this.pos);
      Model3d.this.sg.cell.transform(d);
      // d.sub(origin);
      // d.sub(delta);

      this.t3d = new Transform3D();
      this.t3d.set(this.radius, d);
      this.tg = new TransformGroup(this.t3d);
      this.tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
      this.tg.setCapability(Group.ALLOW_CHILDREN_READ);

      this.positionedBG = new BranchGroup();
      this.positionedBG.setCapability(Group.ALLOW_CHILDREN_READ);
      this.positionedBG.setCapability(Group.ALLOW_CHILDREN_EXTEND);
      this.positionedBG.setCapability(Group.ALLOW_CHILDREN_WRITE);
      this.positionedBG.addChild(s);
      this.tg.addChild(this.positionedBG);

      s.getShape().setUserData(this);

      BranchGroup objBranch = new BranchGroup();
      objBranch.setCapability(BranchGroup.ALLOW_DETACH);
      objBranch.setCapability(Group.ALLOW_CHILDREN_READ);
      objBranch.setCapability(Group.ALLOW_CHILDREN_EXTEND);
      objBranch.setCapability(Group.ALLOW_CHILDREN_WRITE);

      objBranch.addChild(this.tg);

      return objBranch;
    }
Пример #11
0
  private BranchGroup setApperancePackInBranchGroup(Shape3D shape, Node handle) {
    shape.setUserData(this);

    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

    BranchGroup bg = new BranchGroup();
    bg.setCapability(BranchGroup.ALLOW_DETACH);
    bg.addChild(handle);
    bg.compile();
    return bg;
  }
Пример #12
0
  private BranchGroup createSceneGraph() {
    BranchGroup root = new BranchGroup();
    root.setCapability(BranchGroup.ALLOW_DETACH);
    createSpinTG();
    root.addChild(spin);

    SimpleBehavior myRotationBehavior = new SimpleBehavior(spin);
    myRotationBehavior.setSchedulingBounds(new BoundingSphere());
    root.addChild(myRotationBehavior);

    KeyNavigatorBehavior behavior = new KeyNavigatorBehavior(spin);
    BoundingSphere bounds = new BoundingSphere();
    behavior.setSchedulingBounds(bounds);
    root.addChild(behavior);

    // mouse-directed rotation
    MouseRotate rotator = new MouseRotate(spin);
    rotator.setSchedulingBounds(bounds);
    root.addChild(rotator);

    // mouse-based translation
    MouseTranslate translator = new MouseTranslate(spin);
    translator.setSchedulingBounds(bounds);
    root.addChild(translator);

    // mouse-directed zoom
    MouseZoom zoom = new MouseZoom();
    zoom.setSchedulingBounds(bounds);
    root.addChild(zoom);

    // make background blue
    Background background = new Background(Colors.blue);
    background.setApplicationBounds(bounds);
    root.addChild(background);

    // light
    AmbientLight light = new AmbientLight(true, new Color3f(Color.red));
    light.setInfluencingBounds(bounds);
    root.addChild(light);
    PointLight ptlight =
        new PointLight(new Color3f(Color.red), new Point3f(0f, 0f, -5f), new Point3f(1f, 0f, 0f));
    ptlight.setInfluencingBounds(bounds);
    root.addChild(ptlight);
    PointLight ptlight2 =
        new PointLight(
            new Color3f(Color.orange), new Point3f(-2f, 2f, 2f), new Point3f(1f, 0f, 0f));
    ptlight2.setInfluencingBounds(bounds);
    root.addChild(ptlight2);

    // let Java3d perform optimization on this scene graph
    root.compile();
    return root;
  }
Пример #13
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();
  }
Пример #14
0
  public BranchGroup addTriangle(Simplex simplex, Color3f color) {

    int[] p = simplex.getPoints();
    BranchGroup bgTriangle = new BranchGroup();
    bgTriangle.setCapability(BranchGroup.ALLOW_DETACH);

    javax.vecmath.Point3d[] coords = new javax.vecmath.Point3d[6];
    TriangleArray ta = new TriangleArray(6, TriangleArray.COORDINATES | TriangleArray.COLOR_3);

    Point3d p0 = (Point3d) complex.getPoints().get(simplex.getPoints()[0]);
    Point3d p1 = (Point3d) complex.getPoints().get(simplex.getPoints()[1]);
    Point3d p2 = (Point3d) complex.getPoints().get(simplex.getPoints()[2]);
    coords[0] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coords[1] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coords[2] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coords[3] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coords[4] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coords[5] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());

    ta.setCoordinates(0, coords);
    Color3f[] colors = new Color3f[6];
    for (int i = 0; i < 3; i++) colors[i] = Colors.black;
    for (int i = 3; i < 6; i++) colors[i] = Colors.yellow;

    ta.setColors(0, colors);

    Appearance ap = new Appearance();
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    ap.setLineAttributes(new LineAttributes(2, LineAttributes.PATTERN_SOLID, false));
    ap.setMaterial(new Material());
    ap.setTransparencyAttributes(
        new TransparencyAttributes(TransparencyAttributes.SCREEN_DOOR, 0.5f));

    Shape3D shape = new Shape3D(ta, ap);

    shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    simplex.setTriangle(shape);
    //			 simplex.bgTriangle = bgTriangle;

    TransformGroup tgTriangle = new TransformGroup();
    tgTriangle.addChild(shape);

    bgTriangle.addChild(tgTriangle);
    spin.addChild(bgTriangle);
    return bgTriangle;
  }
Пример #15
0
 public BranchGroup addSphere(geom3d.Point3d p, double radius, Color3f color) {
   BranchGroup bgSphere = new BranchGroup();
   bgSphere.setCapability(BranchGroup.ALLOW_DETACH);
   Appearance ap = new Appearance();
   ap.setColoringAttributes(new ColoringAttributes(color, ColoringAttributes.NICEST));
   ap.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, 0.5f));
   Sphere sphere = new Sphere(new Float(radius), ap);
   Transform3D tr = new Transform3D();
   tr.setTranslation(new javax.vecmath.Vector3d(p.getX(), p.getY(), p.getZ()));
   TransformGroup tgSphere = new TransformGroup(tr);
   tgSphere.addChild(sphere);
   bgSphere.addChild(tgSphere);
   spin.addChild(bgSphere);
   return bgSphere;
 }
Пример #16
0
 public void addSphere(Simplex simplex, double radius, Color3f color) {
   geom3d.Point3d p = (Point3d) complex.getPoints().get(simplex.getPoints()[0]);
   BranchGroup bgSphere = new BranchGroup();
   bgSphere.setCapability(BranchGroup.ALLOW_DETACH);
   Appearance ap = new Appearance();
   ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
   ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
   ap.setColoringAttributes(new ColoringAttributes(color, ColoringAttributes.NICEST));
   simplex.setSphere(new Sphere(new Float(radius), ap));
   simplex.getSphere().getShape().setCapability(Shape3D.ALLOW_APPEARANCE_READ);
   simplex.getSphere().getShape().setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
   Transform3D tr = new Transform3D();
   tr.setTranslation(new javax.vecmath.Vector3d(p.getX(), p.getY(), p.getZ()));
   TransformGroup tgSphere = new TransformGroup(tr);
   tgSphere.addChild(simplex.getSphere());
   bgSphere.addChild(tgSphere);
   spin.addChild(bgSphere);
 }
Пример #17
0
  public static void main(String args[]) {
    JFrame frame = new JFrame("Box and Sphere");

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D canvas = new Canvas3D(config);

    canvas.setSize(400, 400);

    SimpleUniverse universe = new SimpleUniverse(canvas);
    universe.getViewingPlatform().setNominalViewingTransform();

    BranchGroup group = new BranchGroup();
    group.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    // group.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

    universe.addBranchGraph(group);

    frame.setSize(500, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(canvas, BorderLayout.CENTER);
    frame.setVisible(true);
    Sphere sphere =
        new Sphere(1.1f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, null);

    BranchGroup b = new BranchGroup();
    b.addChild(sphere);

    group.addChild(b);

    {
      Sphere sphere2 =
          new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, null);

      b = new BranchGroup();
      b.addChild(sphere2);

      Util3D.enablePicking(b);

      group.addChild(b);
    }
  }
Пример #18
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);
  }
Пример #19
0
  public Annotations(View view, Context context, Volume vol) {
    super(view, context, vol);
    viewPtAttr = (CoordAttr) context.getAttr("Vol Ref Pt");
    perspectiveAttr = (ToggleAttr) context.getAttr("Perspective");
    boxAttr[PLUS_X] = (ToggleAttr) context.getAttr("Plus X Box");
    boxAttr[PLUS_Y] = (ToggleAttr) context.getAttr("Plus Y Box");
    boxAttr[PLUS_Z] = (ToggleAttr) context.getAttr("Plus Z Box");
    boxAttr[MINUS_X] = (ToggleAttr) context.getAttr("Minus X Box");
    boxAttr[MINUS_Y] = (ToggleAttr) context.getAttr("Minus Y Box");
    boxAttr[MINUS_Z] = (ToggleAttr) context.getAttr("Minus Z Box");
    imageAttr[PLUS_X] = (StringAttr) context.getAttr("Plus X Image");
    imageAttr[PLUS_Y] = (StringAttr) context.getAttr("Plus Y Image");
    imageAttr[PLUS_Z] = (StringAttr) context.getAttr("Plus Z Image");
    imageAttr[MINUS_X] = (StringAttr) context.getAttr("Minus X Image");
    imageAttr[MINUS_Y] = (StringAttr) context.getAttr("Minus Y Image");
    imageAttr[MINUS_Z] = (StringAttr) context.getAttr("Minus Z Image");

    volume = vol;
    frontRoot = new BranchGroup();
    frontRoot.setCapability(BranchGroup.ALLOW_DETACH);
    frontRoot.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
    backRoot = new BranchGroup();
    backRoot.setCapability(BranchGroup.ALLOW_DETACH);
    backRoot.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);

    int stripLength[] = new int[1];
    stripLength[0] = 5;

    ColoringAttributes ca = new ColoringAttributes(1.0f, 0.0f, 0.0f, ColoringAttributes.SHADE_FLAT);
    Appearance boxAppearance = new Appearance();
    boxAppearance.setColoringAttributes(ca);

    TexCoord2f[] texCoords = new TexCoord2f[4];
    texCoords[0] = new TexCoord2f(0.0f, 0.0f);
    texCoords[1] = new TexCoord2f(1.0f, 0.0f);
    texCoords[2] = new TexCoord2f(1.0f, 1.0f);
    texCoords[3] = new TexCoord2f(0.0f, 1.0f);

    TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.0f);
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    PolygonAttributes pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    RenderingAttributes ra = new RenderingAttributes();
    ra.setDepthBufferEnable(false);

    for (int i = 0; i < 6; i++) {
      faceGroup[i] = new SharedGroup();
      frontAnnotations.addChild(new Link(faceGroup[i]));
      backAnnotations.addChild(new Link(faceGroup[i]));
      boxLine[i] = new LineStripArray(5, GeometryArray.COORDINATES, stripLength);
      boxLine[i].setCoordinates(0, volume.facePoints[i], 0, 4);
      boxLine[i].setCoordinate(4, volume.facePoints[i][0]);
      boxLine[i].setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
      Shape3D box = new Shape3D(boxLine[i], boxAppearance);
      boxSwitch[i] = new Switch();
      boxSwitch[i].setCapability(Switch.ALLOW_SWITCH_WRITE);
      boxSwitch[i].addChild(box);
      if (boxAttr[i].getValue() == true) {
        boxSwitch[i].setWhichChild(Switch.CHILD_ALL);
      } else {
        boxSwitch[i].setWhichChild(Switch.CHILD_NONE);
      }
      faceGroup[i].addChild(boxSwitch[i]);
      imageQuad[i] =
          new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
      imageQuad[i].setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
      imageQuad[i].setCoordinates(0, volume.facePoints[i], 0, 4);
      imageQuad[i].setTextureCoordinates(0, 0, texCoords, 0, 4);
      imageAppearance[i] = new Appearance();
      imageAppearance[i].setTransparencyAttributes(ta);
      imageAppearance[i].setPolygonAttributes(pa);
      imageAppearance[i].setRenderingAttributes(ra);
      imageAppearance[i].setTextureAttributes(texAttr);
      imageAppearance[i].setCapability(Appearance.ALLOW_TEXTURE_WRITE);
      imageSwitch[i] = new Switch();
      imageSwitch[i].setCapability(Switch.ALLOW_SWITCH_WRITE);
      imageFile[i] = imageAttr[i].getValue();
      if (imageFile[i].length() > 0) {
        try {
          URL imageURL = new URL(context.getCodeBase().toString() + imageFile[i]);
          imageTexture[i] = new TextureLoader(imageURL, null).getTexture();
        } catch (Exception e) {
          System.err.println("Error " + e + " loading image:" + imageFile[i] + ".");
        }
      }
      imageAppearance[i].setTexture(imageTexture[i]);
      if (imageTexture[i] != null) {
        imageSwitch[i].setWhichChild(Switch.CHILD_ALL);
      } else {
        imageSwitch[i].setWhichChild(Switch.CHILD_NONE);
      }
      Shape3D imageShape = new Shape3D(imageQuad[i], imageAppearance[i]);
      imageSwitch[i].addChild(imageShape);
      faceGroup[i].addChild(imageSwitch[i]);
    }
    frontAnnotations.setCapability(Switch.ALLOW_SWITCH_WRITE);
    backAnnotations.setCapability(Switch.ALLOW_SWITCH_WRITE);

    faceNormal[PLUS_X] = new Vector3d(1.0, 0.0, 0.0);
    faceCenter[PLUS_X] = new Point3d(volume.maxCoord.x, 0.0, 0.0);
    faceNormal[PLUS_Y] = new Vector3d(0.0, 1.0, 0.0);
    faceCenter[PLUS_Y] = new Point3d(0.0, volume.maxCoord.y, 0.0);
    faceNormal[PLUS_Z] = new Vector3d(0.0, 0.0, 1.0);
    faceCenter[PLUS_Z] = new Point3d(0.0, 0.0, volume.maxCoord.z);
    faceNormal[MINUS_X] = new Vector3d(-1.0, 0.0, 0.0);
    faceCenter[MINUS_X] = new Point3d(volume.minCoord.x, 0.0, 0.0);
    faceNormal[MINUS_Y] = new Vector3d(0.0, -1.0, 0.0);
    faceCenter[MINUS_Y] = new Point3d(0.0, volume.minCoord.y, 0.0);
    faceNormal[MINUS_Z] = new Vector3d(0.0, 0.0, -1.0);
    faceCenter[MINUS_Z] = new Point3d(0.0, 0.0, volume.minCoord.z);
    volCenter.x = (volume.maxCoord.x + volume.minCoord.x) / 2;
    volCenter.y = (volume.maxCoord.y + volume.minCoord.y) / 2;
    volCenter.z = (volume.maxCoord.z + volume.minCoord.z) / 2;

    frontRoot.addChild(frontAnnotations);
    backRoot.addChild(backAnnotations);
  }
Пример #20
0
 public void addToTerrainBranch(BranchGroup newGroup) {
   newGroup.setCapability(BranchGroup.ALLOW_DETACH);
   terrainGroup.addChild(newGroup);
 }
Пример #21
0
 public void addToSceneBranch(BranchGroup newGroup) {
   newGroup.setCapability(BranchGroup.ALLOW_DETACH);
   mainSceneGroup.addChild(newGroup);
 }
Пример #22
0
  private void start() throws PluginException, IfcModelInterfaceException {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    try {
      setIconImage(ImageIO.read(getClass().getResource("haussmall.png")));
    } catch (IOException e) {
      LOGGER.error("", e);
    }
    setSize(800, 600);
    getContentPane().setBackground(Color.BLACK);
    setTitle("IFC Visualiser");
    setVisible(true);

    VirtualUniverse universe = new VirtualUniverse();
    Locale locale = new Locale(universe);
    canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

    sceneBranchGroup = new BranchGroup();
    sceneBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    sceneBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    createLoaderSceneGraph();
    locale.addBranchGraph(sceneBranchGroup);

    showLoader = true;
    new Thread() {
      public void run() {
        float x = 0;
        float y = 0;
        while (showLoader) {
          Matrix3f matrixX = new Matrix3f();
          matrixX.rotX(x);

          Matrix3f matrixY = new Matrix3f();
          matrixY.rotY(y);

          Matrix3f rot = new Matrix3f();
          rot.mul(matrixX, matrixY);

          Transform3D transform3d = new Transform3D();
          transform3d.setRotation(rot);
          transform3d.setTranslation(new Vector3d(10, 0, 0));
          loaderTransformGroup.setTransform(transform3d);
          y -= 0.05;
          x += 0.015;
          try {
            Thread.sleep(25);
          } catch (InterruptedException e) {
            LOGGER.error("", e);
          }
        }
      };
    }.start();

    viewBranchGroup = new BranchGroup();
    createViewBranch();
    viewBranchGroup.compile();
    locale.addBranchGraph(viewBranchGroup);

    add(canvas, BorderLayout.CENTER);

    canvas.setVisible(true);
    validate();

    sharedGroup = new SharedGroup();
    try {
      pluginManager = LocalDevPluginLoader.createPluginManager(new File("home"));
    } catch (PluginException e) {
      LOGGER.error("", e);
    }

    DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", true);
    Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
    deserializer.init(pluginManager.requireSchemaDefinition());
    File file = new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc");

    try {
      model = deserializer.read(file);
    } catch (DeserializationException e) {
      LOGGER.error("", e);
    } catch (Exception e) {
      LOGGER.error("", e);
    }

    ifcEngine = pluginManager.requireRenderEngine().createRenderEngine(new PluginConfiguration());
    ifcEngine.init();
    try {
      ifcEngineModel = ifcEngine.openModel(file);
      try {
        RenderEngineSurfaceProperties initializeModelling = ifcEngineModel.initializeModelling();
        geometry = ifcEngineModel.finalizeModelling(initializeModelling);
        createSceneGraph();
      } finally {
        ifcEngineModel.close();
      }
    } finally {
      ifcEngine.close();
    }
  }
Пример #23
0
 public void addToEnvironmentBranch(BranchGroup newGroup) {
   newGroup.setCapability(BranchGroup.ALLOW_DETACH);
   environmentGroup.addChild(newGroup);
 }
Пример #24
0
 public void addToBehaviorBranch(BranchGroup newGroup) {
   newGroup.setCapability(BranchGroup.ALLOW_DETACH);
   behaviorGroup.addChild(newGroup);
 }
Пример #25
0
  public DefaultUniverse() {
    super(
        createVWorldPlatform(),
        new Viewer(new Canvas3D(SimpleUniverse.getPreferredConfiguration())));

    // some useful parts of this universe
    // Viewer viewer = getViewer();
    // ViewingPlatform viewingPlatform = getViewingPlatform();
    // View view = viewer.getView();
    // ViewPlatform viewPlatform = viewingPlatform.getViewPlatform();
    // TransformGroup viewTransGroup = getViewingPlatform().getViewPlatformTransform();

    // set up the view
    getViewer().getView().setFrontClipPolicy(View.VIRTUAL_EYE);
    getViewer().getView().setBackClipDistance(BACK_CLIP);
    getViewer().getView().setFrontClipDistance(FRONT_CLIP);
    // set max frame rate to 50 so server can get in
    getViewer().getView().setMinimumFrameCycleTime(2);

    // TODO: I believe I can remove these calls
    PlatformGeometry pg = new PlatformGeometry();
    pg.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    getViewingPlatform().setPlatformGeometry(pg);

    getViewer().createAudioDevice();

    // set capabilities for the various branch groups
    mainSceneGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    mainSceneGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    environmentGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    environmentGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    behaviorGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    behaviorGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    terrainGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    terrainGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    terrainGroup.setCapability(BranchGroup.ALLOW_DETACH);
    terrainGroup.setUserData("Terrain Group");

    // initialise the sound system
    // SoundEngine mt = new SoundEngine();
    // behaviorGroup.addChild(mt);

    // put a sky in place
    sky.setApplicationBounds(Utils3D.defaultBounds);
    environmentGroup.addChild(sky);

    // Create ambient light	and add it
    Color3f alColor = new Color3f(0.6f, 0.6f, 0.6f);
    ambLight = new AmbientLight(true, alColor);
    ambLight.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
    ambLight.setInfluencingBounds(Utils3D.defaultBounds);
    environmentGroup.addChild(ambLight);

    // Create sun light and add it
    Color3f slColor = new Color3f(1.0f, 1.0f, 1.0f);
    sunLight = new DirectionalLight(slColor, new Vector3f(0.2f, -1.0f, -0.2f));
    sunLight.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
    sunLight.setInfluencingBounds(Utils3D.defaultBounds);
    environmentGroup.addChild(sunLight);

    // Add the fog
    fog.setCapability(Fog.ALLOW_INFLUENCING_BOUNDS_WRITE);
    environmentGroup.addChild(fog);

    nightClip.setApplicationBounds(Utils3D.defaultBounds);
    fogClip.setApplicationBounds(Utils3D.defaultBounds);
    nightClipGroup.addChild(nightClip);
    nightClipGroup.setCapability(BranchGroup.ALLOW_DETACH);
    fogClipGroup.addChild(fogClip);
    fogClipGroup.setCapability(BranchGroup.ALLOW_DETACH);

    // initialise the rain model
    // Color3f rainColor = new Color3f(0.6f, 0.6f, 0.65f);
    // Vector3f windVector = new Vector3f(0.2f, 0f, 0f);
    // rainyModel = new RainyArea(14, 0, 25000, rainColor, 4.5f, 0.8f, 50, windVector, 80f, 80f,
    // 20f, 20000);
    // rainyModel.hoverOver(getViewingPlatform().getViewPlatformTransform());
    // environmentGroup.addChild(rainyModel);

    mainSceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
    environmentGroup.setCapability(BranchGroup.ALLOW_DETACH);
    behaviorGroup.setCapability(BranchGroup.ALLOW_DETACH);

    addBranchGraph(mainSceneGroup);
    addBranchGraph(environmentGroup);
    addBranchGraph(behaviorGroup);
    addBranchGraph(terrainGroup);
  }
Пример #26
0
 public void createMenuItems(Node<MenuData.MenuItemData> tree, String category) {
   if (tree.data == null) {
     // ROOT
     BranchGroup catBrGr = new BranchGroup();
     catBrGr.setCapability(BranchGroup.ALLOW_DETACH);
     menuBranches.put("root", catBrGr);
     menuItems.put("root", new ArrayList<MenuItem>());
     for (Node<MenuData.MenuItemData> child : tree.children) {
       createMenuItems(child, "root");
     }
     System.out.println("placing menu items for root");
     placeMenuItems(catBrGr.getAllChildren(), catBrGr.numChildren(), DEFAULT_GAP);
     return;
   }
   if (tree.data.type == MenuItemType.CATEGORY) {
     // create category
     System.out.println("created category " + tree.data.name);
     BranchGroup catBrGr = new BranchGroup();
     catBrGr.setCapability(BranchGroup.ALLOW_DETACH);
     menuBranches.put(tree.data.name, catBrGr);
     menuItems.put(tree.data.name, new ArrayList<MenuItem>());
     //			ModelObject model = null;
     //			try {
     //				model = ModelFactory.loadModel(tree.data.modelFileName, tree.data.modelType);
     //			} catch (Exception e) {
     //				// TODO Auto-generated catch block
     //				e.printStackTrace();
     //			}
     BottleObject model = new BottleObject();
     MenuItem ciao;
     if (tree.data.offset == null) {
       ciao = createMenuItem(tree.data.name, tree.data.name, model, true, tree.data.glassColor);
     } else {
       System.out.println("adding offset and scaling");
       ciao =
           createMenuItem(
               tree.data.name,
               tree.data.name,
               model,
               true,
               tree.data.glassColor,
               tree.data.scaling,
               tree.data.offset);
     }
     menuBranches.get(category).addChild(ciao);
     menuItems.get(category).add(ciao);
     // continue walking
     if (tree.children == null) return;
     for (Node<MenuData.MenuItemData> child : tree.children) {
       createMenuItems(child, tree.data.name);
     }
     ArrowObject arrObj = new ArrowObject();
     Transform3D arrAdj = new Transform3D();
     arrAdj.rotX(Math.PI / 2);
     arrAdj.rotY(Math.PI / 2);
     arrAdj.rotZ(Math.PI / 2);
     arrObj.transGroup.setTransform(arrAdj);
     MenuItem back = createMenuItem(category, "Back", arrObj, true, null);
     menuBranches.get(tree.data.name).addChild(back);
     System.out.println("placing menu items for category: " + tree.data.name);
     placeMenuItems(catBrGr.getAllChildren(), catBrGr.numChildren(), DEFAULT_GAP);
   } else { // tree.data.type == MenuItemType.ITEM
     // create item
     System.out.println("created item " + tree.data.name);
     //			ModelObject model = null;
     //			try {
     //				model = ModelFactory.loadModel(tree.data.modelFileName, tree.data.modelType);
     //			} catch (Exception e) {
     //				// TODO Auto-generated catch block
     //				e.printStackTrace();
     //			}
     BottleObject model = new BottleObject();
     MenuItem ciao;
     if (tree.data.offset == null)
       ciao = createMenuItem(tree.data.name, tree.data.name, model, false, tree.data.glassColor);
     else
       ciao =
           createMenuItem(
               tree.data.name,
               tree.data.name,
               model,
               false,
               tree.data.glassColor,
               tree.data.scaling,
               tree.data.offset);
     menuBranches.get(category).addChild(ciao);
     menuItems.get(category).add(ciao);
   }
 }
Пример #27
0
  public BranchGroup addTetrahedron(Simplex simplex, Color3f color) {

    BranchGroup bgTetrahedron = new BranchGroup();
    bgTetrahedron.setCapability(BranchGroup.ALLOW_DETACH);

    javax.vecmath.Point3d[] coords = new javax.vecmath.Point3d[12];
    LineArray la = new LineArray(12, LineArray.COORDINATES | LineArray.COLOR_3);

    Point3d p0 = (Point3d) complex.getPoints().get(simplex.getPoints()[0]);
    Point3d p1 = (Point3d) complex.getPoints().get(simplex.getPoints()[1]);
    Point3d p2 = (Point3d) complex.getPoints().get(simplex.getPoints()[2]);
    Point3d p3 = (Point3d) complex.getPoints().get(simplex.getPoints()[3]);

    coords[0] = coords[2] = coords[4] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coords[1] = coords[6] = coords[8] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coords[3] = coords[7] = coords[10] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coords[5] = coords[9] = coords[11] = new javax.vecmath.Point3d(p3.getX(), p3.getY(), p3.getZ());

    la.setCoordinates(0, coords);
    Color3f[] colors = new Color3f[12];
    for (int i = 0; i < 12; i++) colors[i] = Colors.black;
    la.setColors(0, colors);

    javax.vecmath.Point3d[] coordsTr = new javax.vecmath.Point3d[24];
    TriangleArray tr = new TriangleArray(24, TriangleArray.COORDINATES | TriangleArray.COLOR_3);
    coordsTr[0] =
        coordsTr[3] = coordsTr[6] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coordsTr[1] =
        coordsTr[4] = coordsTr[9] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coordsTr[2] =
        coordsTr[7] = coordsTr[10] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coordsTr[5] =
        coordsTr[8] = coordsTr[11] = new javax.vecmath.Point3d(p3.getX(), p3.getY(), p3.getZ());

    coordsTr[12] =
        coordsTr[15] = coordsTr[18] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ());
    coordsTr[14] =
        coordsTr[17] = coordsTr[21] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ());
    coordsTr[13] =
        coordsTr[20] = coordsTr[23] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ());
    coordsTr[16] =
        coordsTr[19] = coordsTr[22] = new javax.vecmath.Point3d(p3.getX(), p3.getY(), p3.getZ());

    tr.setCoordinates(0, coordsTr);
    Color3f[] colorsTr = new Color3f[24];
    for (int i = 0; i < 24; i++) colorsTr[i] = Colors.green;
    tr.setColors(0, colorsTr);

    Appearance ap = new Appearance();
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
    ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    //			 ap.setCapability(Appearance.ALLOW_MATERIAL_READ);
    //			 ap.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
    ap.setLineAttributes(new LineAttributes(2, LineAttributes.PATTERN_SOLID, false));
    ap.setMaterial(new Material());
    //			 ap.setTransparencyAttributes(new
    // TransparencyAttributes(TransparencyAttributes.SCREEN_DOOR, 0.5f));

    //			 LineArray la = cell.getLineArray();
    Shape3D shape = new Shape3D(la, ap);
    Shape3D shapeTr = new Shape3D(tr, ap);

    shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    simplex.setTetrahedron(shape);
    //			 cell.setLineArray(la);
    simplex.setTriangleArray(tr);
    simplex.setBgTetrahedron(bgTetrahedron);

    TransformGroup tgTetrahedron = new TransformGroup();
    tgTetrahedron.addChild(shape);
    tgTetrahedron.addChild(shapeTr);

    bgTetrahedron.addChild(tgTetrahedron);
    spin.addChild(bgTetrahedron);
    return bgTetrahedron;
  }
Пример #28
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;
  }
Пример #29
0
  public BranchGroup doTransform() throws VisADException, RemoteException {

    DataDisplayLink[] Links = getLinks();
    if (Links == null || Links.length == 0) {
      return null;
    }

    DataDisplayLink link = Links[0];
    ShadowTypeJ3D type = (ShadowTypeJ3D) link.getShadow();
    boolean doByRef = false;
    if (isByRefUsable(link, type) && ShadowType.byReference) {
      doByRef = true;
      type =
          new ShadowImageByRefFunctionTypeJ3D(
              link.getData().getType(),
              link,
              null,
              ((ShadowFunctionOrSetType) type.getAdaptedShadowType()).getInheritedValues(),
              (ShadowFunctionOrSetType) type.getAdaptedShadowType(),
              type.getLevelOfDifficulty());
    }

    BranchGroup branch = null;
    if ((lastByRef && doByRef) || (!lastByRef && !doByRef)) {
      branch = getBranch();
    }
    lastByRef = doByRef;

    if (branch == null) {
      branch = new BranchGroup();
      branch.setCapability(BranchGroup.ALLOW_DETACH);
      branch.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
      branch.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
      branch.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
      last_curve_size = -1;
      last_zaxis_value = Float.NaN;
      last_alpha_value = Float.NaN;
      last_data_hash_code = -1;
      adjust_projection_seam = false; // 27FEB2012: Projection Seam Change Bug Fix
    }

    // initialize valueArray to missing
    int valueArrayLength = getDisplay().getValueArrayLength();
    float[] valueArray = new float[valueArrayLength];
    for (int i = 0; i < valueArrayLength; i++) {
      valueArray[i] = Float.NaN;
    }

    Data data;
    try {
      data = link.getData();
    } catch (RemoteException re) {
      if (visad.collab.CollabUtil.isDisconnectException(re)) {
        getDisplay().connectionFailed(this, link);
        removeLink(link);
        return null;
      }
      throw re;
    }

    if (data == null) {
      branch = null;
      addException(new DisplayException("Data is null: DefaultRendererJ3D.doTransform"));
    } else {
      // check MathType of non-null data, to make sure it is a single-band
      // image or a sequence of single-band images
      MathType mtype = link.getType();
      if (!isImageType(mtype)) {
        throw new BadMappingException("must be image or image sequence");
      }
      link.start_time = System.currentTimeMillis();
      link.time_flag = false;
      vbranch = null;
      // transform data into a depiction under branch
      long t1 = System.currentTimeMillis();
      try {
        if (type
            instanceof
            ShadowImageByRefFunctionTypeJ3D) { // GEOMETRY/COLORBYTE REUSE LOGIC Only for ByRef for
                                               // Time being
          if (checkAction()) { // This generally decides whether at all retransformation is required
                               // or not.
            type.doTransform(branch, data, valueArray, link.getDefaultValues(), this);
          }
        } else { // Not byRef (ShadowImageFunctionTypeJ3D)
          type.doTransform(branch, data, valueArray, link.getDefaultValues(), this);
        }
      } catch (RemoteException re) {
        if (visad.collab.CollabUtil.isDisconnectException(re)) {
          getDisplay().connectionFailed(this, link);
          removeLink(link);
          return null;
        }
        throw re;
      }
      long t2 = System.currentTimeMillis();
      // System.err.println("Time taken:" + (t2-t1));
    }
    link.clearData();

    return branch;
  }