Esempio n. 1
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);
 }
Esempio n. 2
0
  @Override
  public final TransformGroup getNode() {
    TransformGroup tg = super.getNode();

    ArrayList<KeyFrameObj> frames = this.getFrames();
    float[] knots = new float[frames.size()];
    Point3f[] positions = new Point3f[frames.size()];

    for (int i = 0; i < knots.length; i++) {
      KeyFrameObj f = frames.get(i);
      knots[i] = f.getKnots();
      // System.out.println(knots[i]);
      positions[i] = f.getPoint3f();
    }

    //        frames = null;

    PositionPathInterpolator interpolator =
        new PositionPathInterpolator(getAlpha(), tg, getAxis(), knots, positions);
    interpolator.setSchedulingBounds(bound);

    tg.addChild(interpolator);
    // System.out.println("a");
    return tg;
    // g.addChild(getTransformGroup());
  }
Esempio n. 3
0
  private void updateView() {
    Transform3D rotateXY = new Transform3D();

    Transform3D rotateY = new Transform3D();
    rotateXY.rotX(angleH);
    rotateY.rotY(angleV);
    rotateXY.mul(rotateY);
    rotateXY.setScale(scale);

    Vector3d trans = new Vector3d(-center.x, -center.y, -center.z);
    Transform3D translation = new Transform3D();
    translation.set(trans);
    rotateXY.mul(translation);

    rotation.setTransform(rotateXY);
    for (TransformGroup tg : textLabels) {
      Transform3D t = new Transform3D();
      tg.getTransform(t);
      Transform3D rotX = new Transform3D();
      Transform3D rotY = new Transform3D();

      rotY.rotY(lastAngleV - angleV);
      rotX.rotX(lastAngleH - angleH);
      t.mul(rotX);
      t.mul(rotY);

      tg.setTransform(t);
    }
    lastAngleH = angleH;
    lastAngleV = angleV;
  }
Esempio n. 4
0
  void rotate(final int xNew, final int yNew) {
    if (content == null || content.isLocked()) return;

    final int dx = xNew - xLast;
    final int dy = yNew - yLast;

    aaX.set(axisPerDx, dx * anglePerPix);
    aaY.set(axisPerDy, dy * anglePerPix);

    transX.set(aaX);
    transY.set(aaY);

    rotateTG.getTransform(rotateOld);

    rotateNew.set(transl_inv);
    rotateNew.mul(transY);
    rotateNew.mul(transX);
    rotateNew.mul(transl);
    rotateNew.mul(rotateOld);

    rotateTG.setTransform(rotateNew);
    xLast = xNew;
    yLast = yNew;

    transformChanged(BehaviorCallback.ROTATE, rotateNew);
  }
Esempio n. 5
0
  /**
   * This method creates a planar polygon shape with lava texture.
   *
   * @param radius a float for the size of the base polygon.
   * @param divisions an int for the number of divisons.
   * @param appearance an Appearance object.
   * @return Node a polygon.
   */
  private Node createShape(final float radius, final int divisions) {
    TriangleFanArray geometry =
        new TriangleFanArray(
            divisions,
            TriangleFanArray.COORDINATES | TriangleFanArray.TEXTURE_COORDINATE_2,
            new int[] {divisions});
    for (int i = 0; i < divisions; i++) {
      float baseX = (float) Math.cos(2 * Math.PI * i / divisions);
      float baseZ = -(float) Math.sin(2 * Math.PI * i / divisions);
      geometry.setCoordinate(i, new Point3f(radius * baseX, 0, radius * baseZ));
      geometry.setTextureCoordinate(0, i, new TexCoord2f((baseX + 1) / 2, (-baseZ + 1) / 2));
    }

    GeometryInfo gInfo = new GeometryInfo(geometry);
    new NormalGenerator().generateNormals(gInfo);
    gInfo.convertToIndexedTriangles();
    Shape3D fin = new Shape3D(gInfo.getGeometryArray());

    PolygonAttributes polyAttr =
        new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
    my_appearance.setPolygonAttributes(polyAttr);
    geometry.setCapability(Geometry.ALLOW_INTERSECT);
    fin = new Shape3D(geometry, my_appearance);
    Transform3D rotate = new Transform3D();
    rotate.rotY(Math.PI / 4);
    TransformGroup tg = new TransformGroup(rotate);
    tg.addChild(fin);
    return tg;
  }
Esempio n. 6
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;
  }
