source: java/main/src/main/java/com/framsticks/visualization/Viewer.java @ 84

Last change on this file since 84 was 84, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

File size: 5.5 KB
Line 
1package com.framsticks.visualization;
2
3import com.sun.j3d.loaders.IncorrectFormatException;
4import com.sun.j3d.loaders.ParsingErrorException;
5import com.sun.j3d.loaders.Scene;
6import com.sun.j3d.loaders.objectfile.ObjectFile;
7import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
8import com.sun.j3d.utils.universe.PlatformGeometry;
9import com.sun.j3d.utils.universe.SimpleUniverse;
10import com.sun.j3d.utils.universe.ViewingPlatform;
11
12import javax.media.j3d.*;
13import javax.swing.*;
14import javax.vecmath.Color3f;
15import javax.vecmath.Point3d;
16import javax.vecmath.Vector3f;
17import java.awt.*;
18import java.io.*;
19
20// import org.apache.log4j.Logger;
21
22public class Viewer {
23
24    // private static Logger log = Logger.getLogger(Viewer.class);
25
26    Canvas3D canvas3d;
27    SimpleUniverse universe;
28
29    public Viewer() {
30        super();
31
32        init();
33    }
34
35        public BranchGroup createSceneGraph() {
36        // Create the root of the branch graph
37        BranchGroup objRoot = new BranchGroup();
38
39        // Create a Transform group to scale all objects so they
40        // appear in the scene.
41        TransformGroup objScale = new TransformGroup();
42        Transform3D t3d = new Transform3D();
43        t3d.setScale(0.7);
44        objScale.setTransform(t3d);
45        objRoot.addChild(objScale);
46
47        TransformGroup objTrans = new TransformGroup();
48        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
49        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
50        objScale.addChild(objTrans);
51
52        String filename = "/visualization/models/cylinder.obj";
53        int flags = ObjectFile.RESIZE;
54        flags |= ObjectFile.TRIANGULATE;
55        flags |= ObjectFile.STRIPIFY;
56                double creaseAngle = 60.0;
57                ObjectFile f = new ObjectFile(flags,
58                (float) (creaseAngle * Math.PI / 180.0));
59        Scene s = null;
60        try {
61                        InputStream is = this.getClass().getResourceAsStream(filename);
62            s = f.load(new InputStreamReader(is));
63        } catch (FileNotFoundException e) {
64            System.err.println(e);
65            System.exit(1);
66        } catch (ParsingErrorException e) {
67            System.err.println(e);
68            System.exit(1);
69        } catch (IncorrectFormatException e) {
70            System.err.println(e);
71            System.exit(1);
72        }
73
74        objTrans.addChild(s.getSceneGroup());
75
76        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
77
78        Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
79        Background bgNode = new Background(bgColor);
80        bgNode.setApplicationBounds(bounds);
81        objRoot.addChild(bgNode);
82
83        return objRoot;
84    }
85
86    private void init() {
87
88            JTextPane textPane = new JTextPane();
89        textPane.setEditable(false);
90
91        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
92
93        // Create a Canvas3D using the preferred configuration
94        canvas3d = new Canvas3D(config);
95
96        // Create simple universe with view branch
97        universe = new SimpleUniverse(canvas3d);
98        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
99
100        // add mouse behaviours to the ViewingPlatform
101        ViewingPlatform viewingPlatform = universe.getViewingPlatform();
102
103        PlatformGeometry platformGeometry = new PlatformGeometry();
104
105        // Set up the ambient light
106        Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
107        AmbientLight ambientLightNode = new AmbientLight(ambientColor);
108        ambientLightNode.setInfluencingBounds(bounds);
109        platformGeometry.addChild(ambientLightNode);
110
111        // Set up the directional lights
112        Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
113        Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
114        Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
115        Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);
116
117        DirectionalLight light1 = new DirectionalLight(light1Color,
118                light1Direction);
119        light1.setInfluencingBounds(bounds);
120        platformGeometry.addChild(light1);
121
122        DirectionalLight light2 = new DirectionalLight(light2Color,
123                light2Direction);
124        light2.setInfluencingBounds(bounds);
125        platformGeometry.addChild(light2);
126
127        viewingPlatform.setPlatformGeometry(platformGeometry);
128
129        viewingPlatform.setNominalViewingTransform();
130
131        // Ensure at least 5 msec per frame (i.e., < 200Hz)
132        universe.getViewer().getView().setMinimumFrameCycleTime(5);
133
134        BranchGroup scene = new BranchGroup();
135        BranchGroup content = createSceneGraph();
136
137        // canvas3d.addMouseListener(behaviour);
138        TransformGroup transformGroup = new TransformGroup(new Transform3D());
139        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
140        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
141        MouseRotate behaviour = new MouseRotate();
142        behaviour.setTransformGroup(transformGroup);
143        transformGroup.addChild(behaviour);
144        // behaviour.addListener(canvas3d);
145        // behaviour.initialize();
146        behaviour.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
147        transformGroup.addChild(content);
148        // transformGroup.addChild(behaviour);
149        scene.addChild(transformGroup);
150
151        universe.addBranchGraph(scene);
152                canvas3d.startRenderer();
153                Dimension d = new Dimension(500, 500);
154                canvas3d.setMinimumSize(d);
155                canvas3d.setSize(d);
156    }
157
158    public Component getViewComponent() {
159        return canvas3d;
160    }
161
162
163}
Note: See TracBrowser for help on using the repository browser.