Mercurial > hg > jslab
view examples/java3d/hello9.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | 5df24c91468d |
children |
line wrap: on
line source
/* hello9.java Construct universe without using SimpleUniverse utility class - this puts together the view group explicitly. Shading */ import samer.core.*; import java.awt.event.*; import java.awt.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.geometry.*; public class hello9 extends util implements Agent { // create universe LocalUniverse U=new LocalUniverse(); BranchGroup root=new BranchGroup(); public static void main(String[] arse) { init(); new hello9(); } public hello9() { // create scene // root.addChild(pointLight(2,2,2,new Color3f(1f,1f,1f))); root.addChild(color(pointLight(0,1,0),new Color3f(.2f,.1f,0.1f))); root.addChild(directionalLight(6,-1,4)); root.addChild(ambientLight()); root.addChild(createSceneGraph()); root.addChild(new Viewer("view")); root.setCapability(Group.ALLOW_CHILDREN_EXTEND); root.setCapability(Group.ALLOW_CHILDREN_WRITE); root.compile(); U.addGroup(root); Shell.registerAgent(this); Shell.exposeCommands(this); } private static Group createSceneGraph() { Transform3D r=new Transform3D(); r.rotX(1.1); r.setScale(0.5); TransformGroup t2=new TransformGroup(r); GeometryInfo gi=yoyoGeometryInfo(32); new NormalGenerator().generateNormals(gi); Geometry g=gi.getGeometryArray(); Shape3D faces=new Shape3D(); Shape3D edges=new Shape3D(); faces.setGeometry(g); faces.setAppearance(material1()); edges.setGeometry(g); edges.setAppearance(shadedwireframe()); TransformGroup tg = new TransformGroup(); addRotator(tg); t2.addChild(faces); t2.addChild(edges); tg.addChild(t2); return tg; } public void getCommands(Agent.Registry r) { r.add("view").add("axis"); r.setTarget(null); r.add("start").add("stop"); } public void execute(String cmd, Environment env) throws Exception { if (cmd.equals("view")) { root.addChild(new Viewer(X.string(env.datum("name"),"view"))); } else if (cmd.equals("axis")) { Transform3D t3d=new Transform3D(); t3d.set(0.5); TransformGroup tg=new TransformGroup(t3d); BranchGroup bg=new BranchGroup(); Axis axis=new Axis(); axis.setAppearance(wireframe1()); tg.addChild(axis); bg.addChild(tg); bg.compile(); root.addChild(bg); } } }