Presentation is loading. Please wait.

Presentation is loading. Please wait.

3D-Online Product Configuration by Java3D

Similar presentations


Presentation on theme: "3D-Online Product Configuration by Java3D"— Presentation transcript:

1 3D-Online Product Configuration by Java3D
Fachhochschule Stralsund University of Applied Science Prof.Dr.-Ing. Christine Wahmkow Department of Mechanical Engineering only Phylosophy of Java3D and an easy example

2 Philosophy of Java3D – think in Scenegraph
3D-Online Product Configuration by Java3D Philosophy of Java3D – think in Scenegraph Virtual universe as the root The virtual universe is described by a scenegraph Each scenegraph has always only one rrot The virrtual universe can have a lot of local objects. Normally a 3D program has only one licale objekt The locale object is a startpoint to which the virtual object get their position A branchgroup is the root of a subgraph of the local tree In maintenance there are 2 branchs: content and view branch Content branch: describes the 3D virtual world (Geometry, Light Behavior, outfit of the objects) View Branch: specifys how the world is showing Here you can select options for thedifferent output devices for normal PC‘s you can use default values canvas3D : the surface where the object are rendered Content Branch: is lived when he is hanging under the locale node The developer has to describe the objects Objects are living, if you set the necessary capabilities

3 Philosophy of Java3D – think in Scenegraph
3D-Online Product Configuration by Java3D Philosophy of Java3D – think in Scenegraph View Branch: Very complex and complicated But: Java3D offers a utility class The developer can concentrate on the virtual world

4 An easy recipe to produce a Java3D-application
3D-Online Product Configuration by Java3D An easy recipe to produce a Java3D-application create a subclass of class Applet public class HelloJava3D extends Applet create a constructor for the subclass which then builds the virtual world public HelloJava3D() define a method to create the Content branch public BranchGroup createSceneGraph() call the applet in a MainFrame object in the main method of the applet public static void main(String[] args){ Frame frame=new MainFrame(new HelloJava3D(),400,400); }

5 An easy recipe to produce a constructor (scenegraph)
3D-Online Product Configuration by Java3D An easy recipe to produce a constructor (scenegraph) Create a Canvas3D object Canvas3D canvas3D=new Canvas3D(null); Create a SimpleUniverse object, which has a reference to the canvas3D SimpleUniverse simpleU=new SimpleUniverse(canvas3D); simpleU.getViewingPlatform().setNominalViewingTransform(); Create the Content branch BranchGroup scene=createScenegraph(); Compile the Content branch scene.compile(); Add the Content branch to the locale object of the SimpleUniverse simpleU.addBranchgraph(scene); 2 5 1 4 3

6 3D-Online Product Configuration by Java3D
The constructor public class HelloJava3D1 extends Applet { public HelloJava3D1() { setLayout(new BorderLayout()); Canvas3D canvas3D = new Canvas3D(null); add("Center", canvas3D); BranchGroup scene = createSceneGraph(); SimpleUniverse simpleU = new SimpleUniverse(canvas3D); // This will move the ViewPlatform back a bit so the objects in the scene can be viewed. simpleU.getViewingPlatform().setNominalViewingTransform(); simpleU.addBranchGraph(scene); } // end of HelloJava3D1 (constructor)

7 3D-Online Product Configuration by Java3D
The content branch public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.compile(); return objRoot; } // end of CreateSceneGraph method of HelloJava3D1 // The following allows this to be run as an applicationas well as an applet public static void main(String[] args) { Frame frame = new MainFrame(new HelloJava3D1(), 256, 256); } // end of main (method of HelloJava3D1)

8 3D-Online Product Configuration by Java3D
import java.applet.Applet import java.awt.BorderLayout; import java.awt.Frame; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*;

9 3D-Online Product Configuration by Java3D
The expanded content branch public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.compile(); return objRoot; } // end of CreateSceneGraph method of HelloJava3D1 objRoot.addChild(new ColorCube(0.4));

10 Mouse behavior BranchGroup objRoot = new BranchGroup();
TransformGroup objTransform = new TransformGroup(); objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(objTransform); objTransform.addChild(new ColorCube(0.4)); MouseRotate myMouseRotate = new MouseRotate(); myMouseRotate.setTransformGroup(objTransform); myMouseRotate.setSchedulingBounds(new BoundingSphere()); objTransform.addChild(myMouseRotate); MouseTranslate myMouseTranslate = new MouseTranslate(); myMouseTranslate.setTransformGroup(objTransform); myMouseTranslate.setSchedulingBounds(new BoundingSphere()); objTransform.addChild(myMouseTranslate); MouseZoom myMouseZoom = new MouseZoom(); myMouseZoom.setTransformGroup(objTransform); myMouseZoom.setSchedulingBounds(new BoundingSphere()); objTransform.addChild(myMouseZoom); objRoot.compile(); return objRoot; Add the packages: import com.sun.j3d.utils.behaviors.mouse.*; import java.awt.event.*; import java.util.Enumeration;

11 AWT-Interaction- example to change the background color
Additional packeges: import java.awt.*; import java.awt.event.*; import java.util.Enumeration; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; Background define in the Content branch bg=new Background(); bg.setCapability(bg.ALLOW_COLOR_READ); bg.setCapability(bg.ALLOW_COLOR_WRITE); bg.setColor(0.0f,0.0f,0.0f); //black bg.setApplicationBounds(new BoundingSphere()); objTransform.addChild(bg); AWT Interaction by an additional method public void actionPerformed(ActionEvent e ) { if (e.getSource()==Backg){ bg.setColor(0.0f,0.0f,0.8f); //blue }

12 AWT-Interaction- example to change the rotation speed of the cube
Alpha define // Alpha as an object of time Alpha rotationAlpha; rotationAlpha=new Alpha(-1,rottime); RotationInterpolator rotator= new RotationInterpolator(rotationAlpha,objTransform); BoundingSphere bounds=new BoundingSphere(); rotator.setSchedulingBounds(bounds); objTransform.addChild(rotator); public void actionPerformed(ActionEvent e ) { if (e.getSource()==RottimeP){ rottime=rottime+2000; rotationAlpha.setIncreasingAlphaDuration(rottime); } if (e.getSource()==Rotstop){ rotationAlpha.setLoopCount(0); }


Download ppt "3D-Online Product Configuration by Java3D"

Similar presentations


Ads by Google