Esempio n. 1
0
 private static Map<Geometry, SceneGraphComponent> getGeometries_R(
     SceneGraphComponent root, SceneGraphPath p) {
   p.push(root);
   Map<Geometry, SceneGraphComponent> r = new HashMap<Geometry, SceneGraphComponent>();
   if (root.getGeometry() != null) {
     Geometry g = root.getGeometry();
     if (g instanceof PointSet) { // remove vertex normals if flat shading
       PointSet pSet = (PointSet) g;
       if (pSet.getVertexAttributes().containsAttribute(Attribute.NORMALS)) {
         EffectiveAppearance ea = EffectiveAppearance.create(p);
         DefaultGeometryShader dgs = ShaderUtility.createDefaultGeometryShader(ea);
         DefaultPolygonShader ps = (DefaultPolygonShader) dgs.getPolygonShader();
         if (!ps.getSmoothShading()) {
           pSet.setVertexAttributes(Attribute.NORMALS, null);
         }
       }
     }
     r.put(root.getGeometry(), root);
   }
   for (int i = 0; i < root.getChildComponentCount(); i++) {
     Map<Geometry, SceneGraphComponent> subList = getGeometries_R(root.getChildComponent(i), p);
     if (subList.size() != 0) {
       r.putAll(subList);
     }
   }
   p.pop();
   return r;
 }
Esempio n. 2
0
  /**
   * *******************************************************************************
   * initializeShaders
   *
   * <p>This helper method is used in the "initializeAppearance" methods below to set up the shaders
   * the appearance will use. Basically, this ensures the shaders are set up in a consistent way
   * (not doing this has created odd bugs in the past).
   *
   * <p>We set whether edges and vertices are drawn elsewhere (in View.java). In the past, we've
   * found that trying to use the "Appearance.setAttribute(CommonAttributes.*)" method of setting
   * attributes and setting this properties on a shader (Ex. dgs.setDrawLines(false);) leads to
   * problems. Thus, we don't specify whether edges/vertices should be drawn in the properties
   * below. *******************************************************************************
   */
  public static void initializeShaders(Appearance app, Color faceColor) {
    DefaultGeometryShader dgs =
        (DefaultGeometryShader) ShaderUtility.createDefaultGeometryShader(app, true);
    DefaultPolygonShader dps = (DefaultPolygonShader) dgs.createPolygonShader("default");

    dps.setAmbientColor(faceColor); // dps.setAmbientColor(c);
    dps.setDiffuseColor(faceColor); // dps.setDiffuseColor(c);
    dps.setAmbientCoefficient(0.3); // These coefficients seem to help the
    // texture look "bright"
    dps.setDiffuseCoefficient(0.8); // when it gets mapped to the surface.
    dps.setSpecularCoefficient(0.0); // We don't need faces to look shiny by
    // default.

    DefaultLineShader dls = (DefaultLineShader) dgs.getLineShader();
    dls.setDiffuseColor(Color.orange);
    dls.setTubeDraw(true);
    dls.setTubeRadius(0.05);
  }
Esempio n. 3
0
  @Override
  public void addMesh(double[][][] vertices, double[][][] normals, AppearanceState appearance) {

    if (vertices.length == 0) return;
    int l = vertices[0].length;
    for (int i = 0; i < vertices.length; ++i)
      if (vertices[i].length == 0 || vertices[i].length != l) return;

    SceneGraphComponent sgc = SceneGraphUtility.createFullSceneGraphComponent();
    QuadMeshFactory qmf = new QuadMeshFactory();

    qmf.setVLineCount(vertices.length);
    qmf.setULineCount(l);

    qmf.setClosedInUDirection(false);
    qmf.setClosedInVDirection(false);
    qmf.setVertexCoordinates(vertices);
    if (normals == null) {
      qmf.setGenerateFaceNormals(true);
      // qmf.setGenerateVertexNormals(true);
    } else {
      qmf.setVertexNormals(normals);
    }
    qmf.setGenerateTextureCoordinates(false);
    qmf.setGenerateEdgesFromFaces(true);
    qmf.setEdgeFromQuadMesh(true);

    Color[] colors = new Color[vertices.length * l];
    for (int i = 0; i < vertices.length * l; ++i) {
      colors[i] = appearance.getColor();
    }

    qmf.setVertexColors(colors);

    qmf.update();
    sgc.setGeometry(qmf.getGeometry());

    DefaultGeometryShader dgs =
        ShaderUtility.createDefaultGeometryShader(sgc.getAppearance(), true);

    dgs.setShowLines(true);
    dgs.setShowPoints(true);
    dgs.setShowFaces(true);

    dgs.createPointShader("my");

    MyLineShader ls = (MyLineShader) dgs.createLineShader("my");
    ls.setDiffuseColor(appearance.getColor());
    ls.setLineType(0);

    DefaultPolygonShader dps = (DefaultPolygonShader) dgs.getPolygonShader();

    dps.setTransparency(1 - appearance.getOpacity());

    sceneMeshes.addChild(sgc);
  }
