Java 3D Programming

Daniel Selman



 


Who should read it?


How is it organized?


Source code


Typographical conventions


How to use the book


Author Online


CHAPTER 1


1.1 Strengths


1.2 Weaknesses


1.3 System requirements (developer and end user)


1.4 EXPECTED PERFORMANCE


1.4.1 Memory footprint


1.5 Running the examples


1.6 Summary


CHAPTER 2


2.1 Learning 3D graphics programming


2.2 Projecting from 3D world coordinates to 2D screen coordinates


2.2.1 A simple 3D projection routine


From AwtRenderingEngine.java


2.2.2 Comparing output


2.2.3 Drawing filled triangles


Hidden surface removal


Depth sorting (Painter’s algorithm)


Depth buffer (Z−buffer)


2.3 Lighting effects


From AwtRenderingEngine.java


2.4 Putting it together—MyJava3D


From AwtRenderingEngine.java


From RotatingGeometryUpdater.java


From MyJava3D.java


2.5 Summary


CHAPTER 3


3.1 Installation


3.1.1 Java 2 SDK


3.1.2 Java 3D 1.2 JDK


IMPORTANT


3.1.3 Documentation


3.1.4 Java 2 development environment (optional)


3.1.5 Performance analysis tools (optional)


3.1.6 Java class decompiler (optional)


3.2 Your first Java 3D application


From SimpleTest.java


3.3 Exercises for the reader


Colors and lighting


Animation parameters


Background geometry


Scheduling bounds


Capability bits


The position of the viewer of the scene


Size of sphere primitives


3.4 Summary


CHAPTER 4


4.1 Overview


4.2 What is a scenegraph?


4.3 Java 3D and the scenegraph


4.4 Elements of scenegraph design


Object−oriented


Compilable


Level of detail independent


Polymorphic (customizable)


Bounds and level of detail aware


4.5 Scenegraph advantages


Object management


Rendering optimization


Picking support


Behavior model


Collision detection


Multiple thread aware


Hierarchical control


4.6 Hierarchical control


4.7 Immediate mode vs. retained mode vs. mixed mode


4.7.1 Immediate mode


From ImmediateTest.java


4.7.2 Mixed mode


From MixedTest.java


4.7.3 Summary of modes


Retained mode


Mixed mode


4.8 Summary


CHAPTER 5


5.1 Scenegraph compilation


5.1.1 Appearance merging and sorting


5.1.2 Geometry merging


5.2 Node


5.3 Bounds and CollisionBounds


From BoundsTest.java


5.4 Group


5.4.1 Remove a child Node by reference


5.5 Switch


From SwitchTest.java


5.6 BranchGroup


5.7 OrderedGroup


From NodesTest.java


5.8 SharedGroup and link


From NodesTest.java


5.9 Primitive


5.10 TransformGroup


5.11 Summary


CHAPTER 6


6.1 Locales and HiResCoord


From HiResCoordTest.java


6.2 View, ViewPlatform, and Locale


CLIPPING PLANES


Based on Java3dApplet.java


6.3 SimpleUniverse


From PlatformTest.java


From AvatarTest.java (see also PlatformTest.java)


6.4 Background geometry


From AvatarTest.java


6.5 Using multiple views


6.5.1 Billboards and LOD behaviors


6.6 Summary


CHAPTER 7


7.1 Choosing a data model


7.1.1 Surface models


7.1.2 Volumetric and mathematical models


VOXELS OR SKIN DESCRIPTION?


7.1.3 Implementing in Java 3D


7.2 Performance objectives


7.2.1 Rendering quality


7.2.2 Load time


7.2.3 Memory footprint


7.2.4 Development time and asset management


7.3 Summary


CHAPTER 8


8.1 Shape3D


8.1.1 The user data field


8.2 Primitives


8.2.1 Box


8.2.2 Cone


8.2.3 Cylinder


8.2.4 Sphere


8.2.5 Primitive flags


8.2.6 Primitives and the geometry cache


8.3 GeomBuffer


8.4 Rasters


