Exemple #1
0
 private void updateFaceColor() {
   if (appearance != null) {
     appearance.setAttribute(
         CommonAttributes.POLYGON_SHADER + "." + CommonAttributes.DIFFUSE_COLOR, getFaceColor());
   }
   faceColorButton.setColor(getFaceColor());
 }
Exemple #2
0
 private void updateFaceReflection() {
   if (isFacesReflecting()) {
     appearance.setAttribute(
         "polygonShader.reflectionMap:blendColor",
         new Color(1f, 1f, 1f, (float) getFaceReflection()));
   }
 }
 public static void main(String[] args) {
   // a little Scene (two boxes and a bangle, transfomation, appearance)
   IndexedFaceSet box = Primitives.box(2, .5, .5, false);
   IndexedFaceSet box2 = Primitives.box(2, .6, 0.4, true);
   IndexedFaceSet zyl = Primitives.cylinder(20, 1, 0, .5, 5);
   SceneGraphComponent original = new SceneGraphComponent();
   SceneGraphComponent childNode1 = new SceneGraphComponent();
   MatrixBuilder.euclidean().translate(0, 0, 1).assignTo(childNode1);
   SceneGraphComponent childNode2 = new SceneGraphComponent();
   Appearance app = new Appearance();
   app.setAttribute(
       CommonAttributes.POLYGON_SHADER + "." + CommonAttributes.DIFFUSE_COLOR,
       new Color(255, 255, 0));
   childNode2.setAppearance(app);
   original.addChild(childNode1);
   original.addChild(childNode2);
   original.setGeometry(box2);
   childNode1.setGeometry(box);
   childNode2.setGeometry(zyl);
   // the Factory:
   GeometryMergeFactory mergeFact = new GeometryMergeFactory();
   // play with the following 3 optional settings (by default they are true)
   mergeFact.setRespectFaces(true);
   mergeFact.setRespectEdges(true);
   mergeFact.setGenerateVertexNormals(true);
   // you can set some defaults:
   List defaultAtts = new LinkedList();
   List defaultAttValue = new LinkedList();
   List value = new LinkedList();
   defaultAtts.add(Attribute.COLORS);
   defaultAttValue.add(value);
   value.add(new double[] {0, 1, 0, 1}); // remember: only 4d colors
   mergeFact.setDefaultFaceAttributes(defaultAtts, defaultAttValue);
   // merge a list of geometrys:
   // IndexedFaceSet[] list= new IndexedFaceSet[]{box2,zyl};
   // IndexedFaceSet result=mergeFact.mergeIndexedFaceSets(list);
   // or  a complete tree:
   IndexedFaceSet result = mergeFact.mergeGeometrySets(original);
   SceneGraphComponent world = SceneGraphUtility.createFullSceneGraphComponent("world");
   SceneGraphComponent merged = SceneGraphUtility.createFullSceneGraphComponent("merged");
   merged.setGeometry(result);
   MatrixBuilder.euclidean().translate(3, 0, 0).assignTo(merged);
   world.addChildren(merged, original);
   JRViewer.display(world);
 }
  /**
   * *******************************************************************************
   * prepareNewSceneGraphComponent
   *
   * <p>This method is the primary method called by users of MarkerAppearance. Given the appearance
   * data provided to a given instance of MarkerAppearance, that instance can use this method to
   * create a new scene graph component (not referenced in any other scene graph) representing that
   * data. Thus, users of MarkerAppearance are freed from having to load model meshes, deal with
   * their textures, etc.
   * *******************************************************************************
   */
  public SceneGraphComponent makeSceneGraphComponent() {
    SceneGraphComponent sgc = new SceneGraphComponent();
    sgc = copySceneGraph(templateSGCs.get(this.model));

    Appearance app = getBasicAppearance();
    if (this.model == ModelType.ARROWHEAD || this.model == ModelType.ARROWBODY) {
      app.setAttribute(LINE_SHADER + "." + TUBE_RADIUS, .05);
      app.setAttribute(POINT_SHADER + "." + POINT_RADIUS, .05);
    } else if (this.model == ModelType.FLAG) {
      app.setAttribute(LINE_SHADER + "." + DIFFUSE_COLOR, Color.red);
      app.setAttribute(POINT_SHADER + "." + DIFFUSE_COLOR, Color.red);
      app.setAttribute(POLYGON_SHADER + "." + DIFFUSE_COLOR, Color.red);
    }
    sgc.setAppearance(app);
    sgc.setTransformation(getScalingTransformation());
    sgc.setVisible(true);

    return sgc;
  }
 protected Appearance getBasicAppearance() {
   Appearance app = new Appearance();
   app.setAttribute(VERTEX_DRAW, false);
   app.setAttribute(EDGE_DRAW, false);
   app.setAttribute(FACE_DRAW, true);
   app.setAttribute(TRANSPARENCY_ENABLED, false);
   app.setAttribute(PICKABLE, false);
   app.setAttribute(LIGHTING_ENABLED, true);
   app.setAttribute(POLYGON_SHADER + "." + SMOOTH_SHADING, true);
   app.setAttribute(POLYGON_SHADER + "." + SPECULAR_COEFFICIENT, 0.15);
   app.setAttribute(LINE_SHADER + "." + DIFFUSE_COLOR, this.color);
   app.setAttribute(POINT_SHADER + "." + DIFFUSE_COLOR, this.color);
   app.setAttribute(POLYGON_SHADER + "." + DIFFUSE_COLOR, this.color);
   app.setAttribute(CommonAttributes.ANTIALIASING_ENABLED, true);
   return app;
 }
