Example #1
0
  private void loadSheep() {
    VrmlLoader loader = new VrmlLoader();
    Scene myScene = null;
    try {
      myScene = loader.load("models" + File.separator + "Sheep.wrl");
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IncorrectFormatException e) {
      e.printStackTrace();
    } catch (ParsingErrorException e) {
      e.printStackTrace();
    }

    BranchGroup bg = new BranchGroup();
    TransformGroup offset = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setRotation(new AxisAngle4d(1.0, 0.0, 0.0, Math.PI / 2));
    t3d.setTranslation(new Vector3d(0.0, 0.0, 0.025));
    offset.setTransform(t3d);
    bg.addChild(offset);
    offset.addChild(myScene.getSceneGroup());

    sheepObject = new ModelObject(bg);

    viewer.addObject(sheepObject);
  }
Example #2
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);
  }
Example #3
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);
 }
Example #4
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;
  }
Example #5
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();
  }
Example #6
0
  public BranchGroup createSceneGraph(URL url) {

    try {
      Loader loader = new com.sun.j3d.loaders.objectfile.ObjectFile();
      Scene scene = loader.load(url);
      BranchGroup bg = scene.getSceneGroup();
      System.out.println(bg);
      TransformGroup[] views = scene.getViewGroups();
      if (views != null) {
        for (int i = 0; i < views.length; i++) {
          System.out.print(views[i]);
        }
        if (views.length > 0) viewStart = views[0];
      }
      return bg;
    } catch (Exception ex) {
      // in case there was a problem, print the stack out
      ex.printStackTrace();
      // System.out.println(ex);
      add("South", new Label(ex.toString()));
      System.out.println("URL: " + url);
      BranchGroup bg = new BranchGroup();
      bg.addChild(new ColorCube());
      System.out.println(bg);
      return bg;
    }
  }
  // In this method, the objects for the scene are generated and added to
  // the SimpleUniverse.
  public void createSceneGraph(SimpleUniverse su) {

    // *** The root of the graph containing the scene (with a cube and a sphere). ***
    BranchGroup theScene = new BranchGroup();

    // Generate an Appearance.
    Color3f ambientColourShaded = new Color3f(0.0f, 0.4f, 0.4f);
    Color3f emissiveColourShaded = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f diffuseColourShaded = new Color3f(0.0f, 0.7f, 0.7f);
    Color3f specularColourShaded = new Color3f(0.0f, 0.5f, 0.5f);

    float shininessShaded = 20.0f;

    Appearance shadedApp = new Appearance();
    shadedApp.setMaterial(
        new Material(
            ambientColourShaded,
            emissiveColourShaded,
            diffuseColourShaded,
            specularColourShaded,
            shininessShaded));

    float r = 0.3f; // The radius of the sphere.
    float boxHL = 0.7f * r; // Half the vertex length of the cube.
    float shift = 3.0f * r; // Distance between cube and sphere.

    // *** The sphere and its transformation group ***
    Sphere s = new Sphere(r, Sphere.GENERATE_NORMALS, 100, shadedApp);
    Transform3D tfSphere = new Transform3D();
    tfSphere.setTranslation(new Vector3f(-0.95f + r, 0.0f, 0.0f));
    TransformGroup tgSphere = new TransformGroup(tfSphere);
    tgSphere.addChild(s);
    theScene.addChild(tgSphere);

    // *** The cube and its transformation group ***
    Box b2 = new Box(boxHL, boxHL, boxHL, shadedApp);
    Transform3D tfBox2 = new Transform3D();
    tfBox2.setTranslation(new Vector3f(-0.95f + r + shift, 0.0f, 0.0f));
    Transform3D rotation = new Transform3D();
    rotation.rotY(Math.PI / 4);
    Transform3D rotationX = new Transform3D();
    rotationX.rotX(Math.PI / 6);
    rotation.mul(rotationX);
    tfBox2.mul(rotation);
    TransformGroup tgBox2 = new TransformGroup(tfBox2);
    tgBox2.addChild(b2);
    theScene.addChild(tgBox2);

    // Generate a white background.
    Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.MAX_VALUE);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);

    theScene.compile();

    // Add the scene to the universe.
    su.addBranchGraph(theScene);
  }
