Upload
kasey-agar
View
215
Download
0
Embed Size (px)
Citation preview
department of computer scienceand engineering
INTRODUCTION TO JAVA 3DINTRODUCTION TO JAVA 3D
Martin Martin ČČadíkadíkCzech Technical University in Prague, Czech RepublicCzech Technical University in Prague, Czech Republic
November 27, 2002
(2)
department of computer scienceand engineering
ContentContent
OverviewOverview Scene graphScene graph Java 3D classesJava 3D classes Simple applicationSimple application Describing objectsDescribing objects Groups, transformsGroups, transforms Behaviors, interpolators, pickingBehaviors, interpolators, picking Lighting, SoundLighting, Sound
November 27, 2002
(3)
department of computer scienceand engineering
What Is Java3D?What Is Java3D?
APIAPI– Applications or AppletsApplications or Applets– ““Write once, run anywhere”Write once, run anywhere”
• platform independent (IBM AIX, HP-UX, Linux, SGI IRIX, Solaris/Sparc, platform independent (IBM AIX, HP-UX, Linux, SGI IRIX, Solaris/Sparc, Windows)Windows)
• display environmentsdisplay environments
– higher level APIhigher level API• objects instead of verticesobjects instead of vertices
• content instead of rendering processcontent instead of rendering process
– scalablescalable– scene graph - basedscene graph - based
November 27, 2002
(4)
department of computer scienceand engineering
Java3D - OverviewJava3D - Overview
JavaJava– JREJRE
– SDKSDK
Java 3DJava 3D– JREJRE
– SDKSDK
– OpenGLOpenGL
– DirectXDirectX
Code examples in distributiCode examples in distributionon
ApplicationsApplications– scientific visualization, scientific visualization,
animation, web design, animation, web design, simulations, virtual world simulations, virtual world construction (CAVE), training, construction (CAVE), training, games, design automationgames, design automation
November 27, 2002
(5)
department of computer scienceand engineering
Java3D Scene GraphJava3D Scene Graph
VirtualUniverseVirtualUniverse– to contain all 3D datato contain all 3D data
– typically one per applicationtypically one per application
– SimpleUniverseSimpleUniverse
– Locale Locale objectobject
ViewView– describes how to view 3D describes how to view 3D
contentcontent
– multiple views per universemultiple views per universe
– View PlatformView Platform (movable) (movable)
Content BranchContent Branch– describes 3D contentdescribes 3D content
November 27, 2002
(6)
department of computer scienceand engineering
Java 3D RendererJava 3D Renderer
Canvas 3DCanvas 3D– surface onto which a surface onto which a View View rendersrenders
– one canvas per viewone canvas per view
– there can be multiple canvases per appthere can be multiple canvases per app
while (true) { Process input if (exit request)break Check for collisions Perform behaviors Start playing sounds Traverse scene graph and render objects }Cleanup
November 27, 2002
(7)
department of computer scienceand engineering
Java 3D ClassesJava 3D Classes
javax.media.j3d packagejavax.media.j3d packagejavax.media.j3d.VirtualUniverse (java.lang.Object)
Enumeration getAllLocales( )
javax.media.j3d.Locale
VirtualUniverse getVirtualUniverse( ) void addBranchGraph( Branchgroup branchGroup )
removeBranchGraph( Branchgroup branchGroup ) void Enumeration getAllBranchGraphs( )
javax.media.j3d.SceneGraphObject
Capabilities (read/write transforms, geometry Capabilities (read/write transforms, geometry coords...)coords...)
javax.media.j3d.Node
javax.media.j3d.NodeComponent
November 27, 2002
(8)
department of computer scienceand engineering
Java 3D ClassesJava 3D Classes
javax.media.j3d.Node– Shapes, Groups, Sounds, Lights, etc.
– parent nodeparent node
– location (local, VWorld transform)location (local, VWorld transform)
– bounding volume (automatical computation)bounding volume (automatical computation)
javax.media.j3d.NodeComponent– attributesattributes– Shape geometry, Shape appearance, Shape texture, etc.
javax.vecmath packagejavax.vecmath packagejavax.vecmath.Tuple3d
Vector3d
Point3d, Color3d, etc.
November 27, 2002
(9)
department of computer scienceand engineering
Coordinate System, ElementsCoordinate System, Elements
Coordinate systemCoordinate system– Right-handedRight-handed
• +X is to the right+X is to the right• ++Y is upY is up• +Z is towards the viewer+Z is towards the viewer
– Angles in radiansAngles in radians
– Distance in metersDistance in meters
Elements in a GeometryElements in a Geometry– CoordinatesCoordinates
– NormalsNormals
– ColorsColors
– TextureCoordinatesTextureCoordinates
November 27, 2002
(10)
department of computer scienceand engineering
Simple Java3D ApplicationSimple Java3D Application
Construct view branchConstruct view branch– Canvas3DCanvas3D
– SimpleUniverseSimpleUniverse• VirtualUniverse, Locale, VirtualUniverse, Locale,
BranchGroup, TransformGroup, BranchGroup, TransformGroup, ViewPlatform, ViewViewPlatform, View
Construct content branchConstruct content branch– BranchGroupBranchGroup
– TransformGroupTransformGroup
– Shape3D, Light, Sound...Shape3D, Light, Sound...
– BehaviorBehavior
SimpleApp3DSimpleApp3D– codecode
November 27, 2002
(11)
department of computer scienceand engineering
ShapeShape3D3D
Fundamental mean of describing objectFundamental mean of describing objectjavax.media.j3d.Shape3D (Leaf)
Geometry Geometry void setGeometry(Geometry geometry)
AppearanceAppearancevoid setAppearance(Appearance appearance)
November 27, 2002
(12)
department of computer scienceand engineering
GeometryGeometry
javax.media.j3d.Geometry (NodeComponent)
GeometryArrayGeometryArray– LineArray, PointArray, TriangleArray, QuadArrayLineArray, PointArray, TriangleArray, QuadArray– Indexed~Indexed~– Stripped versionsStripped versions
Text3DText3Djavax.media.j3d.Text3D
– exampleexample
RasterRaster– raster imageraster image
November 27, 2002
(13)
department of computer scienceand engineering
AppearanceAppearance
javax.media.j3d.Appearance (NodeComponent)
Specifies how to render Specifies how to render GeometryGeometry sibling sibling– Color (intrinsic) and shading (flat, Gouraud)Color (intrinsic) and shading (flat, Gouraud)
• ColoringAttributes• Material
– TransparencyTransparency• TransparencyAttributes
– Line, point, polygon attributesLine, point, polygon attributes• LineAttributes, PointAttributes,
PolygonAttributes
– Rendering controlRendering control– Texture mappingTexture mapping
– exampleexample
November 27, 2002
(14)
department of computer scienceand engineering
Loading contentLoading content
LoaderLoader– creates scene graph elements creates scene graph elements
from a filefrom a file
com.sun.j3d.loaders– only the interface included in only the interface included in
Java 3DJava 3D
UsageUsage– import loaderimport loader
– create loader objectcreate loader object
– Scene Scene variablevariable
– load fileload file
– insert insert Scene Scene into the scene into the scene graphgraph
Available loadersAvailable loaders– 3DS, COB, DEM, DXF, IOB, 3DS, COB, DEM, DXF, IOB,
LWS, NFF, OBJ, PDB, PLAY, LWS, NFF, OBJ, PDB, PLAY, SLD, VRT, VTK, WRLSLD, VRT, VTK, WRL
November 27, 2002
(15)
department of computer scienceand engineering
GroupingGrouping
exactly one parent, arbitrary childrenexactly one parent, arbitrary childrenjavax.media.j3d.Group (Node)
BranchGroup, OrderedGroup, SharedGroup (Link), Switch, TransformGroup
child rendering order determines Java 3Dchild rendering order determines Java 3D– can perform sorting for better rendering efficiencycan perform sorting for better rendering efficiency
BranchGroupsBranchGroups– can be attached to can be attached to Locale Locale ---->> it makes it it makes it live live --> constrains by --> constrains by
capabilitiescapabilities– can be compiledcan be compiled
November 27, 2002
(16)
department of computer scienceand engineering
TransformingTransforming
world coordinate systemworld coordinate systemTransformGroup
– new coordinate system relative to new coordinate system relative to parentparent
transformation accumulate as graph is traversedtransformation accumulate as graph is traversed
Transform3D (Object)– 4 x 4 matrix of doubles - 4 x 4 matrix of doubles - Matrix4d– translate, rotate, scale, sheartranslate, rotate, scale, shear– must be affine (no perspective)must be affine (no perspective)– helper methodshelper methods
• setIdentity, rotX.., setScale, setTranslation, setRotation, etc.
November 27, 2002
(17)
department of computer scienceand engineering
Texture mappingTexture mapping
Appearance nodeAppearance nodeTexture2D (abstract Texture (NodeComponent))
- image textures, example- image textures, example
Texture3D - volume textures- volume textures
Texture formatTexture format– IntensityIntensity– Luminance, AlphaLuminance, Alpha– RGB, RGBARGB, RGBA
TextureAttributes (NodeComponent)– Mode: Blend, Decal, Modulate, ReplaceMode: Blend, Decal, Modulate, Replace– TransformTransform– Perspective correctionPerspective correction
November 27, 2002
(18)
department of computer scienceand engineering
BehaviorsBehaviors
javax.media.j3d.Behavior
code to run (code to run (processStimulus)) wakeup conditionswakeup conditions
– frame or milliseconds have elapsedframe or milliseconds have elapsed– AWT eventAWT event– transform changetransform change– collision, view platform or sensor is closecollision, view platform or sensor is close
scheduling boundsscheduling bounds– activation radius intersects scheduling boundsactivation radius intersects scheduling bounds– runs only when necessaryruns only when necessary– common errorcommon error - forgetting scheduling bounds - forgetting scheduling bounds
November 27, 2002
(19)
department of computer scienceand engineering
InterpolatorsInterpolators
javax.media.j3d.Interpolator
simple behaviorssimple behaviors– vary a parameter from starting to ending valuevary a parameter from starting to ending value– Time-to-Alpha mapping Time-to-Alpha mapping (Alpha (Object) <0,1>)– Alpha-to-Value mappingAlpha-to-Value mapping
• transforms, colors, switchestransforms, colors, switches
– Target (f.e. TransformGroup)Target (f.e. TransformGroup)
PositionInterpolator,
RotationInterpolator,
ColorInterpolatorm, etc.
November 27, 2002
(20)
department of computer scienceand engineering
Input devicesInput devices
– joysticksjoysticks– 6DOF devices (Magellan, Ultrasonic tracker...)6DOF devices (Magellan, Ultrasonic tracker...)– buttonsbuttons– real / virtualreal / virtual
javax.media.j3d.InputDevice interface– implementation maps physical detectors onto implementation maps physical detectors onto Sensor objectobject
(process input, return Sensor)(process input, return Sensor)
javax.media.j3d.Sensor (Object)– SensorRead objectobject
• time-stamptime-stamp
• 6DOF value, button state6DOF value, button state
November 27, 2002
(21)
department of computer scienceand engineering
Picking featuresPicking features
– selecting Shapesselecting Shapes– interaction methodsinteraction methods– designed for speed (Bounds)designed for speed (Bounds)
Pick methods (Node)Pick methods (Node)– take take PickShape (PickPoint, PickRay, PickSegment)– return return SceneGraph objectsobjects– f.e.: f.e.: pickAll, pickAllSorted, pickClosest
– example
November 27, 2002
(22)
department of computer scienceand engineering
Lighting the environmentLighting the environment
javax.media.j3d.Light
Types of lightsTypes of lights– ambient - ambient - AmbientLight– directional - directional - DirectionalLight– point - point - PointLight
• attenuationattenuation
– spot - spot - SpotLight
Light attributesLight attributes– on/offon/off
– colorcolor
– bounding volume and scopebounding volume and scope• by default universal scopeby default universal scope
– again: again: common errorcommon error - forgetting - forgetting scheduling boundsscheduling bounds
November 27, 2002
(23)
department of computer scienceand engineering
SoundsSounds
javax.media.j3d.Sound
SoundsSounds– triggeredtriggered
– continuouscontinuous
Sound typesSound types– background - background - BackgroundSound– point - point - PointSound
• attenuatedattenuated
– cone - cone - ConeSound• attenuatedattenuated
Sound propertiesSound properties– sound data sound data (MediaContainer)
• AIF, AU, WAVAIF, AU, WAV
– looping parameterslooping parameters
– playback priorityplayback priority
– scheduling boundsscheduling bounds
November 27, 2002
(24)
department of computer scienceand engineering
MiscMisc
BackgroundBackgroundjavax.media.j3d.Background
FogFog– exponential, linearexponential, linearjavax.media.j3d.Fog
November 27, 2002
(25)
department of computer scienceand engineering
AccelerationAcceleration
Performance GuidePerformance Guide– capability bitscapability bits– compilationcompilation– bounds, activation radiusbounds, activation radius– geometry by referencegeometry by reference– unordered renderingunordered rendering
November 27, 2002
(26)
department of computer scienceand engineering
NewsNews
FastScript 3DFastScript 3D– open sourceopen source– web applets using Java3D via JavaScript and HTMLweb applets using Java3D via JavaScript and HTML– Java, Java3D requiredJava, Java3D required– fs.jarfs.jar
November 27, 2002
(27)
department of computer scienceand engineering
Java 3DJava 3D
Thank youThank youfor your attentionfor your attention