1 package tim.prune.threedee;
3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
6 import java.awt.GraphicsConfiguration;
7 import java.awt.GraphicsEnvironment;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.awt.event.WindowAdapter;
11 import java.awt.event.WindowEvent;
12 import java.awt.geom.GeneralPath;
14 import javax.media.j3d.AmbientLight;
15 import javax.media.j3d.Appearance;
16 import javax.media.j3d.Billboard;
17 import javax.media.j3d.BoundingSphere;
18 import javax.media.j3d.BranchGroup;
19 import javax.media.j3d.Canvas3D;
20 import javax.media.j3d.DirectionalLight;
21 import javax.media.j3d.Font3D;
22 import javax.media.j3d.FontExtrusion;
23 import javax.media.j3d.GeometryArray;
24 import javax.media.j3d.GraphicsConfigTemplate3D;
25 import javax.media.j3d.Group;
26 import javax.media.j3d.Material;
27 import javax.media.j3d.PointLight;
28 import javax.media.j3d.QuadArray;
29 import javax.media.j3d.Shape3D;
30 import javax.media.j3d.Text3D;
31 import javax.media.j3d.Texture;
32 import javax.media.j3d.TextureAttributes;
33 import javax.media.j3d.Transform3D;
34 import javax.media.j3d.TransformGroup;
35 import javax.swing.JButton;
36 import javax.swing.JFrame;
37 import javax.swing.JOptionPane;
38 import javax.swing.JPanel;
39 import javax.vecmath.Color3f;
40 import javax.vecmath.Matrix3d;
41 import javax.vecmath.Point3d;
42 import javax.vecmath.Point3f;
43 import javax.vecmath.TexCoord2f;
44 import javax.vecmath.Vector3d;
45 import javax.vecmath.Vector3f;
47 import tim.prune.DataStatus;
48 import tim.prune.FunctionLibrary;
49 import tim.prune.I18nManager;
50 import tim.prune.data.Track;
51 import tim.prune.function.Export3dFunction;
52 import tim.prune.function.srtm.LookupSrtmFunction;
53 import tim.prune.gui.map.MapSourceLibrary;
54 import tim.prune.save.GroutedImage;
55 import tim.prune.save.MapGrouter;
57 import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
58 import com.sun.j3d.utils.geometry.Box;
59 import com.sun.j3d.utils.geometry.Cylinder;
60 import com.sun.j3d.utils.geometry.GeometryInfo;
61 import com.sun.j3d.utils.geometry.NormalGenerator;
62 import com.sun.j3d.utils.geometry.Sphere;
63 import com.sun.j3d.utils.image.TextureLoader;
64 import com.sun.j3d.utils.universe.SimpleUniverse;
68 * Class to hold main window for java3d view of data
70 public class Java3DWindow implements ThreeDWindow
72 private Track _track = null;
73 private JFrame _parentFrame = null;
74 private JFrame _frame = null;
75 private ThreeDModel _model = null;
76 private OrbitBehavior _orbit = null;
77 private double _altFactor = -1.0;
78 private ImageDefinition _imageDefinition = null;
79 private GroutedImage _baseImage = null;
80 private TerrainDefinition _terrainDefinition = null;
81 private DataStatus _dataStatus = null;
83 /** only prompt about big track size once */
84 private static boolean TRACK_SIZE_WARNING_GIVEN = false;
87 private static final double INITIAL_Y_ROTATION = -25.0;
88 private static final double INITIAL_X_ROTATION = 15.0;
89 private static final String CARDINALS_FONT = "Arial";
90 private static final int MAX_TRACK_SIZE = 2500; // threshold for warning
91 private static final double MODEL_SCALE_FACTOR = 20.0;
96 * @param inFrame parent frame
98 public Java3DWindow(JFrame inFrame)
100 _parentFrame = inFrame;
105 * Set the track object
106 * @param inTrack Track object
108 public void setTrack(Track inTrack)
114 * @param inFactor altitude factor to use
116 public void setAltitudeFactor(double inFactor)
118 _altFactor = inFactor;
122 * Set the parameters for the base image and do the grouting already
123 * (setTrack should already be called by now)
125 public void setBaseImageParameters(ImageDefinition inDefinition)
127 _imageDefinition = inDefinition;
128 if (inDefinition != null && inDefinition.getUseImage())
130 _baseImage = new MapGrouter().createMapImage(_track, MapSourceLibrary.getSource(inDefinition.getSourceIndex()),
131 inDefinition.getZoom());
133 else _baseImage = null;
137 * Set the terrain parameters
139 public void setTerrainParameters(TerrainDefinition inDefinition)
141 _terrainDefinition = inDefinition;
145 * Set the current data status
147 public void setDataStatus(DataStatus inStatus)
149 _dataStatus = inStatus;
155 public void show() throws ThreeDException
157 // Make sure altitude exaggeration is positive
158 if (_altFactor < 0.0) {_altFactor = 1.0;}
160 // Set up the graphics config
161 GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
164 // Config shouldn't be null, but we can try to create a new one as a workaround
165 GraphicsConfigTemplate3D gc = new GraphicsConfigTemplate3D();
167 config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(gc);
172 // Second attempt also failed, going to have to give up here.
173 throw new ThreeDException("Couldn't create graphics config");
176 // Check number of points in model isn't too big, and suggest compression
177 Object[] buttonTexts = {I18nManager.getText("button.continue"), I18nManager.getText("button.cancel")};
178 if (_track.getNumPoints() > MAX_TRACK_SIZE && !TRACK_SIZE_WARNING_GIVEN)
180 if (JOptionPane.showOptionDialog(_parentFrame,
181 I18nManager.getText("dialog.3d.warningtracksize"),
182 I18nManager.getText("function.show3d"), JOptionPane.OK_CANCEL_OPTION,
183 JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1])
184 == JOptionPane.OK_OPTION)
186 // opted to continue, don't show warning again
187 TRACK_SIZE_WARNING_GIVEN = true;
190 // opted to cancel - show warning again next time
195 Canvas3D canvas = new Canvas3D(config);
196 canvas.setSize(400, 300);
198 // Create the scene and attach it to the virtual universe
199 BranchGroup scene = createSceneGraph();
200 SimpleUniverse u = new SimpleUniverse(canvas);
202 // This will move the ViewPlatform back a bit so the
203 // objects in the scene can be viewed.
204 u.getViewingPlatform().setNominalViewingTransform();
206 // Add behaviour to rotate using mouse
207 _orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL | OrbitBehavior.STOP_ZOOM);
208 BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
209 _orbit.setSchedulingBounds(bounds);
210 u.getViewingPlatform().setViewPlatformBehavior(_orbit);
211 u.addBranchGraph(scene);
213 // Don't reuse _frame object from last time, because data and/or scale might be different
214 // Need to regenerate everything
215 _frame = new JFrame(I18nManager.getText("dialog.3d.title"));
216 _frame.getContentPane().setLayout(new BorderLayout());
217 _frame.getContentPane().add(canvas, BorderLayout.CENTER);
218 _frame.setIconImage(_parentFrame.getIconImage());
219 // Make panel for render, close buttons
220 JPanel panel = new JPanel();
221 panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
222 // Add button for exporting pov
223 JButton povButton = new JButton(I18nManager.getText("function.exportpov"));
224 povButton.addActionListener(new ActionListener() {
225 /** Export pov button pressed */
226 public void actionPerformed(ActionEvent e)
228 if (_orbit != null) {
229 callbackRender(FunctionLibrary.FUNCTION_POVEXPORT);
232 panel.add(povButton);
234 JButton closeButton = new JButton(I18nManager.getText("button.close"));
235 closeButton.addActionListener(new ActionListener()
237 /** Close button pressed - clean up */
238 public void actionPerformed(ActionEvent e) {
243 panel.add(closeButton);
244 _frame.getContentPane().add(panel, BorderLayout.SOUTH);
245 _frame.setSize(500, 350);
247 // Add a listener to clean up when window closed
248 _frame.addWindowListener(new WindowAdapter() {
249 public void windowClosing(WindowEvent e) {
255 _frame.setVisible(true);
256 if (_frame.getState() == JFrame.ICONIFIED) {
257 _frame.setState(JFrame.NORMAL);
262 * Dispose of the frame and its resources
264 public void dispose()
266 if (_frame != null) {
273 * Create the whole scenery from the given track
274 * @return all objects in the scene
276 private BranchGroup createSceneGraph()
278 // Create the root of the branch graph
279 BranchGroup objRoot = new BranchGroup();
281 // Create the transform group node and initialize it.
282 // Enable the TRANSFORM_WRITE capability so it can be spun by the mouse
283 TransformGroup objTrans = new TransformGroup();
284 objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
286 // Create a translation
287 Transform3D shiftz = new Transform3D();
288 shiftz.setScale(0.055);
289 TransformGroup shiftTrans = new TransformGroup(shiftz);
291 objRoot.addChild(shiftTrans);
292 Transform3D rotTrans = new Transform3D();
293 rotTrans.rotY(Math.toRadians(INITIAL_Y_ROTATION));
294 Transform3D rot2 = new Transform3D();
295 rot2.rotX(Math.toRadians(INITIAL_X_ROTATION));
296 TransformGroup tg2 = new TransformGroup(rot2);
297 objTrans.setTransform(rotTrans);
298 shiftTrans.addChild(tg2);
299 tg2.addChild(objTrans);
302 Appearance planeAppearance = null;
304 planeAppearance = new Appearance();
305 planeAppearance.setMaterial(new Material(new Color3f(0.1f, 0.2f, 0.2f),
306 new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.3f, 0.4f, 0.4f),
307 new Color3f(0.3f, 0.3f, 0.3f), 0.0f));
308 plane = new Box(10f, 0.04f, 10f, planeAppearance);
309 objTrans.addChild(plane);
311 // Image on top of base plane, if specified
312 final boolean showTerrain = _terrainDefinition != null && _terrainDefinition.getUseTerrain();
313 if (_baseImage != null && !showTerrain)
315 QuadArray baseSquare = new QuadArray (4, QuadArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
316 baseSquare.setCoordinate(0, new Point3f(-10f, 0.05f, -10f));
317 baseSquare.setCoordinate(1, new Point3f(-10f, 0.05f, 10f));
318 baseSquare.setCoordinate(2, new Point3f( 10f, 0.05f, 10f));
319 baseSquare.setCoordinate(3, new Point3f( 10f, 0.05f, -10f));
320 // and set anchor points for the texture
321 baseSquare.setTextureCoordinate(0, 0, new TexCoord2f(0.0f, 1.0f));
322 baseSquare.setTextureCoordinate(0, 1, new TexCoord2f(0.0f, 0.0f));
323 baseSquare.setTextureCoordinate(0, 2, new TexCoord2f(1.0f, 0.0f));
324 baseSquare.setTextureCoordinate(0, 3, new TexCoord2f(1.0f, 1.0f));
325 // Set appearance including image
326 Appearance baseAppearance = new Appearance();
327 Texture mapImage = new TextureLoader(_baseImage.getImage(), _frame).getTexture();
328 baseAppearance.setTexture(mapImage);
329 objTrans.addChild(new Shape3D(baseSquare, baseAppearance));
332 // Create model containing track information
333 _model = new ThreeDModel(_track);
334 _model.setAltitudeFactor(_altFactor);
338 TerrainHelper terrainHelper = new TerrainHelper(_terrainDefinition.getGridSize());
339 // See if there's a previously saved terrain track we can reuse
340 Track terrainTrack = TerrainCache.getTerrainTrack(_dataStatus, _terrainDefinition);
341 if (terrainTrack == null)
343 // Construct the terrain track according to these extents and the grid size
344 terrainTrack = terrainHelper.createGridTrack(_track);
345 // Get the altitudes from SRTM for all the points in the track
346 LookupSrtmFunction srtmLookup = (LookupSrtmFunction) FunctionLibrary.FUNCTION_LOOKUP_SRTM;
347 srtmLookup.begin(terrainTrack);
348 while (srtmLookup.isRunning())
351 Thread.sleep(750); // just polling in a wait loop isn't ideal but simple
353 catch (InterruptedException e) {}
357 terrainHelper.fixVoids(terrainTrack);
359 // Store this back in the cache, maybe we'll need it again
360 TerrainCache.storeTerrainTrack(terrainTrack, _dataStatus, _terrainDefinition);
362 // else System.out.println("Yay - reusing the cached track!");
364 // Give the terrain definition to the _model as well
365 _model.setTerrain(terrainTrack);
368 objTrans.addChild(createTerrain(_model, terrainHelper, _baseImage));
372 // No terrain, so just scale the model as it is
377 GeneralPath bevelPath = new GeneralPath();
378 bevelPath.moveTo(0.0f, 0.0f);
379 for (int i=0; i<91; i+= 5)
381 bevelPath.lineTo((float) (0.1 - 0.1 * Math.cos(Math.toRadians(i))),
382 (float) (0.1 * Math.sin(Math.toRadians(i))));
384 for (int i=90; i>0; i-=5)
386 bevelPath.lineTo((float) (0.3 + 0.1 * Math.cos(Math.toRadians(i))),
387 (float) (0.1 * Math.sin(Math.toRadians(i))));
389 Font3D compassFont = new Font3D(
390 new Font(CARDINALS_FONT, Font.PLAIN, 1),
391 new FontExtrusion(bevelPath));
392 objTrans.addChild(createCompassPoint(I18nManager.getText("cardinal.n"), new Point3f(0f, 0f, -11.5f), compassFont));
393 objTrans.addChild(createCompassPoint(I18nManager.getText("cardinal.s"), new Point3f(0f, 0f, 11.5f), compassFont));
394 objTrans.addChild(createCompassPoint(I18nManager.getText("cardinal.w"), new Point3f(-11.5f, 0f, 0f), compassFont));
395 objTrans.addChild(createCompassPoint(I18nManager.getText("cardinal.e"), new Point3f(11.5f, 0f, 0f), compassFont));
397 // Add points to model
398 objTrans.addChild(createDataPoints(_model));
400 // Create lights - always add ambient light
401 BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
402 AmbientLight aLgt = new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f));
403 aLgt.setInfluencingBounds(bounds);
404 objTrans.addChild(aLgt);
406 // Additional lights depend on whether there's a terrain or not
409 // If there's a terrain, just have directional light from northwest
410 DirectionalLight dl = new DirectionalLight(true,
411 new Color3f(1.0f, 1.0f, 1.0f),
412 new Vector3f(1.0f, -1.0f, 1.0f));
413 dl.setInfluencingBounds(bounds);
414 objTrans.addChild(dl);
418 // There is no terrain, so use point lights as before
419 PointLight pLgt = new PointLight(new Color3f(1.0f, 1.0f, 1.0f),
420 new Point3f(0f, 0f, 2f), new Point3f(0.25f, 0.05f, 0.0f) );
421 pLgt.setInfluencingBounds(bounds);
422 objTrans.addChild(pLgt);
424 PointLight pl2 = new PointLight(new Color3f(0.8f, 0.9f, 0.4f),
425 new Point3f(6f, 1f, 6f), new Point3f(0.2f, 0.1f, 0.05f) );
426 pl2.setInfluencingBounds(bounds);
427 objTrans.addChild(pl2);
429 PointLight pl3 = new PointLight(new Color3f(0.7f, 0.7f, 0.7f),
430 new Point3f(0.0f, 12f, -2f), new Point3f(0.1f, 0.1f, 0.0f) );
431 pl3.setInfluencingBounds(bounds);
432 objTrans.addChild(pl3);
435 // Have Java 3D perform optimizations on this scene graph.
443 * Create a text object for compass point, N S E or W
444 * @param inText text to display
445 * @param inLocn position at which to display
446 * @param inFont 3d font to use
447 * @return compound object
449 private TransformGroup createCompassPoint(String inText, Point3f inLocn, Font3D inFont)
451 Text3D txt = new Text3D(inFont, inText, inLocn, Text3D.ALIGN_FIRST, Text3D.PATH_RIGHT);
452 Material mat = new Material(new Color3f(0.5f, 0.5f, 0.55f),
453 new Color3f(0.05f, 0.05f, 0.1f), new Color3f(0.3f, 0.4f, 0.5f),
454 new Color3f(0.4f, 0.5f, 0.7f), 70.0f);
455 mat.setLightingEnable(true);
456 Appearance app = new Appearance();
457 app.setMaterial(mat);
458 Shape3D shape = new Shape3D(txt, app);
460 // Make transform group with billboard behaviour
461 TransformGroup subGroup = new TransformGroup();
462 subGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
463 subGroup.addChild(shape);
464 Billboard billboard = new Billboard(subGroup, Billboard.ROTATE_ABOUT_POINT, inLocn);
465 BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
466 billboard.setSchedulingBounds(bounds);
467 subGroup.addChild(billboard);
473 * Make a Group of the data points to be added
474 * @param inModel model containing data
475 * @return Group object containing spheres, rods etc
477 private static Group createDataPoints(ThreeDModel inModel)
479 // Add points to model
480 Group group = new Group();
481 int numPoints = inModel.getNumPoints();
482 for (int i=0; i<numPoints; i++)
484 byte pointType = inModel.getPointType(i);
485 if (pointType == ThreeDModel.POINT_TYPE_WAYPOINT)
488 // Note that x, y and z are horiz, altitude, -vert
489 group.addChild(createWaypoint(new Point3d(
490 inModel.getScaledHorizValue(i) * MODEL_SCALE_FACTOR,
491 inModel.getScaledAltValue(i) * MODEL_SCALE_FACTOR,
492 -inModel.getScaledVertValue(i) * MODEL_SCALE_FACTOR)));
496 // Add colour-coded track point
497 // Note that x, y and z are horiz, altitude, -vert
498 group.addChild(createTrackpoint(new Point3d(
499 inModel.getScaledHorizValue(i) * MODEL_SCALE_FACTOR,
500 inModel.getScaledAltValue(i) * MODEL_SCALE_FACTOR,
501 -inModel.getScaledVertValue(i) * MODEL_SCALE_FACTOR), inModel.getPointHeightCode(i)));
509 * Create a waypoint sphere
510 * @param inPointPos position of point
511 * @return Group object containing sphere
513 private static Group createWaypoint(Point3d inPointPos)
515 Material mat = getWaypointMaterial();
516 // MAYBE: sort symbol scaling
517 Sphere dot = new Sphere(0.35f); // * symbolScaling / 100f);
518 return createBall(inPointPos, dot, mat);
523 * @return a new Material object to define waypoint colour / shine etc
525 private static Material getWaypointMaterial()
527 return new Material(new Color3f(0.1f, 0.1f, 0.4f),
528 new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.0f, 0.2f, 0.7f),
529 new Color3f(1.0f, 0.6f, 0.6f), 40.0f);
534 * @return track point object
536 private static Group createTrackpoint(Point3d inPointPos, byte inHeightCode)
538 Material mat = getTrackpointMaterial(inHeightCode);
539 // MAYBE: sort symbol scaling
540 Sphere dot = new Sphere(0.2f);
541 return createBall(inPointPos, dot, mat);
546 * @return Material object for track points with the appropriate colour for the height
548 private static Material getTrackpointMaterial(byte inHeightCode)
550 // create default material
551 Material mat = new Material(new Color3f(0.3f, 0.2f, 0.1f),
552 new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.0f, 0.6f, 0.0f),
553 new Color3f(1.0f, 0.6f, 0.6f), 70.0f);
554 // change colour according to height code
555 if (inHeightCode == 1) mat.setDiffuseColor(new Color3f(0.4f, 0.9f, 0.2f));
556 else if (inHeightCode == 2) mat.setDiffuseColor(new Color3f(0.7f, 0.8f, 0.2f));
557 else if (inHeightCode == 3) mat.setDiffuseColor(new Color3f(0.3f, 0.6f, 0.4f));
558 else if (inHeightCode == 4) mat.setDiffuseColor(new Color3f(0.1f, 0.9f, 0.9f));
559 else if (inHeightCode >= 5) mat.setDiffuseColor(new Color3f(1.0f, 1.0f, 1.0f));
566 * Create a ball at the given point
567 * @param inPosition scaled position of point
568 * @param inSphere sphere object
569 * @param inMaterial material object
570 * @return Group containing sphere
572 private static Group createBall(Point3d inPosition, Sphere inSphere, Material inMaterial)
574 Group group = new Group();
575 // Create ball and add to group
576 Transform3D ballShift = new Transform3D();
577 ballShift.setTranslation(new Vector3d(inPosition));
578 TransformGroup ballShiftTrans = new TransformGroup(ballShift);
579 inMaterial.setLightingEnable(true);
580 Appearance ballApp = new Appearance();
581 ballApp.setMaterial(inMaterial);
582 inSphere.setAppearance(ballApp);
583 ballShiftTrans.addChild(inSphere);
584 group.addChild(ballShiftTrans);
585 // Also create rod for ball to sit on
586 Cylinder rod = new Cylinder(0.1f, (float) inPosition.y);
587 Material rodMat = new Material(new Color3f(0.2f, 0.2f, 0.2f),
588 new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.2f, 0.2f, 0.2f),
589 new Color3f(0.05f, 0.05f, 0.05f), 0.4f);
590 rodMat.setLightingEnable(true);
591 Appearance rodApp = new Appearance();
592 rodApp.setMaterial(rodMat);
593 rod.setAppearance(rodApp);
594 Transform3D rodShift = new Transform3D();
595 rodShift.setTranslation(new Vector3d(inPosition.x, inPosition.y/2.0, inPosition.z));
596 TransformGroup rodShiftTrans = new TransformGroup(rodShift);
597 rodShiftTrans.addChild(rod);
598 group.addChild(rodShiftTrans);
604 * Create a java3d Shape for the terrain
605 * @param inModel threedModel
606 * @param inHelper terrain helper
607 * @param inBaseImage base image for shape, or null for no image
608 * @return Shape3D object
610 private static Shape3D createTerrain(ThreeDModel inModel, TerrainHelper inHelper, GroutedImage inBaseImage)
612 final int numNodes = inHelper.getGridSize();
613 final int RESULT_SIZE = numNodes * (numNodes * 2 - 2);
614 int[] stripData = inHelper.getStripLengths();
616 // Get the scaled terrainTrack coordinates (or just heights) from the model
617 final int nSquared = numNodes * numNodes;
618 Point3d[] rawPoints = new Point3d[nSquared];
619 for (int i=0; i<nSquared; i++)
621 double height = inModel.getScaledTerrainValue(i) * MODEL_SCALE_FACTOR;
622 rawPoints[i] = new Point3d(inModel.getScaledTerrainHorizValue(i) * MODEL_SCALE_FACTOR,
623 Math.max(height, 0.05), // make sure it's above the box
624 -inModel.getScaledTerrainVertValue(i) * MODEL_SCALE_FACTOR);
627 GeometryInfo gi = new GeometryInfo(GeometryInfo.TRIANGLE_STRIP_ARRAY);
628 gi.setCoordinates(inHelper.getTerrainCoordinates(rawPoints));
629 gi.setStripCounts(stripData);
631 Appearance tAppearance = new Appearance();
632 if (inBaseImage != null)
634 gi.setTextureCoordinateParams(1, 2); // one coord set of two dimensions
635 gi.setTextureCoordinates(0, inHelper.getTextureCoordinates());
636 Texture mapImage = new TextureLoader(inBaseImage.getImage()).getTexture();
637 tAppearance.setTexture(mapImage);
638 TextureAttributes texAttr = new TextureAttributes();
639 texAttr.setTextureMode(TextureAttributes.MODULATE);
640 tAppearance.setTextureAttributes(texAttr);
644 Color3f[] colours = new Color3f[RESULT_SIZE];
645 Color3f terrainColour = new Color3f(0.1f, 0.2f, 0.2f);
646 for (int i=0; i<RESULT_SIZE; i++) {colours[i] = terrainColour;}
647 gi.setColors(colours);
649 new NormalGenerator().generateNormals(gi);
650 Material terrnMat = new Material(new Color3f(0.4f, 0.4f, 0.4f), // ambient colour
651 new Color3f(0f, 0f, 0f), // emissive (none)
652 new Color3f(0.8f, 0.8f, 0.8f), // diffuse
653 new Color3f(0.2f, 0.2f, 0.2f), //specular
655 tAppearance.setMaterial(terrnMat);
656 return new Shape3D(gi.getGeometryArray(), tAppearance);
660 * Calculate the angles and call them back to the app
661 * @param inFunction function to call for export
663 private void callbackRender(Export3dFunction inFunction)
665 Transform3D trans3d = new Transform3D();
666 _orbit.getViewingPlatform().getViewPlatformTransform().getTransform(trans3d);
667 Matrix3d matrix = new Matrix3d();
669 Point3d point = new Point3d(0.0, 0.0, 1.0);
670 matrix.transform(point);
671 // Set up initial rotations
672 Transform3D firstTran = new Transform3D();
673 firstTran.rotY(Math.toRadians(-INITIAL_Y_ROTATION));
674 Transform3D secondTran = new Transform3D();
675 secondTran.rotX(Math.toRadians(-INITIAL_X_ROTATION));
676 // Apply inverse rotations in reverse order to the test point
677 Point3d result = new Point3d();
678 secondTran.transform(point, result);
679 firstTran.transform(result);
681 // Give the settings to the rendering function
682 inFunction.setCameraCoordinates(result.x, result.y, result.z);
683 inFunction.setAltitudeExaggeration(_altFactor);
684 inFunction.setTerrainDefinition(_terrainDefinition);
685 inFunction.setImageDefinition(_imageDefinition);