8.4.1 Rendering an image using a Raster


8.4.2 Retrieving scene depth components using a Raster


From RasterTest.java


8.5 Text2D


8.6 Text3D


From BillboardTest.java (see also Text3DTest.java)


From Text3DTest.java


8.6.2 SetString problems


8.7 Morph


8.8 Summary


CHAPTER 9


9.1 Introduction


9.2 Appearance


NOTE


9.3 ColoringAttributes


9.4 LineAttributes


9.5 Material


9.6 PointAttributes


NOTE


9.7 PolygonAttributes


9.8 RenderingAttributes


9.9 TexCoordGeneration


9.10 TextureAttributes


9.11 Texture


9.12 TransparencyAttributes


9.12.1 A warning about transparency


9.13 Summary


CHAPTER 10


10.1 Lights


10.1.1 Lighting equations


10.1.2 Normal vectors and lighting


Lambert shading


Gouraud shading


Phong shading


10.1.3 Lighting and material properties


10.1.4 What about shadows?


10.2 Light node


10.2.1 Light properties


Color


Influencing bounds


Scope


State


10.3 AmbientLight


10.4 DirectionalLight


10.5 PointLight


NOTE


10.6 SpotLight


NOTE


10.7 Lighting, material attributes, and per−vertex colors


10.8 Summary


CHAPTER 11


11.1 Introduction


11.2 Behavior class


Scheduling bounds


Enable State


WakeUp Condition


processStimulus method


initialize method


When do Behaviors run?


11.3 Anatomy of a typical behavior


Constructor


initialize method


processStimulus method


11.4 Overview of the built−in behaviors


11.5 Overview of Wakeup criteria


WakeupCriterion


WakeupCondition


From StretchBehavior.java


Summary


11.6 Using keyboard behaviors


KeyNavigatorBehavior


From AppearanceTest.java


Writing a simple keyboard behavior


From the AvatarTest example, CarSteering.java


Implementing DOOM and DOOM−style keyboard navigation


Loading and creating the world from a 2D map


Implementing collision detection


Simple texture image animation for flaming torches


Conclusions


11.7 Using mouse behaviors


Java 3D and the mouse


Building improved mouse behaviors


Example usage of the new behaviors, from MouseNavigateTest.java


11.8 Billboard behavior


NOTE


From BillboardTest.java


11.9 Using LOD behaviors


DistanceLOD Class


From SplineInterpolatorTest.java


11.10 Summary


CHAPTER 12


12.1 The Interpolator class


12.2 The Alpha class


NOTE


From the file Values.xls from the CustomAlphaTest example


12.2.2 Summary


12.3 Example of Interpolator usage


SwitchValueInterpolator


ColorInterpolator


PositionInterpolator


RotationInterpolator


ScaleInterpolator


TransparencyInterpolator


RotPosScalePathInterpolator


From InterpolatorTest.java


12.4 Using a cubic−spline interpolator


Tension parameter


Continuity


Bias


12.4.2 Creating the LOD behavior


12.4.3 Reading spline key frames from disk


From Utils.java in the org.selman.java3d.book package


12.4.4 Creating the texture−mapped sky backdrop


From SplineInterpolatorTest.java


12.4.5 Controlling the extent of the audio for the helicopters


From Helicopter.java


12.5 Summary


CHAPTER 13


13.1 The BehaviorTest example


13.2 ObjectSizeBehavior


From ObjectSizeBehavior.java


13.3 ExplodeBehavior


From ExplodeBehavior.java


13.4 StretchBehavior


From StretchBehavior.java


13.5 Using behaviors for debugging


13.5.1 Calculating the rendered FPS using a behavior


NOTE


13.6 Summary


CHAPTER 14


14.1 Introduction


14.1.1 Static mapping using per−vertex texture coordinates


IMPORTANT


14.1.2 Dynamic mapping using TexCoordGeneration


OBJECT_LINEAR mode


EYE_LINEAR mode


SPHERE_MAP mode


Conclusions


14.2 3D texture coordinates


