1 / 69

Java FX 3D: The Third Dimension

Java FX 3D: The Third Dimension. Kevin Rushforth & Chien Yang Oracle Corporation. Disclaimer.

orpah
Download Presentation

Java FX 3D: The Third Dimension

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java FX 3D: The Third Dimension Kevin Rushforth & Chien YangOracle Corporation

  2. Disclaimer The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decision. The development, release, and timing of any features or functionality described for Oracle's products remains at the sole discretion of Oracle.

  3. Program Agenda • JavaFX Graphics Overview • Transforms • Camera and Coordinate System • Z-buffer (depth test) • Movable Camera

  4. Program Agenda • 3D Geometry • 3D Attributes • Wrapup • Q&A

  5. JavaFX Graphics Overview Scene graph model Hierarchy of group and leaf (graphic primitive) nodes Leaf nodes have individual graphical attributes Group nodes can have collective attributes Parent/child directed graph similar to component trees

  6. JavaFX Graphics Overview Capabilities Transformation (translate, rotate, scale and shear) Animation (timeline and transitions) Effects (blurs, drop shadows, color filters, etc.) Rendering attributes

  7. JavaFX Graphics Overview Primary graphical node types Shape (rectangle, circle, path, etc.) Text (a specialized form of Shape) ImageView MediaView

  8. JavaFX SW Block Diagram

  9. A Simple JavaFX Scene Graph

  10. Simple Scenegraph Demo

  11. 3D Transforms: Node Transform Properties layoutX, layoutY – X and Y translation used for layout translateX, translateY, translateZ – X, Y and Z translation rotate – angle of rotation in degrees (about Node center) rotationAxis – axis about which rotation is done (default Z-axis) scaleX, scaleY, scaleZ – X, Y and Z scale (about Node center) transforms – A list of Transform objects (applied in order)

  12. Transforms Transform objects Translate(x, y, z, pivotX, pivotY, pivotZ) Scale(x, y, z, pivotX, pivotY, pivotZ) Rotate(angle, pivotX, pivotY, pivotZ, axis) Affine(mxx, mxy, mxz, tx, myx, myy, myz, ty, mzx, mzy, mzz, tz)

  13. Order of Transform Operations Translate(layoutX+translateX, layoutY+translateY, translateZ) Translate(pivotX, pivotY, pivotZ) // computed center of node Rotate(rotate, rotationAxis) Scale(scaleX, scaleY, scaleZ) Translate(-pivotX, -pivotY, -pivotZ) // computed center of node transform[0] transform[1] ...

  14. Depth Buffer (Z-buffer) Objects rendered in scene graph order Render order defines z order for 2D scene Render order != z value of objects in 3D scene (unless you reorder the scene graph) Depth buffer will sort objects based on their z value Sort is done per pixel by GPU

  15. Depth Buffer (Z-buffer)

  16. Depth Buffer (Z-buffer) Objects rendered in scene graph order Render order defines z order for 2D scene Render order != z value of objects in 3D scene (unless you reorder the scene graph) Depth buffer will sort objects based on their z value Sort is done per pixel by GPU

  17. Depth Buffer (Z-buffer)

  18. Depth Buffer (Z-buffer) Objects rendered in scene graph order Render order defines z order for 2D scene Render order != z value of objects in 3D scene (unless you reorder the scene graph) Depth buffer will sort objects based on their z value Sort is done per pixel by GPU

  19. Depth Buffer (Z-buffer) Construct scene with depth buffer attribute Node has depthTest property DISABLE, ENABLE and INHERIT depthTest is only used on Scene with a depth buffer Its default value is INHERIT If depthTest = INHERIT, depth testing is enabled if it is enabled for its parent node (or its parent node is null)

  20. How To Query 3D Support 3D is an optional feature Runs on AMD/ATI, Intel and NVIDIA with Pixel Shader 3 support Certain cards and drivers “blacklisted” Use ConditionalFeature.SCENE3D to check Indicates that 3D is available on the platform Perspective camera, 3D transforms, depth test ignored on platform without 3D support

  21. JavaFX on Windows Windows Vista / 7 / 8 (32-bit or 64-bit) HW acceleration via DirectX 9.0c, Pixel Shader 3 GPUs include: NVIDIA, AMD, Intel HD May need newer driver (especially for Intel HD) Run with -Dprism.verbose=true to check

  22. JavaFX on Mac OS X Mac OS X 10.7 (Lion) and 10.8 (Mountain Lion) HW acceleration via OpenGL 2.0 GPUs include: NVIDIA, AMD, Intel HD Run with -Dprism.verbose=true to check

  23. JavaFX on Linux Ubuntu 12.04 LTS or later, OEL 6 or later HW acceleration via OpenGL 2.0 GPUs include: NVIDIA, AMD Run with -Dprism.verbose=true to check Requires vendor-supplied driver

  24. Depth Test Demo

  25. VideoCube Demo

  26. Cameras and Coordinate System ParallelCamera Class A viewing volume for a parallel (ortho) projection; a rectangular box Located at center of the scene; looks along the positive Z-axis Origin in the upper left corner of the scene with the Y-axis pointing down and the Z-axis pointing away from the viewer (into the screen) The units are in pixel coordinates This is the default if no camera is specified

  27. Cameras and Coordinate System PerspectiveCamera Class A viewing volume for a perspective projection; a truncated right pyramid Field of view property (default = 30 degrees) It is always located at center of the scene and looks along the positive Z-axis Origin in the upper left corner of the scene with the Y-axis pointing down and the Z-axis pointing away from the viewer (into the screen) The units are in pixel coordinates at the projection plane (Z=0)

  28. JavaFX Coordinate System Differences from typical 3D coordinate systems Origin: top-left vs. center Direction: Y down vs. Y up Unit: pixel vs. normalized [-1, 1]

  29. Coordinate System

  30. Coordinate System Demo

  31. JavaFX 3D Features for Version 8 Movable cameras 3D primitives (e.g., meshes, predefined solids) 3D attributes (e.g., lights, materials, MSAA) 3D picking

  32. Camera Class Hierarchy javafx.scene.Node javafx.scene.Camera javafx.scene.ParallelCamera javafx.scene.PerspectiveCamera javafx.scene.SubScene

  33. Movable Camera Camera is now a Node Add to scene graph to move the camera Position and aim camera using transforms Fixed camera need not be added to scene New properties for near & far clipping plane

  34. Specifying a Fixed Camera // Create a camera and add it to the Scene Camera camera = new PerspectiveCamera(); scene.setCamera(camera);

  35. Specifying a Movable Camera // Create a movable camera and add it to the Scene Camera camera = new PerspectiveCamera(true); scene.setCamera(camera); // Add camera to scene graph (so it can move) Group cameraGroup = new Group(); cameraGroup.getChildren().add(camera); root.getChildren().add(cameraGroup); // Rotate the camera camera.rotate(45); // Move the cameraGroup (camera moves with it) cameraGroup.setTranslateZ(-75);

  36. SubScene Use SubScene node to render part of scene with different camera Used to separate 2D and 3D content Overlay or “heads-up” display for UI controls in a scene with a moving camera

  37. Movable Camera Demo

  38. 3D Shapes So far we have only shown 2D shapes (with 3D xform) 3D shapes will be added in FX 8 User-defined shapes Predefined shapes

  39. Shape3D Class Hierarchy javafx.scene.Node javafx.scene.shape.Shape3D javafx.scene.shape.MeshView javafx.scene.shape.Box javafx.scene.shape.Cylinder javafx.scene.shape.Sphere

  40. Shape3D Class Hierarchy, continued java.lang.Object javafx.scene.shape.Mesh javafx.scene.shape.TriangleMesh

  41. TriangleMesh Geometry A set of positions A set of texture coordinates A set of faces (triangles) that describe the topology Smoothing group Used to group triangles that are part of same curved surface Hard edges between triangles in different smoothing groups Sharable among multiple MeshView nodes

  42. Defining a MeshView // Create the arrays of positions, texCoords float[] positions = createPositions(); float[] texCoords = createUVs(); // Create faces (indices into the positions, texCoord arrays) int[] faces = createFaces(); // Create a mesh TriangleMesh mesh = new TriangleMesh(); mesh.getPositions.setAll(positions); mesh.getTexCoords.setAll(texCoords); mesh.getFaces.setAll(faces); // Create meshView MeshView mv = new MeshView(mesh);

  43. MeshView Demo

  44. Using Predefined Shapes // Create a sphere with the given radius Sphere sphere = new Sphere(10.0); // Create a sphere with the given radius, number of divisions Sphere sphere = new Sphere(10.0, 40); // Create a cylinder with the given radius, and height Sphere sphere = new Cylinder(10.0, 30.0); // Create a box with the given width, height, and depth Box box = new Box(1.0, 1.0, 1.0); // NOTE: All 3D shapes are centered at (0,0,0)

  45. Predefined Shapes Demo

  46. 3D Attributes Lights Materials Used to specify the appearance of a 3D shape Face culling Drawing mode (fill versus wireframe) Scene antialiasing (MSAA)

  47. Light Class Hierarchy javafx.scene.Node javafx.scene.LightBase javafx.scene.AmbientLight javafx.scene.PointLight

  48. 3D Attributes: Lights Defined as nodes in the scene graph Scene contains a set of active lights Default light provided when the set is empty Each light contains a set of affected nodes If a Parent is in the set, all children are affected Default is root node of Scene

  49. Defining Lights // Create point light and add it to the Scene PointLight light = new PointLight(); light.setColor(Color.RED); scene.getLights().add(light); // Add light to scene graph (so it can move) Group lightGroup = new Group(); lightGroup.getChildren().add(light); root.getChildren().add(lightGroup); // Rotate the light light.rotate(45); // Move the lightGroup (light moves with it) lightGroup.setTranslateZ(-75);

More Related