Java 3D API in a computer graphics course on ... nowadays 3D programming
concepts at the same time. ... In computer graphics good teaching is not possible.
TEACHING COMPUTER GRAPHICS WITH JAVA 3D Ingmar Peter
Stefan Gumhold
WSI/GRIS University of Tübingen Auf der Morgenstelle 10, C9 72074 Tübingen Germany
ABSTRACT
greatly improved.
To present and explore topics in computer graphics traditional teaching methodologies and tools are not sufficient. An approach is needed which provides students with an easy to use programming environment and which enables them to build their own interactive graphic applications. In this paper we present our experiences with the Java 3D API in a computer graphics course on modeling and simulation. We present the applications used in the practical exercises during the course. It is shown how students can learn computer graphic algorithms and deepen their understanding of nowadays 3D programming concepts at the same time.
But there is a serious problem accompanying this approach. It is difficult to provide students with a suitable software environment, which
Keywords: Java, teaching, modeling, simulation
INTRODUCTION In computer graphics good teaching is not possible if only traditional methodologies and tools like blackboard or slides are used during a course. The subjects in computer graphics are primarily of an inherent three-dimensional nature. So the problems and challenges can only be completely understood in detail if practical exercises provide a three dimensional impression of the course material. Such an impression is mostly deduced from the illumination of the objects and strengthened by interaction, i.e. rotation of the objects and movement through a scene. Therefore, the ideal teaching tool for exercises of a computer graphics course is a computer together with a software package that generates realistic three-dimensional scenes and allows intuitive user interaction. Furthermore, working with programs not only helps to illustrate problems, but also increases student motivation. Providing students with programs enables them to do their exercises, deepen their understanding of the problems and build up their own settings. In this way learning can be
• • •
covers the whole content of a computer graphics lecture, does not need special graphics hardware to run, so the students can use the programs at home, is easy to learn for the students in a short time and, of course, for the staff.
Besides this, buying an adequate number of licenses from a bunch of commercial programs can be too expensive. Up to now there have been only two ways to supply the students with a software environment which meets the conditions mentioned above: students build up their own graphics software systems from scratch or the staff develops a software package tailored to the specific needs of the course. Both approaches were nearly impossible due to time constraints. The most common compromise was to deal in the exercises only with a small amount of the taught content of the computer graphics course. In the meantime, with Java [3] exists an object oriented programming language which runs the same code under almost every existing operating system. It comes with a growing number of software APIs providing manifold functionality. With the increased performance of modern personal computer Java has become a considerable choice for practical exercises in a computer graphics course. In this paper we describe the use of the new Java 3D API (J3D) [4] in the practical exercises in a computer graphics course dealing with modeling and simulation in virtual worlds. In the following sections, we give a brief overview of the course contents and
a) b) c) Figure 1: Applet showing geometric primitives in a) wire frame mode, b)&c) illuminated and colored according to the curvature. describe the Java 3D API. After that we describe the various practical lessons we have developed with J3D in detail. Finally, we conclude by reporting some experiences with the Java 3D API and give a brief overview of our future activities.
THE COURSE The course modeling and simulation at Computer Graphics Lab (WSI/GRIS) at the University of Tübingen consists of two parts. It is based on the two semester course on computer graphics, which has a web-based counter part [5]. In the first semester of the modeling and simulation course the students learn about different representations for solids and surfaces and about suitable modeling techniques. At the end of the first part of the course the basics of physical simulation are introduced. The second part of the course deals with advanced topics like reconstruction techniques, multi-resolution modeling and simulation with multi-particle systems and finite element methods applied to cloths and tissues. The material of both parts of the course is reflected in theoretical and practical exercises. The course is intended for graduate students who want to pass one of their final examinations in computer graphics.
THE JAVA 3D API Although the Java 3D API had only been released in a beta version when we began the development of our exercises, we selected this API nevertheless because the combination of portability, 3D hardware support and object oriented design convinced us. A broad range of classes, which combine some of the most powerful concepts known from graphics programming, supports building of complex interactive graphics applications. J3D classes can easily be adapted to the users needs by derivation and
specialization. And last but not least the Java programming language can be learned easily by everyone with some experience in object oriented programming. The Java 3D API was developed by Sun Microsystems [4], who briefly describe their API as follows: “The Java 3D API is a set of classes for writing three-dimensional graphics applications and 3D applets. It gives developers high level constructs for creating and manipulating 3D geometry and for constructing the structures used in rendering that geometry. Application developers can describe very large virtual worlds using these constructs, which provides Java 3D with enough information to render these worlds efficiently.” At the moment the Java 3D API is available for Solaris and Microsoft Windows.
APPLETS On the one hand the graphics algorithms discussed in the lecture should be implemented during the practical exercises and on the other hand the students should learn something about the programming concepts in the area of modeling and simulation. In the following we describe for each exercise the related course material and the mediated programming concepts. The exercises cover the following areas: 1. 2. 3. 4. 5.
Basic concepts of surface visualization User interaction CSG modeling Polynomial curves and surfaces Subdivision surfaces Each exercise consists of instructions available via
WWW [1] and a code frame of classes, in which the implementation code has to be filled in by the students.
•
EXERCISE 1: RECTANGULAR SURFACES
•
The first exercise familiarize the students with J3D. The students learn how to create simple surfaces and how to manipulate them. They also learn how to compute surface normals and curvature. In the exercise the students implement a surface over a rectangular domain which may describe a rectangle, a cylinder or a torus. The surfaces can be represented as a list of triangles, a list of triangle strips or a list of quads. The students have to compute the surface normals and color the torus according to the Gaussian curvature and the average curvature.
•
Translation orthogonal to the view plain, such that one can zoom in the object along the ray through the view point and the mouse pointer. Rotations around the axes orthogonal to the view plain. Movement of the observer relative to view plain.
The pick and drag behaviors were added to the applet of exercise 1. The new mouse interactions allow to arrange the objects arbitrarily and to study intersection curves. An example is shown in Figure 1c).
Figure 1 shows three snap-shots of the applet. The 3D-canvas shows nine objects, the rectangle, the cylinder and the torus each in the triangle, the triangle strip and the quad representation. In Figure 1a) the surfaces are rendered in the wire-frame mode such that the difference between the triangle and the quad representation can be seen. Figure 1b) shows the illuminated surfaces. The colors of the top and bottom torus reflect the Gaussian curvature and the torus in the middle is colored with the average curvature. Green represents negative curvature values and red positive values. Each of the nine objects can be translated and rotated with the mouse. The applet introduces the scenegraph concept of J3D. The surface classes extend the geometry classes of J3D, which provides triangle arrays, triangle strip arrays and quad arrays. In this first exercise the pick and drag classes of J3D are used. The students can also learn about illumination of objects and Gouraud shading. EXERCISE 2: PICK&DRAG The behavior of the classes provided by the J3D API for translating and rotating objects with the mouse depends on the orientation of the observer and the relative position of the object to the observer. Thus the objects cannot be manipulated in an intuitive way. In this exercise we developed a class hierarchy which implements the following intuitive pick and drag behaviors for mouse interaction: • •
Translation parallel to the view plain, such that the mouse pointer stays at the same surface point of the object Rotation around axes parallel to the view plain, such that the mouse pointer stays for small mouse movements at the same point of the object.
Figure 2: Applet for building and manipulating CSG objects. EXERCISE 3: CSG-MODELING In this exercise with Constructive Solid Geometry (CSG) [6] an advanced modeling technique is introduced. The students have to implement the recursive calculations for a CSG tree built over axially parallel boxes. At every knot in the CSG tree one of the operations intersection, union and difference can be carried out. We developed an applet as shown in figure 2, which provides a comfortable interface for building complex CSG objects. The applet is based on a similar applet in the web-based computer graphic course [5]. The user can create new boxes with arbitrary dimensions and insert them into the scene. With the mouse two existing CSG objects are selected, one of the operations union, difference or intersection is chosen and a new CSG object is created. The students have to implement the CSG operations. They also learn how to manipulate an existing J3D scenegraph at runtime. For the manipulation of the CSG objects the pick & drag
a) Figure 3: Applets used to construct polygonal curves (a) and surfaces (b). behavior of exercise 2 were reused. EXERCISE 4: POLYNOMIAL CURVES AND SURFACES Rational polynomial curves and surfaces [2] are a standard tool to construct objects with smooth surfaces and can be found in almost every nowadays modeling application. The applets shown in figure 3 provide an easy to use interface for construction and manipulation of polynomial curves and surfaces in three-dimensional space. New control points can easily be inserted into the scene, extending the modeled curve or surface respectively. Individual weight values can be attached to the control points. The points can be picked and translated through the modeling space reusing the behaviors of exercise 2. The applet shown in figure 3a), which is used to model rational polynomial curves allows one to choose between Bernstein and B-Spline basis functions. The students are expected to implement the de-Boor algorithm and de Casteljau algorithm for calculating the curve points. Because of the interactive nature of the applet the students can easily verify the correctness of their implementations. In two further exercises the degree elevation for Bezier curves and the insertion of new control points for NURBS has to be implemented. The de-Boor algorithm and de Casteljau algorithm implemented to calculate curve points, are used in the next exercise to build polynomial surfaces using a tensor product approach. Figure 3b) shows the applet which allows the construction and manipulation of rational polynomial surfaces. As in the previous
b)
exercise all control points can be positioned with the mouse and their weights can be manipulated individually. To enhance the three dimensional impression of the surface its normals have to be calculated for correct illumination calculation. In this exercise the calculation of the surface points reusing the implementations from the previous exercise have to be implemented. After that, the calculation of the normals for arbitrary parameter values have to be realized for both Bernstein and BSpline basis. EXERCISE 5: SUBDIVISION SURFACES Subdivision surfaces are the perfect tool to model smooth surfaces with arbitrary topology. See [7] for an introduction to subdivision surfaces. A coarse polygonal mesh is refined by introducing new vertices on the old vertices, edges and faces. The connectivity of the refined mesh is defined upon the new vertices before the locations of the new vertices are computed from the old vertices by a smoothing scheme. In this exercise two subdivision methods are investigated – Loop and Catmull-Clark subdivision. The Loop Subdivision Surfaces refine triangular meshes by introducing new vertices on the old vertices and edges. The Catmull-Clark Subdivision Surfaces can be defined on arbitrary polygonal meshes and introduce new vertices additionally on the old faces. Loop produces triangular meshes whereas Catmull-Clark produces quad meshes. The refinement and smoothing is based on a half-edge data structure for polygonal
a) b) Figure 4: Subdivision applet a) cube in wire-frame b) cube riddled with holes illuminated meshes. Figure 4 shows two snap-shots of the applet on the left the refinement of a cube in a wire frame version and on the right a cube with lots of holes shaded with illumination. In the first row we see the Loop subdivision scheme and in the second row the CatmullClark. The first column shows the original mesh and each following column contains one further subdivision step. A simple extension of the pick and drag interaction from exercise 2 allowed to synchronize the translations and rotations of all subdivision steps in one row, such that the different levels of detail can be easily compared. The students have to implement parts of the halfedge data structure and the major functions of the subdivision step.
EXPERIENCES WITH JAVA 3D API Our experiences with the Java 3D API were primarily positive. The API provides all the functionality which was needed in our exercises for visualization and interaction. The performance was surprisingly good even on personal computers without 3D-hardware support. Standard Java together with the Java 3D API significantly improved the development of applets, which combine graphical user interface elements with 3D-visualization and interaction. With some experience the effort for developing the graphical user interface, the 3D-visualization and interaction becomes negligibly small such that one can concentrate on the implemented algorithms alone. The main problem with the Java 3D API during our experiences was the lack of a debugger. The SUN Java Workshop did not support debugging in
conjuction with the Java 3D API and the Java 3D API can not be integrated into other development environments at this time.
CONCLUSIONS AND FUTURE WORK It turned out that the Java 3D API is a suitable and valuable tool to develop applets for teaching computer graphics. Although there does not yet exist a satisfactory development environment for J3D we will push forward our J3D applets in the future. We plan to integrate the existing, but stand alone applets into a small modeling system, which will serve as framework for future exercises.
REFERENCES [1] [2]
[3] [4] [5]
[6] [7]
http://www.gris.uni-tuebingen.de /gris/vvz/ModSim/WS98/ Uebungen.html G.E. Farin, “Curves and surfaces for computer aided geometric design” Academic Press, San Diego, 1988 M. Grand, “Java Language Reference” O’Reilly & Associates, 1997 http://java.sun.com/products/ java-media/3D/index.html R.Klein, F.Hanisch, W.Straßer, “Web-Based Teaching of Computer Graphics: Concepts and Realization of an Interactive Online Course” SIGGRAPH 98 Educational Program, ACM, 1998 M. Mäntylä, “Solid modeling” Computer Science Press, Rockville, 1988 P. Schröder, D. Zorin, “Subdivision for Modeling and Animation” SIGGRAPH 98 Course Notes, Course 36, ACM, 1998