samer@0
|
1 /*
|
samer@0
|
2 */
|
samer@0
|
3 package samer.j3d;
|
samer@0
|
4
|
samer@0
|
5 import samer.core.*;
|
samer@0
|
6 import samer.maths.*;
|
samer@0
|
7 import samer.tools.*;
|
samer@0
|
8 import java.io.*;
|
samer@0
|
9 import java.awt.event.*;
|
samer@0
|
10 import javax.media.j3d.*;
|
samer@0
|
11 import javax.vecmath.*;
|
samer@0
|
12
|
samer@0
|
13 public class J3DViewer extends Util
|
samer@0
|
14 {
|
samer@0
|
15 Shape3D shape;
|
samer@0
|
16
|
samer@0
|
17 public J3DViewer(Root root, Matrix P, VVector A) throws Exception
|
samer@0
|
18 {
|
samer@0
|
19 if (P==null) {
|
samer@0
|
20 Shell.print("creating PointsMatrix");
|
samer@0
|
21 P=new Matrix("PointsMatrix",A.size(),4);
|
samer@0
|
22 new MatrixAgent(P).execute("load",Shell.env());
|
samer@0
|
23 }
|
samer@0
|
24 // create scene
|
samer@0
|
25 {
|
samer@0
|
26 int viewerType=Shell.getInt("viewerType",0);
|
samer@0
|
27 Shape3D shape;
|
samer@0
|
28
|
samer@0
|
29 switch (viewerType) {
|
samer@0
|
30 case 1:
|
samer@0
|
31 shape=new Shape3D(new MatrixPointArrayAlpha(P,A), transparent(0,points()));
|
samer@0
|
32 break;
|
samer@0
|
33 case 2:
|
samer@0
|
34 shape=new Shape3D(new MatrixPoints4D(P,A), transparent(0,points()));
|
samer@0
|
35 break;
|
samer@0
|
36 case 3:
|
samer@0
|
37 Geometry geom=new PatchArrayAlpha(P,A);
|
samer@0
|
38 shape=new Shape3D(geom, rndr(flat(transparent(0,patch())),false));
|
samer@0
|
39 break;
|
samer@0
|
40 default:
|
samer@0
|
41 shape=new Shape3D(new MatrixPointArray(P,A), points());
|
samer@0
|
42 addBackground(root,new Background(new Color3f(0.26f,0.23f,0.35f)));
|
samer@0
|
43 break;
|
samer@0
|
44 }
|
samer@0
|
45 }
|
samer@0
|
46 }
|
samer@0
|
47
|
samer@0
|
48 public javax.media.j3d.Node getShape() { return rotaterise(shape); }
|
samer@0
|
49
|
samer@0
|
50 private Appearance rndr(Appearance a, boolean ignore)
|
samer@0
|
51 {
|
samer@0
|
52 RenderingAttributes ra=new RenderingAttributes();
|
samer@0
|
53 ra.setDepthBufferEnable(false);
|
samer@0
|
54 ra.setIgnoreVertexColors(ignore);
|
samer@0
|
55 a.setRenderingAttributes(ra);
|
samer@0
|
56 return a;
|
samer@0
|
57 }
|
samer@0
|
58
|
samer@0
|
59
|
samer@0
|
60 private static Group rotaterise(javax.media.j3d.Node n)
|
samer@0
|
61 {
|
samer@0
|
62 TransformGroup tg = new TransformGroup();
|
samer@0
|
63 TransformGroup tg2=new TransformGroup();
|
samer@0
|
64
|
samer@0
|
65 mouseRotate(tg);
|
samer@0
|
66 mouseTranslate(tg);
|
samer@0
|
67 mouseZoom(tg);
|
samer@0
|
68 addRotator(tg2,Shell.getInt("rotation.period",10000));
|
samer@0
|
69 tg.addChild(n);
|
samer@0
|
70 tg2.addChild(tg);
|
samer@0
|
71 return tg2;
|
samer@0
|
72 }
|
samer@0
|
73 } |