From Erights
#!/usr/bin/env rune
# Translated a Java 3D example into E. Written 2008-12-05.
#
# I was pondering writing a 3D-spatial interface to Den and looking into 3D
# API choices; that would be a Very Large Project I don't currently have
# enough interest in. (I've also heard that Java 3D is abandoned...) I'm
# posting this just so the work isn't entirely wasted.
# -- Kevin Reid 2009-12-30
#
# https://j3d-examples.dev.java.net/source/browse/j3d-examples/src/classes/org/jdesktop/j3d/examples/hello_universe/HelloUniverse.java?rev=1.2&view=markup
def <j3d> := <unsafe:javax.media.j3d.*>
def <universe> := <unsafe:com.sun.j3d.utils.universe.*>
def <vecmath> := <unsafe:javax.vecmath.*>
def pi := (-1.0).acos()
def createSceneGraph() { # :BranchGroup
# Create the root of the branch graph
def objRoot := <j3d:makeBranchGroup>();
# Create the TransformGroup node and initialize it to the
# identity. Enable the TRANSFORM_WRITE capability so that
# our behavior code can modify it at run time. Add it to
# the root of the subgraph.
def objTrans := <j3d:makeTransformGroup>();
objTrans.setCapability(<j3d:makeTransformGroup>.getALLOW_TRANSFORM_WRITE());
objRoot.addChild(objTrans);
# Create a simple Shape3D node; add it to the scene graph.
objTrans.addChild(<unsafe:com.sun.j3d.utils.geometry.makeColorCube>(0.4));
# Create a new Behavior object that will perform the
# desired operation on the specified transform and add
# it into the scene graph.
def yAxis := <j3d:makeTransform3D>();
def rotationAlpha := <j3d:makeAlpha>(-1, 4000);
def rotator :=
<j3d:makeRotationInterpolator>(rotationAlpha, objTrans, yAxis,
0.0, pi*2);
def bounds :=
<j3d:makeBoundingSphere>(<vecmath:makePoint3d>(0.0,0.0,0.0), 100.0);
rotator.setSchedulingBounds(bounds);
objRoot.addChild(rotator);
# Have Java 3D perform optimizations on this scene graph.
objRoot.compile();
return objRoot;
}
def canvas := <j3d:makeCanvas3D>(<universe:makeSimpleUniverse>.getPreferredConfiguration())
def univ := <universe:makeSimpleUniverse>(canvas)
univ.getViewingPlatform().setNominalViewingTransform()
univ.getViewer().getView().setMinimumFrameCycleTime(5)
# Canvas3D is an AWT component so it doesn't have a preferredSize
def swingContainer := JPanel`$canvas`
swingContainer.setPreferredSize(<awt:makeDimension>(250, 250))
def frame := <swing:makeJFrame>("3d")
frame.getContentPane()."add(Component)"(swingContainer)
def scene := createSceneGraph();
univ.addBranchGraph(scene);
frame.pack()
frame.show()
interp.blockAtTop()