annotate examples/java3d/hello9.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents 5df24c91468d
children
rev   line source
samer@1 1 /*
samer@1 2 hello9.java
samer@1 3
samer@1 4 Construct universe without using SimpleUniverse
samer@1 5 utility class - this puts together the view
samer@1 6 group explicitly.
samer@1 7
samer@1 8 Shading
samer@1 9 */
samer@1 10
samer@1 11 import samer.core.*;
samer@1 12 import java.awt.event.*;
samer@1 13 import java.awt.*;
samer@1 14 import javax.media.j3d.*;
samer@1 15 import javax.vecmath.*;
samer@1 16 import com.sun.j3d.utils.geometry.*;
samer@1 17
samer@1 18 public class hello9 extends util implements Agent
samer@1 19 {
samer@1 20 // create universe
samer@1 21 LocalUniverse U=new LocalUniverse();
samer@1 22 BranchGroup root=new BranchGroup();
samer@1 23
samer@1 24 public static void main(String[] arse) { init(); new hello9(); }
samer@1 25
samer@1 26 public hello9()
samer@1 27 {
samer@1 28 // create scene
samer@1 29 // root.addChild(pointLight(2,2,2,new Color3f(1f,1f,1f)));
samer@1 30 root.addChild(color(pointLight(0,1,0),new Color3f(.2f,.1f,0.1f)));
samer@1 31 root.addChild(directionalLight(6,-1,4));
samer@1 32 root.addChild(ambientLight());
samer@1 33
samer@1 34 root.addChild(createSceneGraph());
samer@1 35 root.addChild(new Viewer("view"));
samer@1 36 root.setCapability(Group.ALLOW_CHILDREN_EXTEND);
samer@1 37 root.setCapability(Group.ALLOW_CHILDREN_WRITE);
samer@1 38 root.compile();
samer@1 39
samer@1 40 U.addGroup(root);
samer@1 41
samer@1 42 Shell.registerAgent(this);
samer@1 43 Shell.exposeCommands(this);
samer@1 44 }
samer@1 45
samer@1 46 private static Group createSceneGraph()
samer@1 47 {
samer@1 48 Transform3D r=new Transform3D();
samer@1 49 r.rotX(1.1);
samer@1 50 r.setScale(0.5);
samer@1 51
samer@1 52 TransformGroup t2=new TransformGroup(r);
samer@1 53 GeometryInfo gi=yoyoGeometryInfo(32);
samer@1 54 new NormalGenerator().generateNormals(gi);
samer@1 55
samer@1 56 Geometry g=gi.getGeometryArray();
samer@1 57 Shape3D faces=new Shape3D();
samer@1 58 Shape3D edges=new Shape3D();
samer@1 59 faces.setGeometry(g); faces.setAppearance(material1());
samer@1 60 edges.setGeometry(g); edges.setAppearance(shadedwireframe());
samer@1 61
samer@1 62 TransformGroup tg = new TransformGroup();
samer@1 63 addRotator(tg);
samer@1 64 t2.addChild(faces);
samer@1 65 t2.addChild(edges);
samer@1 66 tg.addChild(t2);
samer@1 67
samer@1 68 return tg;
samer@1 69 }
samer@1 70
samer@1 71 public void getCommands(Agent.Registry r) {
samer@1 72 r.add("view").add("axis");
samer@1 73 r.setTarget(null);
samer@1 74 r.add("start").add("stop");
samer@1 75 }
samer@1 76
samer@1 77 public void execute(String cmd, Environment env) throws Exception
samer@1 78 {
samer@1 79 if (cmd.equals("view")) {
samer@1 80 root.addChild(new Viewer(X.string(env.datum("name"),"view")));
samer@1 81 } else if (cmd.equals("axis")) {
samer@1 82 Transform3D t3d=new Transform3D();
samer@1 83 t3d.set(0.5);
samer@1 84
samer@1 85 TransformGroup tg=new TransformGroup(t3d);
samer@1 86 BranchGroup bg=new BranchGroup();
samer@1 87 Axis axis=new Axis();
samer@1 88
samer@1 89 axis.setAppearance(wireframe1());
samer@1 90 tg.addChild(axis);
samer@1 91 bg.addChild(tg);
samer@1 92 bg.compile();
samer@1 93 root.addChild(bg);
samer@1 94 }
samer@1 95
samer@1 96 }
samer@1 97 }