Example #8
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);
 }
Example #9
0
 public void setGround(boolean groundOn) {
   if (!groundOn) {
     kainBG.removeChild(groundBG);
     groundState = false;
   } else {
     kainBG.addChild(groundBG);
     groundState = true;
   }
 }
Example #10
0
 public void setAxisLines(boolean axisOn) {
   if (!axisOn) {
     kainBG.removeChild(axisBG);
     axisState = false;
   } else {
     kainBG.addChild(axisBG);
     axisState = true;
   }
 }
Example #11
0
  /**
   * Simple algorithm to add or remove an edge from the selection Ideas: 1. Use one shape per quad
   * => easy, but can become very fast too big to fit in memory. => pb: flicker when adding /
   * removing because the scene is detached 2. Use only one shape, modify geometry TODO: pre-create
   * an empty shape to avoid initial flicker
   *
   * @param on
   * @param p
   * @param u
   * @param v
   * @param groupIdx2
   */
  protected void toggleSelectedEdge(boolean on, SelectionEdge se) {
    if (on) {
      // add the given edge to the list
      if (edgeSelection.contains(se)) return; // already in
      edgeSelection.add(se);
    } else {
      // remove the given edge from the list
      if (!edgeSelection.contains(se)) return; // not present
      edgeSelection.remove(se);
      if (edgeSelection.size() == 0) {
        LineArray la = (LineArray) edgeSelectionShape.getGeometry();
        la.setValidVertexCount(0);
        return;
      }
    }
    // Use in-memory arrays instead of NIO because edgeSelection should not
    // be too big
    // => faster
    LineArray la =
        new LineArray(
            edgeSelection.size() * 2,
            GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.BY_REFERENCE);
    double[] coords = new double[edgeSelection.size() * 2 * 3];
    float[] colors = new float[edgeSelection.size() * 2 * 3];

    for (int i = 0; i < coords.length; i += 6) {
      SelectionEdge edge = edgeSelection.get(i / 6);
      edge.updateCoords(grid, coords, i);
      edge.updateColors(colors, i);
    }
    la.setCoordRefDouble(coords);
    la.setColorRefFloat(colors);
    la.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    // update edgeSelection Shape with the new edgeSelection list
    if (edgeSelectionShape == null) {
      Appearance a = new Appearance();
      // PolygonAttributes pa = new
      // PolygonAttributes(PolygonAttributes.POLYGON_LINE,
      // PolygonAttributes.CULL_NONE, 0);
      // pa.setPolygonOffset(1); // above edges
      // pa.setPolygonOffsetFactor(1);
      LineAttributes lat = new LineAttributes();
      lat.setLineWidth(2.0f);
      lat.setLineAntialiasingEnable(true);
      a.setLineAttributes(lat);
      // a.setPolygonAttributes(pa);
      edgeSelectionShape = new Shape3D(la, a);
      edgeSelectionShape.setUserData(this);
      edgeSelectionShape.setPickable(false);
      edgeSelectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
      edgeSelectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

      BranchGroup bg = new BranchGroup();
      bg.addChild(edgeSelectionShape);
      addChild(bg);
    } else edgeSelectionShape.setGeometry(la);
  }
 public BranchGroup createSceneGraph() {
   BranchGroup root = new BranchGroup(); // Create the root of the branch graph
   if (geometry_ == null) {
     int NUM_PARTICLES = 10;
     geometry_ = new Java3DParticlesGeometry(NUM_PARTICLES);
   }
   root.addChild(createPointShape(geometry_));
   return root;
 }
  // In this method, the objects for the scene are generated and added to
  // the SimpleUniverse.
  public void createSceneGraph(SimpleUniverse su) {

    // Create the root of the branch group for the scene.
    BranchGroup theScene = new BranchGroup();

    // Generate an Appearance for the sphere.
    Color3f ambientColourSphere = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f emissiveColourSphere = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f diffuseColourSphere = new Color3f(0.6f, 0.6f, 0.6f);
    Color3f specularColourSphere = new Color3f(0.5f, 0.5f, 0.5f);

    float shininessSphere = 20.0f;

    Appearance sphereApp = new Appearance();

    sphereApp.setMaterial(
        new Material(
            ambientColourSphere,
            emissiveColourSphere,
            diffuseColourSphere,
            specularColourSphere,
            shininessSphere));

    // n spheres with radius r will be shown.
    int n = 5;
    float r = 0.15f;
    float shift = 2 * r + 0.05f; // The distance between the centres of the spheres.

    // Arrays for the sphere, their transformations and their transformation groups
    // transformation groups (for positioning).
    Sphere[] spheres = new Sphere[n];
    TransformGroup[] tg = new TransformGroup[n];
    Transform3D[] tf = new Transform3D[n];

    // Generate the sphere, their transformations and their
    // transformation groups. Add everyting to the scene.
    for (int i = 0; i < n; i++) {
      spheres[i] = new Sphere(r, Sphere.GENERATE_NORMALS, 4 + i * i * i, sphereApp);
      tf[i] = new Transform3D();
      tf[i].setTranslation(new Vector3f(-0.95f + r + shift * i, 0.0f, 0.0f));
      tg[i] = new TransformGroup(tf[i]);
      tg[i].addChild(spheres[i]);
      theScene.addChild(tg[i]);
    }

    // Generate a white background.
    Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);

    theScene.compile();

    // Add the scene to the universe.
    su.addBranchGraph(theScene);
  }
