Title: PowerPoint-Pr
13D-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
23D-Online Product Configuration by Java3D
Philosophy of Java3D think in Scenegraph
33D-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
43D-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 framenew
MainFrame(new HelloJava3D(),400,400) -
53D-Online Product Configuration by Java3D
An easy recipe to produce a constructor
(scenegraph)
- Create a Canvas3D object Canvas3D
canvas3Dnew Canvas3D(null) - Create a SimpleUniverse object, which has a
reference to the canvas3D SimpleUniverse
simpleUnew SimpleUniverse(canvas3D)
simpleU.getViewingPlatform().setNominalViewingTran
sform() - Create the Content branch BranchGroup
scenecreateScenegraph() - Compile the Content branch scene.compile()
- Add the Content branch to the locale object of
the SimpleUniverse simpleU.addBranchgraph(scene
)
63D-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.getViewingPla
tform().setNominalViewingTransform()
simpleU.addBranchGraph(scene) // end of
HelloJava3D1 (constructor)
73D-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)
83D-Online Product Configuration by Java3D
import java.applet.Appletimport
java.awt.BorderLayoutimport java.awt.Frameimpo
rt java.awt.event.import com.sun.j3d.utils.appl
et.MainFrame import com.sun.j3d.utils.universe.
import com.sun.j3d.utils.geometry.ColorCubeim
port javax.media.j3d.import javax.vecmath.
93D-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))
10Mouse behavior
BranchGroup objRoot new BranchGroup()
TransformGroup objTransform new
TransformGroup() objTransform.setCapabili
ty(TransformGroup.ALLOW_TRANSFORM_WRITE)
objTransform.setCapability(TransformGroup.ALLOW_TR
ANSFORM_READ) objRoot.addChild(objTransf
orm) objTransform.addChild(new
ColorCube(0.4)) MouseRotate
myMouseRotate new MouseRotate()
myMouseRotate.setTransformGroup(objTransform)
myMouseRotate.setSchedulingBounds(new
BoundingSphere()) objTransform.addChild(m
yMouseRotate) MouseTranslate
myMouseTranslate new MouseTranslate()
myMouseTranslate.setTransformGroup(objTransform)
myMouseTranslate.setSchedulingBounds(new
BoundingSphere()) objTransform.addChild(m
yMouseTranslate) MouseZoom myMouseZoom
new MouseZoom() myMouseZoom.setTransfor
mGroup(objTransform) myMouseZoom.setSched
ulingBounds(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
11AWT-Interaction- example to change the
background color
Additional packeges import java.awt. import
java.awt.event. import java.util.Enumeration im
port java.awt.event.ActionEvent import
java.awt.event.WindowAdapter
Background define in the Content branch
bgnew Background() bg.setCapability(bg.ALLO
W_COLOR_READ) bg.setCapability(bg.ALLOW_COLO
R_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
12AWT-Interaction- example to change the
rotation speed of the cube
Alpha define // Alpha as an object of time
Alpha rotationAlpha rotationAlphanew
Alpha(-1,rottime) RotationInterpolator
rotator new RotationInterpolator(rotationAlpha,ob
jTransform) BoundingSphere boundsnew
BoundingSphere() rotator.setSchedulingBounds
(bounds) objTransform.addChild(rotator)
public void actionPerformed(ActionEvent e )
if (e.getSource()RottimeP)
rottimerottime2000
rotationAlpha.setIncreasingAlphaDuration(rottime)
if (e.getSource()Rotstop)
rotationAlpha.setLoopCount(0)