Creating New Geometric Content in Java 3D: A Comprehensive Guide
200 likes | 335 Vues
This tutorial explores three major methods for creating new geometric content in Java 3D: using geometric utility classes, specifying vertex coordinates, and employing a geometry loader with Shape3D objects. Gain insights into creating visual objects that define geometry and appearance, including the use of cones for creating a yoyo model. The guide also covers mathematical classes in Java for representation of points, colors, vectors, and texture coordinates, enhancing your understanding of 3D graphics programming.
Creating New Geometric Content in Java 3D: A Comprehensive Guide
E N D
Presentation Transcript
CSC 308 – Graphics Programming Java 3D – New Geometry Content Information from online tutorial at http://java.sun.com/developer/onlineTraining/java3d/ Dr. Paige H. Meeker Computer Science Presbyterian College, Clinton, SC
Creating New Content in Java 3D There are three major ways to create new geometric content using Java3D: • Use the Geometric Utility Classes • Specify Vertex Coordinates • Use a Geometry Loader
Shape3D Objects • Defines a visual object • Can only be a leaf of the scene graph • Does not contain information about shape or color • Refers to node component objects to obtain geometry and appearance
Node Components • Contain exact specifications of attributes of visual objects
Geometry Utility Classes • Box • Cone • Cylinder • Sphere • Inside the com.sun.j3d.utils.geometry package
Creating a Yoyo using two cones public ConeYoyo() { yoyoBG = new BranchGroup(); Transform3D rotate = new Transform3D(); Appearance yoyoAppear = new Appearance(); rotate.rotZ(Math.PI/2.0d); TransformGroup yoyoTGR1 = new TransformGroup(rotate); translate.set(new Vector3f(0.1f,0.0f,0.0f); TransformGroup yoyoTGT1 = new TransformGroup(translate); Cone cone1 = new Cone(0.6f, 0.2f); cone1.setAppearance(yoyoAppear); yoyoBG.addChild(yoyoTGT1); yoyoTGT1.addChild(yoyoTGR1); yoyoTGR1.addChild(cone1); translate.set(newVector3f(-0.1f, 0.0f, 0.0f); TransformGroup yoyoTGT2 = new TransformGroup(translate); rotate.rotZ(-Math.PI/2.0d); TransformGroup yoyoTGR2 = new TransformGroup(rotate); Cone cone2 = new Cone(0.6f, 0.2f); cone2.setAppearance(yoyoAppear); yoyoBG.addChild(yoyo.TGT2); yoyoTGT2.addChild(yoyoTGR2); yoyoTGR2.addChild(cone2); yoyoGB.compile(); } // end of ConeYoyo constructor
Mathematical Classes • Found in javax.vecmath.* • Each vertex of a visual object made up of up to four javax.vecmath objects – commonly: • Point (for coordinates) • Color (for colors) • Vector (for surface normals) • TexCoord (for texture coordinates)
Point* • Point classes represent • the coordinates of a vertex • Position of a raster image • Point light sources • Spatial location of a sound
Color* • Color classes represent a color for • A vertex • A material property • Fog • Other visual object
Vector* • Vector classes represent • A surface normal • Direction of light source • Direction of sound source
TexCoord* • Two types – used to represent a set of texture coordinates at a vertex • TexCoord2f – maintains texture coordinates as an (s,t) coordinate pair • TexCoord3f – maintains texture coordinates as an (s,t,r) coordinate triple
Appearance Bundle • Refers to several different NodeComponent subclasses called appearance attribute objects • PointAttributes • LineAttributes • PolygonAttributes • ColoringAttributes • TransparencyAttributes • RenderingAttributes • Material • TextureAttributes • Texture • TexCoordGeneration
Sharing NodeComponent Objects Sharing NodeComponent Objects can enhance performance
Back Face Culling • Polygons have two faces. For many visual objects, only one needs to be rendered, so the renderer can cull the unnecessary faces. • Front face is the face for which the vertices are defined in counter-clockwise order. • By default, back faces are culled
Not Culling • Sometimes backface culling is a problem – you can turn it off.