Example #14
0
  public void showCategory(String categoryName) {
    if (displayedMenuItems.numChildren() != 0) displayedMenuItems.removeAllChildren();

    BranchGroup category = menuBranches.get(categoryName);
    displayedMenuItems.addChild(category);
    Enumeration<MenuItem> children = category.getAllChildren();
    while (children.hasMoreElements()) {
      MenuItem child = (MenuItem) children.nextElement();
      child.armBehavior();
    }
  }
Example #15
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;
  }
Example #16
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);
  }
Example #17
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;
  }
Example #18
0
  /**
   * Simple algorithm to add or remove a quad from the selection Ideas: 1. Use one shape per quad =>
   * easy, but can become very fast too big to fit in memory. => pb: flicker when adding / removing
   * because the scene is detached 2. Use only one shape, modify geometry TODO: pre-create an empty
   * shape to avoid initial flicker
   *
   * @param on
   * @param p
   * @param u
   * @param v
   * @param groupIdx2
   */
  protected void toggleSelectedQuad(boolean on, SelectionQuad sq) {
    LOGGER.finest("on=" + on + " selectionQuad=" + sq);
    if (on) {
      // add the given quad to the list
      if (selection.contains(sq)) return; // already in
      selection.add(sq);
    } else {
      // remove the given quad from the list
      if (!selection.contains(sq)) return; // not present
      selection.remove(sq);
      if (selection.size() == 0) {
        QuadArray qa = (QuadArray) selectionShape.getGeometry();
        qa.setValidVertexCount(0);
        return;
      }
    }
    // Use in-memory arrays instead of NIO because selection should not be
    // too big
    // => faster
    QuadArray qa =
        new QuadArray(
            selection.size() * 4,
            GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.BY_REFERENCE);
    float[] coords = new float[selection.size() * 4 * 3];
    float[] colors = new float[selection.size() * 4 * 3];

    for (int i = 0; i < coords.length; i += 12) {
      SelectionQuad quad = selection.get(i / 12);
      quad.updateCoords(grid, coords, i);
      quad.updateColors(colors, i);
    }
    qa.setCoordRefFloat(coords);
    qa.setColorRefFloat(colors);
    qa.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    // update selection Shape with the new selection list
    if (selectionShape == null) {
      Appearance a = new Appearance();
      PolygonAttributes pa =
          new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
      pa.setPolygonOffset(0.5f); // between faces and edges
      pa.setPolygonOffsetFactor(0.5f);
      a.setPolygonAttributes(pa);
      selectionShape = new Shape3D(qa, a);
      selectionShape.setUserData(this);
      selectionShape.setPickable(false);
      selectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
      selectionShape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
      BranchGroup bg = new BranchGroup();
      bg.addChild(selectionShape);
      addChild(bg);
    } else selectionShape.setGeometry(qa);
  }
