1 / 61

Introduction to Java 3D

Introduction to Java 3D . 1. Java 3D Overview. API for 3D applications Portable. Some Application Areas. Scientific/Medical/Data visualization Geographical information systems (GIS) Computer-aided design (CAD) Simulation Computer-aided education (CAE) Games. The Java 3D API.

olesia
Download Presentation

Introduction to Java 3D

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. Introduction to Java 3D

  2. 1. Java 3D Overview • API for 3D applications • Portable

  3. Some Application Areas • Scientific/Medical/Data visualization • Geographical information systems (GIS) • Computer-aided design (CAD) • Simulation • Computer-aided education (CAE) • Games

  4. The Java 3D API • Packages related to the Java 3D API: • Core classes: javax.media.j3d • Utility classes: com.sun.j3d.utils • Math classes: javax.vecmath • AWT classes: javax.swing

  5. Introduction • Elements of the rendering • Objects • Camera/View • Canvas/Screen

  6. Introduction • Rendering • Camera / objects may move in time…

  7. Scene Representation • Scene • Representation of elements in the virtual world • How to represent? • What to represent?

  8. The Virtual Universe • Basics • Scene Graph • Locales • Content Branch • View Branch

  9. 2. What is a Scene Graph? • scene graph = tree-like • stores,3D scene • easier than OpenGL or DirectX.

  10. Scene Graph Symbols Arcs (object relationships) Nodes and Node Components (objects) Group =erase head Parent-child link Leaf=cone head Node Component Reference Other objects=block head

  11. Java3D’s SceneGraph VitualUniverse Locale Root group BG BG TG robot arm environment TG TG Group = erase head view sphere TG base S S TG bottom arm S up arm S

  12. The Virtual UniverseObjectives • Know what a virtual universe and a scene graph is. • Understand the basic parts and elements of a scene graph. • Know the basic recipe for a Java 3D program.

  13. A Typical Scene Graph Leaf=cone head Content Branch View Branch

  14. The Virtual UniverseBasics • A virtual universe can be seen as a 1:1 representation of our own universe. • Represent structures from astronomical to subatomic. • Floating point 3D space: 2^256 (!!) for each x,y,z. • Decimal point for 1 meter at 2^128 • There is one VU-instance only (Singleton).

  15. The Virtual UniverseLocales (1) • How to handle the huge extend of a virtual universe efficiently? • Our virtual universe contains at least one Locale. • The locale is a 3D-reference point inside the virtual universe.

  16. The Virtual UniverseLocales (2) • Standard Locale resides at (0,0,0) in the VU. • We can have several Locales, eg: • One as reference point of the swiss coordinate system (located in Bordeaux, France). • A second as the architects reference point of a building plan. • The both are related, but depending on the point of view it is more convenient (and precise) to work with one or the other.

  17. The Virtual UniverseContent Branch (1) • Contains all „visible“ objects of our scene. • Contains all transformations for those objects (displacement, animation, ...). • We distinguish between group nodes and leaf nodes (see following slide).

  18. The Virtual UniverseContent Branch (2) • The most common object types Branch Group ... Transform Group ... Appearance Shape3D

  19. VirtualUniverse The Virtual UniverseScene Graph (1) Locale • Scene Graph is the graphical representation of the objects in our VU. • Directed Acyclic Graph (Tree) • Nodes, arcs, parents, childs, leaves, references and other objects. Group Link Leaf Reference NodeComponent Other objects

  20. The Virtual UniverseScene Graph (2) • A Java 3D program may have more objects than those in the scene graph. • A scene graph drawing is the correct documentation for the 3D part of a Java 3D program.

  21. The Virtual UniverseView Branch The Canvas3D will be inserted in our application or applet -> most important!

  22. The Virtual UniverseRecipe for a simple Program • Create a Frame & a Canvas3D instance • Create a SimpleUniverse • Construct the content branch. • Insert the content branch into the Locale of the SimpleUniverse.

  23. Hello World

  24. Hello WorldSource Code public class HelloJava3Da extends Applet { public HelloJava3Da() { setLayout(new BorderLayout()); Canvas3D canvas3D = new Canvas3D(null); add("Center", canvas3D); SimpleUniverse simpleU = new SimpleUniverse(canvas3D); simpleU.getViewingPlatform().setNominalViewingTransform(); BranchGroup scene = createSceneGraph(); simpleU.addBranchGraph(scene); } public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); objRoot.addChild(new ColorCube(0.4)); return objRoot; } public static void main(String[] args) { Frame frame = new MainFrame(new HelloJava3Da(), 256, 256); } }

  25. Hello WorldClass Diagram of HelloJava3D

  26. Hello WorldWhat happens when running? while (true) { Process input Perform Behaviours //none at the moment Traverse scene graph and render visual objects if (request to exit) break } Cleanup and exit

  27. Scene Graph

  28. Java3D (cont.) • The scene graph is a tree • Elements of the scene that have some data component, such asviewable objects, light sources, camera locations and so forth are contained in the graph nodes. From:“The Java 3D Tutorial” by Dennis J Bouvier atjava.sun.com/products/java-media/3D/collateral and http://www.itk.ilstu.edu/faculty/javila/ITk356/Java3D/scene_graph_basics.htm

  29. Symbols representing Scene Graph Objects:

  30. Scene Graph Viewing Objects Canvas3D, Screen3D, View, PhysicalBody, PhysicalEnvironment. From:“The Java 3D Tutorial” by Dennis J Bouvier atjava.sun.com/products/java-media/3D/collateral and http://www.itk.ilstu.edu/faculty/javila/ITk356/Java3D/scene_graph_basics.htm

  31. Java3D (cont.) Terminology The renderer

  32. Code (create robot arm) • public void init() // applet’s init() function • { • setLayout(new BorderLayout()); • GraphicsConfiguration config = • SimpleUniverse.getPreferredConfiguration(); • Canvas3D c = new Canvas3D(config); • add("Center", c); • // create simple universe( camera, lights, ...) • u = new SimpleUniverse(c); • // This will move the ViewPlatform back a bit so the • // objects in the scene can be viewed. • u.getViewingPlatform().setNominalViewingTransform(); • viewTrans = • u.getViewingPlatform().getViewPlatformTransform(); • // Create a robot arm • createSceneGraph(); • // add root group • u.addBranchGraph(rootGroup); • }

  33. public void createSceneGraph() • { • // create root • rootGroup = new BranchGroup(); • rootTrans = new TransformGroup(); • rootTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); • rootTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); • // create bounds • BoundingSphere bounds = • new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); • // create Appearance • Appearance greenLook = new Appearance(); • ColoringAttributes greenColorAttr = new ColoringAttributes(); • greenColorAttr.setColor(new Color3f(0.0f,1.0f,0.0f)); • greenLook.setColoringAttributes(greenColorAttr); • // create Sphere • sphereTrans = new TransformGroup(); • sphere = new Sphere(0.1f,redLook);

  34. // transform sphere • Transform3D sphereT3d = new Transform3D(); • sphereT3d.setTranslation(new Vector3f(0.5f,0.0f,0.0f)); • sphereTrans.setTransform(sphereT3d); • // add sphere into scenegraph • sphereTrans.addChild(sphere); • rootTrans.addChild(sphereTrans); • // create arm • ….. • } // end of createSceneGraph()

  35. 3. A Java 3D Skeleton • All our Java 3D programs embed a scene inside a JPanel, which is part of a JFrame • this allows Swing GUI controls to be utilized along side the Java 3D panel (if necessary) • We will develop an example called Checkers3D during the course of these slides.

  36. Checkers3D • The scene consists of • a dark green and blue tiled surface (and red center) • labels along the X and Z axes • a blue background • a floating sphere lit from two different directions • the user (viewer) can move through the scene by moving the mouse

  37. Checkers3D.java public class Checkers3D extends JFrame{ public Checkers3D() { super("Checkers3D"); Container c = getContentPane(); c.setLayout( new BorderLayout() );WrapCheckers3D w3d = new WrapCheckers3D(); // panel holding the 3D scene c.add(w3d, BorderLayout.CENTER); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); pack(); setResizable(false); // fixed size display show(); } // end of Checkers3D() public static void main(String[] args) { new Checkers3D(); }} // end of Checkers3D class

  38. Scene Graph for Checkers3D view branch not shown

  39. Building the Scene Graph • The VirtualUniverse, Locale, and view branch graph often have the same structure across different applications • programmers usually create them with the SimpleUniverse utility class

  40. WrapChecker3D Constructor private SimpleUniverse su; private BranchGroup sceneBG; // for content branch private BoundingSphere bounds; : public WrapCheckers3D() { setLayout( new BorderLayout() ); setOpaque( false ); setPreferredSize( new Dimension(PWIDTH, PHEIGHT));GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas3D = new Canvas3D(config); add("Center", canvas3D); canvas3D.setFocusable(true); canvas3D.requestFocus();su = new SimpleUniverse(canvas3D); :

  41. createSceneGraph(); initUserPosition(); // set user's viewpoint orbitControls(canvas3D); // controls for moving the viewpoint su.addBranchGraph( sceneBG ); } // end of WrapCheckers3D()

  42. createSceneGraph() private void createSceneGraph() // initilise the scene below sceneBG { sceneBG = new BranchGroup(); bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE); lightScene(); // add the light addBackground(); // add the sky sceneBG.addChild( new CheckerFloor().getBG() ); // add the floor floatingSphere(); // add the floating sphere sceneBG.compile(); // fix the scene } // end of createSceneGraph()

  43. 1. Checkers3D Again • The scene consists of • a dark green and blue tiled surface (and red center) • labels along the X and Z axes • a blue background • a floating sphere lit from two different directions • the user (viewer) can move through the scene by moving the mouse

  44. Scene Graph for Checkers3D view branch not shown

  45. WrapChecker3D Constructor private SimpleUniverse su; private BranchGroup sceneBG; // for content branch private BoundingSphere bounds; : public WrapCheckers3D() { setLayout( new BorderLayout() ); setOpaque( false ); setPreferredSize( new Dimension(PWIDTH, PHEIGHT)); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas3D = new Canvas3D(config); add("Center", canvas3D); canvas3D.setFocusable(true); canvas3D.requestFocus(); su = new SimpleUniverse(canvas3D); :

  46. createSceneGraph(); initUserPosition(); // set user's viewpoint orbitControls(canvas3D); // controls for moving the viewpoint su.addBranchGraph( sceneBG ); } // end of WrapCheckers3D()

  47. createSceneGraph() private void createSceneGraph() // initilise the scene below sceneBG { sceneBG = new BranchGroup(); bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE); lightScene(); // add the light addBackground(); // add the sky sceneBG.addChild( new CheckerFloor().getBG() ); // add the BranchGroup for the floor floatingSphere(); // add the floating sphere sceneBG.compile(); // fix the scene } // end of createSceneGraph()

  48. 2. The Floor • The floor is made of tiles created with the our ColouredTiles class, and axis labels made with the Text2D utility class.

  49. Floor Branch of the Scene Graph floorBG axisTG

  50. CheckerFloor Constructor // constants for various colours : private BranchGroup floorBG; public CheckerFloor() // create tiles, add origin marker, // then the axes labels { ArrayList blueCoords = new ArrayList() ArrayList greenCoords = new ArrayList(); floorBG = new BranchGroup(); :

More Related