14.3 Texture and multiple levels of detail


14.3.1 Boundary color


14.3.2 Boundary mode


14.3.3 Setting the image


From TextureTest.java


14.3.4 MIPMAP mode, filter, and multiple texture images


From AppearanceTest.java


14.4 TextureAttributes


14.4.1 Blend color


14.4.2 Mode


14.4.3 Transform


From TextureTransformTest.java


14.5 Using transparent geometry with transparent texture images


14.6 Animated (video) texture mapping


14.7 Summary


CHAPTER 15


15.1 Introduction


15.2 Triangulator, normal vector generator, stripifier


From TriangulatorTest.java


15.3 Object loaders


15.3.1 LoaderBase


15.3.2 SceneBase interface


15.3.3 Using the ObjectFile loader


From LoaderTest.java


15.3.4 Third−party object loaders


15.4 Summary


CHAPTER 16


16.1 Introduction to picking


16.2 PickShapes


16.3 PickTool


16.4 PickCanvas


16.5 PickIntersection


16.6 PickResult


16.7 VRML picking example


From VrmlPickingTest.java


16.8 Using picking for collision detection


From PickCollisionTest.java


16.9 Conclusions


CHAPTER 17


17.1 Building the Java 3D Swing application


From SwingTest.java


17.2 Adding support for running as an applet


17.2.1 Original HTML applet code


17.2.2 Using the Java 2 plug−in HTMLConverter


17.2.3 The end−user experience


17.2.4 Automatic Java 3D installation


17.2.5 Applets and security


17.3 Conclusions


CHAPTER 18


18.1 Introduction


18.2 Threads running a Java 3D application


18.2.1 Native Windows threads running a Java 3D application


18.3 MasterControl


Message processing and threading architecture


J3dMessage


18.4 BehaviorScheduler


18.5 InputDeviceScheduler


18.6 Renderer


18.6.1 GraphicsContext3D commands


18.6.2 RenderAtoms and RenderMolecule


18.7 StructureUpdateThread


18.8 TimerThread


18.9 SceneGraphObject


BitSet capabilities


SceneGraphObjectRetained retained


private boolean compiled


private boolean live


private boolean liveOrCompiled


private Object userData


Hashtable nodeHashtable


18.10 Node types


18.11 Exception Strings


18.12 J3D DLL


18.12.1 Exported methods


Canvas3D


ColoringAttributesRetained


CompressedGeometryRetained


DirectionalLightRetained


ExponentialFogRetained


GeometryArrayRetained


GraphicsContext3D


LineAttributesRetained


LinearFogRetained


MasterControl


MaterialRetained


ModelClipRetained


NativeConfigTemplate3D


NativeWSInfo


PointAttributesRetained


PointLightRetained


PolygonAttributesRetained


RasterRetained


Renderer


RenderingAttributesRetained


Screen3D


SpotLightRetained


TexCoordGenerationRetained


Texture3DRetained


TextureAttributesRetained


TextureRetained


TextureUnitStateRetained


Texture


TransparencyAttributesRetained


18.12.2 Imported methods


KERNEL32.dll


USER32.dll


GDI32.dll


OPENGL32.dll


18.13 Summary


appendix A


A.1 List of examples


A.2 Installation notes


A.3 Instructions for running the examples


A.3.1 Running applet examples


appendix B


Online courses


Introduction to Computer Graphics


Reading resources


Software and software companies


appendix C


C.1 Box objects and GeomBuffer


From CuboidTest\Cuboid.java


OldGeomBuffer gbuf = new OldGeomBuffer(4); gbuf.begin(OldGeomBuffer.QUAD_STRIP);


From CuboidTest\OldGeomBuffer.java


private GeometryArray processQuadStrips()


obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);


obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2);


obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS);


obj = new QuadArray(totalVerts, QuadArray.COORDINATES);


C.2 Primitives and the geometry cache


From Primitive.java


protected GeomBuffer getCachedGeometry( int kind, float a, float b,


From Cylinder.java


C.3 GeomBuffer