Example #19
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;
  }
Example #20
0
  private void createSceneGraph() throws PluginException, IfcModelInterfaceException {
    buildingTransformGroup = new TransformGroup();

    Set<Class<? extends IfcRoot>> classesToConvert = new HashSet<Class<? extends IfcRoot>>();
    classesToConvert.add(IfcWall.class);
    classesToConvert.add(IfcWallStandardCase.class);
    classesToConvert.add(IfcWindow.class);
    classesToConvert.add(IfcOpeningElement.class);
    classesToConvert.add(IfcSlab.class);
    classesToConvert.add(IfcRoof.class);
    classesToConvert.add(IfcColumn.class);
    classesToConvert.add(IfcSpace.class);
    classesToConvert.add(IfcDoor.class);
    classesToConvert.add(IfcRailing.class);
    classesToConvert.add(IfcFurnishingElement.class);
    classesToConvert.add(IfcStair.class);
    classesToConvert.add(IfcBeam.class);
    classesToConvert.add(IfcFlowTerminalType.class);
    classesToConvert.add(IfcDistributionFlowElement.class);
    classesToConvert.add(IfcSite.class);
    // classesToConvert.add(IfcProxy.class);

    for (IdEObject idEObject : model.getValues()) {
      if (classesToConvert.contains(idEObject.eClass().getInstanceClass())) {
        setGeometry((IfcRoot) idEObject);
      }
    }
    buildingBranchGroup = new BranchGroup();
    addLights(buildingBranchGroup);
    buildingBranchGroup.addChild(buildingTransformGroup);
    showLoader = false;
    sceneBranchGroup.removeChild(loaderBranchGroup);
    sharedGroup.addChild(buildingBranchGroup);

    // for (int x = 0; x < 5; x++) {
    // for (int y = 0; y < 5; y++) {
    Link link1 = new Link(sharedGroup);
    Transform3D t3d1 = new Transform3D();
    // t3d1.setTranslation(new Vector3f(x * 20, y * 20, 0f));
    BranchGroup x1 = new BranchGroup();
    TransformGroup t1 = new TransformGroup(t3d1);
    x1.addChild(t1);
    t1.addChild(link1);
    sceneBranchGroup.addChild(x1);
    // }
    // }

    reInitView();
  }
Example #21
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;
 }
  private void labelAxes()
        // Place numbers along the X- and Z-axes at the integer positions
      {
    Vector3d pt = new Vector3d();
    for (int i = -FLOOR_LEN / 2; i <= FLOOR_LEN / 2; i++) {
      pt.x = i;
      floorBG.addChild(makeText(pt, "" + i)); // along x-axis
    }

    pt.x = 0;
    for (int i = -FLOOR_LEN / 2; i <= FLOOR_LEN / 2; i++) {
      pt.z = i;
      floorBG.addChild(makeText(pt, "" + i)); // along z-axis
    }
  } // end of labelAxes()
Example #23
0
 @Override
 public void stopBehavior() {
   Enumeration<MenuItem> children = ((Group) displayedMenuItems.getChild(0)).getAllChildren();
   while (children.hasMoreElements()) {
     MenuItem child = (MenuItem) children.nextElement();
     child.behavior.setEnable(false);
   }
 }