Exemple #6
0
  public Terrain() {
    appearance.setAttribute(CommonAttributes.EDGE_DRAW, false);
    appearance.setAttribute(CommonAttributes.VERTEX_DRAW, false);
    terrain.setAppearance(appearance);

    MatrixBuilder.euclidean().rotateX(Math.PI / 2).assignTo(plane);
    plane.setGeometry(bigMesh(50, 50, 2000));
    plane.getGeometry().setGeometryAttributes("infinite plane", Boolean.TRUE);
    PickUtility.assignFaceAABBTrees(plane);
    terrain.addChild(plane);

    textures.put("2 Grid", "textures/grid.jpeg");
    textures.put("3 Black Grid", "textures/gridBlack.jpg");
    textures.put("4 Tiles", "textures/recycfloor1_clean2.png");
    textures.put("5 Rust", "textures/outfactory3.png");
    textures.put("1 None", null);

    shrinkPanel.setLayout(new GridLayout());
    shrinkPanel.setIcon(getPluginInfo().icon);
    shrinkPanel.setShrinked(true);
    shrinkPanel.add(panel);
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(1, 0, 1, 0);
    c.fill = BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridwidth = REMAINDER;
    c.anchor = WEST;
    colorPanel.setLayout(new GridBagLayout());
    faceColorChooser.setMinimumSize(new Dimension(10, 230));
    faceColorChooser.setPreferredSize(new Dimension(10, 230));
    colorPanel.add(faceColorChooser, c);
    c.fill = VERTICAL;
    c.weighty = 0.0;
    colorPanel.add(closeButton, c);

    // panel
    panel.setLayout(new MinSizeGridBagLayout());
    c.fill = BOTH;

    visibleCheckBox.setSelected(DEFAULT_TERRAIN_VISIBLE);
    c.weightx = 0.0;
    c.gridwidth = RELATIVE;
    panel.add(visibleCheckBox, c);
    c.weightx = 1.0;
    c.gridwidth = REMAINDER;
    panel.add(faceColorButton, c);

    c.weightx = 0.0;
    c.weighty = 0.0;
    c.gridwidth = RELATIVE;
    panel.add(facesReflecting, c);
    c.weightx = 1.0;
    c.gridwidth = REMAINDER;
    panel.add(faceReflectionSlider, c);

    c.weightx = 0.0;
    c.gridwidth = RELATIVE;
    panel.add(transparency, c);
    c.weightx = 1.0;
    c.gridwidth = REMAINDER;
    panel.add(transparencySlider, c);

    c.weightx = 1.0;
    c.gridwidth = REMAINDER;
    panel.add(reflectScene, c);
    reflectScene.setEnabled(false);
    reflectScene.setToolTipText("Coming soon...");

    textureInspector.setMaximalTextureScale(MAXIMAL_TEXTURE_SCALE);
    textureInspector.setLogarithmicRange(LOGARITHMIC_RANGE);
    textureInspector.setTextureUScale(DEFAULT_TEXTURE_SCALE);
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridwidth = REMAINDER;
    textureShrinker.setIcon(ImageHook.getIcon("photo.png"));
    textureShrinker.setShrinked(true);
    textureShrinker.setLayout(new GridLayout());
    textureShrinker.add(textureInspector);
    panel.add(textureShrinker, c);

    closeButton.addActionListener(this);
    visibleCheckBox.addActionListener(this);
    facesReflecting.addActionListener(this);
    transparency.addActionListener(this);
    faceColorButton.addActionListener(this);
    reflectScene.addActionListener(this);
    faceReflectionSlider.addChangeListener(this);
    transparencySlider.addChangeListener(this);
    faceColorChooser.getColorPanel().addChangeListener(this);
  }
Exemple #7
0
 private void updateTransparencyEnabled() {
   if (appearance != null) {
     appearance.setAttribute(CommonAttributes.TRANSPARENCY_ENABLED, isTransparencyEnabled());
   }
 }