Esempio n. 4
0
  public JRealityViewer() {
    psf = new PointSetFactory();
    pointCoordinates = new ArrayList<double[]>();
    pointColors = new ArrayList<Color>();
    pointSizes = new ArrayList<Double>();

    psf2 = new PointSetFactory();
    circleCenters = new ArrayList<double[]>();
    circleNormals = new ArrayList<double[]>();
    circleRadii = new ArrayList<Double>();
    circleColors = new ArrayList<Color>();

    ilsf = new IndexedLineSetFactory();
    lineCoordinates = new ArrayList<double[]>();
    lineIndices = new ArrayList<Integer>();
    lineSizes = new ArrayList<Double>();
    lineColors = new ArrayList<Color>();
    lineTypes = new ArrayList<Integer>();

    ifsf = new IndexedFaceSetFactory();
    polygonVertices = new ArrayList<double[][]>();
    polygonColors = new ArrayList<Color>();
    polygonTotalVertexCount = 0;

    sceneRoot = new SceneGraphComponent("root");

    // TODO: Set custom appearances for these components
    scenePoints = SceneGraphUtility.createFullSceneGraphComponent("points");
    scenePoints.setGeometry(psf.getGeometry());
    DefaultGeometryShader dgs =
        ShaderUtility.createDefaultGeometryShader(scenePoints.getAppearance(), true);
    dgs.createPointShader("my");

    sceneCircles = SceneGraphUtility.createFullSceneGraphComponent("circles");
    sceneCircles.setGeometry(psf2.getGeometry());
    dgs = ShaderUtility.createDefaultGeometryShader(sceneCircles.getAppearance(), true);
    dgs.createPointShader("circle");

    sceneLines = SceneGraphUtility.createFullSceneGraphComponent("lines");
    sceneLines.setGeometry(ilsf.getGeometry());
    dgs = ShaderUtility.createDefaultGeometryShader(sceneLines.getAppearance(), true);
    dgs.createPointShader("my");
    dgs.createLineShader("my");

    scenePolygons = new SceneGraphComponent("polygons");
    scenePolygons.setGeometry(ifsf.getGeometry());

    sceneMeshes = SceneGraphUtility.createFullSceneGraphComponent("meshes");

    sceneRoot.addChild(scenePoints);
    sceneRoot.addChild(sceneCircles);
    sceneRoot.addChild(sceneLines);
    sceneRoot.addChild(scenePolygons);
    sceneRoot.addChild(sceneMeshes);

    viewer = new JRViewer();
    viewer.setContent(sceneRoot);
    // viewer.registerPlugin(new DirectContent());
    viewer.registerPlugin(new ContentTools());
    // viewer.registerPlugin(new ContentLoader());
    // viewer.addBasicUI();

    // All plugins from as in BasicUI except shell
    viewer.registerPlugin(new Inspector());
    // viewer.registerPlugin(new Shell());

    viewer.registerPlugin(new BackgroundColor());
    viewer.registerPlugin(new DisplayOptions());
    viewer.registerPlugin(new ViewMenuBar());
    viewer.registerPlugin(new ViewToolBar());

    viewer.registerPlugin(new ExportMenu());
    viewer.registerPlugin(new CameraMenu());
    viewer.registerPlugin(new PropertiesMenu());
    //

    viewer.setShowPanelSlots(false, true, false, false);

    frame = new JFrame("Cindy3D");
    frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(viewer.startupLocal(), BorderLayout.CENTER);
    frame.pack();

    RenderingHintsShader rhs =
        ShaderUtility.createDefaultRenderingHintsShader(
            viewer.getViewer().getSceneRoot().getAppearance(), true);
    rhs.setTransparencyEnabled(true);

    // Set camera near and far plane
    camera = CameraUtility.getCamera(viewer.getViewer());
    camera.setNear(0.1);
    camera.setFar(1000.0);
  }