Example #24
0
 /**
  * Specify whether to make axes visible.
  *
  * @param b whether visible.
  */
 public void setViewAxis(boolean b) {
   if (b) {
     if (!axisView) objTrans.addChild(axisGroup);
   } else {
     if (axisView) axisGroup.detach();
   }
   axisView = b;
 }
  private void renderScene(IScene scene) {
    if (scene == null || scene.getBranchGroupContainer().getSize() < 1) {
      canvas3D.setSceneGraph(new BranchGroup());
      lastSceneRef = null;
    } else {
      // reconstruction de la scène complète
      final Bounds bounds = new BoundingSphere(new Point3d(), Double.POSITIVE_INFINITY);

      final BranchGroup root = new BranchGroup();
      root.addChild(
          Java3DUtils.addMouseBehavior(
              Java3DUtils.scale(scene.getBranchGroupContainer().getBranchGraph(), scale), bounds));

      canvas3D.setSceneGraph(root);
      lastSceneRef = new WeakReference<IScene>(scene);
    }
  }
Example #26
0
 /** Dispose of any old scene and create a new one */
 public void setupScene() {
   if (scene != null) {
     scene.detach();
     scene = null;
   }
   scene = createSceneGraph();
   if (uni == null) uni = new SimpleUniverse(this);
 }
Example #27
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);
  }
Example #28
0
 /**
  * Specify whether to make equator visible.
  *
  * @param b whether visible.
  */
 public void setViewEquator(boolean b) {
   if (b) {
     if (!equatorView) objTrans.addChild(equatorGroup);
   } else {
     if (equatorView) equatorGroup.detach();
   }
   equatorView = b;
 }
Example #29
0
  @SuppressWarnings("unchecked")
  public void saveAsFile() {
    TransformGroup themodel = lobj.getModel3D();
    File file = showSaveImageDialog();
    if (file != null) {
      BranchGroup scene = new BranchGroup();
      render.removeObj3D(lobj);
      Enumeration<Group> enume = themodel.getAllChildren();

      while (enume.hasMoreElements()) {
        Group next = enume.nextElement();
        themodel.removeChild(next);
        scene.addChild(next);
      }

      // String file=this.getModel3DHref();
      // file.replace(".3ds", ".j3d");

      // OutputStream outS;
      try {
        SceneGraphFileWriter filew =
            new SceneGraphFileWriter(file, null, false, "genereted by Neptus", null);
        filew.writeBranchGraph(scene);
        System.err.println("vehicle w:" + file.getPath() + "\n");
        filew.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (UnsupportedUniverseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      TransformGroup themodel2 = new TransformGroup();
      enume = scene.getAllChildren();
      while (enume.hasMoreElements()) {
        Group next = enume.nextElement();
        scene.removeChild(next);
        themodel2.addChild(next);
      }

      lobj = new Obj3D();
      lobj.setModel3D(themodel2);
      render.addObj3D(lobj);
    }
  }
Example #30
0
 public Model3d(Univers univers) {
   this.univers = univers;
   this.atoms = new Vector(50, 100);
   this.setExpand(1, 1, 1);
   BranchGroup bg = new BranchGroup();
   this.root = new BranchGroup();
   this.root.setCapability(Group.ALLOW_CHILDREN_WRITE);
   this.root.setCapability(Group.ALLOW_CHILDREN_EXTEND);
   this.deltaroot = new BranchGroup();
   this.deltaroot.setCapability(Group.ALLOW_CHILDREN_WRITE);
   this.deltaroot.setCapability(Group.ALLOW_CHILDREN_EXTEND);
   this.delta = new TransformGroup();
   this.delta.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
   this.delta.addChild(this.deltaroot);
   this.root.addChild(this.delta);
   bg.addChild(this.root);
   univers.root.addChild(bg);
 }