Exemple #8
0
 private void updateTransparency() {
   if (appearance != null) {
     appearance.setAttribute(
         CommonAttributes.POLYGON_SHADER + "." + CommonAttributes.TRANSPARENCY, getTransparency());
   }
 }
  public static SceneGraphComponent getSkyBox(JrScene scene) {
    Appearance rootApp = scene.getSceneRoot().getAppearance();
    if (rootApp == null || rootApp.getAttribute(SKY_BOX) == INHERITED) {
      return null;
    }
    CubeMap skyBox = (CubeMap) createAttributeEntity(CubeMap.class, SKY_BOX, rootApp, true);
    if (skyBox == null) return null;
    if (skyBox.getFront() == null
        || skyBox.getBack() == null
        || skyBox.getLeft() == null
        || skyBox.getRight() == null
        || skyBox.getTop() == null
        || skyBox.getBottom() == null) return null;
    SceneGraphComponent r = new SceneGraphComponent();
    IndexedFaceSetFactory ifsf = new IndexedFaceSetFactory();
    ifsf.setVertexCount(4);
    ifsf.setFaceCount(1);
    ifsf.setVertexCoordinates(new double[][] {{1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 1, 0}});
    ifsf.setFaceIndices(new int[][] {{0, 1, 2, 3}});
    double o = 0.005;
    ifsf.setVertexTextureCoordinates(
        new double[][] {{1 - o, 1 - o}, {1 - o, o}, {o, o}, {o, 1 - o}});
    ifsf.update();

    SceneGraphComponent front = new SceneGraphComponent();
    Appearance frontApp = new Appearance();
    createTexture(frontApp, POLYGON_SHADER, skyBox.getFront());
    front.setAppearance(frontApp);
    front.setGeometry(ifsf.getGeometry());
    front.setName("front");
    euclidean().translate(0, 0, 1.0).rotate(PI, 0, 1, 0).assignTo(front);

    SceneGraphComponent back = new SceneGraphComponent();
    Appearance backApp = new Appearance();
    createTexture(backApp, POLYGON_SHADER, skyBox.getBack());
    back.setAppearance(backApp);
    back.setGeometry(ifsf.getGeometry());
    back.setName("back");
    euclidean().translate(0, 0, -1.0).assignTo(back);

    SceneGraphComponent top = new SceneGraphComponent();
    Appearance topApp = new Appearance();
    createTexture(topApp, POLYGON_SHADER, skyBox.getTop());
    top.setAppearance(topApp);
    top.setGeometry(ifsf.getGeometry());
    top.setName("bottom");
    euclidean().translate(0, 1.0, 0).rotate(PI / 2, 1, 0, 0).rotate(-PI / 2, 0, 0, 1).assignTo(top);

    SceneGraphComponent bottom = new SceneGraphComponent();
    Appearance bottomApp = new Appearance();
    createTexture(bottomApp, POLYGON_SHADER, skyBox.getBottom());
    bottom.setAppearance(bottomApp);
    bottom.setGeometry(ifsf.getGeometry());
    bottom.setName("top");
    euclidean()
        .translate(0, -1.0, 0)
        .rotate(-PI / 2, 1, 0, 0)
        .rotate(PI / 2, 0, 0, 1)
        .assignTo(bottom);

    SceneGraphComponent left = new SceneGraphComponent();
    Appearance leftApp = new Appearance();
    createTexture(leftApp, POLYGON_SHADER, skyBox.getLeft());
    left.setAppearance(leftApp);
    left.setGeometry(ifsf.getGeometry());
    left.setName("left");
    euclidean().translate(-1.0, 0, 0).rotate(PI / 2, 0, 1, 0).assignTo(left);

    SceneGraphComponent right = new SceneGraphComponent();
    Appearance rightApp = new Appearance();
    createTexture(rightApp, POLYGON_SHADER, skyBox.getRight());
    right.setAppearance(rightApp);
    right.setGeometry(ifsf.getGeometry());
    right.setName("right");
    euclidean().translate(1.0, 0, 0).rotate(-PI / 2, 0, 1, 0).assignTo(right);

    r.addChildren(front, back, top, bottom, left, right);
    r.setName("skybox");
    euclidean().rotate(PI / 2, 0, 1, 0).rotate(PI, 1, 0, 0).scale(1000.0).assignTo(r);

    Appearance skyBoxApp = new Appearance();
    skyBoxApp.setAttribute(POLYGON_SHADER + "." + LIGHTING_ENABLED, false);
    skyBoxApp.setAttribute(POLYGON_SHADER + "." + AMBIENT_COLOR, WHITE);
    skyBoxApp.setAttribute(POLYGON_SHADER + "." + AMBIENT_COEFFICIENT, 1.0);
    skyBoxApp.setAttribute(POLYGON_SHADER + "." + DIFFUSE_COEFFICIENT, 0.0);
    skyBoxApp.setAttribute(POLYGON_SHADER + "." + SPECULAR_COEFFICIENT, 0.0);
    r.setAppearance(skyBoxApp);
    return r;
  }