Esempio n. 7
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);
  }
  /**
   * setLinkStatus
   *
   * <p>Debugようにこのメソッドを叩くと現在のRobotの状態をIntegratorに通知する
   *
   * @param objectName
   */
  private void _setLinkStatus(String objectName) {
    if (robot_ == null) robot_ = (GrxModelItem) manager_.getItem(GrxModelItem.class, objectName);

    TransformGroup tg = robot_.getTransformGroupRoot();
    Transform3D t3d = new Transform3D();
    tg.getTransform(t3d);
    Vector3d pos = new Vector3d();
    Matrix3d mat = new Matrix3d();
    t3d.get(mat, pos);

    double[] value = new double[12];
    pos.get(value);
    value[3] = mat.m00;
    value[4] = mat.m01;
    value[5] = mat.m02;
    value[6] = mat.m10;
    value[7] = mat.m11;
    value[8] = mat.m12;
    value[9] = mat.m20;
    value[10] = mat.m21;
    value[11] = mat.m22;

    integrator_.setCharacterLinkData(
        objectName, robot_.rootLink().getName(), LinkDataType.ABS_TRANSFORM, value);
    integrator_.setCharacterAllLinkData(
        objectName, LinkDataType.JOINT_VALUE, robot_.getJointValues());
    integrator_.calcCharacterForwardKinematics(objectName);
  }
  // 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);
  }
Esempio n. 10
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);
 }
Esempio n. 11
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;
  }
Esempio n. 12
0
  /** Constructor that creates a group with its transformations */
  public SMGroup() {
    _rotation = new TransformGroup();
    _translation = new TransformGroup();
    _scale = new TransformGroup();
    _child = new BranchGroup();

    // Constructs the tree of the SMGroup
    super.addChild(_translation);
    _translation.addChild(_rotation);
    _rotation.addChild(_scale);
    _scale.addChild(_child);
  }
Esempio n. 13
0
  /**
   * 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);
  }
  private TransformGroup makeText(Vector3d vertex, String text)
        // Create a Text2D object at the specified vertex
      {
    Text2D message = new Text2D(text, white, "SansSerif", 36, Font.BOLD);
    // 36 point bold Sans Serif

    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(vertex);
    tg.setTransform(t3d);
    tg.addChild(message);
    return tg;
  } // end of getTG()
Esempio n. 15
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;
  }
Esempio n. 16
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();
  }
Esempio n. 17
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();
  }
Esempio n. 18
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;
 }
Esempio n. 19
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;
  }
  @Deprecated
  public void addText2D(String text, Font font, Color3f color, Point3f position) {
    Text2D renderedText = new Text2D(text, color, font.getName(), font.getSize(), font.getStyle());

    Transform3D transform = new Transform3D();
    transform.setTranslation(new Vector3f(position));

    TransformGroup transformations = new TransformGroup();
    transformations.setTransform(transform);
    transformations.addChild(renderedText);

    PlatformGeometry platformGeometry = new PlatformGeometry();
    platformGeometry.addChild(transformations);

    getViewingPlatform().setPlatformGeometry(platformGeometry);
  }
Esempio n. 21
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();
  }
Esempio n. 22
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;
 }
Esempio n. 23
0
  void translate(final int xNew, final int yNew) {
    if (content == null || content.isLocked()) return;
    final int dx = xNew - xLast;
    final int dy = yNew - yLast;
    translateTG.getTransform(translateOld);
    v1.scale(dx, translationPerDx);
    v2.scale(-dy, translationPerDy);
    translation.add(v1, v2);
    translateNew.set(translation);
    translateNew.mul(translateOld);

    translateTG.setTransform(translateNew);
    transformChanged(BehaviorCallback.TRANSLATE, translateNew);

    xLast = xNew;
    yLast = yNew;
  }
Esempio n. 24
0
 @Override
 public double calcRenderSize() {
   if (!centerGroup.isLive()) {
     return 0.0;
   } else {
     return renderer.calcRenderSize(calculator, canvas);
   }
 }
Esempio n. 25
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;
 }
Esempio n. 26
0
  /**
   * This is called from InfiniteWire when the current changes. Scales the arrow indicator to
   * reflect the change in current.
   *
   * @param current
   */
  public void setArrowDirection(double current) {
    Transform3D t = new Transform3D();
    t.setScale(current);

    arrow.setTransform(t);
    // txt.setString("Current: " + current + "\n linebreak?");

  }
Esempio n. 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);
  }
Esempio n. 28
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);
    }
  }
Esempio n. 29
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);
  }
Esempio n. 30
0
 /**
  * Specify whether to make the view of a single face visible.
  *
  * @param b whether visible.
  */
 public void setViewSpecificFace(boolean b) {
   if (b) {
     if (loneFaceGroup == null) setFace(faceNo);
     if (!loneFaceView && loneFaceGroup != null) objTrans.addChild(loneFaceGroup);
   } else {
     if (loneFaceView && loneFaceGroup != null) loneFaceGroup.detach();
   }
   loneFaceView = b;
 }