Docstoc

A Simple Talk on Java 3D

Document Sample
A Simple Talk on Java 3D Powered By Docstoc
					A Simple Talk on Java 3D

Presented by C.H. Chen on Jul. 6, 2004

Outlines
• Introduction • Deployment of your Development Environment • Understanding Java 3D • Demo

Introduction

Introduction

Introduction
• Flight simulators and medical-imaging
• Developments in high-performance hardware led to developments in high-performance graphics APIs— beginning in the 1970s with Siggraph’s CORE API, continuing in the 1980s with SGI’s OpenGL and on through today with MS’s Direct3D and Java 3D.

• 3D Graphic • Java 3D: high-level graphic-programming API write once run anywhere simplifying the complex graphics

Introduction
• Four major goals of Java 3D APIs -application portability -hardware independence -performance scalibility -ability to produce 3D graphics over a network

Introduction

Introduction
• Features of Java 3D for development - Behavior - Fog - Geometry - Light - Sound - Texture

Deployment of your Development Environment
• Requirement:

J2SE or J2EE, OpenGL or Direct X • Java 3D API 1.3.1 (current version) • http://java.sun.com/product/java-media/3D • other IDE : eg. Java 3D NetBeans Module 1.0 beta

Deployment of your Development Environment

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D
• Scene : Virtual Universe • VirtualUniverse • Scene Graph

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D
• Partial subclasses of - Group : BranchGroup, Switch TransformGroup … - Leaf : Behavior, Light, Shape3D ViewPlatform … - NodeComponent : Appearance, Material Texture …

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D
• SimpleUniverse class creates a scene graph including: VirtualUniverse, locale objects, complete view branch graph • View branch graph ViewingPlatform, viewer

Understanding Java 3D

Understanding Java 3D

Understanding Java 3D

Sample code tracing
// Java extension packages import javax.swing.event.*; import javax.media.j3d.*; import javax.vecmath.*; // Java3D utility packages import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.behaviors.mouse.*;

public class Java3DWorld extends Canvas3D {

private Appearance appearance; // 3D object's appearance private Light ambientLight; // ambient scene lighting private Box shape; // 3D object to manipulate private Color3f lightColor; // Light color private Light directionalLight; private Material material; // 3D objects color object private SimpleUniverse simpleUniverse; // 3D scene environment private TextureLoader textureLoader; // 3D object's texture
// holds 3D transformation information private TransformGroup transformGroup;

private String imageName; // texture image file name
// Java3DWorld constructor public Java3DWorld( String imageFileName ) {

super( SimpleUniverse.getPreferredConfiguration() );
imageName = imageFileName;

Sample code tracing
// create SimpleUniverse ( 3D Graphics environment ) simpleUniverse = new SimpleUniverse( this );

// set viewing distance for 3D scene ViewingPlatform viewPlatform = simpleUniverse.getViewingPlatform();
viewPlatform.setNominalViewingTransform();

// create 3D scene BranchGroup branchGroup = createScene();
// attach BranchGroup to SimpleUniverse simpleUniverse.addBranchGraph( branchGroup ); } // end Java3DWorld constructor

5

// create 3D scene public BranchGroup createScene() { BranchGroup scene = new BranchGroup(); // initialize TransformGroup transformGroup = new TransformGroup(); // set TransformGroup's WRITE permission transformGroup.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE ); transformGroup.setCapability( TransformGroup.ALLOW_TRANSFORM_READ ); // add TransformGroup to BranchGroup scene.addChild( transformGroup ); // create BoundingSphere BoundingSphere bounds = new BoundingSphere( new Point3d( 0.0f, 0.0f, 0.0f ), 100.0 );

1

appearance = new Appearance(); // create object appearance material = new Material(); // create texture matieral appearance.setMaterial( material ); String rgb = new String( "RGB" ); // load texture for scene object textureLoader = new TextureLoader( Java3DWorld.class.getResource( imageName ), rgb, this ); // set capability bits for enabling texture textureLoader.getTexture().setCapability( Texture.ALLOW_ENABLE_WRITE ); // initial texture will not show textureLoader.getTexture().setEnable( false ); // set object's texture appearance.setTexture( textureLoader.getTexture() ); Box.GENERATE_NORMALS | Box.GENERATE_TEXTURE_COORDS, appearance );

// add geometry to TransformGroup 2 transformGroup.addChild( shape ); // initialize Ambient lighting ambientLight = new AmbientLight(); ambientLight.setInfluencingBounds( bounds );

// initialize directionalLight directionalLight = new DirectionalLight();
lightColor = new Color3f(); // initialize light color // set initial DirectionalLight color directionalLight.setColor( lightColor ); // set capability bits to allow DirectionalLight's // Color and Direction to be changed directionalLight.setCapability( DirectionalLight.ALLOW_DIRECTION_WRITE ); directionalLight.setCapability( DirectionalLight.ALLOW_DIRECTION_READ );

directionalLight.setCapability( DirectionalLight.ALLOW_COLOR_WRITE );
directionalLight.setCapability( DirectionalLight.ALLOW_COLOR_READ );

directionalLight.setInfluencingBounds( bounds );
// add light nodes to BranchGroup scene.addChild( ambientLight ); scene.addChild( directionalLight ); // initialize rotation behavior MouseRotate rotateBehavior = new MouseRotate(); rotateBehavior.setTransformGroup( transformGroup ); rotateBehavior.setSchedulingBounds( bounds );

3

// initialize translation behavior MouseTranslate translateBehavior = new MouseTranslate(); translateBehavior.setTransformGroup( transformGroup ); translateBehavior.setSchedulingBounds( new BoundingBox( new Point3d( -1.0f, -1.0f, -1.0f ), new Point3d( 1.0f, 1.0f, 1.0f ) ) );

// initialize scaling behavior MouseZoom scaleBehavior = new MouseZoom(); scaleBehavior.setTransformGroup( transformGroup ); scaleBehavior.setSchedulingBounds( bounds );
// add behaviors to BranchGroup scene.addChild( scaleBehavior ); scene.addChild( rotateBehavior ); scene.addChild( translateBehavior ); scene.compile(); return scene; } // end method createScene

4

Scene Graph of sample code

5 BG 3 1 L TG 2 S Appearance Geometry 4 B

Demo
• Java 3D demo • Java 3D Fly Through v 1.0

References
• Sun Microsystem Java 3D http://java.sun.com/products/java-media/3D/ • Java 3D Tutorial • Java 3D Scene Graph Editor http://java3d.netbeans.org/ • http://java.sun.com/products/javamedia/3D/collateral/presentation/index.html • Sample code: Advanced Java how to program


				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:133
posted:11/19/2009
language:English
pages:42