Java 3D Introduction - PowerPoint PPT Presentation

java 3d introduction n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Java 3D Introduction PowerPoint Presentation
Download Presentation
Java 3D Introduction

play fullscreen
1 / 101
Java 3D Introduction
143 Views
Download Presentation
baris
Download Presentation

Java 3D Introduction

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Java 3D Introduction http://www.hta-bi.bfh.ch/~rfs/pwf/java3/ Stefan Rufer Assistant Computer Science Departement rfs@hta-bi.bfh.ch

  2. Todays Contents • Start • Introduction to Computer Graphics • Java 3D Tutorial Chapters – Layout: • Technical Introduction • Application in Java 3D • Example Programs Java 3D – an Introduction

  3. Start • Foreword • Installing Java 3D • Running Java 3D Programs • Warm-up • Course overview • References & Sources Java 3D – an Introduction

  4. StartObjectives • Appetizer for the Course. • Know how to compile and run Java 3D programs. • Know where to search in case of troubles or further interest. Java 3D – an Introduction

  5. StartForeword • Determine the correct color for every pixel. • This course is programming oriented. • Why to learn Java 3D? • It is object oriented. • It is 3D. • It is fun. Java 3D – an Introduction

  6. StartInstalling Java 3D • School PCs have Java 3D installed • Make sure that JDK 1.2.2 or later has been initialized (NAL -> Java -> Initialize ...). • The SUN environment does not include Java 3D per default • Check web-page for details and troubleshooting # Add some directories to your PATH#original: PATH ${HOME}/bin:${PATH}:PATH /tools/java/JDK-1.2-AND-Java3D-1.1/bin:${HOME}/bin:${PATH}: Java 3D – an Introduction

  7. StartRunning Java 3D Programs • Copy source from intranet • It is so simple – but IF... have a look on the web page for troubleshooting (all JARs at the right place, also in the JRE?). >javac Program.java>java Program Java 3D – an Introduction

  8. StartWarm-up • Simply let us try some examples...! http://www.hta-bi.bfh.ch/~rfs/pwf/java3/Chapter Start, paragraph Warm-up. Java 3D – an Introduction

  9. StartCourse Overview Java 3D – an Introduction

  10. StartReferences & Sources • SUN and intranet web pages, links found in documentation. • Use the glossary, it makes live easier if you know about what exactly you are talking. Java 3D – an Introduction

  11. Intro to Computer Graphics • Why Java 3D • 2D versus 3D • Color Models • Hardware • Java 3D Tutorial Java 3D – an Introduction

  12. Introduction to Computer GraphicsObjectives • Understand some essential basics of computer graphics like color models. • Get an idea of what hardware is involved if doing computer graphics. Java 3D – an Introduction

  13. Introduction to Computer GraphicsWhy Java 3D • 3D-modelers like Art*lantis • Easy content creation • Pre-programmed „static“ behaviour • Many pre-defined shapes, extrusions, textures... • 3D-languages like Java 3D or OpenGL • High degree of user interaction • Start on the „green field“ • Create new 3D applications (CAD, Simulator, ...) • 3D-renderers like PovRay • No interaction, only one picture Java 3D – an Introduction

  14. Introduction to Computer Graphics2D versus 3D • 2D • R2 => R2 • Simply two dimensional • picture on 2D-Screen. • 3D • R3 => R2 • Match three dimensional mathematical model to two dimensional Screen. • A new approach are Holography techniques R3 => R3 but that‘s maybe beyond the scope of this course... Java 3D – an Introduction

  15. Introduction to Computer GraphicsColor Models • RGB is the most most important color model for computer graphics. • Additive system • Red, Green, Blue, 8bit each • Java 3D: each color has values 0..1 • Application example: ColorSpace • Other systems: CMYK, HSB... Java 3D – an Introduction

  16. Introduction to Computer GraphicsHardware (1) • Graphic Cards minimize processor load by executing graphic commands in hardware. • DirectX • OpenGL • Raster Screen have an x-y pixel array (=raster) to display our graphics • CRT • LCD • Counterpart: Vector graphic devices such as analog cathode-ray oscilloscopes. Java 3D – an Introduction

  17. Introduction to Computer GraphicsHardware (2) Java 3D – an Introduction

  18. Introduction to Computer GraphicsJava 3D Tutorial • Tutorial by SUN • Great (as usual, it is SUN...) • Use this and the API as your reference! Java 3D – an Introduction

  19. The Virtual Universe • Basics • Scene Graph • Locales • Content Branch • View Branch • Understanding MyUniverse • Recipe for a simple Program Java 3D – an Introduction

  20. 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. Java 3D – an Introduction

  21. 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 -> incredible precision at incredible extend. • There is one VU-instance only (Singleton). Java 3D – an Introduction

  22. 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 Java 3D – an Introduction

  23. 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. Java 3D – an Introduction

  24. The Virtual UniverseScene Graph (3) myVirtualUniverse • Basic parts of a scene graph myLocale Locale(s) BranchGroup BranchGroup Content Branch View Branch a3Dobject myViewPlatform Java 3D – an Introduction

  25. 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. Java 3D – an Introduction

  26. 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. Java 3D – an Introduction

  27. 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). Java 3D – an Introduction

  28. The Virtual UniverseContent Branch (2) • The most common object types Branch Group ... Transform Group ... Appearance Shape3D Java 3D – an Introduction

  29. The Virtual UniverseView Branch The Canvas3D will be inserted in our application or applet -> most important! Java 3D – an Introduction

  30. The Virtual UniverseRecipe for a simple Program • Create a Frame & a Canvas3D object. • Create a SimpleUniverse object which gets a reference to the Canvas3D. • Construct the content branch. • Insert the content branch into the Locale of the SimpleUniverse. Java 3D – an Introduction

  31. The Virtual UniverseExercises • Check Web-Page, chapter „Virtual Universe“ http://www.hta-bi.bfh.ch/~rfs/pwf/java3/ Java 3D – an Introduction

  32. Hello World • The Java 3D API • Finally: Hello World! • Source Code • Class Diagram of HelloJava3D • What happens when running? • Exercises Java 3D – an Introduction

  33. Hello WorldObjectives • Understand the high-level structure of the APIs involved in a Java 3D program. • Understand the code of the HelloJava3Da example line by line. Java 3D – an Introduction

  34. Hello WorldThe 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 Java 3D – an Introduction

  35. Hello WorldFinally: Hello World! • Probably the most simple Scene Graph  Java 3D – an Introduction

  36. 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); } } Java 3D – an Introduction

  37. Hello WorldClass Diagram of HelloJava3D Java 3D – an Introduction

  38. 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 Java 3D – an Introduction

  39. Hello WorldExercises • Check Web-Page, chapter „Hello World“ http://www.hta-bi.bfh.ch/~rfs/pwf/java3/ Java 3D – an Introduction

  40. Creating Content • Geometic Utility Classes • Mathematical Classes • Geometry Classes • GeometryArray Classes • GeometryStrip Array Classes • Indexed Geometry • Appearance and Attributes • Point- + LineAttributes • PolygonAttributes Java 3D – an Introduction

  41. Creating ContentObjectives • Get an overview on how to handle polygones in Java 3D. • Know the most important attributes that determine the look of a polygone. Java 3D – an Introduction

  42. Tutorial Page 2-6 Creating ContentGeometric Utility Classes • Box (2x2x2 m) • Cone (Ø2m, height 2m) • Cylinder (Ø2m, height 2m) • Sphere (Ø2m) • Default color white Java 3D – an Introduction

  43. Tutorial Page 2-15 Creating ContentMathematical Classes (1) • Tuples are simply pairs or triples of numbers. • For each vertex there can be up to four javax.vecmath objects: • Points for coordinates • Colors • Vectors for normals • TexCoords for texture coordinates Java 3D – an Introduction

  44. Creating ContentMathematical Classes (2) • Vectors: mostly used for normals and position information in 3D-space. • Normals: determined using the right hand (remember: we have a right-handed system). P2 n P0 P1 Java 3D – an Introduction

  45. Tutorial Page 2-20 Creating ContentGeometry Classes • What to do if our shape is not a box or a cylinder? • Create Shape3D-object, use setGeometry() method! • For a triangle: • Three-element array • One point per element Java 3D – an Introduction

  46. Tutorial Page 2-212-26 Creating ContentGeometryArray Classes • Most primitive form to create shapes: • Points or lines are one pixel wide per default. • Colors are interpolated from vertex to vertex if specified.(see code page 2-24, line 9+10) P0 P1 Java 3D – an Introduction

  47. Tutorial Page 2-27 Creating ContentGeometryStripArray Classes • More convenient: share some vertices: • Example Yoyo: Ever tried to model a Jumbo-Jet by hand? Often geometry is generated by mathematical calculations. Java 3D – an Introduction

  48. Tutorial Page 2-27 Creating ContentIndexed Geometry • Best re-use of vertices but we lose performance using the index array. Java 3D – an Introduction

  49. Tutorial Page 2-34 Creating ContentAppearance and Attributes • Appearance class does not specify the appearance directrly but contains many links to appearance objects: Java 3D – an Introduction

  50. Tutorial Page 2-37 Creating ContentPoint- + LineAttributes • Points and Lines are 1 pixel wide by default. Zooming does not affect this. • Let‘s try to change: • Thikness of the line • Antialiasing Java 3D – an Introduction