Areas
  • J3D FAQ
  • Tutorials
  • Utilities
  • Books
  • News
  • Other Sites
  • FAQ Topics
  • Introduction to Java 3D
  • Documentation
  • Speed issues
  • Running Java 3D
  • Object manipulation
  • Scene appearance
  • Java 3D and Swing
  • Image capturing
  • Stereo viewing
  • Input Devices
  • Textures
  • Web browsers
  • Video Hardware
  • VRML
  •   

    Scene appearance

    1. Objects not appearing in the right order

    2. Only seeing one side of a flat object

    3. Shading does not appear to be correct

    4. Transparency not working with multiple transparent objects

    5. Displaying only the points of an object

    6. Automatically placing an object in the center of the Canvas3D

    Return to the main FAQ page for more questions and answers.

      

    1. Objects not appearing in the right order

    Sometimes when you place objects in a scene, the objects in the back appear to be in the front.

    There are a couple of ways to fix this, depending on what effect you are trying to achieve.

    The easiest way is to turn on Z-buffering. You can do this by setting the RenderingAttributes object within the Appearance Node in a Shape3D object.

    		Appearance app = new Appearance();
    		// 
    		// set Appearance attributes as you'd like
    		// 
    		RenderingAttributes ra = new RenderingAttributes();
    		ra.setDepthBufferEnable(true);
    		app.setRenderingAttributes(ra);
    

    Back to top

    2. Only seeing one side of a flat object

    The reason you're seeing this is that the faces are only visible in the direction that the normals are pointing. There are couple of different ways to do what you want. One way is to take the faces you currently have, duplicate them, wind the polygons in the opposite direction, and set the normals in the opposite direction from the original. Another (easier) way is to take an appearance ("app" in the example below) and do the following:

    		PolygonAttributes pa = new PolygonAttributes();
    		pa.setCullFace(PolygonAttributes.CULL_NONE);
    		app.setPolygonAttributes(pa);
    

    Back to top

    3. Shading does not appear to be correct

    Sometimes an object may appear to be correctly colored on one side, and not the other. The reason you're seeing that is the normals for that polygons are facing away from the light source, negating the calculation for how the surface should be lit. The method setBackFaceNormalFlip in PolygonAttributes addresses this. By setting this value to "true", the lighting calculations are done as if the normals for the surface are pointing the correct way. Note that you must also have setCullFace set to CULL_NONE in order for this to take effect.

    		PolygonAttributes pa = new PolygonAttributes();
    		pa.setCullFace(PolygonAttributes.CULL_NONE);
    		pa.setBackFaceNormalFlip(true);
    		app.setPolygonAttributes(pa);
    

    Back to top

    4. Transparency not working with multiple transparent objects

    From Kevin Rushforth:

    The basic problem is that transparency is inherently an order-dependent operation. For the rendering to be correct in all cases, all triangles must be rendered from back to front. In cases without a lot of overlapping transparent objects, you can usually get good results by rendering all of the opaque objects, freezing the Z-buffer, and then rendering all of the transparent objects. However, this sometimes has the side-effect of causing transparent objects that are further away to look like they are in front of transparent objects that are closer. Turning on the Z-buffer (by disabling DepthBufferFreezeTransparent) fixes this, but creates other problems.

    Without sorting your geometry--and breaking it up in the case of intersecting objects--there is no solution. In Java 3D 1.2 we have proposed new blending modes that will allow you to blend transparent objects in a truly order-independent manner, but with the side effect that you get an additive effect where two objects intersect.

    Back to top

    5. Displaying only the points of an object

    The example program, DisplayPoints.java shows how to do this. Thanks to Doug Gehringer for providing this example.

    Back to top

    6. Automatically placing an object in the center of the Canvas3D

    Doug Gehringer suggests the following:

    If you have the "usual" scene graph structure which puts the object in one BranchGraph and the view in another BranchGraph you can inquire the bounds of the object and modify the view to show the object. An example of this is the SimpleVrml97Viewer. I've attached the source this class below.

    The basic idea is to add the object to the scene, inquire the bounds of the object and then modify the view to show the object. Set the view by translating the view so that it is located at the center of the bounds and then translating the view "back" far enough to display the entire diameter of the bounds.

    Another way to do this (used by Vrml97Viewer) is use a constant view and modify a transform above the object to translate and scale the object to fit in the view. The source for Vrml97Viewer (along with alot of other good J3D/VRML content) can be found at http://www.vrml.org/WorkingGroups/vrml-java3d.

    Back to top

      

    [ Copyright Info ] [ FAQ Home ] [ J3D.org Home ] [ Tutorials ] [ Utilities ] [ Books ] [ Contact Us ]