Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Simple Talk on Java 3D Presented by C.H. Chen on Jul. 6, 2004.

Similar presentations


Presentation on theme: "A Simple Talk on Java 3D Presented by C.H. Chen on Jul. 6, 2004."— Presentation transcript:

1 A Simple Talk on Java 3D Presented by C.H. Chen on Jul. 6, 2004

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

3 Introduction

4

5 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

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

7 Introduction

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

9 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

10 Deployment of your Development Environment

11 Understanding Java 3D

12

13 Scene : Virtual Universe VirtualUniverse Scene Graph

14 Understanding Java 3D

15

16

17

18

19

20

21

22

23

24 Partial subclasses of - Group : BranchGroup, Switch TransformGroup … - Leaf : Behavior, Light, Shape3D ViewPlatform … - NodeComponent : Appearance, Material Texture …

25 Understanding Java 3D

26

27

28 SimpleUniverse class creates a scene graph including: VirtualUniverse, locale objects, complete view branch graph View branch graph ViewingPlatform, viewer

29 Understanding Java 3D

30

31

32 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.*;

33 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;

34 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

35 // 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

36 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 );

37 // add geometry to TransformGroup 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 ); 2

38 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 ); // 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 ) ) ); 3

39 // 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

40 Scene Graph of sample code BG TG S B L Appearance Geometry 5 1 2 3 4

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

42 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/java- media/3D/collateral/presentation/index.htmlhttp://java.sun.com/products/java- media/3D/collateral/presentation/index.html Sample code: Advanced Java how to program


Download ppt "A Simple Talk on Java 3D Presented by C.H. Chen on Jul. 6, 2004."

Similar presentations


Ads by Google