comparison examples/java3d/hello9.java @ 1:5df24c91468d

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