aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-examples/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'ardor3d-examples/src/main/java')
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/ExampleBase.java4
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/applet/LwjglBaseApplet.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/BoxExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/JoglBasicExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglBasicExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglHeadlessExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/MatrixLookAtExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/MouseManagerExample.java4
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/ShapesExample.java4
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/basic/SwitchNodeExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglAwtExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglSwtExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/CombinerExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DisplayListExample.java4
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java4
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MandelbrotExplorerExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MeshDataSharingExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/PointCubeExample.java6
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/RenderQueueExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/StereoExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/Texture3DExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/UpdateTextureExample.java4
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/VBOSpeedExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExampleMultiTextured.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/terrain/ImageMapTerrainExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java2
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/terrain/TerrainWaterExample.java2
34 files changed, 42 insertions, 42 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ExampleBase.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ExampleBase.java
index 64807b6..30ca4dd 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/ExampleBase.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ExampleBase.java
@@ -31,8 +31,8 @@ import com.ardor3d.framework.jogl.JoglNewtWindow;
import com.ardor3d.framework.lwjgl.LwjglCanvas;
import com.ardor3d.framework.lwjgl.LwjglCanvasRenderer;
import com.ardor3d.image.TextureStoreFormat;
-import com.ardor3d.image.util.AWTImageLoader;
-import com.ardor3d.image.util.ScreenShotImageExporter;
+import com.ardor3d.image.util.awt.AWTImageLoader;
+import com.ardor3d.image.util.awt.ScreenShotImageExporter;
import com.ardor3d.input.GrabbedState;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseButton;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java b/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java
index f27e330..148d765 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/applet/JoglBaseApplet.java
@@ -24,7 +24,7 @@ import com.ardor3d.framework.Scene;
import com.ardor3d.framework.Updater;
import com.ardor3d.framework.jogl.JoglCanvasRenderer;
import com.ardor3d.framework.jogl.JoglNewtAwtCanvas;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.GrabbedState;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseButton;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/LwjglBaseApplet.java b/ardor3d-examples/src/main/java/com/ardor3d/example/applet/LwjglBaseApplet.java
index 394e141..ab1d9f9 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/applet/LwjglBaseApplet.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/applet/LwjglBaseApplet.java
@@ -26,7 +26,7 @@ import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.framework.Scene;
import com.ardor3d.framework.lwjgl.LwjglCanvasRenderer;
import com.ardor3d.framework.lwjgl.LwjglDisplayCanvas;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.GrabbedState;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseButton;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/BoxExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/BoxExample.java
index b25850a..c000f3b 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/BoxExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/BoxExample.java
@@ -18,8 +18,8 @@ import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.shape.Box;
import com.ardor3d.util.ReadOnlyTimer;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/JoglBasicExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/JoglBasicExample.java
index 2c17e1c..4e6bd8b 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/JoglBasicExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/JoglBasicExample.java
@@ -19,7 +19,7 @@ import com.ardor3d.framework.Scene;
import com.ardor3d.framework.jogl.JoglCanvas;
import com.ardor3d.framework.jogl.JoglCanvasRenderer;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.intersection.PickResults;
import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglBasicExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglBasicExample.java
index 1523c4d..26f5118 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglBasicExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglBasicExample.java
@@ -19,7 +19,7 @@ import com.ardor3d.framework.Scene;
import com.ardor3d.framework.lwjgl.LwjglCanvas;
import com.ardor3d.framework.lwjgl.LwjglCanvasRenderer;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.intersection.PickResults;
import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglHeadlessExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglHeadlessExample.java
index 516b46a..e1e8fe4 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglHeadlessExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/LwjglHeadlessExample.java
@@ -30,7 +30,7 @@ import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.framework.Scene;
import com.ardor3d.framework.lwjgl.LwjglHeadlessCanvas;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.intersection.PickResults;
import com.ardor3d.light.PointLight;
import com.ardor3d.math.ColorRGBA;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MatrixLookAtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MatrixLookAtExample.java
index a884fa1..5bf947d 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MatrixLookAtExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MatrixLookAtExample.java
@@ -21,8 +21,8 @@ import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.shape.Box;
import com.ardor3d.scenegraph.shape.Sphere;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MouseManagerExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MouseManagerExample.java
index ed6393c..6f29e91 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MouseManagerExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/MouseManagerExample.java
@@ -18,7 +18,7 @@ import com.ardor3d.example.Purpose;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Image;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.GrabbedState;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseButton;
@@ -33,8 +33,8 @@ import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.shape.Box;
import com.ardor3d.util.ReadOnlyTimer;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/ShapesExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/ShapesExample.java
index b5dbe21..d847eaf 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/ShapesExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/ShapesExample.java
@@ -32,8 +32,8 @@ import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.IndexMode;
import com.ardor3d.renderer.state.BlendState;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.RenderState.StateType;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Line;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.Spatial;
@@ -51,6 +51,7 @@ import com.ardor3d.scenegraph.shape.Disk;
import com.ardor3d.scenegraph.shape.Dodecahedron;
import com.ardor3d.scenegraph.shape.Dome;
import com.ardor3d.scenegraph.shape.GeoSphere;
+import com.ardor3d.scenegraph.shape.GeoSphere.TextureMode;
import com.ardor3d.scenegraph.shape.Hexagon;
import com.ardor3d.scenegraph.shape.Icosahedron;
import com.ardor3d.scenegraph.shape.MultiFaceBox;
@@ -64,7 +65,6 @@ import com.ardor3d.scenegraph.shape.StripBox;
import com.ardor3d.scenegraph.shape.Teapot;
import com.ardor3d.scenegraph.shape.Torus;
import com.ardor3d.scenegraph.shape.Tube;
-import com.ardor3d.scenegraph.shape.GeoSphere.TextureMode;
import com.ardor3d.ui.text.BasicText;
import com.ardor3d.util.TextureManager;
import com.ardor3d.util.geom.BufferUtils;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/SwitchNodeExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/SwitchNodeExample.java
index 5366891..6752d8b 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/basic/SwitchNodeExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/basic/SwitchNodeExample.java
@@ -23,8 +23,8 @@ import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.extension.SwitchNode;
import com.ardor3d.scenegraph.hint.CullHint;
import com.ardor3d.scenegraph.hint.LightCombineMode;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkExample.java
index c404ae7..54fd6e7 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkExample.java
@@ -24,7 +24,7 @@ import com.ardor3d.framework.lwjgl.LwjglCanvas;
import com.ardor3d.framework.lwjgl.LwjglCanvasRenderer;
import com.ardor3d.image.Texture;
import com.ardor3d.image.TextureStoreFormat;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.intersection.PickResults;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.Ray3;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java
index 03c6161..f190e1e 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java
@@ -31,7 +31,7 @@ import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.framework.FrameHandler;
import com.ardor3d.framework.jogl.JoglAwtCanvas;
import com.ardor3d.framework.jogl.JoglCanvasRenderer;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.ControllerWrapper;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseCursor;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java
index 66316cf..4a13137 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java
@@ -29,7 +29,7 @@ import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.framework.FrameHandler;
import com.ardor3d.framework.jogl.JoglAwtCanvas;
import com.ardor3d.framework.jogl.JoglCanvasRenderer;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.ControllerWrapper;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseCursor;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java
index 4ad5954..2dcad67 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java
@@ -29,7 +29,7 @@ import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.framework.FrameHandler;
import com.ardor3d.framework.jogl.JoglCanvasRenderer;
import com.ardor3d.framework.jogl.JoglNewtAwtCanvas;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.ControllerWrapper;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseCursor;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java
index 840b9b8..15f2e92 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java
@@ -39,7 +39,7 @@ import com.ardor3d.framework.CanvasRenderer;
import com.ardor3d.framework.FrameHandler;
import com.ardor3d.framework.jogl.JoglCanvasRenderer;
import com.ardor3d.framework.swt.SwtCanvas;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.ControllerWrapper;
import com.ardor3d.input.GrabbedState;
import com.ardor3d.input.Key;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglAwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglAwtExample.java
index a59b4cf..a45df8f 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglAwtExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglAwtExample.java
@@ -29,7 +29,7 @@ import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.framework.FrameHandler;
import com.ardor3d.framework.lwjgl.LwjglAwtCanvas;
import com.ardor3d.framework.lwjgl.LwjglCanvasRenderer;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.ControllerWrapper;
import com.ardor3d.input.Key;
import com.ardor3d.input.MouseCursor;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglSwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglSwtExample.java
index 14bc43b..e564393 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglSwtExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/LwjglSwtExample.java
@@ -41,7 +41,7 @@ import com.ardor3d.framework.FrameHandler;
import com.ardor3d.framework.lwjgl.LwjglCanvasCallback;
import com.ardor3d.framework.lwjgl.LwjglCanvasRenderer;
import com.ardor3d.framework.swt.SwtCanvas;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.ControllerWrapper;
import com.ardor3d.input.GrabbedState;
import com.ardor3d.input.Key;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/CombinerExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/CombinerExample.java
index ae9c275..0fd57d4 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/CombinerExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/CombinerExample.java
@@ -24,8 +24,8 @@ import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.hint.CullHint;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DisplayListExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DisplayListExample.java
index 314ac24..14ee582 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DisplayListExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DisplayListExample.java
@@ -25,8 +25,8 @@ import com.ardor3d.renderer.ContextManager;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.state.BlendState;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.Spatial;
@@ -41,6 +41,7 @@ import com.ardor3d.scenegraph.shape.Disk;
import com.ardor3d.scenegraph.shape.Dodecahedron;
import com.ardor3d.scenegraph.shape.Dome;
import com.ardor3d.scenegraph.shape.GeoSphere;
+import com.ardor3d.scenegraph.shape.GeoSphere.TextureMode;
import com.ardor3d.scenegraph.shape.Hexagon;
import com.ardor3d.scenegraph.shape.Icosahedron;
import com.ardor3d.scenegraph.shape.MultiFaceBox;
@@ -54,7 +55,6 @@ import com.ardor3d.scenegraph.shape.StripBox;
import com.ardor3d.scenegraph.shape.Teapot;
import com.ardor3d.scenegraph.shape.Torus;
import com.ardor3d.scenegraph.shape.Tube;
-import com.ardor3d.scenegraph.shape.GeoSphere.TextureMode;
import com.ardor3d.ui.text.BasicText;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.TextureManager;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java
index 619b16d..4fdc002 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java
@@ -19,10 +19,10 @@ import com.ardor3d.extension.ui.util.SubTex;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Image;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.Texture2D;
-import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.image.Texture.MagnificationFilter;
import com.ardor3d.image.Texture.MinificationFilter;
+import com.ardor3d.image.Texture2D;
+import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.image.util.GeneratedImageFactory;
import com.ardor3d.input.logical.InputTrigger;
import com.ardor3d.input.logical.TriggerAction;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MandelbrotExplorerExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MandelbrotExplorerExample.java
index 7e88c73..d9d82c5 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MandelbrotExplorerExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MandelbrotExplorerExample.java
@@ -15,9 +15,9 @@ import com.ardor3d.example.Purpose;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Image;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.Texture2D;
import com.ardor3d.image.Texture.MagnificationFilter;
import com.ardor3d.image.Texture.MinificationFilter;
+import com.ardor3d.image.Texture2D;
import com.ardor3d.image.util.GeneratedImageFactory;
import com.ardor3d.input.MouseButton;
import com.ardor3d.input.MouseState;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MeshDataSharingExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MeshDataSharingExample.java
index ce95e25..036632f 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MeshDataSharingExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MeshDataSharingExample.java
@@ -21,8 +21,8 @@ import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.state.CullState;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.MaterialFace;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.hint.DataMode;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/PointCubeExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/PointCubeExample.java
index 6277a97..c73fa30 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/PointCubeExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/PointCubeExample.java
@@ -17,11 +17,11 @@ import com.ardor3d.example.Purpose;
import com.ardor3d.framework.Canvas;
import com.ardor3d.framework.DisplaySettings;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.Texture2D;
-import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.image.Texture.MagnificationFilter;
import com.ardor3d.image.Texture.MinificationFilter;
import com.ardor3d.image.Texture.WrapMode;
+import com.ardor3d.image.Texture2D;
+import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.input.Key;
import com.ardor3d.input.logical.InputTrigger;
import com.ardor3d.input.logical.KeyPressedCondition;
@@ -38,9 +38,9 @@ import com.ardor3d.renderer.TextureRenderer;
import com.ardor3d.renderer.TextureRendererFactory;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.BlendState;
+import com.ardor3d.renderer.state.BlendState.DestinationFunction;
import com.ardor3d.renderer.state.GLSLShaderObjectsState;
import com.ardor3d.renderer.state.TextureState;
-import com.ardor3d.renderer.state.BlendState.DestinationFunction;
import com.ardor3d.renderer.state.TextureState.CorrectionType;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.Point;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/RenderQueueExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/RenderQueueExample.java
index 39112ea..08483f8 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/RenderQueueExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/RenderQueueExample.java
@@ -1 +1 @@
-/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.renderer; import com.ardor3d.bounding.BoundingBox; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.framework.Canvas; import com.ardor3d.image.Texture.MinificationFilter; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Vector2; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.BlendState; import com.ardor3d.renderer.state.LightState; import com.ardor3d.renderer.state.MaterialState; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.renderer.state.BlendState.DestinationFunction; import com.ardor3d.renderer.state.BlendState.SourceFunction; import com.ardor3d.renderer.state.MaterialState.MaterialFace; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TransparencyType; import com.ardor3d.scenegraph.shape.Box; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.scenegraph.shape.Torus; import com.ardor3d.util.TextureManager; /** * Illustrates the Render Queue, which controls how Nodes are drawn when overlapping occurs. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.renderer.RenderQueueExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/renderer_RenderQueueExample.jpg", // maxHeapMemory = 64) public class RenderQueueExample extends ExampleBase { private boolean useQueue = false; private boolean twoPass = false; protected Node opaques, transps, orthos; private boolean _updateTitle; public static void main(final String[] args) { start(RenderQueueExample.class); } @Override protected void renderExample(final Renderer renderer) { transps.getSceneHints().setTransparencyType(twoPass ? TransparencyType.TwoPass : TransparencyType.OnePass); if (_updateTitle) { _canvas.setTitle("Test Render Queue - " + useQueue + " - hit 'M' to toggle Queue mode - 'R' Two Pass: - " + twoPass); _updateTitle = false; } if (!useQueue) { renderer.setOrtho(); renderer.draw(orthos); renderer.unsetOrtho(); } else { renderer.draw(orthos); } transps.draw(renderer); opaques.draw(renderer); } @Override protected void initExample() { _canvas.setTitle("Test Render Queue - false - hit 'M' to toggle Queue mode - 'R' Two Pass: - false"); _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(10, 0, 50)); final Vector3 max = new Vector3(5, 5, 5); final Vector3 min = new Vector3(-5, -5, -5); opaques = new Node("Opaques"); transps = new Node("Transps"); orthos = new Node("Orthos"); transps.getSceneHints().setRenderBucketType(RenderBucketType.Skip); opaques.getSceneHints().setRenderBucketType(RenderBucketType.Skip); orthos.getSceneHints().setRenderBucketType(RenderBucketType.Skip); _root.attachChild(orthos); _root.attachChild(transps); _root.attachChild(opaques); final Box b1 = new Box("Box", min, max); b1.setModelBound(new BoundingBox()); b1.setTranslation(new Vector3(0, 0, -15)); opaques.attachChild(b1); final Box b2 = new Box("Box", min, max); b2.setModelBound(new BoundingBox()); b2.setTranslation(new Vector3(0, 0, -30)); opaques.attachChild(b2); final Box b3 = new Box("Box", min, max); b3.setModelBound(new BoundingBox()); b3.setTranslation(new Vector3(0, -15, -15)); opaques.attachChild(b3); final TextureState ts = new TextureState(); ts.setEnabled(true); ts.setTexture(TextureManager.load("images/ardor3d_white_256.jpg", MinificationFilter.Trilinear, true)); opaques.setRenderState(ts); final LightState ls = new LightState(); ls.setEnabled(true); final DirectionalLight dLight = new DirectionalLight(); dLight.setEnabled(true); dLight.setDiffuse(new ColorRGBA(1, 1, 1, 1)); dLight.setDirection(new Vector3(1, 1, 1)); ls.attach(dLight); final DirectionalLight dLight2 = new DirectionalLight(); dLight2.setEnabled(true); dLight2.setDiffuse(new ColorRGBA(1, 1, 1, 1)); dLight2.setDirection(new Vector3(-1, -1, -1)); ls.attach(dLight2); ls.setTwoSidedLighting(false); transps.setRenderState(ls); transps.getSceneHints().setLightCombineMode(LightCombineMode.Replace); final Box tb1 = new Box("TBox Blue", min, max); tb1.setModelBound(new BoundingBox()); tb1.setTranslation(new Vector3(0, 15, 15)); transps.attachChild(tb1); final MaterialState ms1 = new MaterialState(); ms1.setEnabled(true); ms1.setDiffuse(MaterialFace.FrontAndBack, new ColorRGBA(0, 0, 1, .75f)); ms1.setShininess(MaterialFace.FrontAndBack, 128); tb1.setRenderState(ms1); final Torus tb2 = new Torus("TBox Green", 20, 20, 3, 6); tb2.setModelBound(new BoundingBox()); tb2.setTranslation(new Vector3(0, 0, 30)); transps.attachChild(tb2); final MaterialState ms2 = new MaterialState(); ms2.setEnabled(true); ms2.setDiffuse(MaterialFace.FrontAndBack, new ColorRGBA(0, 1, 0, .5f)); ms2.setShininess(MaterialFace.FrontAndBack, 128); tb2.setRenderState(ms2); final Box tb3 = new Box("TBox Red", min, max); tb3.setModelBound(new BoundingBox()); tb3.setTranslation(new Vector3(0, 0, 15)); transps.attachChild(tb3); final MaterialState ms3 = new MaterialState(); ms3.setEnabled(true); ms3.setDiffuse(MaterialFace.FrontAndBack, new ColorRGBA(1, 0, 0, .5f)); ms3.setShininess(MaterialFace.FrontAndBack, 128); tb3.setRenderState(ms3); final BlendState as = new BlendState(); as.setEnabled(true); as.setBlendEnabled(true); as.setSourceFunction(SourceFunction.SourceAlpha); as.setDestinationFunction(DestinationFunction.OneMinusSourceAlpha); transps.setRenderState(as); final Vector2 center = new Vector2(_canvas.getCanvasRenderer().getCamera().getWidth() >> 1, _canvas .getCanvasRenderer().getCamera().getWidth() >> 1); final Quad q1 = new Quad("Ortho Q1", 40, 40); q1.setTranslation(new Vector3(100 + center.getX(), 100 + center.getY(), 0)); q1.getSceneHints().setOrthoOrder(1); q1.setDefaultColor(ColorRGBA.WHITE); q1.getSceneHints().setLightCombineMode(LightCombineMode.Off); orthos.attachChild(q1); final Quad q2 = new Quad("Ortho Q2", 100, 100); q2.setTranslation(new Vector3(60 + center.getX(), 60 + center.getY(), 0)); q2.getSceneHints().setOrthoOrder(5); q2.setDefaultColor(ColorRGBA.RED); q2.getSceneHints().setLightCombineMode(LightCombineMode.Off); orthos.attachChild(q2); final Quad q3 = new Quad("Ortho Q3", 120, 60); q3.setTranslation(new Vector3(-20 + center.getX(), -150 + center.getY(), 0)); q3.getSceneHints().setOrthoOrder(2); q3.setDefaultColor(ColorRGBA.BLUE); q3.getSceneHints().setLightCombineMode(LightCombineMode.Off); orthos.attachChild(q3); final ZBufferState zstate = new ZBufferState(); zstate.setWritable(false); zstate.setEnabled(false); orthos.setRenderState(zstate); orthos.setRenderState(new LightState()); _root.getSceneHints().setCullHint(CullHint.Always); opaques.getSceneHints().setCullHint(CullHint.Dynamic); transps.getSceneHints().setCullHint(CullHint.Dynamic); orthos.getSceneHints().setCullHint(CullHint.Never); } @Override protected void registerInputTriggers() { super.registerInputTriggers(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.M), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (useQueue) { transps.getSceneHints().setRenderBucketType(RenderBucketType.Skip); opaques.getSceneHints().setRenderBucketType(RenderBucketType.Skip); orthos.getSceneHints().setRenderBucketType(RenderBucketType.Skip); } else { transps.getSceneHints().setRenderBucketType(RenderBucketType.Transparent); opaques.getSceneHints().setRenderBucketType(RenderBucketType.Opaque); orthos.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); } useQueue = !useQueue; _updateTitle = true; } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { twoPass = !twoPass; _updateTitle = true; } })); } } \ No newline at end of file
+/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.renderer; import com.ardor3d.bounding.BoundingBox; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.framework.Canvas; import com.ardor3d.image.Texture.MinificationFilter; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Vector2; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.BlendState; import com.ardor3d.renderer.state.BlendState.DestinationFunction; import com.ardor3d.renderer.state.BlendState.SourceFunction; import com.ardor3d.renderer.state.LightState; import com.ardor3d.renderer.state.MaterialState; import com.ardor3d.renderer.state.MaterialState.MaterialFace; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TransparencyType; import com.ardor3d.scenegraph.shape.Box; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.scenegraph.shape.Torus; import com.ardor3d.util.TextureManager; /** * Illustrates the Render Queue, which controls how Nodes are drawn when overlapping occurs. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.renderer.RenderQueueExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/renderer_RenderQueueExample.jpg", // maxHeapMemory = 64) public class RenderQueueExample extends ExampleBase { private boolean useQueue = false; private boolean twoPass = false; protected Node opaques, transps, orthos; private boolean _updateTitle; public static void main(final String[] args) { start(RenderQueueExample.class); } @Override protected void renderExample(final Renderer renderer) { transps.getSceneHints().setTransparencyType(twoPass ? TransparencyType.TwoPass : TransparencyType.OnePass); if (_updateTitle) { _canvas.setTitle("Test Render Queue - " + useQueue + " - hit 'M' to toggle Queue mode - 'R' Two Pass: - " + twoPass); _updateTitle = false; } if (!useQueue) { renderer.setOrtho(); renderer.draw(orthos); renderer.unsetOrtho(); } else { renderer.draw(orthos); } transps.draw(renderer); opaques.draw(renderer); } @Override protected void initExample() { _canvas.setTitle("Test Render Queue - false - hit 'M' to toggle Queue mode - 'R' Two Pass: - false"); _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(10, 0, 50)); final Vector3 max = new Vector3(5, 5, 5); final Vector3 min = new Vector3(-5, -5, -5); opaques = new Node("Opaques"); transps = new Node("Transps"); orthos = new Node("Orthos"); transps.getSceneHints().setRenderBucketType(RenderBucketType.Skip); opaques.getSceneHints().setRenderBucketType(RenderBucketType.Skip); orthos.getSceneHints().setRenderBucketType(RenderBucketType.Skip); _root.attachChild(orthos); _root.attachChild(transps); _root.attachChild(opaques); final Box b1 = new Box("Box", min, max); b1.setModelBound(new BoundingBox()); b1.setTranslation(new Vector3(0, 0, -15)); opaques.attachChild(b1); final Box b2 = new Box("Box", min, max); b2.setModelBound(new BoundingBox()); b2.setTranslation(new Vector3(0, 0, -30)); opaques.attachChild(b2); final Box b3 = new Box("Box", min, max); b3.setModelBound(new BoundingBox()); b3.setTranslation(new Vector3(0, -15, -15)); opaques.attachChild(b3); final TextureState ts = new TextureState(); ts.setEnabled(true); ts.setTexture(TextureManager.load("images/ardor3d_white_256.jpg", MinificationFilter.Trilinear, true)); opaques.setRenderState(ts); final LightState ls = new LightState(); ls.setEnabled(true); final DirectionalLight dLight = new DirectionalLight(); dLight.setEnabled(true); dLight.setDiffuse(new ColorRGBA(1, 1, 1, 1)); dLight.setDirection(new Vector3(1, 1, 1)); ls.attach(dLight); final DirectionalLight dLight2 = new DirectionalLight(); dLight2.setEnabled(true); dLight2.setDiffuse(new ColorRGBA(1, 1, 1, 1)); dLight2.setDirection(new Vector3(-1, -1, -1)); ls.attach(dLight2); ls.setTwoSidedLighting(false); transps.setRenderState(ls); transps.getSceneHints().setLightCombineMode(LightCombineMode.Replace); final Box tb1 = new Box("TBox Blue", min, max); tb1.setModelBound(new BoundingBox()); tb1.setTranslation(new Vector3(0, 15, 15)); transps.attachChild(tb1); final MaterialState ms1 = new MaterialState(); ms1.setEnabled(true); ms1.setDiffuse(MaterialFace.FrontAndBack, new ColorRGBA(0, 0, 1, .75f)); ms1.setShininess(MaterialFace.FrontAndBack, 128); tb1.setRenderState(ms1); final Torus tb2 = new Torus("TBox Green", 20, 20, 3, 6); tb2.setModelBound(new BoundingBox()); tb2.setTranslation(new Vector3(0, 0, 30)); transps.attachChild(tb2); final MaterialState ms2 = new MaterialState(); ms2.setEnabled(true); ms2.setDiffuse(MaterialFace.FrontAndBack, new ColorRGBA(0, 1, 0, .5f)); ms2.setShininess(MaterialFace.FrontAndBack, 128); tb2.setRenderState(ms2); final Box tb3 = new Box("TBox Red", min, max); tb3.setModelBound(new BoundingBox()); tb3.setTranslation(new Vector3(0, 0, 15)); transps.attachChild(tb3); final MaterialState ms3 = new MaterialState(); ms3.setEnabled(true); ms3.setDiffuse(MaterialFace.FrontAndBack, new ColorRGBA(1, 0, 0, .5f)); ms3.setShininess(MaterialFace.FrontAndBack, 128); tb3.setRenderState(ms3); final BlendState as = new BlendState(); as.setEnabled(true); as.setBlendEnabled(true); as.setSourceFunction(SourceFunction.SourceAlpha); as.setDestinationFunction(DestinationFunction.OneMinusSourceAlpha); transps.setRenderState(as); final Vector2 center = new Vector2(_canvas.getCanvasRenderer().getCamera().getWidth() >> 1, _canvas .getCanvasRenderer().getCamera().getWidth() >> 1); final Quad q1 = new Quad("Ortho Q1", 40, 40); q1.setTranslation(new Vector3(100 + center.getX(), 100 + center.getY(), 0)); q1.getSceneHints().setOrthoOrder(1); q1.setDefaultColor(ColorRGBA.WHITE); q1.getSceneHints().setLightCombineMode(LightCombineMode.Off); orthos.attachChild(q1); final Quad q2 = new Quad("Ortho Q2", 100, 100); q2.setTranslation(new Vector3(60 + center.getX(), 60 + center.getY(), 0)); q2.getSceneHints().setOrthoOrder(5); q2.setDefaultColor(ColorRGBA.RED); q2.getSceneHints().setLightCombineMode(LightCombineMode.Off); orthos.attachChild(q2); final Quad q3 = new Quad("Ortho Q3", 120, 60); q3.setTranslation(new Vector3(-20 + center.getX(), -150 + center.getY(), 0)); q3.getSceneHints().setOrthoOrder(2); q3.setDefaultColor(ColorRGBA.BLUE); q3.getSceneHints().setLightCombineMode(LightCombineMode.Off); orthos.attachChild(q3); final ZBufferState zstate = new ZBufferState(); zstate.setWritable(false); zstate.setEnabled(false); orthos.setRenderState(zstate); orthos.setRenderState(new LightState()); _root.getSceneHints().setCullHint(CullHint.Always); opaques.getSceneHints().setCullHint(CullHint.Dynamic); transps.getSceneHints().setCullHint(CullHint.Dynamic); orthos.getSceneHints().setCullHint(CullHint.Never); } @Override protected void registerInputTriggers() { super.registerInputTriggers(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.M), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (useQueue) { transps.getSceneHints().setRenderBucketType(RenderBucketType.Skip); opaques.getSceneHints().setRenderBucketType(RenderBucketType.Skip); orthos.getSceneHints().setRenderBucketType(RenderBucketType.Skip); } else { transps.getSceneHints().setRenderBucketType(RenderBucketType.Transparent); opaques.getSceneHints().setRenderBucketType(RenderBucketType.Opaque); orthos.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); } useQueue = !useQueue; _updateTitle = true; } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { twoPass = !twoPass; _updateTitle = true; } })); } } \ No newline at end of file
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/StereoExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/StereoExample.java
index f7eff8c..7c5905d 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/StereoExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/StereoExample.java
@@ -22,9 +22,9 @@ import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.StereoCamera;
import com.ardor3d.renderer.state.ColorMaskState;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
import com.ardor3d.renderer.state.RenderState.StateType;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.shape.Box;
import com.ardor3d.scenegraph.shape.Sphere;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/Texture3DExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/Texture3DExample.java
index 245e447..9884266 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/Texture3DExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/Texture3DExample.java
@@ -18,9 +18,9 @@ import com.ardor3d.example.Purpose;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Image;
import com.ardor3d.image.Texture;
-import com.ardor3d.image.Texture3D;
import com.ardor3d.image.Texture.EnvironmentalMapMode;
import com.ardor3d.image.Texture.MinificationFilter;
+import com.ardor3d.image.Texture3D;
import com.ardor3d.image.util.GeneratedImageFactory;
import com.ardor3d.input.Key;
import com.ardor3d.input.logical.InputTrigger;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/UpdateTextureExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/UpdateTextureExample.java
index cdcd5dc..c4b5ae3 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/UpdateTextureExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/UpdateTextureExample.java
@@ -25,7 +25,7 @@ import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Image;
import com.ardor3d.image.Texture;
import com.ardor3d.image.Texture2D;
-import com.ardor3d.image.util.AWTImageLoader;
+import com.ardor3d.image.util.awt.AWTImageLoader;
import com.ardor3d.input.Key;
import com.ardor3d.input.logical.InputTrigger;
import com.ardor3d.input.logical.KeyPressedCondition;
@@ -37,9 +37,9 @@ import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.MaterialState;
+import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
import com.ardor3d.renderer.state.RenderState;
import com.ardor3d.renderer.state.TextureState;
-import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.hint.LightCombineMode;
import com.ardor3d.scenegraph.shape.Box;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/VBOSpeedExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/VBOSpeedExample.java
index 7205227..c82a548 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/VBOSpeedExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/VBOSpeedExample.java
@@ -29,8 +29,8 @@ import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.CullState;
import com.ardor3d.renderer.state.MaterialState;
-import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
+import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.hint.DataMode;
import com.ardor3d.scenegraph.hint.LightCombineMode;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExample.java
index 234523c..ce1c13e 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExample.java
@@ -24,7 +24,7 @@ import com.ardor3d.extension.atlas.TexturePacker;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Texture;
import com.ardor3d.image.Texture.WrapMode;
-import com.ardor3d.image.util.AWTImageUtil;
+import com.ardor3d.image.util.awt.AWTImageUtil;
import com.ardor3d.input.Key;
import com.ardor3d.input.logical.InputTrigger;
import com.ardor3d.input.logical.KeyPressedCondition;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExampleMultiTextured.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExampleMultiTextured.java
index 168bab0..e8e4921 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExampleMultiTextured.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/AtlasExampleMultiTextured.java
@@ -25,7 +25,7 @@ import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Texture;
import com.ardor3d.image.Texture.ApplyMode;
import com.ardor3d.image.Texture.WrapMode;
-import com.ardor3d.image.util.AWTImageUtil;
+import com.ardor3d.image.util.awt.AWTImageUtil;
import com.ardor3d.input.Key;
import com.ardor3d.input.logical.InputTrigger;
import com.ardor3d.input.logical.KeyPressedCondition;
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/ImageMapTerrainExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/ImageMapTerrainExample.java
index 6b3666d..02a004e 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/ImageMapTerrainExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/ImageMapTerrainExample.java
@@ -1 +1 @@
-/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.TerrainDataProvider; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.util.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.intersection.PickingUtil; import com.ardor3d.intersection.PrimitivePickResults; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Matrix3; import com.ardor3d.math.Ray3; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.CullState; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.shape.Box; import com.ardor3d.scenegraph.shape.Sphere; import com.ardor3d.ui.text.BasicText; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class ImageMapTerrainExample extends ExampleBase { private boolean updateTerrain = true; private final float farPlane = 8000.0f; private Terrain terrain; private final Sphere sphere = new Sphere("sp", 16, 16, 1); private final Mesh arrow = new Box("normal", new Vector3(-0.2, -0.2, 0), new Vector3(0.2, 0.2, 4)); private final Ray3 pickRay = new Ray3(); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final BasicText _exampleInfo[] = new BasicText[5]; private double counter = 0; private int frames = 0; public static void main(final String[] args) { ExampleBase.start(ImageMapTerrainExample.class); } @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); } if (updateTerrain) { terrainCamera.set(camera); } // if we're picking... if (sphere.getSceneHints().getCullHint() == CullHint.Dynamic) { // Set up our pick ray pickRay.setOrigin(camera.getLocation()); pickRay.setDirection(camera.getDirection()); // do pick and move the sphere final PrimitivePickResults pickResults = new PrimitivePickResults(); pickResults.setCheckDistance(true); PickingUtil.findPick(_root, pickRay, pickResults); if (pickResults.getNumber() != 0) { final Vector3 intersectionPoint = pickResults.getPickData(0).getIntersectionRecord() .getIntersectionPoint(0); sphere.setTranslation(intersectionPoint); final Vector3 intersectionNormal = pickResults.getPickData(0).getIntersectionRecord() .getIntersectionNormal(0); final Matrix3 rotation = new Matrix3(); rotation.lookAt(intersectionNormal, Vector3.UNIT_Z); arrow.setRotation(rotation); arrow.setTranslation(intersectionPoint); } } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 300, 0)); _canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(1, 300, 1), Vector3.UNIT_Y); _canvas.getCanvasRenderer() .getCamera() .setFrustumPerspective( 70.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Void>() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.GRAY); return null; } }); _controlHandle.setMoveSpeed(200); setupDefaultStates(); sphere.getSceneHints().setAllPickingHints(false); sphere.getSceneHints().setCullHint(CullHint.Always); _root.attachChild(sphere); arrow.getSceneHints().setAllPickingHints(false); arrow.getSceneHints().setCullHint(CullHint.Always); _root.attachChild(arrow); try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage logo = ImageIO.read(ResourceLocatorTool.getClassPathResource( ImageMapTerrainExample.class, "com/ardor3d/example/media/images/water/dudvmap.png")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(logo, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.1f, .3f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final TerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3( 3, 50, 3)); terrain = new TerrainBuilder(terrainDataProvider, terrainCamera).setShowDebugPanels(true).build(); _root.attachChild(terrain); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } // Setup labels for presenting example info. final Node textNodes = new Node("Text"); _root.attachChild(textNodes); textNodes.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); textNodes.getSceneHints().setLightCombineMode(LightCombineMode.Off); final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = BasicText.createDefaultTextLabel("Text", "", 16); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); textNodes.attachChild(_exampleInfo[i]); } textNodes.updateGeometricState(0.0); updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.U), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { updateTerrain = !updateTerrain; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.P), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (sphere.getSceneHints().getCullHint() == CullHint.Dynamic) { sphere.getSceneHints().setCullHint(CullHint.Always); arrow.getSceneHints().setCullHint(CullHint.Always); } else if (sphere.getSceneHints().getCullHint() == CullHint.Always) { sphere.getSceneHints().setCullHint(CullHint.Dynamic); arrow.getSceneHints().setCullHint(CullHint.Dynamic); } updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.getTextureClipmap().setShowDebug(!terrain.getTextureClipmap().isShowDebug()); terrain.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.G), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.reloadShader(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FIVE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.getTextureClipmap().setScale(terrain.getTextureClipmap().getScale() / 2); terrain.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SIX), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.getTextureClipmap().setScale(terrain.getTextureClipmap().getScale() * 2); terrain.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SEVEN), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX() + 500.0, camera.getLocation().getY(), camera .getLocation().getZ()); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.EIGHT), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX() - 500.0, camera.getLocation().getY(), camera .getLocation().getZ()); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.NINE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX(), camera.getLocation().getY(), camera.getLocation() .getZ() + 1500.0); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX(), camera.getLocation().getY(), camera.getLocation() .getZ() - 1500.0); } })); } private void setupDefaultStates() { _lightState.detachAll(); final DirectionalLight dLight = new DirectionalLight(); dLight.setEnabled(true); dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(dLight); _lightState.setEnabled(true); final CullState cs = new CullState(); cs.setEnabled(true); cs.setCullFace(CullState.Face.Back); _root.setRenderState(cs); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); _root.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[P] Do picking: " + (sphere.getSceneHints().getCullHint() == CullHint.Dynamic)); _exampleInfo[2].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); _exampleInfo[3].setText("[J] Regenerate heightmap/texture"); _exampleInfo[4].setText("[U] Freeze terrain(debug): " + !updateTerrain); } } \ No newline at end of file
+/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.TerrainDataProvider; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.util.awt.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.intersection.PickingUtil; import com.ardor3d.intersection.PrimitivePickResults; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Matrix3; import com.ardor3d.math.Ray3; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.CullState; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.shape.Box; import com.ardor3d.scenegraph.shape.Sphere; import com.ardor3d.ui.text.BasicText; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class ImageMapTerrainExample extends ExampleBase { private boolean updateTerrain = true; private final float farPlane = 8000.0f; private Terrain terrain; private final Sphere sphere = new Sphere("sp", 16, 16, 1); private final Mesh arrow = new Box("normal", new Vector3(-0.2, -0.2, 0), new Vector3(0.2, 0.2, 4)); private final Ray3 pickRay = new Ray3(); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final BasicText _exampleInfo[] = new BasicText[5]; private double counter = 0; private int frames = 0; public static void main(final String[] args) { ExampleBase.start(ImageMapTerrainExample.class); } @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); } if (updateTerrain) { terrainCamera.set(camera); } // if we're picking... if (sphere.getSceneHints().getCullHint() == CullHint.Dynamic) { // Set up our pick ray pickRay.setOrigin(camera.getLocation()); pickRay.setDirection(camera.getDirection()); // do pick and move the sphere final PrimitivePickResults pickResults = new PrimitivePickResults(); pickResults.setCheckDistance(true); PickingUtil.findPick(_root, pickRay, pickResults); if (pickResults.getNumber() != 0) { final Vector3 intersectionPoint = pickResults.getPickData(0).getIntersectionRecord() .getIntersectionPoint(0); sphere.setTranslation(intersectionPoint); final Vector3 intersectionNormal = pickResults.getPickData(0).getIntersectionRecord() .getIntersectionNormal(0); final Matrix3 rotation = new Matrix3(); rotation.lookAt(intersectionNormal, Vector3.UNIT_Z); arrow.setRotation(rotation); arrow.setTranslation(intersectionPoint); } } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 300, 0)); _canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(1, 300, 1), Vector3.UNIT_Y); _canvas.getCanvasRenderer() .getCamera() .setFrustumPerspective( 70.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Void>() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.GRAY); return null; } }); _controlHandle.setMoveSpeed(200); setupDefaultStates(); sphere.getSceneHints().setAllPickingHints(false); sphere.getSceneHints().setCullHint(CullHint.Always); _root.attachChild(sphere); arrow.getSceneHints().setAllPickingHints(false); arrow.getSceneHints().setCullHint(CullHint.Always); _root.attachChild(arrow); try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage logo = ImageIO.read(ResourceLocatorTool.getClassPathResource( ImageMapTerrainExample.class, "com/ardor3d/example/media/images/water/dudvmap.png")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(logo, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.1f, .3f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final TerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3( 3, 50, 3)); terrain = new TerrainBuilder(terrainDataProvider, terrainCamera).setShowDebugPanels(true).build(); _root.attachChild(terrain); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } // Setup labels for presenting example info. final Node textNodes = new Node("Text"); _root.attachChild(textNodes); textNodes.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); textNodes.getSceneHints().setLightCombineMode(LightCombineMode.Off); final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = BasicText.createDefaultTextLabel("Text", "", 16); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); textNodes.attachChild(_exampleInfo[i]); } textNodes.updateGeometricState(0.0); updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.U), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { updateTerrain = !updateTerrain; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.P), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (sphere.getSceneHints().getCullHint() == CullHint.Dynamic) { sphere.getSceneHints().setCullHint(CullHint.Always); arrow.getSceneHints().setCullHint(CullHint.Always); } else if (sphere.getSceneHints().getCullHint() == CullHint.Always) { sphere.getSceneHints().setCullHint(CullHint.Dynamic); arrow.getSceneHints().setCullHint(CullHint.Dynamic); } updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.getTextureClipmap().setShowDebug(!terrain.getTextureClipmap().isShowDebug()); terrain.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.G), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.reloadShader(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FIVE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.getTextureClipmap().setScale(terrain.getTextureClipmap().getScale() / 2); terrain.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SIX), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { terrain.getTextureClipmap().setScale(terrain.getTextureClipmap().getScale() * 2); terrain.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SEVEN), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX() + 500.0, camera.getLocation().getY(), camera .getLocation().getZ()); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.EIGHT), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX() - 500.0, camera.getLocation().getY(), camera .getLocation().getZ()); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.NINE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX(), camera.getLocation().getY(), camera.getLocation() .getZ() + 1500.0); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(camera.getLocation().getX(), camera.getLocation().getY(), camera.getLocation() .getZ() - 1500.0); } })); } private void setupDefaultStates() { _lightState.detachAll(); final DirectionalLight dLight = new DirectionalLight(); dLight.setEnabled(true); dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(dLight); _lightState.setEnabled(true); final CullState cs = new CullState(); cs.setEnabled(true); cs.setCullFace(CullState.Face.Back); _root.setRenderState(cs); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); _root.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[P] Do picking: " + (sphere.getSceneHints().getCullHint() == CullHint.Dynamic)); _exampleInfo[2].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); _exampleInfo[3].setText("[J] Regenerate heightmap/texture"); _exampleInfo[4].setText("[U] Freeze terrain(debug): " + !updateTerrain); } } \ No newline at end of file
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java
index 10a8bb1..a699d74 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java
@@ -1 +1 @@
-/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.EnumSet; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.model.collada.jdom.ColladaImporter; import com.ardor3d.extension.model.collada.jdom.data.ColladaStorage; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass.Filter; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.UrlInputSupplier; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIFrame.FrameButtons; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UILabel; import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.layout.RowLayout; import com.ardor3d.extension.ui.text.StyleConstants; import com.ardor3d.extension.ui.util.Insets; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture2D; import com.ardor3d.image.util.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Quaternion; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.renderer.state.RenderState.StateType; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TextureCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.Debugger; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class MountainShadowTerrainExample extends ExampleBase { private final float farPlane = 8000.0f; /** Quads used for debug showing shadowmaps. */ private Quad _orthoQuad[]; private Terrain terrain; private final Node terrainNode = new Node("terrain"); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final UILabel _exampleInfo[] = new UILabel[2]; /** Pssm shadow map pass. */ private ParallelSplitShadowMapPass _pssmPass; private DirectionalLight light; private double lightTime; private boolean moveLight = false; private UIHud hud; public static void main(final String[] args) { ExampleBase._minDepthBits = 24; ExampleBase.start(MountainShadowTerrainExample.class); } @Override protected void renderExample(final Renderer renderer) { // Lazy init since it needs the renderer... if (!_pssmPass.isInitialised()) { _pssmPass.init(renderer); _pssmPass.setPssmShader(terrain.getGeometryClipmapShader()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { terrain.getClipTextureState().setTexture(_pssmPass.getShadowMapTexture(i), i + 1); } for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { terrain.getGeometryClipmapShader().setUniform("shadowMap" + i, i + 1); } } terrain.getGeometryClipmapShader().setUniform("lightDir", light.getDirection()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { TextureState screen = (TextureState) _orthoQuad[i].getLocalRenderState(StateType.Texture); Texture copy; if (screen == null) { screen = new TextureState(); _orthoQuad[i].setRenderState(screen); copy = new Texture2D(); screen.setTexture(copy); _orthoQuad[i].updateGeometricState(0.0); } else { copy = screen.getTexture(); } copy.setTextureKey(_pssmPass.getShadowMapTexture(i).getTextureKey()); } // XXX: Use a rougher LOD for shadows - tweak? terrain.setMinVisibleLevel(4); // Update shadowmaps - this will update our terrain camera to light pos _pssmPass.updateShadowMaps(renderer); // XXX: reset LOD for drawing from view camera terrain.setMinVisibleLevel(0); // Render scene and terrain with shadows terrainNode.onDraw(renderer); _root.onDraw(renderer); // Render overlay shadows for all objects except the terrain renderer.renderBuckets(); _pssmPass.renderShadowedScene(renderer); renderer.renderBuckets(); // draw ui renderer.draw(hud); } private double counter = 0; private int frames = 0; @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); terrainCamera.set(camera); } else { terrainCamera.set(_canvas.getCanvasRenderer().getCamera()); } // move terrain to view pos terrainNode.updateGeometricState(timer.getTimePerFrame()); hud.updateGeometricState(timer.getTimePerFrame()); if (moveLight) { lightTime += timer.getTimePerFrame(); light.setDirection(new Vector3(Math.sin(lightTime), -.8, Math.cos(lightTime)).normalizeLocal()); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); final Camera canvasCamera = _canvas.getCanvasRenderer().getCamera(); canvasCamera.setLocation(new Vector3(2176, 790, 688)); canvasCamera.lookAt(new Vector3(canvasCamera.getLocation()).addLocal(-0.87105768019686, -0.4349655341112313, 0.22817427967541867), Vector3.UNIT_Y); canvasCamera.setFrustumPerspective(45.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Void>() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.BLUE); return null; } }); _controlHandle.setMoveSpeed(400); setupDefaultStates(); addRover(); addUI(); // Initialize PSSM shadows _pssmPass = new ParallelSplitShadowMapPass(light, 2048, 4); _pssmPass.setFiltering(Filter.None); _pssmPass.setRenderShadowedScene(false); _pssmPass.setKeepMainShader(true); // _pssmPass.setMinimumLightDistance(500); // XXX: Tune this _pssmPass.setUseSceneTexturing(false); _pssmPass.setUseObjectCullFace(false); _pssmPass.getShadowOffsetState().setFactor(1.1f); _pssmPass.getShadowOffsetState().setUnits(4.0f); // _pssmPass.setDrawDebug(true); // TODO: backside lock test final Quad floor = new Quad("floor", 2048, 2048); floor.updateModelBound(); floor.setRotation(new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X)); floor.setTranslation(1024, 0, 1024); terrainNode.attachChild(floor); _pssmPass.addBoundsReceiver(terrainNode); // Add objects that will get shadowed through overlay render _pssmPass.add(_root); // Add our occluders that will produce shadows _pssmPass.addOccluder(terrainNode); _pssmPass.addOccluder(_root); final int quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; _orthoQuad = new Quad[ParallelSplitShadowMapPass._MAX_SPLITS]; for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { _orthoQuad[i] = new Quad("OrthoQuad", quadSize, quadSize); _orthoQuad[i].setTranslation(new Vector3(quadSize / 2 + 5 + (quadSize + 5) * i, quadSize / 2 + 5, 1)); _orthoQuad[i].setScale(1, -1, 1); _orthoQuad[i].getSceneHints().setRenderBucketType(RenderBucketType.Ortho); _orthoQuad[i].getSceneHints().setLightCombineMode(LightCombineMode.Off); _orthoQuad[i].getSceneHints().setTextureCombineMode(TextureCombineMode.Replace); _orthoQuad[i].getSceneHints().setCullHint(CullHint.Never); hud.attachChild(_orthoQuad[i]); } try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage heightmap = ImageIO.read(ResourceLocatorTool.getClassPathResource( MountainShadowTerrainExample.class, "com/ardor3d/example/media/images/heightmap.jpg")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(heightmap, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.05f, .33f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final ArrayTerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(5, 2048, 5), true); terrainDataProvider.setHeightMax(0.34f); final TerrainBuilder builder = new TerrainBuilder(terrainDataProvider, terrainCamera) .setShowDebugPanels(true); terrain = builder.build(); terrain.setPixelShader(new UrlInputSupplier(ResourceLocatorTool.getClassPathResource( ShadowedTerrainExample.class, "com/ardor3d/extension/terrain/shadowedGeometryClipmapShader_normalMap.frag"))); terrain.reloadShader(); terrain.getGeometryClipmapShader().setUniform("normalMap", 5); terrainNode.attachChild(terrain); terrain.setCullingEnabled(false); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = new UILabel("Text"); _exampleInfo[i].setForegroundColor(ColorRGBA.WHITE, true); _exampleInfo[i].addFontStyle(StyleConstants.KEY_SIZE, 16); _exampleInfo[i].addFontStyle(StyleConstants.KEY_BOLD, Boolean.TRUE); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); hud.add(_exampleInfo[i]); } updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); } private void addRover() { try { final ColladaStorage storage = new ColladaImporter().load("collada/sketchup/NASA Mars Rover.dae"); final Node rover = storage.getScene(); rover.setTranslation(440, 102, 160.1); rover.setScale(3); rover.setRotation(new Quaternion().fromAngleAxis(-MathUtils.HALF_PI, Vector3.UNIT_X)); _root.attachChild(rover); } catch (final IOException ex) { ex.printStackTrace(); } } private void setupDefaultStates() { terrainNode.setRenderState(_lightState); terrainNode.setRenderState(_wireframeState); terrainNode.setRenderState(new ZBufferState()); _lightState.detachAll(); light = new DirectionalLight(); light.setEnabled(true); light.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); light.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); light.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); light.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(light); _lightState.setEnabled(true); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); terrainNode.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3/4] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); } @Override protected void updateLogicalLayer(final ReadOnlyTimer timer) { hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); } @Override protected void renderDebug(final Renderer renderer) { super.renderDebug(renderer); if (_showBounds) { Debugger.drawBounds(terrainNode, renderer, true); } } private void addUI() { // setup hud hud = new UIHud(); hud.setupInput(_canvas, _physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); frame.setResizeable(false); final UILabel distLabel = new UILabel("Max Shadow Distance: 1500"); final UISlider distSlider = new UISlider(Orientation.Horizontal, 0, 2000, 1500); distSlider.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setMaxShadowDistance(distSlider.getValue()); distLabel.setText("Max Shadow Distance: " + distSlider.getValue()); } }); final UIButton updateCamera = new UIButton("Update Shadow Camera"); updateCamera.setSelectable(true); updateCamera.setSelected(true); updateCamera.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setUpdateMainCamera(updateCamera.isSelected()); updateText(); } }); final UIButton rotateLight = new UIButton("Rotate Light"); rotateLight.setSelectable(true); rotateLight.setSelected(false); rotateLight.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { moveLight = rotateLight.isSelected(); updateText(); } }); final UIPanel panel = new UIPanel(new RowLayout(false, true, false)); panel.setPadding(new Insets(10, 20, 10, 20)); panel.add(distLabel); panel.add(distSlider); panel.add(updateCamera); panel.add(rotateLight); frame.setContentPanel(panel); frame.pack(); final Camera cam = _canvas.getCanvasRenderer().getCamera(); frame.setLocalXY(cam.getWidth() - frame.getLocalComponentWidth(), cam.getHeight() - frame.getLocalComponentHeight()); hud.add(frame); } } \ No newline at end of file
+/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.EnumSet; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.model.collada.jdom.ColladaImporter; import com.ardor3d.extension.model.collada.jdom.data.ColladaStorage; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass.Filter; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.UrlInputSupplier; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIFrame.FrameButtons; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UILabel; import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.layout.RowLayout; import com.ardor3d.extension.ui.text.StyleConstants; import com.ardor3d.extension.ui.util.Insets; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture2D; import com.ardor3d.image.util.awt.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Quaternion; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.renderer.state.RenderState.StateType; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TextureCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.Debugger; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class MountainShadowTerrainExample extends ExampleBase { private final float farPlane = 8000.0f; /** Quads used for debug showing shadowmaps. */ private Quad _orthoQuad[]; private Terrain terrain; private final Node terrainNode = new Node("terrain"); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final UILabel _exampleInfo[] = new UILabel[2]; /** Pssm shadow map pass. */ private ParallelSplitShadowMapPass _pssmPass; private DirectionalLight light; private double lightTime; private boolean moveLight = false; private UIHud hud; public static void main(final String[] args) { ExampleBase._minDepthBits = 24; ExampleBase.start(MountainShadowTerrainExample.class); } @Override protected void renderExample(final Renderer renderer) { // Lazy init since it needs the renderer... if (!_pssmPass.isInitialised()) { _pssmPass.init(renderer); _pssmPass.setPssmShader(terrain.getGeometryClipmapShader()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { terrain.getClipTextureState().setTexture(_pssmPass.getShadowMapTexture(i), i + 1); } for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { terrain.getGeometryClipmapShader().setUniform("shadowMap" + i, i + 1); } } terrain.getGeometryClipmapShader().setUniform("lightDir", light.getDirection()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { TextureState screen = (TextureState) _orthoQuad[i].getLocalRenderState(StateType.Texture); Texture copy; if (screen == null) { screen = new TextureState(); _orthoQuad[i].setRenderState(screen); copy = new Texture2D(); screen.setTexture(copy); _orthoQuad[i].updateGeometricState(0.0); } else { copy = screen.getTexture(); } copy.setTextureKey(_pssmPass.getShadowMapTexture(i).getTextureKey()); } // XXX: Use a rougher LOD for shadows - tweak? terrain.setMinVisibleLevel(4); // Update shadowmaps - this will update our terrain camera to light pos _pssmPass.updateShadowMaps(renderer); // XXX: reset LOD for drawing from view camera terrain.setMinVisibleLevel(0); // Render scene and terrain with shadows terrainNode.onDraw(renderer); _root.onDraw(renderer); // Render overlay shadows for all objects except the terrain renderer.renderBuckets(); _pssmPass.renderShadowedScene(renderer); renderer.renderBuckets(); // draw ui renderer.draw(hud); } private double counter = 0; private int frames = 0; @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); terrainCamera.set(camera); } else { terrainCamera.set(_canvas.getCanvasRenderer().getCamera()); } // move terrain to view pos terrainNode.updateGeometricState(timer.getTimePerFrame()); hud.updateGeometricState(timer.getTimePerFrame()); if (moveLight) { lightTime += timer.getTimePerFrame(); light.setDirection(new Vector3(Math.sin(lightTime), -.8, Math.cos(lightTime)).normalizeLocal()); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); final Camera canvasCamera = _canvas.getCanvasRenderer().getCamera(); canvasCamera.setLocation(new Vector3(2176, 790, 688)); canvasCamera.lookAt(new Vector3(canvasCamera.getLocation()).addLocal(-0.87105768019686, -0.4349655341112313, 0.22817427967541867), Vector3.UNIT_Y); canvasCamera.setFrustumPerspective(45.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Void>() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.BLUE); return null; } }); _controlHandle.setMoveSpeed(400); setupDefaultStates(); addRover(); addUI(); // Initialize PSSM shadows _pssmPass = new ParallelSplitShadowMapPass(light, 2048, 4); _pssmPass.setFiltering(Filter.None); _pssmPass.setRenderShadowedScene(false); _pssmPass.setKeepMainShader(true); // _pssmPass.setMinimumLightDistance(500); // XXX: Tune this _pssmPass.setUseSceneTexturing(false); _pssmPass.setUseObjectCullFace(false); _pssmPass.getShadowOffsetState().setFactor(1.1f); _pssmPass.getShadowOffsetState().setUnits(4.0f); // _pssmPass.setDrawDebug(true); // TODO: backside lock test final Quad floor = new Quad("floor", 2048, 2048); floor.updateModelBound(); floor.setRotation(new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X)); floor.setTranslation(1024, 0, 1024); terrainNode.attachChild(floor); _pssmPass.addBoundsReceiver(terrainNode); // Add objects that will get shadowed through overlay render _pssmPass.add(_root); // Add our occluders that will produce shadows _pssmPass.addOccluder(terrainNode); _pssmPass.addOccluder(_root); final int quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; _orthoQuad = new Quad[ParallelSplitShadowMapPass._MAX_SPLITS]; for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { _orthoQuad[i] = new Quad("OrthoQuad", quadSize, quadSize); _orthoQuad[i].setTranslation(new Vector3(quadSize / 2 + 5 + (quadSize + 5) * i, quadSize / 2 + 5, 1)); _orthoQuad[i].setScale(1, -1, 1); _orthoQuad[i].getSceneHints().setRenderBucketType(RenderBucketType.Ortho); _orthoQuad[i].getSceneHints().setLightCombineMode(LightCombineMode.Off); _orthoQuad[i].getSceneHints().setTextureCombineMode(TextureCombineMode.Replace); _orthoQuad[i].getSceneHints().setCullHint(CullHint.Never); hud.attachChild(_orthoQuad[i]); } try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage heightmap = ImageIO.read(ResourceLocatorTool.getClassPathResource( MountainShadowTerrainExample.class, "com/ardor3d/example/media/images/heightmap.jpg")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(heightmap, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.05f, .33f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final ArrayTerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(5, 2048, 5), true); terrainDataProvider.setHeightMax(0.34f); final TerrainBuilder builder = new TerrainBuilder(terrainDataProvider, terrainCamera) .setShowDebugPanels(true); terrain = builder.build(); terrain.setPixelShader(new UrlInputSupplier(ResourceLocatorTool.getClassPathResource( ShadowedTerrainExample.class, "com/ardor3d/extension/terrain/shadowedGeometryClipmapShader_normalMap.frag"))); terrain.reloadShader(); terrain.getGeometryClipmapShader().setUniform("normalMap", 5); terrainNode.attachChild(terrain); terrain.setCullingEnabled(false); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = new UILabel("Text"); _exampleInfo[i].setForegroundColor(ColorRGBA.WHITE, true); _exampleInfo[i].addFontStyle(StyleConstants.KEY_SIZE, 16); _exampleInfo[i].addFontStyle(StyleConstants.KEY_BOLD, Boolean.TRUE); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); hud.add(_exampleInfo[i]); } updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); } private void addRover() { try { final ColladaStorage storage = new ColladaImporter().load("collada/sketchup/NASA Mars Rover.dae"); final Node rover = storage.getScene(); rover.setTranslation(440, 102, 160.1); rover.setScale(3); rover.setRotation(new Quaternion().fromAngleAxis(-MathUtils.HALF_PI, Vector3.UNIT_X)); _root.attachChild(rover); } catch (final IOException ex) { ex.printStackTrace(); } } private void setupDefaultStates() { terrainNode.setRenderState(_lightState); terrainNode.setRenderState(_wireframeState); terrainNode.setRenderState(new ZBufferState()); _lightState.detachAll(); light = new DirectionalLight(); light.setEnabled(true); light.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); light.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); light.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); light.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(light); _lightState.setEnabled(true); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); terrainNode.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3/4] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); } @Override protected void updateLogicalLayer(final ReadOnlyTimer timer) { hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); } @Override protected void renderDebug(final Renderer renderer) { super.renderDebug(renderer); if (_showBounds) { Debugger.drawBounds(terrainNode, renderer, true); } } private void addUI() { // setup hud hud = new UIHud(); hud.setupInput(_canvas, _physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); frame.setResizeable(false); final UILabel distLabel = new UILabel("Max Shadow Distance: 1500"); final UISlider distSlider = new UISlider(Orientation.Horizontal, 0, 2000, 1500); distSlider.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setMaxShadowDistance(distSlider.getValue()); distLabel.setText("Max Shadow Distance: " + distSlider.getValue()); } }); final UIButton updateCamera = new UIButton("Update Shadow Camera"); updateCamera.setSelectable(true); updateCamera.setSelected(true); updateCamera.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setUpdateMainCamera(updateCamera.isSelected()); updateText(); } }); final UIButton rotateLight = new UIButton("Rotate Light"); rotateLight.setSelectable(true); rotateLight.setSelected(false); rotateLight.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { moveLight = rotateLight.isSelected(); updateText(); } }); final UIPanel panel = new UIPanel(new RowLayout(false, true, false)); panel.setPadding(new Insets(10, 20, 10, 20)); panel.add(distLabel); panel.add(distSlider); panel.add(updateCamera); panel.add(rotateLight); frame.setContentPanel(panel); frame.pack(); final Camera cam = _canvas.getCanvasRenderer().getCamera(); frame.setLocalXY(cam.getWidth() - frame.getLocalComponentWidth(), cam.getHeight() - frame.getLocalComponentHeight()); hud.add(frame); } } \ No newline at end of file
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/TerrainWaterExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/TerrainWaterExample.java
index 9033eeb..2958130 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/TerrainWaterExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/TerrainWaterExample.java
@@ -1 +1 @@
-/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.nio.FloatBuffer; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.effect.water.WaterNode; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.TerrainDataProvider; import com.ardor3d.extension.terrain.providers.procedural.ProceduralTerrainDataProvider; import com.ardor3d.framework.Canvas; import com.ardor3d.image.Texture; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.intersection.PickingUtil; import com.ardor3d.intersection.PrimitivePickResults; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Plane; import com.ardor3d.math.Ray3; import com.ardor3d.math.Vector3; import com.ardor3d.math.functions.FbmFunction3D; import com.ardor3d.math.functions.Function3D; import com.ardor3d.math.functions.Functions; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.CullState; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.extension.Skybox; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.scenegraph.shape.Sphere; import com.ardor3d.ui.text.BasicText; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.TextureManager; /** * Example showing how to combine the terrain and water systems. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.TerrainWaterExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_TerrainWaterExample.jpg", // maxHeapMemory = 128) public class TerrainWaterExample extends ExampleBase { private final int SIZE = 2048; private Terrain terrain; private boolean updateTerrain = true; private final float farPlane = 3500.0f; private final float heightOffset = 3.0f; /** The water instance taking care of the water rendering. */ private WaterNode waterNode; private boolean aboveWater = true; /** Node containing debug quads for showing waternode render textures. */ private Node debugQuadsNode; /** The quad used as geometry for the water. */ private Quad waterQuad; private boolean groundCamera = false; private Camera terrainCamera; private Skybox skybox; private final Sphere sphere = new Sphere("sp", 16, 16, 1); private final double textureScale = 0.05; private FogState fogState; private boolean showUI = true; private final Ray3 pickRay = new Ray3(); /** Text fields used to present info about the example. */ private final BasicText _exampleInfo[] = new BasicText[8]; /** * The main method. * * @param args * the arguments */ public static void main(final String[] args) { start(TerrainWaterExample.class); } private double counter = 0; private int frames = 0; /** * Update the PassManager, skybox, camera position, etc. * * @param timer * the application timer */ @Override protected void updateExample(final ReadOnlyTimer timer) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()) + heightOffset; if (groundCamera || camera.getLocation().getY() < height) { camera.setLocation(new Vector3(camera.getLocation().getX(), height, camera.getLocation().getZ())); } if (aboveWater && camera.getLocation().getY() < waterNode.getWaterHeight()) { fogState.setStart(-1000f); fogState.setEnd(farPlane / 10f); fogState.setColor(new ColorRGBA(0.0f, 0.0f, 0.1f, 1.0f)); aboveWater = false; } else if (!aboveWater && camera.getLocation().getY() >= waterNode.getWaterHeight()) { fogState.setStart(farPlane / 2.0f); fogState.setEnd(farPlane); fogState.setColor(new ColorRGBA(0.96f, 0.97f, 1.0f, 1.0f)); aboveWater = true; } if (updateTerrain) { terrainCamera.set(camera); } skybox.setTranslation(camera.getLocation()); counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = (frames / counter); counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } // if we're picking... if (sphere.getSceneHints().getCullHint() == CullHint.Dynamic) { // Set up our pick ray pickRay.setOrigin(camera.getLocation()); pickRay.setDirection(camera.getDirection()); // do pick and move the sphere final PrimitivePickResults pickResults = new PrimitivePickResults(); pickResults.setCheckDistance(true); PickingUtil.findPick(_root, pickRay, pickResults); if (pickResults.getNumber() != 0) { final Vector3 intersectionPoint = pickResults.getPickData(0).getIntersectionRecord() .getIntersectionPoint(0); sphere.setTranslation(intersectionPoint); // XXX: maybe change the color of the ball for valid vs. invalid? } } final Vector3 transVec = new Vector3(camera.getLocation().getX(), waterNode.getWaterHeight(), camera .getLocation().getZ()); setTextureCoords(0, transVec.getX(), -transVec.getZ(), textureScale); // vertex coords setVertexCoords(transVec.getX(), transVec.getY(), transVec.getZ()); waterNode.update(timer.getTimePerFrame()); } /** * Render example. * * @param renderer * the renderer */ @Override protected void renderExample(final Renderer renderer) { super.renderExample(renderer); if (debugQuadsNode == null) { createDebugQuads(); _root.attachChild(debugQuadsNode); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain + Water - Example"); _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 100, 0)); _canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(0, 100, 1), Vector3.UNIT_Y); _canvas.getCanvasRenderer().getCamera().setFrustumPerspective( 65.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); _controlHandle.setMoveSpeed(50); _lightState.detachAll(); final DirectionalLight dLight = new DirectionalLight(); dLight.setEnabled(true); dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(dLight); _lightState.setEnabled(true); final CullState cs = new CullState(); cs.setEnabled(true); cs.setCullFace(CullState.Face.Back); _root.setRenderState(cs); fogState = new FogState(); fogState.setStart(farPlane / 2.0f); fogState.setEnd(farPlane); fogState.setColor(new ColorRGBA(0.96f, 0.97f, 1.0f, 1.0f)); fogState.setDensityFunction(DensityFunction.Linear); _root.setRenderState(fogState); // add our sphere, but have it off for now. sphere.getSceneHints().setCullHint(CullHint.Always); sphere.getSceneHints().setAllPickingHints(false); _root.attachChild(sphere); try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); final double scale = 1.0 / 4000.0; Function3D functionTmp = new FbmFunction3D(Functions.simplexNoise(), 9, 0.5, 0.5, 3.14); functionTmp = Functions.clamp(functionTmp, -1.2, 1.2); final Function3D function = Functions.scaleInput(functionTmp, scale, scale, 1); final TerrainDataProvider terrainDataProvider = new ProceduralTerrainDataProvider(function, new Vector3(1, 200, 1), -1.2f, 1.2f); terrain = new TerrainBuilder(terrainDataProvider, terrainCamera).setShowDebugPanels(true).build(); } catch (final Exception ex1) { ex1.printStackTrace(); } final Node reflectedNode = new Node("reflectNode"); reflectedNode.attachChild(terrain); skybox = buildSkyBox(); skybox.getSceneHints().setAllPickingHints(false); reflectedNode.attachChild(skybox); final Camera cam = _canvas.getCanvasRenderer().getCamera(); // Create a new WaterNode with refraction enabled. waterNode = new WaterNode(cam, 2, false, true); // Setup textures to use for the water. waterNode.setNormalMapTextureString("images/water/normalmap3.dds"); waterNode.setDudvMapTextureString("images/water/dudvmap.png"); waterNode.setFallbackMapTextureString("images/water/water2.png"); waterNode.useFadeToFogColor(true); waterNode.setSpeedReflection(0.02); waterNode.setSpeedReflection(-0.01); // setting to default value just to show waterNode.setWaterPlane(new Plane(new Vector3(0.0, 1.0, 0.0), 40.0)); // Create a quad to use as geometry for the water. waterQuad = new Quad("waterQuad", 1, 1); // Hack the quad normals to point up in the y-axis. Since we are manipulating the vertices as // we move this is more convenient than rotating the quad. final FloatBuffer normBuf = waterQuad.getMeshData().getNormalBuffer(); normBuf.clear(); normBuf.put(0).put(1).put(0); normBuf.put(0).put(1).put(0); normBuf.put(0).put(1).put(0); normBuf.put(0).put(1).put(0); waterNode.attachChild(waterQuad); waterNode.addReflectedScene(reflectedNode); waterNode.setSkybox(skybox); _root.attachChild(reflectedNode); _root.attachChild(waterNode); // Setup cam above water and terrain final Camera camera = _canvas.getCanvasRenderer().getCamera(); final double height = Math.max(terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()), waterNode.getWaterHeight()) + heightOffset; if (camera.getLocation().getY() < height) { camera.setLocation(new Vector3(camera.getLocation().getX(), height, camera.getLocation().getZ())); } // Setup labels for presenting example info. final Node textNodes = new Node("Text"); _root.attachChild(textNodes); textNodes.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); textNodes.getSceneHints().setLightCombineMode(LightCombineMode.Off); final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() - 20; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = BasicText.createDefaultTextLabel("Text", "", 16); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); textNodes.attachChild(_exampleInfo[i]); } textNodes.updateGeometricState(0.0); updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.U), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { updateTerrain = !updateTerrain; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.P), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { sphere.getSceneHints().setCullHint( sphere.getSceneHints().getCullHint() == CullHint.Always ? CullHint.Dynamic : CullHint.Always); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.V), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { showUI = !showUI; if (showUI) { textNodes.getSceneHints().setCullHint(CullHint.Never); debugQuadsNode.getSceneHints().setCullHint(CullHint.Never); } else { textNodes.getSceneHints().setCullHint(CullHint.Always); debugQuadsNode.getSceneHints().setCullHint(CullHint.Always); } updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.B), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { waterNode.setDoBlurReflection(!waterNode.isDoBlurReflection()); waterNode.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.F), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(new Vector3(camera.getLocation().getX() + 5000, camera.getLocation().getY(), camera .getLocation().getZ())); updateText(); } })); } /** * Sets the vertex coords of the quad. * * @param x * the x * @param y * the y * @param z * the z */ private void setVertexCoords(final double x, final double y, final double z) { final FloatBuffer vertBuf = waterQuad.getMeshData().getVertexBuffer(); vertBuf.clear(); vertBuf.put((float) (x - farPlane)).put((float) y).put((float) (z - farPlane)); vertBuf.put((float) (x - farPlane)).put((float) y).put((float) (z + farPlane)); vertBuf.put((float) (x + farPlane)).put((float) y).put((float) (z + farPlane)); vertBuf.put((float) (x + farPlane)).put((float) y).put((float) (z - farPlane)); } /** * Sets the texture coords of the quad. * * @param buffer * the buffer * @param x * the x * @param y * the y * @param textureScale * the texture scale */ private void setTextureCoords(final int buffer, double x, double y, double textureScale) { x *= textureScale * 0.5f; y *= textureScale * 0.5f; textureScale = farPlane * textureScale; FloatBuffer texBuf; texBuf = waterQuad.getMeshData().getTextureBuffer(buffer); texBuf.clear(); texBuf.put((float) x).put((float) (textureScale + y)); texBuf.put((float) x).put((float) y); texBuf.put((float) (textureScale + x)).put((float) y); texBuf.put((float) (textureScale + x)).put((float) (textureScale + y)); } /** * Builds the sky box. */ private Skybox buildSkyBox() { final Skybox skybox = new Skybox("skybox", 10, 10, 10); final String dir = "images/skybox/"; final Texture north = TextureManager .load(dir + "1.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture south = TextureManager .load(dir + "3.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture east = TextureManager.load(dir + "2.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture west = TextureManager.load(dir + "4.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture up = TextureManager.load(dir + "6.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture down = TextureManager.load(dir + "5.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); skybox.setTexture(Skybox.Face.North, north); skybox.setTexture(Skybox.Face.West, west); skybox.setTexture(Skybox.Face.South, south); skybox.setTexture(Skybox.Face.East, east); skybox.setTexture(Skybox.Face.Up, up); skybox.setTexture(Skybox.Face.Down, down); return skybox; } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("Heightmap size: " + SIZE + "x" + SIZE); _exampleInfo[1].setText("Spec: One meter per heightmap value"); _exampleInfo[2].setText("[1/2/3] Moving speed: " + _controlHandle.getMoveSpeed() + " m/s"); _exampleInfo[3].setText("[U] Update terrain: " + updateTerrain); _exampleInfo[4].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); _exampleInfo[5].setText("[P] Toggle showing a sphere that follows the ground using picking: " + (sphere.getSceneHints().getCullHint() != CullHint.Always)); _exampleInfo[6].setText("[B] Blur reflection: " + waterNode.isDoBlurReflection()); _exampleInfo[7].setText("[V] Show/Hide UI"); } /** * Creates the debug quads. */ private void createDebugQuads() { debugQuadsNode = new Node("quadNode"); debugQuadsNode.getSceneHints().setCullHint(CullHint.Never); final double quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; Quad debugQuad = new Quad("reflectionQuad", quadSize, quadSize); debugQuad.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); debugQuad.getSceneHints().setCullHint(CullHint.Never); debugQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off); TextureState ts = new TextureState(); ts.setTexture(waterNode.getTextureReflect()); debugQuad.setRenderState(ts); debugQuad.setTranslation(quadSize * 0.6, quadSize * 1.0, 1.0); debugQuadsNode.attachChild(debugQuad); if (waterNode.getTextureRefract() != null) { debugQuad = new Quad("refractionQuad", quadSize, quadSize); debugQuad.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); debugQuad.getSceneHints().setCullHint(CullHint.Never); debugQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off); ts = new TextureState(); ts.setTexture(waterNode.getTextureRefract()); debugQuad.setRenderState(ts); debugQuad.setTranslation(quadSize * 0.6, quadSize * 2.1, 1.0); debugQuadsNode.attachChild(debugQuad); } } } \ No newline at end of file
+/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package com.ardor3d.example.terrain; import java.nio.FloatBuffer; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.effect.water.WaterNode; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.TerrainDataProvider; import com.ardor3d.extension.terrain.providers.procedural.ProceduralTerrainDataProvider; import com.ardor3d.framework.Canvas; import com.ardor3d.image.Texture; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.intersection.PickingUtil; import com.ardor3d.intersection.PrimitivePickResults; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Plane; import com.ardor3d.math.Ray3; import com.ardor3d.math.Vector3; import com.ardor3d.math.functions.FbmFunction3D; import com.ardor3d.math.functions.Function3D; import com.ardor3d.math.functions.Functions; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.CullState; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.extension.Skybox; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.scenegraph.shape.Sphere; import com.ardor3d.ui.text.BasicText; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.TextureManager; /** * Example showing how to combine the terrain and water systems. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.TerrainWaterExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_TerrainWaterExample.jpg", // maxHeapMemory = 128) public class TerrainWaterExample extends ExampleBase { private final int SIZE = 2048; private Terrain terrain; private boolean updateTerrain = true; private final float farPlane = 3500.0f; private final float heightOffset = 3.0f; /** The water instance taking care of the water rendering. */ private WaterNode waterNode; private boolean aboveWater = true; /** Node containing debug quads for showing waternode render textures. */ private Node debugQuadsNode; /** The quad used as geometry for the water. */ private Quad waterQuad; private boolean groundCamera = false; private Camera terrainCamera; private Skybox skybox; private final Sphere sphere = new Sphere("sp", 16, 16, 1); private final double textureScale = 0.05; private FogState fogState; private boolean showUI = true; private final Ray3 pickRay = new Ray3(); /** Text fields used to present info about the example. */ private final BasicText _exampleInfo[] = new BasicText[8]; /** * The main method. * * @param args * the arguments */ public static void main(final String[] args) { start(TerrainWaterExample.class); } private double counter = 0; private int frames = 0; /** * Update the PassManager, skybox, camera position, etc. * * @param timer * the application timer */ @Override protected void updateExample(final ReadOnlyTimer timer) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()) + heightOffset; if (groundCamera || camera.getLocation().getY() < height) { camera.setLocation(new Vector3(camera.getLocation().getX(), height, camera.getLocation().getZ())); } if (aboveWater && camera.getLocation().getY() < waterNode.getWaterHeight()) { fogState.setStart(-1000f); fogState.setEnd(farPlane / 10f); fogState.setColor(new ColorRGBA(0.0f, 0.0f, 0.1f, 1.0f)); aboveWater = false; } else if (!aboveWater && camera.getLocation().getY() >= waterNode.getWaterHeight()) { fogState.setStart(farPlane / 2.0f); fogState.setEnd(farPlane); fogState.setColor(new ColorRGBA(0.96f, 0.97f, 1.0f, 1.0f)); aboveWater = true; } if (updateTerrain) { terrainCamera.set(camera); } skybox.setTranslation(camera.getLocation()); counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = (frames / counter); counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } // if we're picking... if (sphere.getSceneHints().getCullHint() == CullHint.Dynamic) { // Set up our pick ray pickRay.setOrigin(camera.getLocation()); pickRay.setDirection(camera.getDirection()); // do pick and move the sphere final PrimitivePickResults pickResults = new PrimitivePickResults(); pickResults.setCheckDistance(true); PickingUtil.findPick(_root, pickRay, pickResults); if (pickResults.getNumber() != 0) { final Vector3 intersectionPoint = pickResults.getPickData(0).getIntersectionRecord() .getIntersectionPoint(0); sphere.setTranslation(intersectionPoint); // XXX: maybe change the color of the ball for valid vs. invalid? } } final Vector3 transVec = new Vector3(camera.getLocation().getX(), waterNode.getWaterHeight(), camera .getLocation().getZ()); setTextureCoords(0, transVec.getX(), -transVec.getZ(), textureScale); // vertex coords setVertexCoords(transVec.getX(), transVec.getY(), transVec.getZ()); waterNode.update(timer.getTimePerFrame()); } /** * Render example. * * @param renderer * the renderer */ @Override protected void renderExample(final Renderer renderer) { super.renderExample(renderer); if (debugQuadsNode == null) { createDebugQuads(); _root.attachChild(debugQuadsNode); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain + Water - Example"); _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 100, 0)); _canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(0, 100, 1), Vector3.UNIT_Y); _canvas.getCanvasRenderer().getCamera().setFrustumPerspective( 65.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); _controlHandle.setMoveSpeed(50); _lightState.detachAll(); final DirectionalLight dLight = new DirectionalLight(); dLight.setEnabled(true); dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(dLight); _lightState.setEnabled(true); final CullState cs = new CullState(); cs.setEnabled(true); cs.setCullFace(CullState.Face.Back); _root.setRenderState(cs); fogState = new FogState(); fogState.setStart(farPlane / 2.0f); fogState.setEnd(farPlane); fogState.setColor(new ColorRGBA(0.96f, 0.97f, 1.0f, 1.0f)); fogState.setDensityFunction(DensityFunction.Linear); _root.setRenderState(fogState); // add our sphere, but have it off for now. sphere.getSceneHints().setCullHint(CullHint.Always); sphere.getSceneHints().setAllPickingHints(false); _root.attachChild(sphere); try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); final double scale = 1.0 / 4000.0; Function3D functionTmp = new FbmFunction3D(Functions.simplexNoise(), 9, 0.5, 0.5, 3.14); functionTmp = Functions.clamp(functionTmp, -1.2, 1.2); final Function3D function = Functions.scaleInput(functionTmp, scale, scale, 1); final TerrainDataProvider terrainDataProvider = new ProceduralTerrainDataProvider(function, new Vector3(1, 200, 1), -1.2f, 1.2f); terrain = new TerrainBuilder(terrainDataProvider, terrainCamera).setShowDebugPanels(true).build(); } catch (final Exception ex1) { ex1.printStackTrace(); } final Node reflectedNode = new Node("reflectNode"); reflectedNode.attachChild(terrain); skybox = buildSkyBox(); skybox.getSceneHints().setAllPickingHints(false); reflectedNode.attachChild(skybox); final Camera cam = _canvas.getCanvasRenderer().getCamera(); // Create a new WaterNode with refraction enabled. waterNode = new WaterNode(cam, 2, false, true); // Setup textures to use for the water. waterNode.setNormalMapTextureString("images/water/normalmap3.dds"); waterNode.setDudvMapTextureString("images/water/dudvmap.png"); waterNode.setFallbackMapTextureString("images/water/water2.png"); waterNode.useFadeToFogColor(true); waterNode.setSpeedReflection(0.02); waterNode.setSpeedReflection(-0.01); // setting to default value just to show waterNode.setWaterPlane(new Plane(new Vector3(0.0, 1.0, 0.0), 40.0)); // Create a quad to use as geometry for the water. waterQuad = new Quad("waterQuad", 1, 1); // Hack the quad normals to point up in the y-axis. Since we are manipulating the vertices as // we move this is more convenient than rotating the quad. final FloatBuffer normBuf = waterQuad.getMeshData().getNormalBuffer(); normBuf.clear(); normBuf.put(0).put(1).put(0); normBuf.put(0).put(1).put(0); normBuf.put(0).put(1).put(0); normBuf.put(0).put(1).put(0); waterNode.attachChild(waterQuad); waterNode.addReflectedScene(reflectedNode); waterNode.setSkybox(skybox); _root.attachChild(reflectedNode); _root.attachChild(waterNode); // Setup cam above water and terrain final Camera camera = _canvas.getCanvasRenderer().getCamera(); final double height = Math.max(terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()), waterNode.getWaterHeight()) + heightOffset; if (camera.getLocation().getY() < height) { camera.setLocation(new Vector3(camera.getLocation().getX(), height, camera.getLocation().getZ())); } // Setup labels for presenting example info. final Node textNodes = new Node("Text"); _root.attachChild(textNodes); textNodes.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); textNodes.getSceneHints().setLightCombineMode(LightCombineMode.Off); final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() - 20; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = BasicText.createDefaultTextLabel("Text", "", 16); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); textNodes.attachChild(_exampleInfo[i]); } textNodes.updateGeometricState(0.0); updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.U), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { updateTerrain = !updateTerrain; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.P), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { sphere.getSceneHints().setCullHint( sphere.getSceneHints().getCullHint() == CullHint.Always ? CullHint.Dynamic : CullHint.Always); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.V), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { showUI = !showUI; if (showUI) { textNodes.getSceneHints().setCullHint(CullHint.Never); debugQuadsNode.getSceneHints().setCullHint(CullHint.Never); } else { textNodes.getSceneHints().setCullHint(CullHint.Always); debugQuadsNode.getSceneHints().setCullHint(CullHint.Always); } updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.B), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { waterNode.setDoBlurReflection(!waterNode.isDoBlurReflection()); waterNode.reloadShader(); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.F), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(new Vector3(camera.getLocation().getX() + 5000, camera.getLocation().getY(), camera .getLocation().getZ())); updateText(); } })); } /** * Sets the vertex coords of the quad. * * @param x * the x * @param y * the y * @param z * the z */ private void setVertexCoords(final double x, final double y, final double z) { final FloatBuffer vertBuf = waterQuad.getMeshData().getVertexBuffer(); vertBuf.clear(); vertBuf.put((float) (x - farPlane)).put((float) y).put((float) (z - farPlane)); vertBuf.put((float) (x - farPlane)).put((float) y).put((float) (z + farPlane)); vertBuf.put((float) (x + farPlane)).put((float) y).put((float) (z + farPlane)); vertBuf.put((float) (x + farPlane)).put((float) y).put((float) (z - farPlane)); } /** * Sets the texture coords of the quad. * * @param buffer * the buffer * @param x * the x * @param y * the y * @param textureScale * the texture scale */ private void setTextureCoords(final int buffer, double x, double y, double textureScale) { x *= textureScale * 0.5f; y *= textureScale * 0.5f; textureScale = farPlane * textureScale; FloatBuffer texBuf; texBuf = waterQuad.getMeshData().getTextureBuffer(buffer); texBuf.clear(); texBuf.put((float) x).put((float) (textureScale + y)); texBuf.put((float) x).put((float) y); texBuf.put((float) (textureScale + x)).put((float) y); texBuf.put((float) (textureScale + x)).put((float) (textureScale + y)); } /** * Builds the sky box. */ private Skybox buildSkyBox() { final Skybox skybox = new Skybox("skybox", 10, 10, 10); final String dir = "images/skybox/"; final Texture north = TextureManager .load(dir + "1.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture south = TextureManager .load(dir + "3.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture east = TextureManager.load(dir + "2.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture west = TextureManager.load(dir + "4.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture up = TextureManager.load(dir + "6.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); final Texture down = TextureManager.load(dir + "5.jpg", Texture.MinificationFilter.BilinearNearestMipMap, true); skybox.setTexture(Skybox.Face.North, north); skybox.setTexture(Skybox.Face.West, west); skybox.setTexture(Skybox.Face.South, south); skybox.setTexture(Skybox.Face.East, east); skybox.setTexture(Skybox.Face.Up, up); skybox.setTexture(Skybox.Face.Down, down); return skybox; } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("Heightmap size: " + SIZE + "x" + SIZE); _exampleInfo[1].setText("Spec: One meter per heightmap value"); _exampleInfo[2].setText("[1/2/3] Moving speed: " + _controlHandle.getMoveSpeed() + " m/s"); _exampleInfo[3].setText("[U] Update terrain: " + updateTerrain); _exampleInfo[4].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); _exampleInfo[5].setText("[P] Toggle showing a sphere that follows the ground using picking: " + (sphere.getSceneHints().getCullHint() != CullHint.Always)); _exampleInfo[6].setText("[B] Blur reflection: " + waterNode.isDoBlurReflection()); _exampleInfo[7].setText("[V] Show/Hide UI"); } /** * Creates the debug quads. */ private void createDebugQuads() { debugQuadsNode = new Node("quadNode"); debugQuadsNode.getSceneHints().setCullHint(CullHint.Never); final double quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; Quad debugQuad = new Quad("reflectionQuad", quadSize, quadSize); debugQuad.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); debugQuad.getSceneHints().setCullHint(CullHint.Never); debugQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off); TextureState ts = new TextureState(); ts.setTexture(waterNode.getTextureReflect()); debugQuad.setRenderState(ts); debugQuad.setTranslation(quadSize * 0.6, quadSize * 1.0, 1.0); debugQuadsNode.attachChild(debugQuad); if (waterNode.getTextureRefract() != null) { debugQuad = new Quad("refractionQuad", quadSize, quadSize); debugQuad.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); debugQuad.getSceneHints().setCullHint(CullHint.Never); debugQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off); ts = new TextureState(); ts.setTexture(waterNode.getTextureRefract()); debugQuad.setRenderState(ts); debugQuad.setTranslation(quadSize * 0.6, quadSize * 2.1, 1.0); debugQuadsNode.attachChild(debugQuad); } } } \ No newline at end of file