diff --git a/.classpath b/.classpath
index ab1559e9..026b971f 100644
--- a/.classpath
+++ b/.classpath
@@ -1,14 +1,14 @@
-
-
+
+
-
-
+
+
diff --git a/build.xml b/build.xml
index de051199..9856ff47 100644
--- a/build.xml
+++ b/build.xml
@@ -73,7 +73,6 @@
-
@@ -219,10 +218,6 @@
-
-
-
-
diff --git a/etc/depends-incl.xml b/etc/depends-incl.xml
index 780b7b93..5000f979 100644
--- a/etc/depends-incl.xml
+++ b/etc/depends-incl.xml
@@ -9,14 +9,6 @@
classname="org.lwjgl.LWJGLException" classpathref="classpath"/>
-
-
-
-
-
-
@@ -29,13 +21,6 @@
classname="com.megginson.sax.DataWriter" classpathref="classpath"/>
-
-
-
-
-
-
-
diff --git a/etc/libs-incl.xml b/etc/libs-incl.xml
index 523fc5f3..6f6bbedf 100644
--- a/etc/libs-incl.xml
+++ b/etc/libs-incl.xml
@@ -18,16 +18,9 @@
-
+
-
-
-
-
-
-
-
diff --git a/rsrc/media/jme/defaultfont.tga b/rsrc/media/jme/defaultfont.tga
deleted file mode 100644
index 563b0968..00000000
Binary files a/rsrc/media/jme/defaultfont.tga and /dev/null differ
diff --git a/rsrc/media/jme/skin.frag b/rsrc/media/jme/skin.frag
deleted file mode 100644
index 0d44c2ee..00000000
--- a/rsrc/media/jme/skin.frag
+++ /dev/null
@@ -1,56 +0,0 @@
-//
-// $Id: ImageCache.java 158 2007-02-24 00:38:17Z mdb $
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://www.threerings.net/code/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-/** The diffuse texture map. */
-uniform sampler2D diffuseMap;
-
-/** The emissive texture map. */
-#ifdef EMISSIVE_MAPPED
- uniform sampler2D emissiveMap;
-#endif
-
-/** The amount of fog. */
-#ifdef FOG
- varying float fogAlpha;
-#endif
-
-/**
- * Fragment shader for skinned meshes.
- */
-void main ()
-{
- // start with the diffuse color
- vec4 fragColor = texture2D(diffuseMap, gl_TexCoord[0].st);
-
- // modulate by the light color
- #ifdef EMISSIVE_MAPPED
- fragColor *= (gl_Color + vec4(texture2D(emissiveMap, gl_TexCoord[0].st).rgb, 0.0));
- #else
- fragColor *= gl_Color;
- #endif
-
- // blend between the computed color and the fog color
- #ifdef FOG
- gl_FragColor = mix(gl_Fog.color, fragColor, fogAlpha);
- #else
- gl_FragColor = fragColor;
- #endif
-}
diff --git a/rsrc/media/jme/skin.vert b/rsrc/media/jme/skin.vert
deleted file mode 100644
index 5bee27d8..00000000
--- a/rsrc/media/jme/skin.vert
+++ /dev/null
@@ -1,67 +0,0 @@
-//
-// $Id: ImageCache.java 158 2007-02-24 00:38:17Z mdb $
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://www.threerings.net/code/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-/** The bone transforms. */
-uniform mat4 boneTransforms[MAX_BONE_COUNT];
-
-/** The bone indices. */
-attribute vec4 boneIndices;
-
-/** The bone weights. */
-attribute vec4 boneWeights;
-
-/** The amount of fog. */
-#ifdef FOG
- varying float fogAlpha;
-#endif
-
-/**
- * Vertex shader for skinned meshes.
- */
-void main ()
-{
- vec4 normal4 = vec4(gl_Normal, 0.0);
-
- // add up the vertex as transformed by each bone and scaled by each weight
- vec4 modelVertex = vec4(0.0, 0.0, 0.0, 0.0);
- vec4 modelNormal = vec4(0.0, 0.0, 0.0, 0.0);
- for (int ii = 0; ii < 4; ii++) {
- mat4 boneTransform = boneTransforms[int(boneIndices[ii])];
- modelVertex += boneTransform * gl_Vertex * boneWeights[ii];
- modelNormal += boneTransform * normal4 * boneWeights[ii];
- }
-
- // apply the standard transformation
- gl_Position = gl_ModelViewProjectionMatrix * modelVertex;
-
- // transform the vertex and normal into eye space
- vec3 eyeVertex = vec3(gl_ModelViewMatrix * modelVertex);
- vec3 eyeNormal = normalize(vec3(gl_ModelViewMatrixInverseTranspose * modelNormal));
-
- // set gl_FrontColor based on vertex, normal and light parameters
- SET_FRONT_COLOR
-
- // set the varying texture coordinates
- SET_TEX_COORDS
-
- // set the fog alpha based on the eye space vertex
- SET_FOG_ALPHA
-}
diff --git a/src/java/com/threerings/jme/JmeApp.java b/src/java/com/threerings/jme/JmeApp.java
deleted file mode 100644
index eedb9b31..00000000
--- a/src/java/com/threerings/jme/JmeApp.java
+++ /dev/null
@@ -1,600 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme;
-
-import java.io.File;
-
-import java.util.Arrays;
-
-import com.samskivert.util.Queue;
-import com.samskivert.util.RunQueue;
-import com.samskivert.util.StringUtil;
-
-import com.jme.renderer.Camera;
-import com.jme.renderer.ColorRGBA;
-import com.jme.renderer.Renderer;
-
-import com.jme.scene.Node;
-import com.jme.scene.state.LightState;
-import com.jme.scene.state.RenderState;
-import com.jme.scene.state.ZBufferState;
-
-import com.jme.system.DisplaySystem;
-import com.jme.system.JmeException;
-import com.jme.system.PropertiesIO;
-import com.jme.system.lwjgl.LWJGLPropertiesDialog;
-
-import com.jme.input.InputHandler;
-import com.jme.input.KeyInput;
-import com.jme.input.MouseInput;
-import com.jmex.bui.BRootNode;
-import com.jmex.bui.PolledRootNode;
-
-import com.jme.light.PointLight;
-import com.jme.math.Vector3f;
-import com.jme.util.Timer;
-
-import com.threerings.jme.camera.CameraHandler;
-
-import static com.threerings.jme.Log.log;
-
-/**
- * Defines a basic application framework providing integration with the
- * Presents networking system and
- * targeting the framerate of the display.
- */
-public class JmeApp
- implements RunQueue
-{
- /**
- * Returns a context implementation that provides access to all the
- * necessary bits.
- */
- public JmeContext getContext ()
- {
- return _ctx;
- }
-
- /**
- * Does the main initialization of the application. This method should
- * be called first, and then the {@link #run} method should be called
- * to begin the rendering/event loop. Derived classes can override
- * this, being sure to call super before doing their own
- * initalization.
- *
- * @return true if the application initialized successfully, false if
- * initialization failed. (See {@link #reportInitFailure}.)
- */
- public boolean init ()
- {
- try {
- // initialize the rendering system
- initDisplay();
- if (!_display.isCreated()) {
- throw new IllegalStateException(
- "Failed to initialize display?");
- }
-
- // create an appropriate timer
- _timer = Timer.getTimer();
-
- // start with the target FPS equal to the refresh rate (but
- // sometimes the refresh rate is reported as zero so don't let that
- // freak us out)
- setTargetFPS(Math.max(_display.getFrequency(), 60));
-
- // initialize our main camera controls and user input handling
- initInput();
-
- // initialize the root node
- initRoot();
-
- // initialize the lighting
- initLighting();
-
- // initialize the UI support stuff
- initInterface();
-
- // update everything for the zeroth tick
- _iface.updateRenderState();
- _geom.updateRenderState();
- _root.updateGeometricState(0f, true);
- _root.updateRenderState();
-
- return true;
-
- } catch (Throwable t) {
- reportInitFailure(t);
- return false;
- }
- }
-
- /**
- * Configures whether or not we display FPS and other statistics atop the
- * display.
- */
- public void displayStatistics (boolean display)
- {
- if (display && (_stats == null)) {
- _stats = new StatsDisplay(_display.getRenderer());
- _stats.updateGeometricState(0f, true);
- _stats.updateRenderState();
- } else if (!display && (_stats != null)) {
- _stats = null;
- }
- }
-
- /**
- * Returns true if we are displaying statistics, false if not.
- */
- public boolean showingStatistics ()
- {
- return (_stats != null);
- }
-
- /**
- * Sets the target frames per second.
- *
- * @return the old target frames per second.
- */
- public int setTargetFPS (int targetFPS)
- {
- int oldTargetFPS = _targetFPS;
- _targetFPS = targetFPS;
- _ticksPerFrame = _timer.getResolution() / _targetFPS;
- return oldTargetFPS;
- }
-
- /**
- * Returns the frames per second averaged over the last 32 frames.
- */
- public float getRecentFrameRate ()
- {
- return _timer.getFrameRate();
- }
-
- /**
- * Enables or disables the update and render part of the
- * update/render/process events application loop.
- */
- public void setEnabled (boolean update, boolean render)
- {
- _updateEnabled = update;
- _renderEnabled = render;
- }
-
- /**
- * Starts up the main rendering and event processing loop. This method
- * will not return until the application is terminated with a call to
- * {@link #stop}.
- */
- public void run ()
- {
- synchronized (this) {
- _dispatchThread = Thread.currentThread();
- }
-
- // enter the main rendering and event processing loop
- while (!_finished) {
- try {
- // render the current frame
- long frameStart = processFrame();
-
- // and process events until it's time to render the next
- PROCESS_EVENTS:
- do {
- Runnable r = _evqueue.getNonBlocking();
- if (r != null) {
- r.run();
- }
- if (_timer.getTime() - frameStart >= _ticksPerFrame) {
- break PROCESS_EVENTS;
- } else {
- try {
- Thread.sleep(1);
- } catch (InterruptedException ie) {
- }
- }
- } while (!_finished);
- _failures = 0;
-
- } catch (Throwable t) {
- log.warning(t);
- // stick a fork in things if we fail too many times in a row
- if (++_failures > MAX_SUCCESSIVE_FAILURES) {
- stop();
- }
- }
- if (_display.isClosing()) {
- stop();
- }
- }
-
- try {
- cleanup();
- } catch (Throwable t) {
- log.warning(t);
- } finally {
- exit();
- }
- }
-
- /**
- * Returns the duration (in seconds) between the previous frame and the
- * current frame.
- */
- public float getFrameTime ()
- {
- return _frameTime;
- }
-
- /**
- * Instructs the application to stop the main loop, cleanup and exit.
- */
- public void stop ()
- {
- _finished = true;
- }
-
- // from interface RunQueue
- public void postRunnable (Runnable r)
- {
- _evqueue.append(r);
- }
-
- // from interface RunQueue
- public boolean isDispatchThread ()
- {
- return Thread.currentThread() == _dispatchThread;
- }
-
- // from interface RunQueue
- public boolean isRunning ()
- {
- return !_finished;
- }
-
- /**
- * Determines the display configuration and creates the display. This must
- * fill in {@link #_api} as a side-effect.
- */
- protected DisplaySystem createDisplay ()
- throws JmeException
- {
- PropertiesIO props = new PropertiesIO(getConfigPath("jme.cfg"));
- if (!props.load()) {
- LWJGLPropertiesDialog dialog =
- new LWJGLPropertiesDialog(props, (String)null);
- while (dialog.isVisible()) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- log.warning("Error waiting for dialog system, " +
- "using defaults.");
- }
- }
- }
- _api = props.getRenderer();
- DisplaySystem display = DisplaySystem.getDisplaySystem(_api);
- display.createWindow(props.getWidth(), props.getHeight(),
- props.getDepth(), props.getFreq(),
- props.getFullscreen());
- return display;
- }
-
- /**
- * Initializes the underlying rendering system, creating a display of
- * the proper resolution and depth.
- */
- protected void initDisplay ()
- throws JmeException
- {
- // create the main display system
- _display = createDisplay();
-
- // create a camera
- int width = _display.getWidth(), height = _display.getHeight();
- _camera = _display.getRenderer().createCamera(width, height);
-
- // start with a black background
- _display.getRenderer().setBackgroundColor(ColorRGBA.black);
-
- // enable all of the "quick compares," which means that states will
- // be refreshed only when necessary
- Arrays.fill(RenderState.QUICK_COMPARE, true);
-
- // set up the camera
- _camera.setFrustumPerspective(45.0f, width/(float)height, 1, 10000);
- Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
- Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
- Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
- Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
- _camera.setFrame(loc, left, up, dir);
- _camera.update();
- _display.getRenderer().setCamera(_camera);
-
- // tell the renderer to keep track of rendering information (total
- // triangles drawn, etc.)
- _display.getRenderer().enableStatistics(true);
- }
-
- /**
- * Sets up a main input controller to handle the camera and deal with
- * global user input.
- */
- protected void initInput ()
- {
- _camhand = createCameraHandler(_camera);
- _input = createInputHandler(_camhand);
- }
-
- /**
- * Creates the camera handler which provides various camera manipulation
- * functionality.
- */
- protected CameraHandler createCameraHandler (Camera camera)
- {
- return new CameraHandler(camera);
- }
-
- /**
- * Creates the input handler used to control our camera and manage non-UI
- * keyboard input.
- */
- protected InputHandler createInputHandler (CameraHandler hand)
- {
- return new InputHandler();
- }
-
- /**
- * Creates our root node and sets up the basic rendering system.
- */
- protected void initRoot ()
- {
- _root = new Node("Root");
-
- // set up a node for our geometry
- _geom = new Node("Geometry");
-
- // make everything opaque by default
- _geom.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
-
- // set up a zbuffer
- ZBufferState zbuf = _display.getRenderer().createZBufferState();
- zbuf.setEnabled(true);
- zbuf.setFunction(ZBufferState.CF_LEQUAL);
- _geom.setRenderState(zbuf);
- _root.attachChild(_geom);
- }
-
- /**
- * Sets up some default lighting.
- */
- protected void initLighting ()
- {
- PointLight light = new PointLight();
- light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
- light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
- light.setLocation(new Vector3f(100, 100, 100));
- light.setEnabled(true);
-
- _lights = _display.getRenderer().createLightState();
- _lights.setEnabled(true);
- _lights.attach(light);
- _geom.setRenderState(_lights);
- }
-
- /**
- * Initializes our user interface bits.
- */
- protected void initInterface ()
- {
- // set up a node for our interface
- _iface = new Node("Interface");
- _root.attachChild(_iface);
-
- // create our root node
- _rnode = createRootNode();
- _iface.attachChild(_rnode);
-
- // we don't hide the cursor
- MouseInput.get().setCursorVisible(true);
- }
-
- /**
- * Allows a customized root node to be created.
- */
- protected BRootNode createRootNode ()
- {
- return new PolledRootNode(_timer, _input);
- }
-
- /**
- * Called when initialization fails to give the application a chance
- * to report the failure to the user.
- */
- protected void reportInitFailure (Throwable t)
- {
- log.warning(t);
- }
-
- /**
- * Processes a single frame.
- */
- protected final long processFrame ()
- {
- // update our simulation and render a frame
- long frameStart = _timer.getTime();
- if (_updateEnabled) {
- update(frameStart);
- }
- if (_renderEnabled) {
- render(frameStart);
- _display.getRenderer().displayBackBuffer();
- }
- return frameStart;
- }
-
- /**
- * Called every frame to update whatever sort of real time business we
- * have that needs updating.
- */
- protected void update (long frameTick)
- {
- // recalculate the frame rate
- _timer.update();
-
- // update the camera handler
- _camhand.update(_frameTime);
-
- // run all of the controllers attached to nodes
- _frameTime = (_lastTick == 0L) ? 0f : (float)(frameTick - _lastTick) /
- _timer.getResolution();
- _lastTick = frameTick;
- _root.updateGeometricState(_frameTime, true);
-
- // update our stats display if we have one
- if (_stats != null) {
- _stats.update(_timer, _display.getRenderer());
- }
- }
-
- /**
- * Called every frame to issue the rendering instructions for this frame.
- */
- protected void render (float frameTime)
- {
- // clear out our previous information
- _display.getRenderer().clearStatistics();
- _display.getRenderer().clearBuffers();
-
- // draw the root node and all of its children
- _display.getRenderer().draw(_root);
-
- // this would render bounding boxes
- // _display.getRenderer().drawBounds(_root);
-
- // draw our stats atop everything
- if (_stats != null) {
- _display.getRenderer().draw(_stats);
- }
- }
-
- /**
- * Called when the application is terminating cleanly after having
- * successfully completed initialization and begun the main loop.
- */
- protected void cleanup ()
- {
- _display.reset();
- KeyInput.destroyIfInitalized();
- MouseInput.destroyIfInitalized();
- }
-
- /**
- * Closes the display and exits the JVM process.
- */
- protected void exit ()
- {
- if (_display != null) {
- _display.close();
- }
- System.exit(0);
- }
-
- /**
- * Prepends the necessary bits onto the supplied path to properly
- * locate it in our configuration directory.
- */
- protected String getConfigPath (String file)
- {
- String cfgdir = ".narya";
- String home = System.getProperty("user.home");
- if (!StringUtil.isBlank(home)) {
- cfgdir = home + File.separator + cfgdir;
- }
- // create the configuration directory if it does not already exist
- File dir = new File(cfgdir);
- if (!dir.exists()) {
- dir.mkdir();
- }
- return cfgdir + File.separator + file;
- }
-
- /** Provides access to various needed bits. */
- protected JmeContext _ctx = new JmeContext() {
- public DisplaySystem getDisplay () {
- return _display;
- }
-
- public Renderer getRenderer () {
- return _display.getRenderer();
- }
-
- public CameraHandler getCameraHandler () {
- return _camhand;
- }
-
- public Node getGeometry () {
- return _geom;
- }
-
- public Node getInterface () {
- return _iface;
- }
-
- public InputHandler getInputHandler () {
- return _input;
- }
-
- public BRootNode getRootNode () {
- return _rnode;
- }
- };
-
- protected Timer _timer;
- protected Thread _dispatchThread;
- protected Queue _evqueue = Queue.newQueue();
- protected long _lastTick;
- protected float _frameTime;
-
- protected String _api;
- protected DisplaySystem _display;
- protected Camera _camera;
- protected CameraHandler _camhand;
-
- protected InputHandler _input;
- protected BRootNode _rnode;
-
- protected long _ticksPerFrame;
- protected int _targetFPS;
- protected boolean _updateEnabled = true, _renderEnabled = true;
- protected boolean _finished;
- protected int _failures;
-
- protected Node _root, _geom, _iface;
- protected LightState _lights;
- protected StatsDisplay _stats;
-
- /** If we fail 100 frames in a row, stick a fork in ourselves. */
- protected static final int MAX_SUCCESSIVE_FAILURES = 100;
-}
diff --git a/src/java/com/threerings/jme/JmeCanvasApp.java b/src/java/com/threerings/jme/JmeCanvasApp.java
deleted file mode 100644
index fe1b9c8a..00000000
--- a/src/java/com/threerings/jme/JmeCanvasApp.java
+++ /dev/null
@@ -1,202 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme;
-
-import java.awt.AWTEvent;
-import java.awt.Canvas;
-import java.awt.Graphics;
-import java.awt.EventQueue;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-
-import org.lwjgl.LWJGLException;
-
-import com.jme.renderer.lwjgl.LWJGLRenderer;
-import com.jme.scene.Node;
-import com.jme.system.DisplaySystem;
-import com.jmex.awt.JMECanvas;
-import com.jmex.awt.JMECanvasImplementor;
-import com.jmex.awt.lwjgl.LWJGLCanvas;
-
-import com.jmex.bui.CanvasRootNode;
-
-import static com.threerings.jme.Log.log;
-
-/**
- * Extends the basic {@link JmeApp} with the necessary wiring to use the
- * GL/AWT bridge to display our GL interface in an AWT component.
- */
-public class JmeCanvasApp extends JmeApp
-{
- public JmeCanvasApp (int width, int height)
- {
- _display = DisplaySystem.getDisplaySystem("LWJGL");
-
- // create a throwaway canvas so that the display system knows it's
- // created, then create our custom canvas
- _display.createCanvas(width, height);
- try {
- _canvas = createCanvas();
- } catch (LWJGLException e) {
- log.warning("Failed to create LWJGL canvas [error=" + e + "].");
- }
- ((JMECanvas)_canvas).setImplementor(_winimp);
- _canvas.setBounds(0, 0, width, height);
- _canvas.addComponentListener(new ComponentAdapter() {
- public void componentResized (ComponentEvent ce) {
- _winimp.resizeCanvas(_canvas.getWidth(), _canvas.getHeight());
- }
- });
- }
-
- /**
- * Returns the AWT canvas that contains our GL display.
- */
- public Canvas getCanvas ()
- {
- return _canvas;
- }
-
- public void run ()
- {
- Thread t = new Thread() {
- public void run () {
- while (!_finished) {
- // queue up another repaint
- _canvas.repaint();
- try {
- Thread.sleep(10);
- } catch (Exception e) {
- }
- }
- }
- };
- t.setDaemon(true);
- t.start();
- }
-
- // documentation inherited from interface RunQueue
- public void postRunnable (Runnable r)
- {
- EventQueue.invokeLater(r);
- }
-
- // documentation inherited from interface RunQueue
- public boolean isDispatchThread ()
- {
- return EventQueue.isDispatchThread();
- }
-
- /**
- * Creates and returns the LWJGL canvas instance.
- */
- protected Canvas createCanvas ()
- throws LWJGLException
- {
- // LWJGL's canvas releases the context after painting. we make it
- // current again, because we want it valid when we process events.
- // block mouse and keyboard events until the context is valid.
- return new LWJGLCanvas() {
- public void addNotify () {
- super.addNotify();
- disableEvents(MOUSE_KEY_EVENT_MASK);
- }
- public void update (Graphics g) {
- super.update(g);
- try {
- makeCurrent();
- } catch (LWJGLException e) {
- log.warning("Failed to make context current [error=" +
- e + "].");
- }
- }
- protected void initGL () {
- super.initGL();
- enableEvents(MOUSE_KEY_EVENT_MASK);
- }
- };
- }
-
- // documentation inherited
- protected DisplaySystem createDisplay ()
- {
- // we've already created our display earlier so just return it
- _api = "LWJGL";
- return _display;
- }
-
- // documentation inherited
- protected void initInterface ()
- {
- _iface = new Node("Interface");
- _root.attachChild(_iface);
-
- _rnode = new CanvasRootNode(_canvas);
- _iface.attachChild(_rnode);
- }
-
- /** This is used if we embed our GL display in an AWT component. */
- protected JMECanvasImplementor _winimp = new JMECanvasImplementor() {
- public void doSetup () {
- super.doSetup();
-
- LWJGLRenderer renderer =
- new LWJGLRenderer(_canvas.getWidth(), _canvas.getHeight());
- renderer.setHeadless(true);
- setRenderer(renderer);
- _display.setRenderer(renderer);
- _display.getCurrentContext().setupRecords(renderer);
- DisplaySystem.updateStates(renderer);
-
- if (!init()) {
- log.warning("JmeCanvasApp init failed.");
- }
- }
-
- public void doUpdate () {
- }
-
- public void doRender () {
- // here we do our normal frame processing
- try {
- processFrame();
- // we don't process events as the AWT queue handles them
- _failures = 0;
- } catch (Throwable t) {
- log.warning(t);
- // stick a fork in things if we fail too many
- // times in a row
- if (++_failures > MAX_SUCCESSIVE_FAILURES) {
- JmeCanvasApp.this.stop();
- }
- }
- }
- };
-
- protected Canvas _canvas;
-
- protected static final long MOUSE_KEY_EVENT_MASK =
- AWTEvent.MOUSE_EVENT_MASK |
- AWTEvent.MOUSE_MOTION_EVENT_MASK |
- AWTEvent.MOUSE_WHEEL_EVENT_MASK |
- AWTEvent.KEY_EVENT_MASK;
-}
diff --git a/src/java/com/threerings/jme/JmeContext.java b/src/java/com/threerings/jme/JmeContext.java
deleted file mode 100644
index f5640710..00000000
--- a/src/java/com/threerings/jme/JmeContext.java
+++ /dev/null
@@ -1,59 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme;
-
-import com.jme.input.InputHandler;
-import com.jme.renderer.Renderer;
-import com.jme.scene.Node;
-import com.jme.system.DisplaySystem;
-
-import com.jmex.bui.BRootNode;
-
-import com.threerings.jme.camera.CameraHandler;
-
-/**
- * Provides access to the various bits needed by things that operate in
- * JME land.
- */
-public interface JmeContext
-{
- /** Returns the display to which we are rendering. */
- public DisplaySystem getDisplay ();
-
- /** Returns the renderer being used to draw everything. */
- public Renderer getRenderer ();
-
- /** Returns the handler for the camera being used to view the scene. */
- public CameraHandler getCameraHandler ();
-
- /** Returns the main geometry of our scene graph. */
- public Node getGeometry ();
-
- /** Returns the main interface node of our scene graph. */
- public Node getInterface ();
-
- /** Returns our main input handler. */
- public InputHandler getInputHandler ();
-
- /** Returns our UI root node. */
- public BRootNode getRootNode ();
-}
diff --git a/src/java/com/threerings/jme/Log.java b/src/java/com/threerings/jme/Log.java
deleted file mode 100644
index 79ddc4f1..00000000
--- a/src/java/com/threerings/jme/Log.java
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme;
-
-import com.samskivert.util.Logger;
-
-/**
- * Contains a reference to the log object used by this package.
- */
-public class Log
-{
- /** We dispatch our log messages through this logger. */
- public static Logger log = Logger.getLogger("com.threerings.nenya.jme");
-}
diff --git a/src/java/com/threerings/jme/StatsDisplay.java b/src/java/com/threerings/jme/StatsDisplay.java
deleted file mode 100644
index 402e54a5..00000000
--- a/src/java/com/threerings/jme/StatsDisplay.java
+++ /dev/null
@@ -1,83 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme;
-
-import com.jme.image.Texture;
-import com.jme.renderer.Renderer;
-import com.jme.scene.Node;
-import com.jme.scene.Text;
-import com.jme.scene.state.AlphaState;
-import com.jme.scene.state.TextureState;
-import com.jme.util.TextureManager;
-import com.jme.util.Timer;
-
-/**
- * Tracks and displays render statistics.
- */
-public class StatsDisplay extends Node
-{
- public StatsDisplay (Renderer renderer)
- {
- super("StatsNode");
-
- // create an alpha state that will allow us to blend the text on
- // top of whatever else is below
- AlphaState astate = renderer.createAlphaState();
- astate.setBlendEnabled(true);
- astate.setSrcFunction(AlphaState.SB_SRC_ALPHA);
- astate.setDstFunction(AlphaState.DB_ONE);
- astate.setTestEnabled(true);
- astate.setTestFunction(AlphaState.TF_GREATER);
- astate.setEnabled(true);
-
- // create a font texture
- TextureState font = renderer.createTextureState();
- font.setTexture(
- TextureManager.loadTexture(
- getClass().getClassLoader().getResource(DEFAULT_JME_FONT),
- Texture.MM_LINEAR, Texture.FM_LINEAR));
- font.setEnabled(true);
-
- _text = new Text("StatsLabel", "");
- _text.setCullMode(CULL_NEVER);
- _text.setTextureCombineMode(TextureState.REPLACE);
-
- attachChild(_text);
- setRenderState(font);
- setRenderState(astate);
- }
-
- public void update (Timer timer, Renderer renderer)
- {
- _stats.setLength(0);
- _stats.append("FPS: ").append((int)timer.getFrameRate());
- _stats.append(" - ").append(renderer.getStatistics(_temp));
- _text.print(_stats.toString());
- }
-
- protected Text _text;
- protected StringBuilder _stats = new StringBuilder();
- protected StringBuffer _temp = new StringBuffer();
-
- protected static final String DEFAULT_JME_FONT =
- "rsrc/media/jme/defaultfont.tga";
-}
diff --git a/src/java/com/threerings/jme/camera/CameraHandler.java b/src/java/com/threerings/jme/camera/CameraHandler.java
deleted file mode 100644
index 47715826..00000000
--- a/src/java/com/threerings/jme/camera/CameraHandler.java
+++ /dev/null
@@ -1,412 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.camera;
-
-import com.jme.math.FastMath;
-import com.jme.math.Matrix3f;
-import com.jme.math.Plane;
-import com.jme.math.Vector3f;
-import com.jme.renderer.Camera;
-
-import com.samskivert.util.ObserverList;
-import com.threerings.jme.JmeApp;
-
-/**
- * Provides various useful mechanisms for manipulating the camera.
- */
-public class CameraHandler
-{
- /**
- * Creates a new camera handler. The camera begins life at the origin,
- * facing in the negative z direction (pointing at the ground).
- */
- public CameraHandler (Camera camera)
- {
- _camera = camera;
- resetAxes();
- }
-
- /**
- * Resets the camera orientation to its initial state.
- */
- public void resetAxes ()
- {
- _camera.getDirection().set(0, 0, -1);
- _camera.getLeft().set(-1, 0, 0);
- _camera.getUp().set(0, 1, 0);
- _camera.update();
-
- _rxdir.set(1, 0, 0);
- _rydir.set(0, 1, 0);
- }
-
- /**
- * Configures limits on the camera tilt.
- */
- public void setTiltLimits (float minAngle, float maxAngle)
- {
- _minTilt = minAngle;
- _maxTilt = maxAngle;
- }
-
- /**
- * Configures limits on the distance the camera can be panned.
- *
- * @param boundViaFrustum if true instead of bounding the camera's
- * position, we will compute the intersections of the view frustum with the
- * ground plan and bound that rectangle into the specified bounds.
- * Note: the camera must generally be pointing down at the ground
- * (up to perhaps 45 degrees or so) for this to work. At higher angles the
- * back of the view frustum will intersect the ground plane at or near
- * infinity.
- */
- public void setPanLimits (float minX, float minY, float maxX, float maxY,
- boolean boundViaFrustum)
- {
- _minX = minX;
- _minY = minY;
- _maxX = maxX;
- _maxY = maxY;
- _boundViaFrustum = boundViaFrustum;
- }
-
- /**
- * Configures the minimum and maximum zoom values allowed for the
- * camera.
- */
- public void setZoomLimits (float minZoom, float maxZoom)
- {
- _minZoom = minZoom;
- _maxZoom = maxZoom;
- }
-
- /**
- * Enables or disables the current set of limits.
- */
- public void setLimitsEnabled (boolean enabled)
- {
- _limitsEnabled = enabled;
- }
-
- /**
- * Sets the camera zoom level to a value between zero (zoomed in maximally)
- * and 1 (zoomed out maximally). Zoom limits must have already been set up
- * via a call to {@link #setZoomLimits}.
- */
- public void setZoomLevel (float level)
- {
-// Log.info("Zoom " + level + " " + _camera.getLocation());
- level = Math.max(0f, Math.min(level, 1f));
- _camera.getLocation().z = _minZ + (_maxZ - _minZ) * level;
- _camera.update();
- }
-
- /**
- * Returns the current camera zoom level.
- */
- public float getZoomLevel ()
- {
- return (_camera.getLocation().z - _minZ) / (_maxZ - _minZ);
- }
-
- /**
- * Adds a camera path observer.
- */
- public void addCameraObserver (CameraPath.Observer camobs)
- {
- _campathobs.add(camobs);
- }
-
- /**
- * Removes a camera path observer.
- */
- public void removeCameraObserver (CameraPath.Observer camobs)
- {
- _campathobs.remove(camobs);
- }
-
- /**
- * Starts the camera moving along a path which will be updated every tick
- * until it is complete.
- */
- public void moveCamera (CameraPath path)
- {
- if (_campath != null) {
- _campath.abort();
- _campathobs.apply(new CompletedOp(_campath));
- }
- _campath = path;
- }
-
- /**
- * Returns true if the camera is currently animating along a path, false if
- * it is not.
- */
- public boolean cameraIsMoving ()
- {
- return (_campath != null);
- }
-
- /**
- * Skips immediately to the end of the current camera path.
- */
- public void skipPath ()
- {
- // fake an update far enough into the future to trick the camera path
- // into thinking it's done
- update(100);
- }
-
- /**
- * This is called by the {@link JmeApp} on every frame to allow the handler
- * to update the camera as necessary.
- */
- public void update (float frameTime)
- {
- if (_campath != null) {
- if (_campath.tick(frameTime)) {
- CameraPath opath = _campath;
- _campath = null;
- _campathobs.apply(new CompletedOp(opath));
- }
- }
- }
-
- /**
- * Returns the camera being manipulated by this handler.
- */
- public Camera getCamera ()
- {
- return _camera;
- }
-
- /**
- * Adjusts the camera's location. The specified location will be bounded
- * within the current pan and zoom limits.
- */
- public void setLocation (Vector3f location)
- {
- _camera.setLocation(bound(location));
- _camera.update();
- }
-
- /**
- * Pans the camera the specified distance in the x and y directions. These
- * distances will be multiplied by the current "view" x and y axes and
- * added to the camera's position.
- */
- public void panCamera (float x, float y)
- {
- Vector3f loc = _camera.getLocation();
- loc.addLocal(_rxdir.mult(x, _temp));
- loc.addLocal(_rydir.mult(y, _temp));
- setLocation(loc);
- }
-
- /**
- * Zooms the camera in (distance < 0) and out (distance > 0) by the
- * specified amount. The distance is multiplied by the camera's current
- * direction and added to its current position, which is then bounded into
- * the pan and zoom volume.
- */
- public void zoomCamera (float distance)
- {
- Vector3f loc = _camera.getLocation();
- float dist = getGroundPoint().distance(loc),
- ndist = Math.min(Math.max(dist + distance, _minZoom), _maxZoom);
- if ((distance = ndist - dist) == 0f) {
- return;
- }
- loc.subtractLocal(_camera.getDirection().mult(distance, _temp));
- setLocation(loc);
- }
-
- /**
- * Locates the point on the ground at which the camera is "looking" and
- * rotates the camera from that point around the specified vector by the
- * specified angle. Additionally zooms the camera in (deltaZoom < 0) or out
- * (deltaZoom > 0) along its direction of view by the specified amount.
- */
- public void rotateCamera (
- Vector3f spot, Vector3f axis, float deltaAngle, float deltaZoom)
- {
- // get a vector from the camera's current position to the point around
- // which we're going to orbit
- Vector3f direction = _camera.getLocation().subtract(spot);
-
- // if we're rotating around the left vector, impose tilt limits
- if (axis == _camera.getLeft()) {
- float angle = FastMath.asin(_ground.normal.dot(direction) /
- direction.length());
- float nangle = Math.min(Math.max(angle + deltaAngle, _minTilt),
- _maxTilt);
- if ((deltaAngle = nangle - angle) == 0f) {
- return;
- }
- }
-
- // create a rotation matrix
- _rotm.fromAngleAxis(deltaAngle, axis);
-
- // rotate the direction vector and the camera itself
- _rotm.mult(direction, direction);
- _rotm.mult(_camera.getUp(), _camera.getUp());
- _rotm.mult(_camera.getLeft(), _camera.getLeft());
- _rotm.mult(_camera.getDirection(), _camera.getDirection());
-
- // if we're rotating around the ground normal, we need to update our
- // notion of side-to-side and forward for panning
- if (axis == _ground.normal) {
- _rotm.mult(_rxdir, _rxdir);
- _rotm.mult(_rydir, _rydir);
- }
-
- // finally move the camera to its new location, zooming in or out in
- // the process
- float scale = 1 + (deltaZoom / direction.length());
- direction.scaleAdd(scale, spot);
- setLocation(direction);
- }
-
- /**
- * Swings the camera perpendicular to the ground normal, around the point
- * on the ground at which it is looking.
- */
- public void orbitCamera (float deltaAngle)
- {
- rotateCamera(getGroundPoint(), _ground.normal, deltaAngle, 0);
- }
-
- /**
- * Swings the camera perpendicular to its left vector around the point on
- * the ground at which it is looking.
- */
- public void tiltCamera (float deltaAngle)
- {
- rotateCamera(getGroundPoint(), _camera.getLeft(), deltaAngle, 0);
- }
-
- /**
- * Returns the point on the ground (z = 0) at which the camera is looking.
- */
- public Vector3f getGroundPoint ()
- {
- float dist = -1f * _ground.normal.dot(_camera.getLocation()) /
- _ground.normal.dot(_camera.getDirection());
- return _camera.getLocation().add(_camera.getDirection().mult(dist));
- }
-
- /**
- * Returns the ground normal. Z is the default ground plane and the normal
- * points in the positive z direction. Do not modify this value.
- */
- public Vector3f getGroundNormal ()
- {
- return _ground.normal;
- }
-
- protected Vector3f bound (Vector3f loc)
- {
- if (!_limitsEnabled) {
- return loc;
- }
- if (_boundViaFrustum) {
- bound(_camera.getFrustumLeft(), _camera.getFrustumTop(), loc);
- bound(_camera.getFrustumLeft(), _camera.getFrustumBottom(), loc);
- bound(_camera.getFrustumRight(), _camera.getFrustumTop(), loc);
- bound(_camera.getFrustumRight(), _camera.getFrustumBottom(), loc);
- } else {
- loc.x = Math.max(Math.min(loc.x, _maxX), _minX);
- loc.y = Math.max(Math.min(loc.y, _maxY), _minY);
- }
- loc.z = Math.max(Math.min(loc.z, _maxZ), _minZ);
- return loc;
- }
-
- protected void bound (float left, float up, Vector3f loc)
- {
- // start with the location of the camera moved out into the near
- // frustum plane
- _temp.set(loc);
- _temp.scaleAdd(_camera.getFrustumNear(), _camera.getDirection(), loc);
-
- // then slide it over to a corner of the near frustum rectangle
- _temp.scaleAdd(left, _camera.getLeft(), _temp);
- _temp.scaleAdd(up, _camera.getUp(), _temp);
-
- // turn this into a vector with origin at the camera's location
- _temp.subtractLocal(loc);
- _temp.normalizeLocal();
-
- // determine the intersection of said vector with the ground plane
- float dist = -1f * _ground.normal.dot(loc) / _ground.normal.dot(_temp);
- _temp.scaleAdd(dist, _temp, loc);
-
- // we then assume that if the corner of the "viewable ground rectangle"
- // is outside our bounds that we can simply adjust the camera location
- // by the amount it is out of bounds
- if (_temp.x > _maxX) {
- loc.x -= (_temp.x - _maxX);
- } else if (_temp.x < _minX) {
- loc.x += (_minX - _temp.x);
- }
- if (_temp.y > _maxY) {
- loc.y -= (_temp.y - _maxY);
- } else if (_temp.y < _minY) {
- loc.y += (_minY - _temp.y);
- }
- }
-
- /** Used to dispatch {@link CameraPath.Observer#pathCompleted}. */
- protected static class CompletedOp implements ObserverList.ObserverOp
- {
- public CompletedOp (CameraPath path) {
- _path = path;
- }
- public boolean apply (CameraPath.Observer observer) {
- return observer.pathCompleted(_path);
- }
- protected CameraPath _path;
- }
-
- protected Camera _camera;
- protected CameraPath _campath;
- protected ObserverList _campathobs = ObserverList.newSafeInOrder();
-
- protected Matrix3f _rotm = new Matrix3f();
- protected Vector3f _temp = new Vector3f();
-
- protected boolean _boundViaFrustum, _limitsEnabled = true;
- protected float _minX = -Float.MAX_VALUE, _maxX = Float.MAX_VALUE;
- protected float _minY = -Float.MAX_VALUE, _maxY = Float.MAX_VALUE;
- protected float _minZ = -Float.MAX_VALUE, _maxZ = Float.MAX_VALUE;
- protected float _minZoom = 0f, _maxZoom = Float.MAX_VALUE;
- protected float _minTilt = -Float.MAX_VALUE, _maxTilt = Float.MAX_VALUE;
-
- protected Vector3f _rxdir = new Vector3f(1, 0, 0);
- protected Vector3f _rydir = new Vector3f(0, 1, 0);
-
- protected static final Vector3f _xdir = new Vector3f(1, 0, 0);
- protected static final Vector3f _ydir = new Vector3f(0, 1, 0);
-
- protected static final Plane _ground = new Plane(new Vector3f(0, 0, 1), 0);
-}
diff --git a/src/java/com/threerings/jme/camera/CameraPath.java b/src/java/com/threerings/jme/camera/CameraPath.java
deleted file mode 100644
index fadbcd76..00000000
--- a/src/java/com/threerings/jme/camera/CameraPath.java
+++ /dev/null
@@ -1,67 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.camera;
-
-/**
- * Used to move the camera along a particular path.
- */
-public abstract class CameraPath
-{
- /** Used to inform observers when a camera path is completed or aborted. */
- public interface Observer
- {
- /**
- * Called when this path is finished (potentially early because another
- * path was set before this path completed).
- *
- * @param path the path that was completed.
- *
- * @return true if the observer should remain in the list, false if it
- * should be removed following this notification.
- */
- public boolean pathCompleted (CameraPath path);
- }
-
- /**
- * This is called on every frame to allow the path to adjust the position
- * of the camera.
- *
- * @return true if the path is completed and can be disposed, false if it
- * is not yet completed.
- */
- public abstract boolean tick (float secondsSince);
-
- /**
- * Called if this path is aborted prior to completion due to being replaced
- * by a new camera path.
- */
- public void abort ()
- {
- }
-
- protected CameraPath (CameraHandler camhand)
- {
- _camhand = camhand;
- }
-
- protected CameraHandler _camhand;
-}
diff --git a/src/java/com/threerings/jme/camera/GodViewHandler.java b/src/java/com/threerings/jme/camera/GodViewHandler.java
deleted file mode 100644
index 9a7a4dce..00000000
--- a/src/java/com/threerings/jme/camera/GodViewHandler.java
+++ /dev/null
@@ -1,202 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.camera;
-
-import com.jme.math.FastMath;
-
-import com.jme.input.InputHandler;
-import com.jme.input.KeyBindingManager;
-import com.jme.input.KeyInput;
-import com.jme.input.action.*;
-import com.jme.input.action.InputActionEvent;
-
-/**
- * Sets up camera controls for moving around from a top-down perspective,
- * suitable for strategy games and their ilk. The "ground" is assumed to be the
- * XY plane.
- */
-public class GodViewHandler extends InputHandler
-{
- /**
- * Creates the handler.
- *
- * @param camhand The camera to move with this handler.
- */
- public GodViewHandler (CameraHandler camhand)
- {
- _camhand = camhand;
- setKeyBindings();
- addActions();
- }
-
- protected void setKeyBindings ()
- {
- KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
-
- // the key bindings for the pan actions
- keyboard.set("forward", KeyInput.KEY_W);
- keyboard.set("arrow_forward", KeyInput.KEY_UP);
- keyboard.set("backward", KeyInput.KEY_S);
- keyboard.set("arrow_backward", KeyInput.KEY_DOWN);
- keyboard.set("left", KeyInput.KEY_A);
- keyboard.set("arrow_left", KeyInput.KEY_LEFT);
- keyboard.set("right", KeyInput.KEY_D);
- keyboard.set("arrow_right", KeyInput.KEY_RIGHT);
-
- // the key bindings for the zoom actions
- keyboard.set("zoomIn", KeyInput.KEY_UP);
- keyboard.set("zoomOut", KeyInput.KEY_DOWN);
-
- // the key bindings for the orbit actions
- keyboard.set("turnRight", KeyInput.KEY_RIGHT);
- keyboard.set("turnLeft", KeyInput.KEY_LEFT);
-
- // the key bindings for the tilt actions
- keyboard.set("tiltForward", KeyInput.KEY_HOME);
- keyboard.set("tiltBack", KeyInput.KEY_END);
-
- keyboard.set("screenshot", KeyInput.KEY_F12);
- }
-
- protected void addActions ()
- {
- addAction(new KeyScreenShotAction(), "screenshot", false);
- addPanActions();
- addZoomActions();
- addOrbitActions();
- addTiltActions();
- }
-
- /**
- * Adds actions for panning the camera around the scene.
- */
- protected void addPanActions ()
- {
- InputAction forward = new InputAction() {
- public void performAction (InputActionEvent evt) {
- _camhand.panCamera(0, speed * evt.getTime());
- }
- };
- forward.setSpeed(0.5f);
- addAction(forward, "forward", true);
- addAction(forward, "arrow_forward", true);
-
- InputAction backward = new InputAction() {
- public void performAction (InputActionEvent evt) {
- _camhand.panCamera(0, -speed * evt.getTime());
- }
- };
- backward.setSpeed(0.5f);
- addAction(backward, "backward", true);
- addAction(backward, "arrow_backward", true);
-
- InputAction left = new InputAction() {
- public void performAction (InputActionEvent evt) {
- _camhand.panCamera(-speed * evt.getTime(), 0);
- }
- };
- left.setSpeed(0.5f);
- addAction(left, "left", true);
- addAction(left, "arrow_left", true);
-
- InputAction right = new InputAction() {
- public void performAction (InputActionEvent evt) {
- _camhand.panCamera(speed * evt.getTime(), 0);
- }
- };
- right.setSpeed(0.5f);
- addAction(right, "right", true);
- addAction(right, "arrow_right", true);
- }
-
- /**
- * Adds actions for zooming the camaera in and out.
- */
- protected void addZoomActions ()
- {
- InputAction zoomIn = new InputAction() {
- public void performAction (InputActionEvent evt) {
- _camhand.zoomCamera(-speed * evt.getTime());
- }
- };
- zoomIn.setSpeed(0.5f);
- addAction(zoomIn, "zoomIn", true);
-
- InputAction zoomOut = new InputAction() {
- public void performAction (InputActionEvent evt) {
- _camhand.zoomCamera(speed * evt.getTime());
- }
- };
- zoomOut.setSpeed(0.5f);
- addAction(zoomOut, "zoomOut", true);
- }
-
- /**
- * Adds actions for orbiting the camera around the viewpoint.
- */
- protected void addOrbitActions ()
- {
- addAction(new OrbitAction(-FastMath.PI / 2), "turnRight", true);
- addAction(new OrbitAction(FastMath.PI / 2), "turnLeft", true);
- }
-
- /**
- * Adds actions for tilting the camera (rotating around the yaw axis).
- */
- protected void addTiltActions ()
- {
- addAction(new TiltAction(-FastMath.PI / 2), "tiltForward", true);
- addAction(new TiltAction(FastMath.PI / 2), "tiltBack", true);
- }
-
- protected class OrbitAction extends InputAction
- {
- public OrbitAction (float radPerSec)
- {
- _radPerSec = radPerSec;
- }
-
- public void performAction (InputActionEvent evt)
- {
- _camhand.orbitCamera(_radPerSec * evt.getTime());
- }
-
- protected float _radPerSec;
- }
-
- protected class TiltAction extends InputAction
- {
- public TiltAction (float radPerSec)
- {
- _radPerSec = radPerSec;
- }
-
- public void performAction (InputActionEvent evt)
- {
- _camhand.tiltCamera(_radPerSec * evt.getTime());
- }
-
- protected float _radPerSec;
- }
-
- protected CameraHandler _camhand;
-}
diff --git a/src/java/com/threerings/jme/camera/PanPath.java b/src/java/com/threerings/jme/camera/PanPath.java
deleted file mode 100644
index cda0b4af..00000000
--- a/src/java/com/threerings/jme/camera/PanPath.java
+++ /dev/null
@@ -1,87 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.camera;
-
-import com.jme.math.Quaternion;
-import com.jme.math.Vector3f;
-import com.jme.renderer.Camera;
-
-/**
- * Pans the camera to the specified location in the specified amount of time.
- */
-public class PanPath extends CameraPath
-{
- /**
- * Creates a panning path for the specified camera that will retain the
- * camera's current orientation.
- *
- * @param target the target position for the camera.
- * @param duration the number of seconds in which to pan the camera.
- */
- public PanPath (CameraHandler camhand, Vector3f target, float duration)
- {
- this(camhand, target, null, duration);
- }
-
- /**
- * Creates a panning path for the specified camera.
- *
- * @param target the target position for the camera.
- * @param trot the target rotation for the camera (or null to
- * keep its current orientation)
- * @param duration the number of seconds in which to pan the camera.
- */
- public PanPath (CameraHandler camhand, Vector3f target, Quaternion trot,
- float duration)
- {
- super(camhand);
-
- Camera cam = camhand.getCamera();
- _start = new Vector3f(cam.getLocation());
- _velocity = target.subtract(_start);
- _velocity.divideLocal(duration);
- if (trot != null) {
- _irot = new Quaternion();
- _irot.fromAxes(cam.getLeft(), cam.getUp(), cam.getDirection());
- _trot = trot;
- }
-
- _duration = duration;
- }
-
- // documentation inherited
- public boolean tick (float secondsSince)
- {
- _elapsed = Math.min(_elapsed + secondsSince, _duration);
- _camloc.scaleAdd(_elapsed, _velocity, _start);
- _camhand.setLocation(_camloc);
- if (_irot != null) {
- _camhand.getCamera().setAxes(_axes.slerp(_irot, _trot,
- _elapsed / _duration));
- }
- return (_elapsed >= _duration);
- }
-
- protected Vector3f _start, _velocity, _camloc = new Vector3f();
- protected Quaternion _irot, _trot, _axes = new Quaternion();
- protected float _elapsed, _duration;
-}
diff --git a/src/java/com/threerings/jme/camera/SplinePath.java b/src/java/com/threerings/jme/camera/SplinePath.java
deleted file mode 100644
index 880552f4..00000000
--- a/src/java/com/threerings/jme/camera/SplinePath.java
+++ /dev/null
@@ -1,111 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.camera;
-
-import com.jme.math.Vector3f;
-import com.jme.renderer.Camera;
-
-/**
- * Moves the camera along a cubic Hermite spline path defined by the start and
- * end locations and directions. Spline formulas obtained from
- * Wikipedia.
- */
-public class SplinePath extends CameraPath
-{
- /**
- * Creates a cubic spline path for the camera to follow.
- *
- * @param tloc the target location
- * @param tdir the target direction
- * @param axis the heading axis (typically {@link Vector3f#UNIT_Z})
- * @param duration the duration of the path
- * @param tension the tension parameter, which can range from zero to one:
- * higher tension values create a more direct path with a sharper turn,
- * lower values create a rounder path with a smoother turn
- */
- public SplinePath (CameraHandler camhand, Vector3f tloc,
- Vector3f tdir, Vector3f axis, float duration, float tension)
- {
- super(camhand);
-
- // get the spline function coefficients
- Camera cam = camhand.getCamera();
- _p0 = new Vector3f(cam.getLocation());
- _p1 = new Vector3f(tloc);
- float tscale = (1f - tension) * _p0.distance(_p1);
- _m0 = cam.getDirection().mult(tscale);
- _m1 = tdir.mult(tscale);
-
- _axis = axis;
- _duration = duration;
- }
-
- // documentation inherited
- public boolean tick (float secondsSince)
- {
- _elapsed = Math.min(_elapsed + secondsSince, _duration);
- float t = _elapsed / _duration, t2 = t*t, t3 = t2*t,
- h00 = 2*t3 - 3*t2 + 1,
- h00p = 6*t2 - 6*t,
- h10 = t3 - 2*t2 + t,
- h10p = 3*t2 - 4*t + 1,
- h01 = -2*t3 + 3*t2,
- h01p = -6*t2 + 6*t,
- h11 = t3 - t2,
- h11p = 3*t2 - 2*t;
-
- // take the derivative to find the direction
- _p0.mult(h00p, _dir);
- _dir.scaleAdd(h10p, _m0, _dir);
- _dir.scaleAdd(h01p, _p1, _dir);
- _dir.scaleAdd(h11p, _m1, _dir);
- _dir.normalizeLocal();
-
- // evaluate the spline function to find the location
- _p0.mult(h00, _loc);
- _loc.scaleAdd(h10, _m0, _loc);
- _loc.scaleAdd(h01, _p1, _loc);
- _loc.scaleAdd(h11, _m1, _loc);
-
- // compute the left and up vectors using the direction and
- // axis vectors
- Camera cam = _camhand.getCamera();
- _axis.cross(_dir, _left);
- _left.normalizeLocal();
- _dir.cross(_left, _up);
-
- // update the camera's location and orientation
- cam.setFrame(_loc, _left, _up, _dir);
-
- return _elapsed >= _duration;
- }
-
- /** The parameters of the spline. */
- Vector3f _p0, _m0, _p1, _m1, _axis;
-
- /** Working vectors. */
- Vector3f _loc = new Vector3f(), _left = new Vector3f(),
- _up = new Vector3f(), _dir = new Vector3f();
-
- /** The elapsed time and total duration. */
- float _elapsed, _duration;
-}
diff --git a/src/java/com/threerings/jme/camera/SwingPath.java b/src/java/com/threerings/jme/camera/SwingPath.java
deleted file mode 100644
index 61ccbcb4..00000000
--- a/src/java/com/threerings/jme/camera/SwingPath.java
+++ /dev/null
@@ -1,167 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.camera;
-
-import com.jme.math.FastMath;
-import com.jme.math.Quaternion;
-import com.jme.math.Vector3f;
-
-import static com.threerings.jme.Log.log;
-
-/**
- * Swings the camera around a point of interest (which should be somewhere
- * along the camera's view vector). Also optionally pans the camera and/or
- * zooms it in or out (moves it along its view vector) in the process.
- *
- *
- */
-public class SwingPath extends CameraPath
-{
- /**
- * Creates a rotating, zooming path for the specified camera.
- *
- * @param spot the point of interest around which to swing the camera.
- * @param axis the axis around which to rotate the camera.
- * @param angle the angle through which to rotate the camera.
- * @param angvel the (absolute value of the) velocity at which to rotate
- * the camera (in radians per second).
- * @param zoom the distance to zoom along the camera's view axis (negative
- * = in, positive = out).
- */
- public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f axis,
- float angle, float angvel, float zoom)
- {
- this(camhand, spot, axis, angle, angvel, null, 0f, null, zoom);
- }
-
- /**
- * Creates a rotating, panning, zooming path for the specified camera.
- *
- * @param spot the point of interest around which to swing the camera.
- * @param paxis the primary axis around which to rotate the camera.
- * @param pangle the angle through which to rotate the camera about the
- * primary axis.
- * @param angvel the (absolute value of the) velocity at which to rotate
- * the camera (in radians per second) about the primary angle.
- * @param saxis the secondary axis around which to rotate the camera, or
- * null for none
- * @param sangle the angle through which to rotate the camera about the
- * secondary axis
- * @param pan the amount to pan the camera, or null for none
- * @param zoom the distance to zoom along the camera's view axis (negative
- * = in, positive = out).
- */
- public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f paxis,
- float pangle, float angvel, Vector3f saxis, float sangle,
- Vector3f pan, float zoom)
- {
- super(camhand);
-
- if (pangle == 0) {
- log.warning("Requested to swing camera through zero degrees " +
- "[spot=" + spot + ", paxis=" + paxis +
- ", angvel=" + angvel + ", zoom=" + zoom + "].");
- pangle = 0.0001f;
- }
- if (angvel <= 0) {
- log.warning("Requested to swing camera with invalid velocity " +
- "[spot=" + spot + ", paxis=" + paxis + ", pangle=" +
- pangle + ", angvel=" + angvel + ", zoom=" + zoom +
- "].");
- angvel = FastMath.PI;
- }
-
- _spot = new Vector3f(spot);
- _paxis = paxis;
- _pangle = pangle;
- _pangvel = (pangle > 0) ? angvel : -1 * angvel;
- _saxis = (saxis == null) ? null : new Vector3f(saxis);
- _sangle = sangle;
- _sangvel = _sangle * _pangvel / _pangle;
- _pan = pan;
- if (_pan != null) {
- _panvel = _pan.mult(_pangvel / _pangle);
- _panned = new Vector3f();
- }
- _zoom = zoom;
- _zoomvel = _zoom * _pangvel / _pangle;
-
-// Log.info("Swinging camera [angle=" + _angle + ", angvel=" + _angvel +
-// ", zoom=" + _zoom + ", zoomvel=" + _zoomvel + "].");
- }
-
- // documentation inherited
- public boolean tick (float secondsSince)
- {
- float deltaPAngle = (secondsSince * _pangvel);
- float deltaSAngle = (secondsSince * _sangvel);
- float deltaZoom = (secondsSince * _zoomvel);
- _protated += deltaPAngle;
- _srotated += deltaSAngle;
- _zoomed += deltaZoom;
- if (_pan != null) {
- _panvel.mult(secondsSince, _deltaPan);
- _panned.addLocal(_deltaPan);
- }
-
- // clamp our rotation at the target angle and determine whether or not
- // we're done
- boolean done = false;
- if (_pangle > 0 && _protated > _pangle ||
- _pangle < 0 && _protated < _pangle) {
- deltaPAngle -= (_protated - _pangle);
- deltaSAngle -= (_srotated - _sangle);
- deltaZoom -= (_zoomed - _zoom);
- if (_pan != null) {
- _deltaPan.subtractLocal(_panned).addLocal(_pan);
- }
- _protated = _pangle;
- _srotated = _sangle;
- _panned = _pan;
- _zoomed = _zoom;
- done = true;
- }
-
- // have the camera handler do the necessary rotating, panning, zooming
- if (_pan != null) {
- _camhand.setLocation(
- _camhand.getCamera().getLocation().addLocal(_deltaPan));
- _spot.addLocal(_deltaPan);
- }
- _camhand.rotateCamera(_spot, _paxis, deltaPAngle, deltaZoom);
- if (_saxis != null) {
- _rot.fromAngleAxis(deltaPAngle, _paxis).multLocal(_saxis);
- _camhand.rotateCamera(_spot, _saxis, deltaSAngle, 0f);
- }
-
- return done;
- }
-
- protected Vector3f _spot, _paxis, _saxis;
- protected float _pangle, _pangvel, _protated;
- protected float _sangle, _sangvel, _srotated;
- protected Vector3f _pan, _panvel, _panned;
- protected float _zoom, _zoomvel, _zoomed;
-
- protected Quaternion _rot = new Quaternion();
- protected Vector3f _deltaPan = new Vector3f();
-}
diff --git a/src/java/com/threerings/jme/camera/rotate_zoom.dia b/src/java/com/threerings/jme/camera/rotate_zoom.dia
deleted file mode 100644
index 603bd5cc..00000000
Binary files a/src/java/com/threerings/jme/camera/rotate_zoom.dia and /dev/null differ
diff --git a/src/java/com/threerings/jme/camera/rotate_zoom.png b/src/java/com/threerings/jme/camera/rotate_zoom.png
deleted file mode 100644
index d04c2484..00000000
Binary files a/src/java/com/threerings/jme/camera/rotate_zoom.png and /dev/null differ
diff --git a/src/java/com/threerings/jme/chat/ChatView.java b/src/java/com/threerings/jme/chat/ChatView.java
deleted file mode 100644
index 5ba8af53..00000000
--- a/src/java/com/threerings/jme/chat/ChatView.java
+++ /dev/null
@@ -1,203 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.chat;
-
-import com.jme.renderer.ColorRGBA;
-
-import com.jmex.bui.BButton;
-import com.jmex.bui.BContainer;
-import com.jmex.bui.BTextArea;
-import com.jmex.bui.BTextField;
-import com.jmex.bui.event.ActionEvent;
-import com.jmex.bui.event.ActionListener;
-import com.jmex.bui.layout.BorderLayout;
-import com.jmex.bui.layout.GroupLayout;
-
-import com.threerings.crowd.chat.client.ChatDirector;
-import com.threerings.crowd.chat.client.ChatDisplay;
-import com.threerings.crowd.chat.client.SpeakService;
-import com.threerings.crowd.chat.data.ChatCodes;
-import com.threerings.crowd.chat.data.ChatMessage;
-import com.threerings.crowd.chat.data.SystemMessage;
-import com.threerings.crowd.chat.data.UserMessage;
-import com.threerings.crowd.data.PlaceObject;
-
-import com.threerings.jme.JmeContext;
-
-import static com.threerings.jme.Log.log;
-
-/**
- * Displays chat messages and allows for their input.
- */
-public class ChatView extends BContainer
- implements ChatDisplay
-{
- public ChatView (JmeContext ctx, ChatDirector chatdtr)
- {
- _chatdtr = chatdtr;
- setLayoutManager(new BorderLayout(2, 2));
- add(_text = new BTextArea(), BorderLayout.CENTER);
- _incont = new BContainer(GroupLayout.makeHStretch());
- add(_incont, BorderLayout.SOUTH);
- _incont.add(_input = new BTextField());
- _input.addListener(_inlist);
- }
-
- public void willEnterPlace (PlaceObject plobj)
- {
- setSpeakService(plobj.speakService, null);
- }
-
- public void didLeavePlace (PlaceObject plobj)
- {
- clearSpeakService();
- }
-
- public void setSpeakService (SpeakService spsvc, String localType)
- {
- if (spsvc != null) {
- _spsvc = spsvc;
- _localType = localType;
- _chatdtr.addChatDisplay(this);
- }
- }
-
- public void clearSpeakService ()
- {
- if (_spsvc != null) {
- _chatdtr.removeChatDisplay(this);
- _spsvc = null;
- _localType = null;
- }
- }
-
- public void setChatButton (BButton button)
- {
- _inBtn = button;
- _incont.add(_inBtn, GroupLayout.FIXED);
- _inBtn.addListener(_inlist);
- }
-
- /**
- * Instructs our chat input field to request focus.
- */
- public void requestFocus ()
- {
- _input.requestFocus();
- }
-
- // documentation inherited from interface ChatDisplay
- public void clear ()
- {
- if (_input.hasFocus() || _inBtn.hasFocus()) {
- _text.clearText();
- }
- }
-
- // documentation inherited from interface ChatDisplay
- public boolean displayMessage (ChatMessage msg, boolean alreadyDisplayed)
- {
- // we may be restricted in the chat types we handle
- if (!handlesType(msg.localtype)) {
- return false;
- }
-
- if (msg instanceof UserMessage) {
- UserMessage umsg = (UserMessage) msg;
- if (ChatCodes.USER_CHAT_TYPE.equals(umsg.localtype)) {
- append("[" + umsg.speaker + " whispers] ", ColorRGBA.green);
- append(umsg.message + "\n");
- } else {
- append("<" + umsg.speaker + "> ", ColorRGBA.blue);
- append(umsg.message + "\n");
- }
- return true;
-
- } else if (msg instanceof SystemMessage) {
- append(msg.message + "\n", ColorRGBA.red);
- return true;
-
- } else {
- log.warning("Received unknown message type: " + msg + ".");
- return false;
- }
- }
-
- // documentation inherited
- public void setEnabled (boolean enabled)
- {
- _input.setEnabled(enabled);
- }
-
- protected void displayError (String message)
- {
- append(message + "\n", ColorRGBA.red);
- }
-
- protected void append (String text, ColorRGBA color)
- {
- _text.appendText(text, color);
- }
-
- protected void append (String text)
- {
- _text.appendText(text);
- }
-
- protected boolean handlesType (String localType)
- {
- return _localType == null || _localType.equals(localType);
- }
-
- protected boolean handleInput (String text)
- {
- if (text.length() == 0) {
- // no empty banter
- return false;
- }
- String msg = _chatdtr.requestChat(_spsvc, text, true);
- if (msg.equals(ChatCodes.SUCCESS)) {
- return true;
- } else {
- _chatdtr.displayFeedback(null, msg);
- return false;
- }
- }
-
- /** Used to trigger sending chat (on return key or button press). */
- protected ActionListener _inlist = new ActionListener() {
- public void actionPerformed (ActionEvent event) {
- if (handleInput(_input.getText())) {
- _input.setText("");
- }
- }
- };
-
- protected ChatDirector _chatdtr;
- protected SpeakService _spsvc;
- protected String _localType;
-
- protected BTextArea _text;
- protected BContainer _incont;
- protected BTextField _input;
- protected BButton _inBtn;
-}
diff --git a/src/java/com/threerings/jme/effect/FadeInOutEffect.java b/src/java/com/threerings/jme/effect/FadeInOutEffect.java
deleted file mode 100644
index 79cd62be..00000000
--- a/src/java/com/threerings/jme/effect/FadeInOutEffect.java
+++ /dev/null
@@ -1,147 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.effect;
-
-import com.jme.math.Vector3f;
-import com.jme.renderer.ColorRGBA;
-import com.jme.renderer.Renderer;
-import com.jme.scene.Node;
-import com.jme.scene.shape.Quad;
-import com.jme.scene.state.AlphaState;
-import com.jme.system.DisplaySystem;
-
-import com.threerings.jme.util.LinearTimeFunction;
-import com.threerings.jme.util.TimeFunction;
-
-/**
- * Fades a supplied quad (or one that covers the screen) in from a solid color
- * or out to a solid color.
- */
-public class FadeInOutEffect extends Node
-{
- public FadeInOutEffect (ColorRGBA color, float startAlpha, float endAlpha,
- float duration, boolean overUI)
- {
- this(color, new LinearTimeFunction(startAlpha, endAlpha, duration),
- overUI);
- }
-
- public FadeInOutEffect (ColorRGBA color, TimeFunction alphaFunc,
- boolean overUI)
- {
- this(null, color, alphaFunc, overUI);
- setQuad(createCurtain());
- }
-
- public FadeInOutEffect (Quad quad, ColorRGBA color, TimeFunction alphaFunc,
- boolean overUI)
- {
- super("FadeInOut");
-
- _color = new ColorRGBA(
- color.r, color.g, color.b, alphaFunc.getValue(0));
- _alphaFunc = alphaFunc;
-
- DisplaySystem ds = DisplaySystem.getDisplaySystem();
- _astate = ds.getRenderer().createAlphaState();
- _astate.setBlendEnabled(true);
- _astate.setSrcFunction(AlphaState.SB_SRC_ALPHA);
- _astate.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
- _astate.setEnabled(true);
-
- if (quad != null) {
- setQuad(quad);
- }
-
- setRenderQueueMode(Renderer.QUEUE_ORTHO);
- setZOrder(overUI ? -1 : 1);
- }
-
- /**
- * Configures the quad that will be faded in or out.
- */
- public void setQuad (Quad quad)
- {
- attachChild(quad);
- quad.setDefaultColor(_color);
- quad.setRenderState(_astate);
- quad.updateRenderState();
- }
-
- /**
- * Allows the fade to be paused.
- */
- public void setPaused (boolean paused)
- {
- _paused = paused;
- }
-
- /**
- * Indicates whether or not the fade is paused.
- */
- public boolean isPaused ()
- {
- return _paused;
- }
-
- // documentation inherited
- public void updateGeometricState (float time, boolean initiator)
- {
- super.updateGeometricState(time, initiator);
- if (_paused) {
- return;
- }
-
- float alpha = _alphaFunc.getValue(time);
- _color.a = Math.min(1f, Math.max(0f, alpha));
- if (_alphaFunc.isComplete()) {
- fadeComplete();
- }
- }
-
- /**
- * Called (only once) when we have reached the end of our fade.
- * Automatically detaches this effect from the hierarchy.
- */
- protected void fadeComplete ()
- {
- getParent().detachChild(this);
- }
-
- /**
- * Creates a quad that covers the entire screen for full-screen fades.
- */
- protected Quad createCurtain ()
- {
- // create a quad the size of the screen
- DisplaySystem ds = DisplaySystem.getDisplaySystem();
- float width = ds.getWidth(), height = ds.getHeight();
- Quad curtain = new Quad("curtain" + hashCode(), width, height);
- curtain.setLocalTranslation(new Vector3f(width/2, height/2, 0f));
- return curtain;
- }
-
- protected ColorRGBA _color;
- protected AlphaState _astate;
- protected TimeFunction _alphaFunc;
- protected boolean _paused;
-}
diff --git a/src/java/com/threerings/jme/effect/WindowSlider.java b/src/java/com/threerings/jme/effect/WindowSlider.java
deleted file mode 100644
index 7b397703..00000000
--- a/src/java/com/threerings/jme/effect/WindowSlider.java
+++ /dev/null
@@ -1,157 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.effect;
-
-import com.jme.scene.Node;
-import com.jme.system.DisplaySystem;
-
-import com.jmex.bui.BWindow;
-
-import com.threerings.jme.util.LinearTimeFunction;
-import com.threerings.jme.util.TimeFunction;
-
-/**
- * Slides a window onto the center of the screen from offscreen or offscreen
- * from the center of the screen.
- */
-public class WindowSlider extends Node
-{
- // slides from the specified location into the center of the screen
- public static final int FROM_TOP = 0;
- public static final int FROM_RIGHT = 1;
-
- // slides from the center of the screen off screen in the specified direction
- public static final int TO_TOP = 2;
- public static final int TO_RIGHT = 3;
-
- // slides down from the specified location stopping when whole window is visible (window
- // remains "stuck" to the edge from which it slid in)
- public static final int FROM_TOP_STICKY = 4;
-
- /**
- * Creates a window slider with the specified mode and window that will
- * slide the window either onto or off of the screen in the specified
- * number of seconds.
- *
- * @param dx an offset applied to the starting or destination position
- * along the x axis (starting for sliding off, destination for sliding on).
- * @param dy an offset applied along the y axis.
- */
- public WindowSlider (BWindow window, int mode, float duration,
- int dx, int dy)
- {
- super("slider");
-
- DisplaySystem ds = DisplaySystem.getDisplaySystem();
- int swidth = ds.getWidth(), sheight = ds.getHeight();
- int wwidth = window.getWidth(), wheight = window.getHeight();
-
- int start = 0, end = 0;
- switch (mode) {
- case FROM_TOP:
- start = sheight+wheight;
- end = (sheight-wheight)/2 + dy;
- window.setLocation((swidth-wwidth)/2 + dx, start);
- break;
-
- case FROM_RIGHT:
- start = swidth+wwidth;
- end = (swidth-wwidth)/2 + dx;
- window.setLocation(start, (sheight-wheight)/2 + dy);
- break;
-
- case TO_TOP:
- start = (sheight-wheight)/2 + dy;
- end = sheight+wheight;
- window.setLocation((swidth-wwidth)/2 + dx, start);
- break;
-
- case TO_RIGHT:
- start = (swidth-wwidth)/2 + dx;
- end = swidth+wwidth;
- window.setLocation(start, (sheight-wheight)/2 + dy);
- break;
-
- case FROM_TOP_STICKY:
- start = sheight+wheight;
- end = sheight-wheight + dy;
- window.setLocation((swidth-wwidth)/2 + dx, start);
- }
-
- _mode = mode;
- _window = window;
- _tfunc = new LinearTimeFunction(start, end, duration);
- }
-
- /**
- * Allows some number of ticks to be skipped to give the window that is
- * being slid a chance to be layed out before we start keeping track of
- * time. The layout may be expensive and cause the frame rate to drop for a
- * frame or two, thus booching our smooth sliding onto the screen.
- */
- public void setSkipTicks (int skipTicks)
- {
- _skipTicks = skipTicks;
- }
-
- // documentation inherited
- public void updateGeometricState (float time, boolean initiator)
- {
- super.updateGeometricState(time, initiator);
-
- // skip ticks as long as we need to
- if (_skipTicks-- > 0) {
- return;
- }
-
- int winx, winy;
- if (_mode % 2 == 1) {
- winx = (int)_tfunc.getValue(time);
- winy = _window.getY();
- } else {
- winx = _window.getX();
- winy = (int)_tfunc.getValue(time);
- }
- _window.setLocation(winx, winy);
-
- if (_tfunc.isComplete()) {
- slideComplete();
- }
- }
-
- /**
- * Called (only once) when we have reached the end of our slide.
- * Automatically detaches this effect from the hierarchy.
- */
- protected void slideComplete ()
- {
- getParent().detachChild(this);
- }
-
- protected int _mode;
- protected BWindow _window;
- protected TimeFunction _tfunc;
-
- // skip two frames by default as that generally handles the normal window
- // layout process
- protected int _skipTicks = 2;
-}
diff --git a/src/java/com/threerings/jme/model/BillboardController.java b/src/java/com/threerings/jme/model/BillboardController.java
deleted file mode 100644
index 60d14738..00000000
--- a/src/java/com/threerings/jme/model/BillboardController.java
+++ /dev/null
@@ -1,177 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.IOException;
-
-import java.util.Properties;
-
-import com.jme.math.FastMath;
-import com.jme.math.Quaternion;
-import com.jme.math.Vector3f;
-import com.jme.renderer.Camera;
-import com.jme.scene.Controller;
-import com.jme.scene.Spatial;
-import com.jme.system.DisplaySystem;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-
-/**
- * Orients its target towards the camera plane.
- */
-public class BillboardController extends ModelController
-{
- /** Determines how the billboard is rotated. */
- public enum Alignment {
- DIR_X_POS_Z(false, true),
- DIR_X_DIR_Z(false, false),
- POS_X_POS_Z(true, true),
- DIR_Z(false),
- POS_Z(true);
-
- /** Determines whether rotation is limited to the Z axis. */
- public boolean isAxial () {
- return _axial;
- }
-
- /** Determines whether to tilt in the direction of the vector from the eyepoint to the
- * target's origin (the eye vector) as opposed to the camera direction. */
- public boolean isEyeRelativeX () {
- return _eyeRelativeX;
- }
-
- /** Determines whether to swivel in the direction of the eye vector as opposed to the
- * camera direction. */
- public boolean isEyeRelativeZ () {
- return _eyeRelativeZ;
- }
-
- Alignment (boolean eyeRelativeX, boolean eyeRelativeZ) {
- _eyeRelativeX = eyeRelativeX;
- _eyeRelativeZ = eyeRelativeZ;
- }
-
- Alignment (boolean eyeRelativeZ) {
- _axial = true;
- _eyeRelativeZ = eyeRelativeZ;
- }
-
- protected boolean _axial, _eyeRelativeX, _eyeRelativeZ;
- };
-
- @Override
- public void configure (Properties props, Spatial target)
- {
- super.configure(props, target);
- _alignment = Enum.valueOf(Alignment.class,
- props.getProperty("alignment", "dir_x_pos_z").toUpperCase());
- }
-
- // documentation inherited
- public void update (float time)
- {
- Camera cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();
- if (!isActive() || cam == null) {
- return;
- }
- if (_alignment.isEyeRelativeZ()) {
- _target.getWorldTranslation().subtract(cam.getLocation(), _yvec);
- } else {
- _yvec.set(cam.getDirection());
- }
- _zvec.set(_alignment.isAxial() ? Vector3f.UNIT_Z : cam.getUp());
- if (_alignment.isEyeRelativeX()) {
- // use the forward vector as-is
- _yvec.normalizeLocal().cross(_zvec, _xvec);
- if (_xvec.length() < FastMath.FLT_EPSILON) {
- return;
- }
- _xvec.normalizeLocal().cross(_yvec, _zvec);
-
- } else {
- // project the forward vector onto the up plane
- _yvec.scaleAdd(-_zvec.dot(_yvec), _zvec, _yvec);
- if (_yvec.length() < FastMath.FLT_EPSILON) {
- return;
- }
- _yvec.normalizeLocal().cross(_zvec, _xvec);
- }
- // compute the world rotation with the axes and rotate into
- // parent's coordinate system
- Quaternion lrot = _target.getLocalRotation();
- lrot.fromAxes(_xvec, _yvec, _zvec);
- Spatial parent = _target.getParent();
- if (parent == null) {
- _rot.loadIdentity();
- } else {
- _rot.set(parent.getWorldRotation()).inverseLocal();
- }
- _rot.mult(lrot, lrot);
- }
-
- @Override
- public Controller putClone (
- Controller store, Model.CloneCreator properties)
- {
- BillboardController bstore;
- if (store == null) {
- bstore = new BillboardController();
- } else {
- bstore = (BillboardController)store;
- }
- super.putClone(bstore, properties);
- bstore._alignment = _alignment;
- return bstore;
- }
-
- @Override
- public void read (JMEImporter im)
- throws IOException
- {
- super.read(im);
- InputCapsule capsule = im.getCapsule(this);
- _alignment = Enum.valueOf(Alignment.class,
- capsule.readString("alignment", "DIR_X_POS_Z"));
- }
-
- @Override
- public void write (JMEExporter ex)
- throws IOException
- {
- super.write(ex);
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(_alignment.name(), "alignment", "DIR_X_POS_Z");
- }
-
- /** The alignment mode. */
- protected Alignment _alignment;
-
- /** A temporary quaternion. */
- protected Quaternion _rot = new Quaternion();
-
- /** Temporary axis vectors. */
- protected Vector3f _xvec = new Vector3f(), _yvec = new Vector3f(), _zvec = new Vector3f();
-
- private static final long serialVersionUID = 1;
-}
diff --git a/src/java/com/threerings/jme/model/EmissionController.java b/src/java/com/threerings/jme/model/EmissionController.java
deleted file mode 100644
index d353fbd1..00000000
--- a/src/java/com/threerings/jme/model/EmissionController.java
+++ /dev/null
@@ -1,97 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.IOException;
-
-import java.util.Properties;
-
-import com.jme.scene.Controller;
-import com.jme.scene.Spatial;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-
-/**
- * A model controller whose target represents an emitter.
- */
-public abstract class EmissionController extends ModelController
-{
- @Override
- public void configure (Properties props, Spatial target)
- {
- super.configure(props, target);
- _hideTarget = Boolean.parseBoolean(
- props.getProperty("hide_target", "true"));
- }
-
- @Override
- public void init (Model model)
- {
- super.init(model);
- if (_hideTarget) {
- _target.setCullMode(Spatial.CULL_ALWAYS);
- if (_target instanceof ModelNode) {
- // make sure the node isn't turned back on by an
- // animation
- ((ModelNode)_target).setForceCull(true);
- }
- }
- }
-
- @Override
- public Controller putClone (
- Controller store, Model.CloneCreator properties)
- {
- if (store == null) {
- return null;
- }
- EmissionController estore = (EmissionController)store;
- super.putClone(estore, properties);
- estore._hideTarget = _hideTarget;
- return estore;
- }
-
- @Override
- public void read (JMEImporter im)
- throws IOException
- {
- super.read(im);
- InputCapsule capsule = im.getCapsule(this);
- _hideTarget = capsule.readBoolean("hideTarget", true);
- }
-
- @Override
- public void write (JMEExporter ex)
- throws IOException
- {
- super.write(ex);
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(_hideTarget, "hideTarget", true);
- }
-
- /** Whether or not the target should be hidden from view. */
- protected boolean _hideTarget;
-
- private static final long serialVersionUID = 1;
-}
diff --git a/src/java/com/threerings/jme/model/Model.java b/src/java/com/threerings/jme/model/Model.java
deleted file mode 100644
index 82995fa5..00000000
--- a/src/java/com/threerings/jme/model/Model.java
+++ /dev/null
@@ -1,1194 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import java.nio.FloatBuffer;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
-import com.jme.bounding.BoundingVolume;
-import com.jme.math.Quaternion;
-import com.jme.math.Vector3f;
-import com.jme.renderer.Camera;
-import com.jme.renderer.Renderer;
-import com.jme.scene.Controller;
-import com.jme.scene.Node;
-import com.jme.scene.Spatial;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-import com.jme.util.export.Savable;
-import com.jme.util.export.binary.BinaryExporter;
-import com.jme.util.export.binary.BinaryImporter;
-
-import com.samskivert.util.ArrayUtil;
-import com.samskivert.util.ObserverList;
-import com.samskivert.util.PropertiesUtil;
-import com.samskivert.util.RandomUtil;
-import com.samskivert.util.StringUtil;
-
-import com.threerings.jme.util.SpatialVisitor;
-
-import static com.threerings.jme.Log.log;
-
-/**
- * The base node for models.
- */
-public class Model extends ModelNode
-{
- /** The supported types of animation in decreasing order of complexity. */
- public enum AnimationMode {
- SKIN, MORPH, FLIPBOOK
- };
-
- /** Lets listeners know when animations are completed (which only happens
- * for non-repeating animations) or cancelled. */
- public interface AnimationObserver
- {
- /**
- * Called when an animation has started.
- *
- * @return true to remain on the observer list, false to remove self
- */
- public boolean animationStarted (Model model, String anim);
-
- /**
- * Called when a non-repeating animation has finished.
- *
- * @return true to remain on the observer list, false to remove self
- */
- public boolean animationCompleted (Model model, String anim);
-
- /**
- * Called when an animation has been cancelled.
- *
- * @return true to remain on the observer list, false to remove self
- */
- public boolean animationCancelled (Model model, String anim);
- }
-
- /** An animation for the model. */
- public static class Animation
- implements Savable
- {
- /** The rate of the animation in frames per second. */
- public int frameRate;
-
- /** The animation repeat type ({@link Controller#RT_CLAMP},
- * {@link Controller#RT_CYCLE}, or {@link Controller#RT_WRAP}). */
- public int repeatType;
-
- /** Any nodes visible that never move within the model. */
- public Spatial[] staticTargets;
-
- /** The transformation targets of the animation. */
- public Spatial[] transformTargets;
-
- /** The animation transforms (one transform per target per frame). */
- public transient Transform[][] transforms;
-
- /** Uniquely identifies this animation within the model. */
- public transient int animId;
-
- /** For each frame, whether the frame has been stored in meshes. */
- public transient boolean[] stored;
-
- /**
- * Returns this animation's duration in seconds.
- */
- public float getDuration ()
- {
- return (float)transforms.length / frameRate;
- }
-
- /**
- * Rebinds this animation for a prototype instance.
- *
- * @param pnodes a mapping from prototype nodes to instance nodes
- */
- public Animation rebind (Map pnodes)
- {
- Animation anim = new Animation();
- anim.frameRate = frameRate;
- anim.repeatType = repeatType;
- anim.staticTargets = rebind(staticTargets, pnodes);
- anim.transformTargets = rebind(transformTargets, pnodes);
- anim.transforms = transforms;
- anim.animId = animId;
- anim.stored = stored;
- return anim;
- }
-
- /**
- * Applies the transforms for a frame of this animation.
- */
- public void applyFrame (int fidx)
- {
- Transform[] xforms = transforms[fidx];
- for (int ii = 0; ii < transformTargets.length; ii++) {
- xforms[ii].apply(transformTargets[ii]);
- }
- }
-
- /**
- * Blends the transforms between two frames of this animation.
- */
- public void blendFrames (int fidx, int nidx, float alpha)
- {
- Transform[] xforms = transforms[fidx], nxforms = transforms[nidx];
- for (int ii = 0; ii < transformTargets.length; ii++) {
- xforms[ii].blend(nxforms[ii], alpha, transformTargets[ii]);
- }
- }
-
- // documentation inherited
- public Class> getClassTag ()
- {
- return getClass();
- }
-
- // documentation inherited
- public void read (JMEImporter im)
- throws IOException
- {
- InputCapsule capsule = im.getCapsule(this);
- frameRate = capsule.readInt("frameRate", 0);
- repeatType = capsule.readInt("repeatType", Controller.RT_CLAMP);
- staticTargets = ArrayUtil.copy(capsule.readSavableArray(
- "staticTargets", null), new Spatial[0]);
- transformTargets = ArrayUtil.copy(capsule.readSavableArray(
- "transformTargets", null), new Spatial[0]);
- FloatBuffer pxforms = capsule.readFloatBuffer("transforms", null);
- transforms = new Transform[pxforms.capacity() /
- Transform.PACKED_SIZE / transformTargets.length][];
- for (int ii = 0; ii < transforms.length; ii++) {
- Transform[] frame = transforms[ii] =
- new Transform[transformTargets.length];
- for (int jj = 0; jj < frame.length; jj++) {
- frame[jj] = new Transform(pxforms);
- }
- }
- }
-
- // documentation inherited
- public void write (JMEExporter ex)
- throws IOException
- {
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(frameRate, "frameRate", 0);
- capsule.write(repeatType, "repeatType", Controller.RT_CLAMP);
- capsule.write(staticTargets, "staticTargets", null);
- capsule.write(transformTargets, "transformTargets", null);
- FloatBuffer pxforms = FloatBuffer.allocate(
- transforms.length * transformTargets.length * Transform.PACKED_SIZE);
- for (Transform[] frame : transforms) {
- for (Transform xform : frame) {
- xform.writeToBuffer(pxforms);
- }
- }
- pxforms.rewind();
- capsule.write(pxforms, "transforms", null);
- }
-
- protected Spatial[] rebind (Spatial[] targets, Map pnodes)
- {
- Spatial[] ntargets = new Spatial[targets.length];
- for (int ii = 0; ii < targets.length; ii++) {
- ntargets[ii] = (Spatial)pnodes.get(targets[ii]);
- }
- return ntargets;
- }
-
- private static final long serialVersionUID = 1;
- }
-
- /** A frame element that manipulates the target's transform. */
- public static final class Transform
- {
- /** The number of floats required to store a packed transform. */
- public static final int PACKED_SIZE = 3 + 4 + 3;
-
- public Transform (
- Vector3f translation, Quaternion rotation, Vector3f scale)
- {
- _translation = translation;
- _rotation = rotation;
- _scale = scale;
- }
-
- public Transform (FloatBuffer buf)
- {
- _translation = new Vector3f(buf.get(), buf.get(), buf.get());
- _rotation = new Quaternion(buf.get(), buf.get(), buf.get(),
- buf.get());
- _scale = new Vector3f(buf.get(), buf.get(), buf.get());
- }
-
- public void apply (Spatial target)
- {
- target.getLocalTranslation().set(_translation);
- target.getLocalRotation().set(_rotation);
- target.getLocalScale().set(_scale);
- }
-
- /**
- * Blends between this transform and the next, applying the result to
- * the given target.
- *
- * @param alpha the blend factor: 0.0 for entirely this frame, 1.0 for
- * entirely the next
- */
- public void blend (Transform next, float alpha, Spatial target)
- {
- target.getLocalTranslation().interpolate(_translation,
- next._translation, alpha);
- target.getLocalRotation().slerp(_rotation, next._rotation, alpha);
- target.getLocalScale().interpolate(_scale, next._scale, alpha);
- }
-
- /**
- * Writes this transform to the current position in the supplied
- * buffer.
- */
- public void writeToBuffer (FloatBuffer buf)
- {
- buf.put(_translation.x);
- buf.put(_translation.y);
- buf.put(_translation.z);
-
- buf.put(_rotation.x);
- buf.put(_rotation.y);
- buf.put(_rotation.z);
- buf.put(_rotation.w);
-
- buf.put(_scale.x);
- buf.put(_scale.y);
- buf.put(_scale.z);
- }
-
- /** The transform at this frame. */
- protected Vector3f _translation, _scale;
- protected Quaternion _rotation;
- }
-
- /** Customized clone creator for models. */
- public static class CloneCreator
- {
- /** A shared seed used to select textures consistently. */
- public int random;
-
- /** Maps original objects to their copies. */
- public Map originalToCopy = Maps.newHashMap();
-
- public CloneCreator (Model toCopy)
- {
- _toCopy = toCopy;
- addProperty("vertices");
- addProperty("colors");
- addProperty("normals");
- addProperty("texcoords");
- addProperty("vboinfo");
- addProperty("indices");
- addProperty("obbtree");
- addProperty("displaylistid");
- addProperty("bound");
- }
-
- /**
- * Sets the named property.
- */
- public void addProperty (String name)
- {
- _properties.add(name);
- }
-
- /**
- * Clears the named property.
- */
- public void removeProperty (String name)
- {
- _properties.remove(name);
- }
-
- /**
- * Checks whether the named property has been set.
- */
- public boolean isSet (String name)
- {
- return _properties.contains(name);
- }
-
- /**
- * Creates a new copy of the target model.
- */
- public Model createCopy ()
- {
- random = RandomUtil.getInt(Integer.MAX_VALUE);
- Model copy = (Model)_toCopy.putClone(null, this);
- originalToCopy.clear(); // make sure no references remain
- return copy;
- }
-
- /** The model to copy. */
- protected Model _toCopy;
-
- /** The set of added properties. */
- protected HashSet _properties = Sets.newHashSet();
- }
-
- /**
- * Attempts to read a model from the specified file.
- */
- public static Model readFromFile (File file)
- throws IOException
- {
- // read the serialized model and its children
- FileInputStream fis = new FileInputStream(file);
- Model model = (Model)BinaryImporter.getInstance().load(fis);
- fis.close();
-
- // initialize the model as a prototype
- model.initPrototype();
-
- return model;
- }
-
- /**
- * No-arg constructor for deserialization.
- */
- public Model ()
- {
- }
-
- /**
- * Standard constructor.
- */
- public Model (String name, Properties props)
- {
- super(name);
- _props = props;
- }
-
- /**
- * Returns a reference to the properties of the model.
- */
- public Properties getProperties ()
- {
- return _props;
- }
-
- /**
- * Initializes this model as prototype. Only necessary when the prototype
- * was not loaded through {@link #readFromFile}.
- */
- public void initPrototype ()
- {
- // initialize shared transient animation state
- if (_anims != null) {
- int nextId = 1;
- for (Animation anim : _anims.values()) {
- anim.animId = nextId++;
- anim.stored = new boolean[anim.transforms.length];
- }
- }
- setReferenceTransforms();
- cullInvisibleNodes();
- initInstance();
- }
-
- /**
- * Returns the names of the model's variant configurations.
- */
- public String[] getVariantNames ()
- {
- return StringUtil.parseStringArray(_props.getProperty("variants", ""));
- }
-
- /**
- * Adds an animation to the model's library. This should only be called by
- * the model compiler.
- */
- public void addAnimation (String name, Animation anim)
- {
- if (_anims == null) {
- _anims = Maps.newHashMap();
- }
- _anims.put(name, anim);
-
- // store the original transforms
- Transform[] oxforms = new Transform[anim.transformTargets.length];
- for (int ii = 0; ii < anim.transformTargets.length; ii++) {
- Spatial target = anim.transformTargets[ii];
- oxforms[ii] = new Transform(
- new Vector3f(target.getLocalTranslation()),
- new Quaternion(target.getLocalRotation()),
- new Vector3f(target.getLocalScale()));
- }
-
- // run through every frame of the animation, expanding the bounding
- // volumes of any deformable meshes
- for (int ii = 0; ii < anim.transforms.length; ii++) {
- for (int jj = 0; jj < anim.transforms[ii].length; jj++) {
- anim.transforms[ii][jj].apply(anim.transformTargets[jj]);
- }
- updateWorldData(0f);
- expandModelBounds();
- }
-
- // restore the original transforms
- for (int ii = 0; ii < anim.transformTargets.length; ii++) {
- oxforms[ii].apply(anim.transformTargets[ii]);
- }
- updateWorldData(0f);
- }
-
- /**
- * Sets the animation mode to use for this model. This should be set
- * on the prototype before any animations are started or any instances
- * are created.
- */
- public void setAnimationMode (AnimationMode mode)
- {
- _animMode = mode;
- }
-
- /**
- * Returns the animation mode configured for this model.
- */
- public AnimationMode getAnimationMode ()
- {
- return _animMode;
- }
-
- /**
- * Returns the names of the model's animations.
- */
- public String[] getAnimationNames ()
- {
- if (_prototype != null) {
- return _prototype.getAnimationNames();
- }
- return (_anims == null) ? new String[0] :
- _anims.keySet().toArray(new String[_anims.size()]);
- }
-
- /**
- * Checks whether the unit has an animation with the given name.
- */
- public boolean hasAnimation (String name)
- {
- if (_prototype != null) {
- return _prototype.hasAnimation(name);
- }
- return (_anims == null) ? false : _anims.containsKey(name);
- }
-
- /**
- * Starts the named animation.
- *
- * @return the duration of the started animation (for looping animations,
- * the duration of one cycle), or -1 if the animation was not found
- */
- public float startAnimation (String name)
- {
- return startAnimation (name, 0, +1);
- }
-
- /**
- * Starts the named animation.
- *
- * @param fidx the frame to start with
- * @param fdir the direction to go (+1 forward, -1 backward)
- *
- * @return the duration of the started animation (for looping animations,
- * the duration of one cycle), or -1 if the animation was not found
- */
- public float startAnimation (String name, int fidx, int fdir)
- {
- Animation anim = getAnimation(name);
- if (anim == null) {
- return -1f;
- }
- if (_anim != null) {
- _animObservers.apply(new AnimCancelledOp(_animName));
- }
-
- // first cull all model nodes, then re-activate the ones in the target lists
- cullModelNodes();
- for (Spatial target : anim.staticTargets) {
- ((ModelNode)target).updateCullMode();
- }
- for (Spatial target : anim.transformTargets) {
- ((ModelNode)target).updateCullMode();
- }
-
- _paused = false;
- _anim = anim;
- _animName = name;
- _fidx = fidx;
- _nidx = fidx;
- _fdir = fdir;
- _elapsed = 0f;
- advanceFrameCounter();
- _animObservers.apply(new AnimStartedOp(_animName));
- return anim.getDuration() / _animSpeed;
- }
-
- /**
- * Fast-forwards the current animation by the given number of seconds.
- */
- public void fastForwardAnimation (float time)
- {
- updateAnimation(time);
- }
-
- /**
- * Gets a reference to the animation with the given name.
- */
- public Animation getAnimation (String name)
- {
- if (_anims == null) {
- return null;
- }
- Animation anim = _anims.get(name);
- if (anim != null) {
- return anim;
- }
- if (_prototype != null) {
- Animation panim = _prototype._anims.get(name);
- if (panim != null) {
- _anims.put(name, anim = panim.rebind(_pnodes));
- return anim;
- }
- }
- log.warning("Requested unknown animation [name=" + name + "].");
- return null;
- }
-
- /**
- * Returns a reference to the currently running animation, or
- * null if no animation is running.
- */
- public Animation getAnimation ()
- {
- return _anim;
- }
-
- /**
- * Stops the currently running animation.
- */
- public void stopAnimation ()
- {
- if (_anim == null) {
- return;
- }
- if (_outside) {
- // make sure the meshes are in the right places when we come back into view
- updateMeshes();
- }
- _paused = false;
- _anim = null;
- _animObservers.apply(new AnimCancelledOp(_animName));
- }
-
- /**
- * Sets the pause state of the animation.
- */
- public void pauseAnimation (boolean pause)
- {
- _paused = pause;
- }
-
- /**
- * Returns the pause state of the animation.
- */
- public boolean isAnimationPaused ()
- {
- return _paused;
- }
-
- /**
- * Causes the animation to start running in reverse.
- */
- public void reverseAnimation ()
- {
- _fdir *= -1;
- }
-
- /**
- * Sets the animation speed, which acts as a multiplier for the frame rate
- * of each animation.
- */
- public void setAnimationSpeed (float speed)
- {
- _animSpeed = speed;
- }
-
- /**
- * Returns the currently configured animation speed.
- */
- public float getAnimationSpeed ()
- {
- return _animSpeed;
- }
-
- /**
- * Adds an animation observer.
- */
- public void addAnimationObserver (AnimationObserver obs)
- {
- _animObservers.add(obs);
- }
-
- /**
- * Removes an animation observer.
- */
- public void removeAnimationObserver (AnimationObserver obs)
- {
- _animObservers.remove(obs);
- }
-
- /**
- * Returns a reference to the node that contains this model's emissions
- * (in world space, so the emissions do not move with the model). This
- * node is created and added when this method is first called.
- */
- public Node getEmissionNode ()
- {
- if (_emissionNode == null) {
- attachChild(_emissionNode = new Node("emissions") {
- public void updateWorldVectors () {
- worldTranslation.set(localTranslation);
- worldRotation.set(localRotation);
- worldScale.set(localScale);
- }
- });
- }
- return _emissionNode;
- }
-
- /**
- * Writes this model out to a file.
- */
- public void writeToFile (File file)
- throws IOException
- {
- // start out by writing this node and its children
- FileOutputStream fos = new FileOutputStream(file);
- BinaryExporter.getInstance().save(this, fos);
- fos.close();
- }
-
- @Override
- public void read (JMEImporter im)
- throws IOException
- {
- super.read(im);
- InputCapsule capsule = im.getCapsule(this);
- String[] propNames = capsule.readStringArray("propNames", null),
- propValues = capsule.readStringArray("propValues", null);
- _props = new Properties();
- for (int ii = 0; ii < propNames.length; ii++) {
- _props.setProperty(propNames[ii], propValues[ii]);
- }
- String[] animNames = capsule.readStringArray("animNames", null);
- if (animNames != null) {
- Savable[] animValues = capsule.readSavableArray(
- "animValues", null);
- _anims = Maps.newHashMap();
- for (int ii = 0; ii < animNames.length; ii++) {
- _anims.put(animNames[ii], (Animation)animValues[ii]);
- }
- } else {
- _anims = null;
- }
- List> controllers = capsule.readSavableArrayList("controllers", null);
- if (controllers != null) {
- for (Object ctrl : controllers) {
- addController((Controller)ctrl);
- }
- }
- }
-
- @Override
- public void write (JMEExporter ex)
- throws IOException
- {
- // don't serialize the emission node; it contains transient geometry
- // created by controllers
- if (_emissionNode != null) {
- detachChild(_emissionNode);
- }
- super.write(ex);
- if (_emissionNode != null) {
- attachChild(_emissionNode);
- }
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(_props.keySet().toArray(new String[_props.size()]),
- "propNames", null);
- capsule.write(_props.values().toArray(new String[_props.size()]),
- "propValues", null);
- if (_anims != null) {
- capsule.write(_anims.keySet().toArray(
- new String[_anims.size()]), "animNames", null);
- capsule.write(_anims.values().toArray(
- new Animation[_anims.size()]), "animValues", null);
- }
- capsule.writeSavableArrayList(getControllers(), "controllers", null);
- }
-
- @Override
- public void resolveTextures (TextureProvider tprov)
- {
- super.resolveTextures(tprov);
- for (Object ctrl : getControllers()) {
- if (ctrl instanceof ModelController) {
- ((ModelController)ctrl).resolveTextures(tprov);
- }
- }
- }
-
- /**
- * Creates a new prototype using the given variant configuration.
- * Use {@link #createInstance} on the returned prototype to create
- * additional instances of the variant.
- */
- public Model createPrototype (String variant)
- {
- if (_prototype != null) {
- return _prototype.createPrototype(variant);
- }
- // create an instance and rebind all animations
- final Model prototype = createInstance();
- if (_anims != null) {
- for (Map.Entry entry : _anims.entrySet()) {
- prototype._anims.put(entry.getKey(),
- entry.getValue().rebind(prototype._pnodes));
- }
- }
- prototype._prototype = null;
- prototype._pnodes = null;
-
- // reconfigure meshes with new variant type
- if (variant != null) {
- prototype._props = PropertiesUtil.getFilteredProperties(
- _props, variant);
- new SpatialVisitor(ModelMesh.class) {
- public void visit (ModelMesh mesh) {
- mesh.reconfigure(PropertiesUtil.getFilteredProperties(
- prototype._props, mesh.getParent().getName()));
- }
- }.traverse(prototype);
- }
- return prototype;
- }
-
- /**
- * Creates and returns a new instance of this model.
- */
- public Model createInstance ()
- {
- if (_prototype != null) {
- return _prototype.createInstance();
- }
- if (_ccreator == null) {
- _ccreator = new CloneCreator(this);
- }
- Model instance = _ccreator.createCopy();
- instance.initInstance();
- return instance;
- }
-
- /**
- * Locks the transforms and bounds of this model in the expectation that it
- * will never be moved from its current position.
- */
- public void lockInstance ()
- {
- // collect the instance's animation and controller targets and lock
- // recursively
- HashSet targets = Sets.newHashSet();
- for (String aname : getAnimationNames()) {
- Collections.addAll(targets, getAnimation(aname).transformTargets);
- }
- for (Object ctrl : getControllers()) {
- if (ctrl instanceof ModelController) {
- targets.add(((ModelController)ctrl).getTarget());
- }
- }
- lockInstance(targets);
- }
-
- @Override
- public Spatial putClone (Spatial store, CloneCreator properties)
- {
- Model mstore = (Model)properties.originalToCopy.get(this);
- if (mstore != null) {
- return mstore;
- } else if (store == null) {
- mstore = new Model(getName(), _props);
- } else {
- mstore = (Model)store;
- }
- // don't clone the emission node, as it contains transient geometry
- if (_emissionNode != null) {
- detachChild(_emissionNode);
- }
- super.putClone(mstore, properties);
- if (_emissionNode != null) {
- attachChild(_emissionNode);
- }
- mstore._prototype = this;
- if (_anims != null) {
- mstore._anims = Maps.newHashMap();
- }
- mstore._pnodes = Maps.newHashMap(properties.originalToCopy);
- mstore._animMode = _animMode;
- return mstore;
- }
-
- @Override
- public void updateGeometricState (float time, boolean initiator)
- {
- // if we were not visible the last time we were rendered, don't do a
- // full update; just update the world bound and wait until we come
- // into view
- boolean wasOutside = _outside;
- _outside = isOutsideFrustum() && worldBound != null;
-
- // slow evvvverything down by the animation speed
- time *= _animSpeed;
- if (_anim != null) {
- updateAnimation(time);
- }
-
- // update controllers and children with accumulated time
- _accum += time;
- if (_outside) {
- if ((lockedMode & LOCKED_TRANSFORMS) != 0) {
- return; // world bound will not changed
- }
- if (!wasOutside) {
- storeWorldBound();
- }
- updateWorldVectors();
- worldBound = _storedBound.transform(getWorldRotation(),
- getWorldTranslation(), getWorldScale(), worldBound);
-
- } else {
- super.updateGeometricState(_shouldAccumulate ? _accum : time,
- initiator);
- _accum = 0f;
- }
- }
-
- @Override
- public void onDraw (Renderer r)
- {
- // if we switch from invisible to visible, we have to do a last-minute
- // full update (which only works if our meshes are enqueued)
- super.onDraw(r);
- if (_outside && !isOutsideFrustum()) {
- updateWorldData(0f);
- }
- }
-
- /**
- * Transforms the current world bound into model space and stores it for
- * when the model is offscreen.
- */
- protected void storeWorldBound ()
- {
- // update the bounds with an identity transform (which will be
- // overwritten after this method is called)
- getWorldRotation().loadIdentity();
- getWorldTranslation().set(Vector3f.ZERO);
- getWorldScale().set(Vector3f.UNIT_XYZ);
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- getChild(ii).updateGeometricState(0f, false);
- }
- updateWorldBound();
-
- _storedBound = worldBound.clone(_storedBound);
- }
-
- /**
- * Determines whether this node was determined to be entirely outside the
- * view frustum.
- */
- protected boolean isOutsideFrustum ()
- {
- for (Node node = this; node != null; node = node.getParent()) {
- if (node.getLastFrustumIntersection() == Camera.OUTSIDE_FRUSTUM) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Initializes the per-instance state of this model.
- */
- protected void initInstance ()
- {
- // initialize the controllers
- for (Object ctrl : getControllers()) {
- if (ctrl instanceof ModelController) {
- ModelController mctrl = (ModelController)ctrl;
- mctrl.init(this);
- _shouldAccumulate |= mctrl.shouldAccumulate();
- }
- }
- }
-
- /**
- * Updates the model's state according to the current animation.
- */
- protected void updateAnimation (float time)
- {
- // no need to update between frames for flipbook animation
- if (_animMode == AnimationMode.FLIPBOOK && _elapsed > 0f &&
- _elapsed < 1f) {
- _elapsed += (time * _anim.frameRate);
- return;
- }
-
- // advance the frame counter if necessary
- while (_elapsed > 1f) {
- if (!_paused) {
- advanceFrameCounter();
- _elapsed -= 1f;
- } else {
- _elapsed = 1f;
- }
- }
-
- // update the target transforms and animation frame if not outside the
- // view frustum
- if (!_outside) {
- updateMeshes();
- }
-
- // if the next index is the same as this one, we are finished
- if (_fidx == _nidx && !_paused) {
- _anim = null;
- _animObservers.apply(new AnimCompletedOp(_animName));
- return;
- }
- _elapsed += (time * _anim.frameRate);
- }
-
- /**
- * Advances the frame counter by one frame.
- */
- protected void advanceFrameCounter ()
- {
- _fidx = _nidx;
- int nframes = _anim.transforms.length;
- if (_anim.repeatType == Controller.RT_CLAMP) {
- _nidx = Math.max(0, Math.min(_nidx + _fdir, nframes - 1));
-
- } else if (_anim.repeatType == Controller.RT_WRAP) {
- // % is not a modulo operator, so is not guaranteed to be positive
- _nidx = (_nidx + _fdir) % nframes;
- if (_nidx < 0) {
- _nidx += nframes;
- }
-
- } else { // _anim.repeatType == Controller.RT_CYCLE
- if ((_nidx + _fdir) < 0 || (_nidx + _fdir) >= nframes) {
- _fdir *= -1; // reverse direction
- }
- _nidx += _fdir;
- }
- }
-
- /**
- * Updates the states of the model's meshes according to the animation state.
- */
- protected void updateMeshes ()
- {
- if (_animMode == AnimationMode.FLIPBOOK) {
- int frameId = (_anim.animId << 16) | _fidx;
- _anim.applyFrame(_fidx);
- if (!_anim.stored[_fidx]) {
- storeMeshFrame(frameId, false);
- updateWorldData(0f);
- _anim.stored[_fidx] = true;
- }
- setMeshFrame(frameId);
-
- } else if (_animMode == AnimationMode.MORPH) {
- int frameId1 = (_anim.animId << 16) | _fidx,
- frameId2 = (_anim.animId << 16) | _nidx;
- if (!_anim.stored[_fidx]) {
- storeMeshFrame(frameId1, true);
- _anim.applyFrame(_fidx);
- updateWorldData(0f);
- _anim.stored[_fidx] = true;
- }
- if (!_anim.stored[_nidx]) {
- storeMeshFrame(frameId2, true);
- _anim.applyFrame(_nidx);
- updateWorldData(0f);
- _anim.stored[_nidx] = true;
- }
- _anim.blendFrames(_fidx, _nidx, _elapsed);
- blendMeshFrames(frameId1, frameId2, _elapsed);
-
- } else { // _animMode == AnimationMode.SKIN
- _anim.blendFrames(_fidx, _nidx, _elapsed);
- }
- }
-
- /** A reference to the prototype, or null if this is a prototype. */
- protected Model _prototype;
-
- /** For prototype models, a customized clone creator used to generate instances. */
- protected CloneCreator _ccreator;
-
- /** The animation mode to use for this model. */
- protected AnimationMode _animMode;
-
- /** For instances, maps prototype nodes to their corresponding instance nodes. */
- protected Map _pnodes;
-
- /** The model properties. */
- protected Properties _props;
-
- /** The model animations. */
- protected HashMap _anims;
-
- /** The currently running animation, or null for none. */
- protected Animation _anim;
-
- /** The name of the currently running animation, if any. */
- protected String _animName;
-
- /** The current animation speed multiplier. */
- protected float _animSpeed = 1f;
-
- /** The index of the current and next frames. */
- protected int _fidx, _nidx;
-
- /** The direction for wrapping animations (+1 forward, -1 backward). */
- protected int _fdir;
-
- /** The frame portion elapsed since the start of the current frame. */
- protected float _elapsed;
-
- /** The pause status of this model. */
- protected boolean _paused;
-
- /** The amount of update time accumulated while outside of view frustum. */
- protected float _accum;
-
- /** Whether or not we should accumulate update time while out of view. */
- protected boolean _shouldAccumulate;
-
- /** The child node that contains the model's emissions in world space. */
- protected Node _emissionNode;
-
- /** The model space bounding volume stored for use when the model is
- * offscreen. */
- protected BoundingVolume _storedBound;
-
- /** Whether or not we were outside the frustum at the last update. */
- protected boolean _outside;
-
- /** Animation completion listeners. */
- protected ObserverList _animObservers =
- new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
-
- /** Used to notify observers of animation initiation. */
- protected class AnimStartedOp
- implements ObserverList.ObserverOp
- {
- public AnimStartedOp (String name)
- {
- _name = name;
- }
-
- // documentation inherited from interface ObserverOp
- public boolean apply (AnimationObserver obs)
- {
- return obs.animationStarted(Model.this, _name);
- }
-
- /** The name of the animation started. */
- protected String _name;
- }
-
- /** Used to notify observers of animation completion. */
- protected class AnimCompletedOp
- implements ObserverList.ObserverOp
- {
- public AnimCompletedOp (String name)
- {
- _name = name;
- }
-
- // documentation inherited from interface ObserverOp
- public boolean apply (AnimationObserver obs)
- {
- return obs.animationCompleted(Model.this, _name);
- }
-
- /** The name of the animation completed. */
- protected String _name;
- }
-
- /** Used to notify observers of animation cancellation. */
- protected class AnimCancelledOp
- implements ObserverList.ObserverOp
- {
- public AnimCancelledOp (String name)
- {
- _name = name;
- }
-
- // documentation inherited from interface ObserverOp
- public boolean apply (AnimationObserver obs)
- {
- return obs.animationCancelled(Model.this, _name);
- }
-
- /** The name of the animation cancelled. */
- protected String _name;
- }
-
- private static final long serialVersionUID = 1;
-}
diff --git a/src/java/com/threerings/jme/model/ModelController.java b/src/java/com/threerings/jme/model/ModelController.java
deleted file mode 100644
index 91e32a25..00000000
--- a/src/java/com/threerings/jme/model/ModelController.java
+++ /dev/null
@@ -1,188 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.IOException;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Properties;
-
-import com.google.common.collect.Sets;
-
-import com.jme.scene.Controller;
-import com.jme.scene.Spatial;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-
-import com.samskivert.util.StringUtil;
-
-/**
- * The superclass of procedural animation controllers for models.
- */
-public abstract class ModelController extends Controller
-{
- /**
- * Configures this controller based on the supplied (sub-)properties and
- * controller target.
- */
- public void configure (Properties props, Spatial target)
- {
- _target = target;
- String[] anims = StringUtil.parseStringArray(
- props.getProperty("animations", ""));
- if (anims.length == 0) {
- return;
- }
- _animations = Sets.newHashSet();
- Collections.addAll(_animations, anims);
- }
-
- /**
- * Returns a reference to the controller's target.
- */
- public Spatial getTarget ()
- {
- return _target;
- }
-
- /**
- * Resolves any textures required by the controller.
- */
- public void resolveTextures (TextureProvider tprov)
- {
- }
-
- /**
- * Initializes this controller.
- */
- public void init (Model model)
- {
- model.addAnimationObserver(_animobs);
- if (_animations != null) {
- setActive(false);
- }
- }
-
- /**
- * Determines whether the controller updates should include time
- * accumulated while the model was out of sight. Accumulating will
- * be turned off only if all controllers are non-accumulating.
- */
- public boolean shouldAccumulate ()
- {
- return true;
- }
-
- /**
- * Creates or populates and returns a clone of this object using the given
- * clone properties.
- *
- * @param store an instance of this class to populate, or null
- * to create a new instance
- */
- public Controller putClone (
- Controller store, Model.CloneCreator properties)
- {
- if (store == null) {
- return null;
- }
- ModelController mstore = (ModelController)store;
- mstore._target = ((ModelSpatial)_target).putClone(null, properties);
- mstore._animations = _animations;
- return mstore;
- }
-
- @Override
- public void read (JMEImporter im)
- throws IOException
- {
- InputCapsule capsule = im.getCapsule(this);
- _target = (Spatial)capsule.readSavable("target", null);
- String[] anims = capsule.readStringArray("animations", null);
- if (anims != null) {
- _animations = Sets.newHashSet();
- Collections.addAll(_animations, anims);
- } else {
- _animations = null;
- }
- }
-
- @Override
- public void write (JMEExporter ex)
- throws IOException
- {
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(_target, "target", null);
- capsule.write((_animations == null) ?
- null : _animations.toArray(new String[_animations.size()]),
- "animations", null);
- }
-
- /**
- * Called when an animation is started on the model.
- */
- protected void animationStarted (String anim)
- {
- if (_animations != null && _animations.contains(anim)) {
- setActive(true);
- }
- }
-
- /**
- * Called when an animation is stopped on the model.
- */
- protected void animationStopped (String anim)
- {
- if (_animations != null) {
- setActive(false);
- }
- }
-
- /** The target to control. */
- protected Spatial _target;
-
- /** The animations for which this controller should be active, or
- * null for all of them. */
- protected HashSet _animations;
-
- /** Listens to the model's animation state. */
- protected Model.AnimationObserver _animobs =
- new Model.AnimationObserver() {
- public boolean animationStarted (Model model, String anim) {
- ModelController.this.animationStarted(anim);
- return true;
- }
- public boolean animationCompleted (Model model, String anim) {
- animationStopped(anim);
- return true;
- }
- public boolean animationCancelled (Model model, String anim) {
- animationStopped(anim);
- return true;
- }
- };
-
- private static final long serialVersionUID = 1;
-}
diff --git a/src/java/com/threerings/jme/model/ModelMesh.java b/src/java/com/threerings/jme/model/ModelMesh.java
deleted file mode 100644
index f5a05c13..00000000
--- a/src/java/com/threerings/jme/model/ModelMesh.java
+++ /dev/null
@@ -1,904 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.IOException;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.google.common.collect.Lists;
-
-import com.jme.bounding.BoundingBox;
-import com.jme.bounding.BoundingSphere;
-import com.jme.bounding.BoundingVolume;
-import com.jme.image.Image;
-import com.jme.image.Texture;
-import com.jme.math.FastMath;
-import com.jme.math.Quaternion;
-import com.jme.math.Vector3f;
-import com.jme.renderer.ColorRGBA;
-import com.jme.renderer.Renderer;
-import com.jme.scene.Spatial;
-import com.jme.scene.TriMesh;
-import com.jme.scene.VBOInfo;
-import com.jme.scene.batch.TriangleBatch;
-import com.jme.scene.state.AlphaState;
-import com.jme.scene.state.CullState;
-import com.jme.scene.state.FogState;
-import com.jme.scene.state.LightState;
-import com.jme.scene.state.RenderState;
-import com.jme.scene.state.TextureState;
-import com.jme.scene.state.ZBufferState;
-import com.jme.system.DisplaySystem;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-import com.jme.util.geom.BufferUtils;
-
-import com.samskivert.util.PropertiesUtil;
-import com.samskivert.util.StringUtil;
-
-import com.threerings.jme.util.ShaderCache;
-
-/**
- * A {@link TriMesh} with a serialization mechanism tailored to stored models.
- */
-public class ModelMesh extends TriMesh
- implements ModelSpatial
-{
- /**
- * No-arg constructor for deserialization.
- */
- public ModelMesh ()
- {
- super("mesh");
- }
-
- /**
- * Creates a mesh with no vertex data.
- */
- public ModelMesh (String name)
- {
- super(name);
- }
-
- @Override
- public int hashCode ()
- {
- // hash on the name rather than the identity for consistent ordering
- return getName().hashCode();
- }
-
- /**
- * Reconfigures this model with a new set of (sub-)properties. Textures
- * must be (re-)resolved after calling this method.
- */
- public void reconfigure (Properties props)
- {
- configure(_solid, _textureKey, _transparent, props);
- setRenderStates();
- }
-
- /**
- * Configures this mesh based on the given parameters and (sub-)properties.
- *
- * @param texture the texture specified in the model export, if any (can be
- * overridden by textures specified in the properties)
- * @param solid whether or not the mesh allows back face culling
- * @param transparent whether or not the mesh is (partially) transparent
- */
- public void configure (
- boolean solid, String texture, boolean transparent, Properties props)
- {
- _textureKey = texture;
- _textures = (texture == null) ? null : StringUtil.parseStringArray(
- props.getProperty(texture, texture));
- Properties tprops = PropertiesUtil.getFilteredProperties(
- props, texture);
- _sphereMapped = Boolean.parseBoolean(tprops.getProperty("sphere_map"));
- _filterMode = "nearest".equals(tprops.getProperty("filter")) ?
- Texture.FM_NEAREST : Texture.FM_LINEAR;
- _mipMapMode = getMipMapMode(tprops.getProperty("mipmap"));
- _compress = Boolean.parseBoolean(tprops.getProperty("compress", "true"));
- String emissive = tprops.getProperty("emissive");
- if (Boolean.parseBoolean(emissive)) {
- _emissive = true;
- } else {
- _emissiveMap = emissive;
- }
- _additive = Boolean.parseBoolean(tprops.getProperty("additive"));
- _solid = solid;
- _transparent = transparent;
- String threshold = tprops.getProperty("alpha_threshold");
- _alphaThreshold = (threshold == null) ?
- DEFAULT_ALPHA_THRESHOLD : Float.parseFloat(threshold);
- _translucent = _transparent &&
- Boolean.parseBoolean(tprops.getProperty("translucent"));
- }
-
- /**
- * Adjusts the vertices and the transform of the mesh so that the mesh's
- * position lies at the center of its bounding volume.
- */
- public void centerVertices ()
- {
- Vector3f offset = getBatch(0).getModelBound().getCenter().negate();
- if (!offset.equals(Vector3f.ZERO)) {
- getLocalTranslation().subtractLocal(offset);
- getBatch(0).getModelBound().getCenter().set(Vector3f.ZERO);
- getBatch(0).translatePoints(offset);
- }
- storeOriginalBuffers();
- }
-
- /**
- * Adds an overlay layer to this mesh. After the mesh is rendered with
- * its configured states, these states will be applied and the mesh will
- * be rendered again.
- */
- public void addOverlay (RenderState[] overlay)
- {
- if (_overlays == null) {
- _overlays = Lists.newArrayListWithCapacity(1);
- }
- _overlays.add(overlay);
- }
-
- /**
- * Removes a layer from this mesh.
- */
- public void removeOverlay (RenderState[] overlay)
- {
- if (_overlays != null) {
- _overlays.remove(overlay);
- if (_overlays.isEmpty()) {
- _overlays = null;
- }
- }
- }
-
- @Override
- public void reconstruct (
- FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors,
- FloatBuffer textures, IntBuffer indices)
- {
- super.reconstruct(vertices, normals, colors, textures, indices);
- for (int ii = 1, nn = getTextureCount(); ii < nn; ii++) {
- setTextureBuffer(0, getTextureBuffer(0, 0), ii);
- }
-
- // store any buffers that will be manipulated on a per-instance basis
- storeOriginalBuffers();
-
- // initialize the model if we're displaying
- setRenderStates();
- }
-
- // documentation inherited from interface ModelSpatial
- public Spatial putClone (Spatial store, Model.CloneCreator properties)
- {
- ModelMesh mstore = (ModelMesh)properties.originalToCopy.get(this);
- if (mstore != null) {
- return mstore;
- } else if (store == null) {
- mstore = new ModelMesh(getName());
- } else {
- mstore = (ModelMesh)store;
- }
- properties.originalToCopy.put(this, mstore);
- mstore.normalsMode = normalsMode;
- mstore.cullMode = cullMode;
- for (int ii = 0; ii < RenderState.RS_MAX_STATE; ii++) {
- RenderState rstate = getRenderState(ii);
- if (rstate != null) {
- mstore.setRenderState(rstate);
- }
- }
- mstore.renderQueueMode = renderQueueMode;
- mstore.lockedMode = lockedMode;
- mstore.lightCombineMode = lightCombineMode;
- mstore.textureCombineMode = textureCombineMode;
- mstore.name = name;
- mstore.isCollidable = isCollidable;
- mstore.localRotation.set(localRotation);
- mstore.localTranslation.set(localTranslation);
- mstore.localScale.set(localScale);
- for (Object controller : getControllers()) {
- if (controller instanceof ModelController) {
- mstore.addController(
- ((ModelController)controller).putClone(null, properties));
- }
- }
- TriangleBatch batch = getBatch(0), mbatch = mstore.getBatch(0);
- mbatch.setVertexBuffer(properties.isSet("vertices") ?
- batch.getVertexBuffer() :
- BufferUtils.clone(batch.getVertexBuffer()));
- mbatch.setColorBuffer(properties.isSet("colors") ?
- batch.getColorBuffer() :
- BufferUtils.clone(batch.getColorBuffer()));
- mbatch.setNormalBuffer(properties.isSet("normals") ?
- batch.getNormalBuffer() :
- BufferUtils.clone(batch.getNormalBuffer()));
- FloatBuffer texcoords;
- for (int ii = 0; (texcoords = batch.getTextureBuffer(ii)) != null;
- ii++) {
- mbatch.setTextureBuffer(properties.isSet("texcoords") ?
- texcoords : BufferUtils.clone(texcoords), ii);
- }
- mbatch.setIndexBuffer((properties.isSet("indices") && !_translucent) ?
- batch.getIndexBuffer() :
- BufferUtils.clone(batch.getIndexBuffer()));
- if (properties.isSet("vboinfo")) {
- mbatch.setVBOInfo(batch.getVBOInfo());
- }
- if (properties.isSet("obbtree")) {
- mbatch.setCollisionTree(batch.getCollisionTree());
- }
- if (properties.isSet("displaylistid")) {
- mbatch.setDisplayListID(batch.getDisplayListID());
- }
- if (batch.getModelBound() != null) {
- mbatch.setModelBound(properties.isSet("bound") ?
- batch.getModelBound() : batch.getModelBound().clone(null));
- }
- mstore._textureKey = _textureKey;
- if (_textures != null && _textures.length > 1) {
- int tidx = properties.random % _textures.length;
- mstore._textures = new String[] { _textures[tidx] };
- mstore._tstates = new TextureState[] { _tstates[tidx] };
- mstore.setRenderState(_tstates[tidx]);
- } else {
- mstore._textures = _textures;
- mstore._tstates = _tstates;
- }
- mstore._sphereMapped = _sphereMapped;
- mstore._filterMode = _filterMode;
- mstore._mipMapMode = _mipMapMode;
- mstore._compress = _compress;
- mstore._emissiveMap = _emissiveMap;
- mstore._emissive = _emissive;
- mstore._additive = _additive;
- mstore._solid = _solid;
- mstore._transparent = _transparent;
- mstore._alphaThreshold = _alphaThreshold;
- mstore._translucent = _translucent;
- mstore._oibuf = _oibuf;
- mstore._vbuf = _vbuf;
- return mstore;
- }
-
- @Override
- public void updateWorldVectors ()
- {
- if (!_transformLocked) {
- super.updateWorldVectors();
- }
- }
-
- @Override
- public void read (JMEImporter im)
- throws IOException
- {
- InputCapsule capsule = im.getCapsule(this);
- setName(capsule.readString("name", null));
- setLocalTranslation((Vector3f)capsule.readSavable(
- "localTranslation", null));
- setLocalRotation((Quaternion)capsule.readSavable(
- "localRotation", null));
- setLocalScale((Vector3f)capsule.readSavable(
- "localScale", null));
- TriangleBatch batch = getBatch(0);
- batch.setModelBound((BoundingVolume)capsule.readSavable(
- "modelBound", null));
- _textureKey = capsule.readString("textureKey", null);
- _textures = capsule.readStringArray("textures", null);
- _sphereMapped = capsule.readBoolean("sphereMapped", false);
- _filterMode = capsule.readInt("filterMode", Texture.FM_LINEAR);
- _mipMapMode = capsule.readInt("mipMapMode", Texture.MM_LINEAR_LINEAR);
- _compress = capsule.readBoolean("compress", true);
- _emissiveMap = capsule.readString("emissiveMap", null);
- _emissive = capsule.readBoolean("emissive", false);
- _additive = capsule.readBoolean("additive", false);
- _solid = capsule.readBoolean("solid", true);
- _transparent = capsule.readBoolean("transparent", false);
- _alphaThreshold = capsule.readFloat("alphaThreshold",
- DEFAULT_ALPHA_THRESHOLD);
- _translucent = capsule.readBoolean("translucent", false);
-
- reconstruct(capsule.readFloatBuffer("vertexBuffer", null),
- capsule.readFloatBuffer("normalBuffer", null), null,
- capsule.readFloatBuffer("textureBuffer", null),
- capsule.readIntBuffer("indexBuffer", null));
- }
-
- @Override
- public void write (JMEExporter ex)
- throws IOException
- {
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(getName(), "name", null);
- capsule.write(getLocalTranslation(), "localTranslation", null);
- capsule.write(getLocalRotation(), "localRotation", null);
- capsule.write(getLocalScale(), "localScale", null);
- capsule.write(getBatch(0).getModelBound(), "modelBound", null);
- capsule.write(getVertexBuffer(0), "vertexBuffer", null);
- capsule.write(getNormalBuffer(0), "normalBuffer", null);
- capsule.write(getTextureBuffer(0, 0), "textureBuffer", null);
- capsule.write(getIndexBuffer(0), "indexBuffer", null);
- capsule.write(_textureKey, "textureKey", null);
- capsule.write(_textures, "textures", null);
- capsule.write(_sphereMapped, "sphereMapped", false);
- capsule.write(_filterMode, "filterMode", Texture.FM_LINEAR);
- capsule.write(_mipMapMode, "mipMapMode", Texture.MM_LINEAR_LINEAR);
- capsule.write(_compress, "compress", true);
- capsule.write(_emissiveMap, "emissiveMap", null);
- capsule.write(_emissive, "emissive", false);
- capsule.write(_additive, "additive", false);
- capsule.write(_solid, "solid", true);
- capsule.write(_transparent, "transparent", false);
- capsule.write(_alphaThreshold, "alphaThreshold",
- DEFAULT_ALPHA_THRESHOLD);
- capsule.write(_translucent, "translucent", false);
- }
-
- // documentation inherited from interface ModelSpatial
- public void expandModelBounds ()
- {
- // no-op
- }
-
- // documentation inherited from interface ModelSpatial
- public void setReferenceTransforms ()
- {
- // no-op
- }
-
- // documentation inherited from interface ModelSpatial
- public void lockStaticMeshes (
- Renderer renderer, boolean useVBOs, boolean useDisplayLists)
- {
- if (useVBOs && renderer.supportsVBO()) {
- VBOInfo vboinfo = new VBOInfo(true);
- vboinfo.setVBOIndexEnabled(!_translucent);
- setVBOInfo(vboinfo);
-
- } else if (useDisplayLists && !_translucent) {
- lockMeshes(renderer);
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void resolveTextures (TextureProvider tprov)
- {
- if (_textures == null) {
- return;
- }
- Texture emissiveTex = null;
- if (_emissiveMap != null && TextureState.getNumberOfFixedUnits() >= 2) {
- TextureState tstate = tprov.getTexture(_emissiveMap);
- emissiveTex = tstate.getTexture();
- emissiveTex.setApply(Texture.AM_BLEND);
- emissiveTex.getBlendColor().set(ColorRGBA.white);
- }
- _tstates = new TextureState[_textures.length];
- for (int ii = 0; ii < _textures.length; ii++) {
- _tstates[ii] = tprov.getTexture(_textures[ii]);
- Texture tex = _tstates[ii].getTexture();
- if (_sphereMapped) {
- tex.setEnvironmentalMapMode(Texture.EM_SPHERE);
- }
- tex.setFilter(_filterMode);
- tex.setMipmapState(_mipMapMode);
- if (_compress && _tstates[ii].isS3TCAvailable()) {
- Image image = tex.getImage();
- int type = image.getType();
- if (type == Image.RGB888) {
- image.setType(Image.RGB888_DXT1);
- } else if (type == Image.RGBA8888) {
- image.setType(Image.RGBA8888_DXT5);
- }
- }
- if (emissiveTex != null) {
- _tstates[ii] = DisplaySystem.getDisplaySystem().
- getRenderer().createTextureState();
- _tstates[ii].setTexture(emissiveTex, 0);
- _tstates[ii].setTexture(tex, 1);
- }
- }
- if (_tstates[0] != null) {
- setRenderState(_tstates[0]);
- } else {
- clearRenderState(RenderState.RS_TEXTURE);
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void configureShaders (ShaderCache scache)
- {
- // no-op
- }
-
- // documentation inherited from interface ModelSpatial
- public void storeMeshFrame (int frameId, boolean blend)
- {
- // no-op
- }
-
- // documentation inherited from interface ModelSpatial
- public void setMeshFrame (int frameId)
- {
- // no-op
- }
-
- // documentation inherited from interface ModelSpatial
- public void blendMeshFrames (int frameId1, int frameId2, float alpha)
- {
- // no-op
- }
-
- @Override
- protected void setupBatchList ()
- {
- batchList = Lists.newArrayListWithCapacity(1);
- TriangleBatch batch = createModelBatch();
- batch.setParentGeom(this);
- batchList.add(batch);
- }
-
- /**
- * Creates a batch for this mesh.
- */
- protected ModelBatch createModelBatch ()
- {
- return new ModelBatch();
- }
-
- /**
- * Returns the number of textures this mesh uses (they must all share the
- * same texture coordinates).
- */
- protected int getTextureCount ()
- {
- return (_emissiveMap == null || TextureState.getNumberOfFixedUnits() < 2) ? 1 : 2;
- }
-
- /**
- * For buffers that must be manipulated in some fashion, this method stores
- * the originals.
- */
- protected void storeOriginalBuffers ()
- {
- if (!_translucent) {
- return;
- }
- IntBuffer ibuf = getIndexBuffer(0);
- ibuf.rewind();
- IntBuffer.wrap(_oibuf = new int[ibuf.capacity()]).put(ibuf);
-
- FloatBuffer vbuf = getVertexBuffer(0);
- vbuf.rewind();
- FloatBuffer.wrap(_vbuf = new float[vbuf.capacity()]).put(vbuf);
- }
-
- /**
- * Sets the model's render states (excluding the texture state, which is
- * set by {@link #resolveTextures}) according to its configuration.
- */
- protected void setRenderStates ()
- {
- if (DisplaySystem.getDisplaySystem() == null) {
- return;
- }
- if (_backCull == null) {
- initSharedStates();
- }
- if (_emissive) {
- setRenderState(_emissiveLight);
- }
- if (_solid) {
- setRenderState(_backCull);
- }
- if (_additive) {
- setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
- setRenderState(_addAlpha);
- setRenderState(_overlayZBuffer);
- setRenderState(_noFog);
- } else if (_transparent) {
- setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
- if (_translucent) {
- setRenderState(_blendAlpha);
- setRenderState(_overlayZBuffer);
- } else if (_alphaThreshold == DEFAULT_ALPHA_THRESHOLD) {
- setRenderState(_defaultTestAlpha);
- } else {
- setRenderState(createTestAlpha(_alphaThreshold));
- }
- }
- }
-
- /**
- * Locks the transform and bounds of this mesh on the assumption that its
- * position will not change.
- */
- protected void lockInstance ()
- {
- lockBounds();
- _transformLocked = true;
- }
-
- /**
- * Returns the mip-map mode corresponding to the given string
- * (defaulting to {@link Texture#MM_LINEAR_LINEAR}).
- */
- protected static int getMipMapMode (String mmode)
- {
- if ("none".equals(mmode)) {
- return Texture.MM_NONE;
- } else if ("nearest".equals(mmode)) {
- return Texture.MM_NEAREST;
- } else if ("linear".equals(mmode)) {
- return Texture.MM_LINEAR;
- } else if ("nearest_nearest".equals(mmode)) {
- return Texture.MM_NEAREST_NEAREST;
- } else if ("nearest_linear".equals(mmode)) {
- return Texture.MM_NEAREST_LINEAR;
- } else if ("linear_nearest".equals(mmode)) {
- return Texture.MM_LINEAR_NEAREST;
- } else {
- return Texture.MM_LINEAR_LINEAR;
- }
- }
-
- /**
- * Initializes the states shared between all models. Requires an active
- * display.
- */
- protected static void initSharedStates ()
- {
- Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
- _backCull = renderer.createCullState();
- _backCull.setCullMode(CullState.CS_BACK);
- _blendAlpha = renderer.createAlphaState();
- _blendAlpha.setBlendEnabled(true);
- _addAlpha = renderer.createAlphaState();
- _addAlpha.setBlendEnabled(true);
- _addAlpha.setDstFunction(AlphaState.DB_ONE);
- _defaultTestAlpha = createTestAlpha(DEFAULT_ALPHA_THRESHOLD);
- _overlayZBuffer = renderer.createZBufferState();
- _overlayZBuffer.setFunction(ZBufferState.CF_LEQUAL);
- _overlayZBuffer.setWritable(false);
- _emissiveLight = renderer.createLightState();
- _emissiveLight.setGlobalAmbient(ColorRGBA.white);
- _noFog = renderer.createFogState();
- _noFog.setEnabled(false);
- }
-
- /**
- * Creates an alpha state what will throw away fragments with alpha
- * values less than or equal to the given threshold.
- */
- protected static AlphaState createTestAlpha (float threshold)
- {
- AlphaState astate = DisplaySystem.getDisplaySystem().
- getRenderer().createAlphaState();
- astate.setBlendEnabled(true);
- astate.setTestEnabled(true);
- astate.setTestFunction(AlphaState.TF_GREATER);
- astate.setReference(threshold);
- return astate;
- }
-
- /**
- * Sorts the encoded triangle index/distance pairs in {@link #_tcodes}
- * using a two-pass (16 bit) radix sort (as described by
- * Pierre
- * Terdiman. {@link #_bcounts} is assumed to be initialized to the
- * counts for the first radix.
- */
- protected static void sortTriangleCodes (int tcount)
- {
- // initialize the offsets for the first radix (LSB) and clear
- // the counts
- initByteOffsets();
-
- // sort by the first radix and get the counts for the second
- // (swapping directions in the hope of using the cache more
- // effectively)
- if (_stcodes == null || _stcodes.length < tcount) {
- _stcodes = new int[tcount];
- }
- int tcode;
- for (int ii = tcount - 1; ii >= 0; ii--) {
- tcode = _tcodes[ii];
- _stcodes[_boffsets[tcode & 0xFF]++] = tcode;
- _bcounts[(tcode >> 8) & 0xFF]++;
- }
-
- // initialize offsets for the second radix, clear counts, and
- // sort by the second radix
- initByteOffsets();
- for (int ii = 0; ii < tcount; ii++) {
- tcode = _stcodes[ii];
- _tcodes[_boffsets[(tcode >> 8) & 0xFF]++] = tcode;
- }
- }
-
- /**
- * Sets the initial byte offsets used to place bytes within the sorted
- * array using the byte counts, clearing the counts in the process.
- */
- protected static void initByteOffsets ()
- {
- _boffsets[0] = 0;
- for (int ii = 1; ii < 256; ii++) {
- _boffsets[ii] = _boffsets[ii - 1] + _bcounts[ii - 1];
- _bcounts[ii - 1] = 0;
- }
- _bcounts[255] = 0;
- }
-
- /** Sorts triangles for transparent meshes and renders overlays as well as
- * the base layer. */
- protected class ModelBatch extends TriangleBatch
- {
- @Override
- public void draw (Renderer r)
- {
- boolean drawing = (isEnabled() && r.isProcessingQueue());
- if (drawing) {
- if (_translucent) {
- sortTriangles(r);
- }
- preDraw();
- }
- super.draw(r);
- if (_overlays != null && drawing) {
- for (int ii = 0, nn = _overlays.size(); ii < nn; ii++) {
- preDrawOverlay(ii);
- r.draw(this);
- postDrawOverlay(ii);
- }
- }
- }
-
- /**
- * Gives derived classes a chance to update states immediately before drawing.
- */
- protected void preDraw ()
- {
- }
-
- /**
- * Updates the batch's states with those of the identified overlay.
- */
- protected void preDrawOverlay (int oidx)
- {
- RenderState[] overlay = _overlays.get(oidx);
- for (RenderState rstate : overlay) {
- int idx = rstate.getType();
- _ostates[idx] = states[idx];
- states[idx] = rstate;
- }
- }
-
- /**
- * Restores the batch's original states after drawing an overlay.
- */
- protected void postDrawOverlay (int oidx)
- {
- RenderState[] overlay = _overlays.get(oidx);
- for (RenderState rstate : overlay) {
- int idx = rstate.getType();
- states[idx] = _ostates[idx];
- }
- }
-
- /**
- * Sorts the batch's triangles by their distance to the camera.
- */
- protected void sortTriangles (Renderer r)
- {
- // using the camera's direction in model space and the position
- // and size of the model bound, find a set of plane parameters
- // that determine the distance to a camera-aligned plane
- // that touches the near edge of the bounding volume, as well
- // as a scaling factor that brings the distance into a 16-bit
- // integer range
- getParentGeom().getWorldRotation().inverse().mult(
- r.getCamera().getDirection(), _cdir);
- BoundingVolume mbound = getModelBound();
- Vector3f mc = mbound.getCenter();
- float radius;
- if (mbound instanceof BoundingSphere) {
- radius = ((BoundingSphere)mbound).getRadius();
- } else { // mbound instanceof BoundingBox
- BoundingBox bbox = (BoundingBox)mbound;
- radius = FastMath.sqrt(3f) * Math.max(bbox.xExtent,
- Math.max(bbox.yExtent, bbox.zExtent));
- }
- float a = _cdir.x, b = _cdir.y, c = _cdir.z,
- d = radius - a*mc.x - b*mc.y - c*mc.z,
- dscale = 65535f / (radius * 2);
-
- // premultiply the scale and averaging factor
- a *= dscale / 3f;
- b *= dscale / 3f;
- c *= dscale / 3f;
- d *= dscale;
-
- // encode the model's triangles into integers such that the
- // high 16 bits represent the original triangle index and the
- // low 16 bits represent the distance to the plane. also
- // increment the byte counts used for radix sorting
- int tcount = getTriangleCount(), idist;
- if (_tcodes == null || _tcodes.length < tcount) {
- _tcodes = new int[tcount];
- }
- int i1, i2, i3;
- for (int ii = 0, idx = 0; ii < tcount; ii++) {
- i1 = _oibuf[idx++] * 3;
- i2 = _oibuf[idx++] * 3;
- i3 = _oibuf[idx++] * 3;
- idist = (int)(
- a * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) +
- b * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) +
- c * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) + d);
- _tcodes[ii] = (ii << 16) | idist;
- _bcounts[idist & 0xFF]++;
- }
-
- // sort the encoded triangles by increasing distance
- sortTriangleCodes(tcount);
-
- // reorder the triangles as dictated by the sorted codes, furthest
- // triangles first
- int icount = tcount * 3, idx;
- if (_sibuf == null || _sibuf.length < icount) {
- _sibuf = new int[icount];
- }
- for (int ii = tcount - 1, sidx = 0; ii >= 0; ii--) {
- idx = ((_tcodes[ii] >> 16) & 0xFFFF) * 3;
- _sibuf[sidx++] = _oibuf[idx++];
- _sibuf[sidx++] = _oibuf[idx++];
- _sibuf[sidx++] = _oibuf[idx];
- }
-
- // copy the indices to the buffer
- IntBuffer ibuf = getIndexBuffer();
- ibuf.rewind();
- ibuf.put(_sibuf, 0, icount);
- }
-
- /**
- * Gives derived classes a chance to update the states immediately before drawing.
- *
- * @param oidx the index of the overlay being rendered, or -1 for the base layer.
- */
- protected void processStates (int oidx)
- {
- }
-
- /** Temporarily stores the original states. */
- protected RenderState[] _ostates =
- new RenderState[RenderState.RS_MAX_STATE];
- }
-
- /** The name of the texture specified in the model file, which acts as a
- * property key and a default value. */
- protected String _textureKey;
-
- /** The name of this model's textures, or null for none. */
- protected String[] _textures;
-
- /** Whether or not to use sphere mapping on this model's textures. */
- protected boolean _sphereMapped;
-
- /** The filter mode to use on magnification. */
- protected int _filterMode;
-
- /** The mipmap mode to use on minification. */
- protected int _mipMapMode;
-
- /** Whether or not to use compressed textures, if available. */
- protected boolean _compress;
-
- /** The emissive map, if specified. */
- protected String _emissiveMap;
-
- /** Whether or not this mesh is completely emissive. */
- protected boolean _emissive;
-
- /** Whether or not this mesh should be rendered with additive blending. */
- protected boolean _additive;
-
- /** Whether or not this mesh can enable back-face culling. */
- protected boolean _solid;
-
- /** Whether or not this mesh must be rendered as transparent. */
- protected boolean _transparent;
-
- /** The alpha threshold below which fragments are discarded. */
- protected float _alphaThreshold;
-
- /** Whether or not the triangles of this mesh should be depth-sorted before
- * rendering. */
- protected boolean _translucent;
-
- /** If non-null, additional layers to render over the base layer. */
- protected ArrayList _overlays;
-
- /** For prototype meshes, the resolved texture states. */
- protected TextureState[] _tstates;
-
- /** Whether or not the transform has been locked. This operates in a
- * slightly different way than JME's locking, in that it allows applying
- * transformations to display lists. */
- protected boolean _transformLocked;
-
- /** For depth-sorted and skinned meshes, the array of vertices. */
- protected float[] _vbuf;
-
- /** For depth-sorted meshes, the original array of indices. */
- protected int[] _oibuf;
-
- /** The shared state for back face culling. */
- protected static CullState _backCull;
-
- /** The shared state for alpha blending. */
- protected static AlphaState _blendAlpha;
-
- /** The shared state for additive blending. */
- protected static AlphaState _addAlpha;
-
- /** The shared state for alpha testing with the default threshold. */
- protected static AlphaState _defaultTestAlpha;
-
- /** The shared state for checking, but not writing to, the z buffer. */
- protected static ZBufferState _overlayZBuffer;
-
- /** A light state that simulates emissivity. */
- protected static LightState _emissiveLight;
-
- /** A fog state that disables fog. */
- protected static FogState _noFog;
-
- /** Work vector to store the camera direction. */
- protected static Vector3f _cdir = new Vector3f();
-
- /** Work arrays used to sort triangles. */
- protected static int[] _tcodes, _stcodes;
-
- /** Holds counts of each byte and array offsets for radix sorting. */
- protected static int[] _bcounts = new int[256], _boffsets = new int[256];
-
- /** Work array used to hold indices of sorted triangles. */
- protected static int[] _sibuf;
-
- /** The default alpha threshold. */
- protected static final float DEFAULT_ALPHA_THRESHOLD = 0.5f;
-
- private static final long serialVersionUID = 1;
-}
diff --git a/src/java/com/threerings/jme/model/ModelNode.java b/src/java/com/threerings/jme/model/ModelNode.java
deleted file mode 100644
index b31bf3e6..00000000
--- a/src/java/com/threerings/jme/model/ModelNode.java
+++ /dev/null
@@ -1,414 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.IOException;
-
-import java.util.HashSet;
-import java.util.List;
-
-import com.jme.math.Matrix4f;
-import com.jme.math.Quaternion;
-import com.jme.math.Vector3f;
-import com.jme.renderer.Renderer;
-import com.jme.scene.Node;
-import com.jme.scene.Spatial;
-import com.jme.scene.state.RenderState;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-
-import com.threerings.jme.util.JmeUtil;
-import com.threerings.jme.util.ShaderCache;
-
-/**
- * A {@link Node} with a serialization mechanism tailored to stored models.
- */
-public class ModelNode extends Node
- implements ModelSpatial
-{
- /**
- * No-arg constructor for deserialization.
- */
- public ModelNode ()
- {
- super("node");
- }
-
- /**
- * Standard constructor.
- */
- public ModelNode (String name)
- {
- super(name);
- }
-
- @Override
- public int hashCode ()
- {
- // hash on the name rather than the identity for consistent ordering
- return getName().hashCode();
- }
-
- /**
- * Recursively searches the scene graph rooted at this node for a
- * node with the provided name.
- */
- public Spatial getDescendant (String name)
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child.getName().equals(name)) {
- return child;
- } else if (child instanceof ModelNode) {
- child = ((ModelNode)child).getDescendant(name);
- if (child != null) {
- return child;
- }
- }
- }
- return null;
- }
-
- /**
- * Returns a reference to the model space transform of the node.
- */
- public Matrix4f getModelTransform ()
- {
- return _modelTransform;
- }
-
- @Override
- public void updateWorldData (float time)
- {
- // we use locked bounds as an indication that we can skip the update
- // altogether
- if ((lockedMode & LOCKED_BOUNDS) == 0) {
- super.updateWorldData(time);
- }
- }
-
- @Override
- public void updateWorldBound ()
- {
- // don't bother updating if we know there are no visible descendants
- if (_hasVisibleDescendants) {
- super.updateWorldBound();
- }
- }
-
- @Override
- public void updateWorldVectors ()
- {
- super.updateWorldVectors();
- if (parent instanceof ModelNode) {
- JmeUtil.setTransform(getLocalTranslation(), getLocalRotation(),
- getLocalScale(), _localTransform);
- ((ModelNode)parent).getModelTransform().mult(_localTransform,
- _modelTransform);
-
- } else {
- _modelTransform.loadIdentity();
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public Spatial putClone (Spatial store, Model.CloneCreator properties)
- {
- ModelNode mstore = (ModelNode)properties.originalToCopy.get(this);
- if (mstore != null) {
- return mstore;
- } else if (store == null) {
- mstore = new ModelNode(getName());
- } else {
- mstore = (ModelNode)store;
- }
- properties.originalToCopy.put(this, mstore);
- mstore.normalsMode = normalsMode;
- mstore.cullMode = cullMode;
- for (int ii = 0; ii < RenderState.RS_MAX_STATE; ii++) {
- RenderState rstate = getRenderState(ii);
- if (rstate != null) {
- mstore.setRenderState(rstate);
- }
- }
- mstore.renderQueueMode = renderQueueMode;
- mstore.lockedMode = lockedMode;
- mstore.lightCombineMode = lightCombineMode;
- mstore.textureCombineMode = textureCombineMode;
- mstore.name = name;
- mstore.isCollidable = isCollidable;
- mstore.localRotation.set(localRotation);
- mstore.localTranslation.set(localTranslation);
- mstore.localScale.set(localScale);
- for (Object controller : getControllers()) {
- if (controller instanceof ModelController) {
- mstore.addController(
- ((ModelController)controller).putClone(null, properties));
- }
- }
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- mstore.attachChild(
- ((ModelSpatial)child).putClone(null, properties));
- }
- }
- mstore._hasVisibleDescendants = _hasVisibleDescendants;
- return mstore;
- }
-
- @Override
- public void read (JMEImporter im)
- throws IOException
- {
- InputCapsule capsule = im.getCapsule(this);
- setName(capsule.readString("name", null));
- setLocalTranslation((Vector3f)capsule.readSavable(
- "localTranslation", null));
- setLocalRotation((Quaternion)capsule.readSavable(
- "localRotation", null));
- setLocalScale((Vector3f)capsule.readSavable(
- "localScale", null));
- List> children = capsule.readSavableArrayList("children", null);
- if (children != null) {
- for (Object child : children) {
- attachChild((Spatial)child);
- }
- }
- }
-
- @Override
- public void write (JMEExporter ex)
- throws IOException
- {
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(getName(), "name", null);
- capsule.write(getLocalTranslation(), "localTranslation", null);
- capsule.write(getLocalRotation(), "localRotation", null);
- capsule.write(getLocalScale(), "localScale", null);
- capsule.writeSavableArrayList(getChildren(), "children", null);
- }
-
- // documentation inherited from interface ModelSpatial
- public void expandModelBounds ()
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).expandModelBounds();
- }
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void setReferenceTransforms ()
- {
- updateWorldVectors();
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).setReferenceTransforms();
- }
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void lockStaticMeshes (
- Renderer renderer, boolean useVBOs, boolean useDisplayLists)
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).lockStaticMeshes(renderer, useVBOs,
- useDisplayLists);
- }
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void resolveTextures (TextureProvider tprov)
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).resolveTextures(tprov);
- }
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void configureShaders (ShaderCache scache)
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).configureShaders(scache);
- }
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void storeMeshFrame (int frameId, boolean blend)
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).storeMeshFrame(frameId, blend);
- }
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void setMeshFrame (int frameId)
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).setMeshFrame(frameId);
- }
- }
- }
-
- // documentation inherited from interface ModelSpatial
- public void blendMeshFrames (int frameId1, int frameId2, float alpha)
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelSpatial) {
- ((ModelSpatial)child).blendMeshFrames(
- frameId1, frameId2, alpha);
- }
- }
- }
-
- /**
- * Sets whether this node should be culled even if it has mesh
- * descendants.
- */
- public void setForceCull (boolean force)
- {
- _forceCull = force;
- }
-
- /**
- * Checks whether this node should be culled even if it has mesh
- * descendants.
- */
- public boolean getForceCull ()
- {
- return _forceCull;
- }
-
- /**
- * Sets the cull state of any nodes that do not contain geometric
- * descendants to {@link CULL_ALWAYS} so that they don't waste
- * rendering time.
- *
- * @return true if this node should be drawn, false if it contains
- * no mesh descendants
- */
- protected boolean cullInvisibleNodes ()
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (!(child instanceof ModelNode) ||
- ((ModelNode)child).cullInvisibleNodes()) {
- _hasVisibleDescendants = true;
- }
- }
- updateCullMode();
- return _hasVisibleDescendants;
- }
-
- /**
- * Locks the transforms and bounds of this instance with the assumption
- * that the position will never change.
- *
- * @param targets the targets of the model's controllers, which determine
- * the subset of nodes that can be locked
- * @return true if this node is a target or contains any targets, otherwise
- * false
- */
- protected boolean lockInstance (HashSet targets)
- {
- updateWorldVectors();
- lockedMode |= LOCKED_TRANSFORMS;
-
- boolean containsTargets = false;
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (targets.contains(child) || (child instanceof ModelNode &&
- ((ModelNode)child).lockInstance(targets))) {
- containsTargets = true;
-
- } else if (child instanceof ModelMesh) {
- ((ModelMesh)child).lockInstance();
- }
- }
- if (containsTargets) {
- return true;
- } else {
- updateWorldBound();
- lockedMode |= LOCKED_BOUNDS;
- return false;
- }
- }
-
- /**
- * Recursively culls all model nodes under this one in preparation for
- * activating the ones listed in an animation.
- */
- protected void cullModelNodes ()
- {
- for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
- Spatial child = getChild(ii);
- if (child instanceof ModelNode) {
- child.setCullMode(CULL_ALWAYS);
- ((ModelNode)child).cullModelNodes();
- }
- }
- }
-
- /**
- * Makes this node visible if and only if it has visible descendants and
- * has not been specifically culled.
- */
- protected void updateCullMode ()
- {
- setCullMode((_hasVisibleDescendants && !_forceCull) ?
- CULL_INHERIT : CULL_ALWAYS);
- }
-
- /** The node's transform in local and model space. */
- protected Matrix4f _localTransform = new Matrix4f(),
- _modelTransform = new Matrix4f();
-
- /** Whether or not this node has mesh descendants. */
- protected boolean _hasVisibleDescendants;
-
- /** If true, cull the node even if it has mesh descendants. */
- protected boolean _forceCull;
-
- private static final long serialVersionUID = 1;
-}
diff --git a/src/java/com/threerings/jme/model/ModelSpatial.java b/src/java/com/threerings/jme/model/ModelSpatial.java
deleted file mode 100644
index 35f38592..00000000
--- a/src/java/com/threerings/jme/model/ModelSpatial.java
+++ /dev/null
@@ -1,97 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import com.jme.renderer.Renderer;
-import com.jme.scene.Spatial;
-
-import com.threerings.jme.util.ShaderCache;
-
-/**
- * Contains method common to both {@link ModelNode}s and {@link ModelMesh}es.
- */
-public interface ModelSpatial
-{
- /**
- * Recursively expands the model bounds of any deformable meshes so that
- * they include the current vertex positions.
- */
- public void expandModelBounds ();
-
- /**
- * Recursively sets the reference transforms for any bones in the model.
- */
- public void setReferenceTransforms ();
-
- /**
- * Recursively compiles any static meshes to vertex buffer objects (VBOs)
- * or display lists.
- *
- * @param useVBOs if true, use VBOs if the graphics card supports them
- * @param useDisplayLists if true and not using VBOs, compile static
- * objects to display lists
- */
- public void lockStaticMeshes (
- Renderer renderer, boolean useVBOs, boolean useDisplayLists);
-
- /**
- * Recursively resolves texture references using the given provider.
- */
- public void resolveTextures (TextureProvider tprov);
-
- /**
- * Recursively creates or reconfigures any shaders used by the model using the supplied cache.
- */
- public void configureShaders (ShaderCache scache);
-
- /**
- * Recursively requests that the current state of all skinned meshes be
- * stored as an animation frame on the next update.
- *
- * @param frameId the frame id, which uniquely identifies one frame of
- * one animation
- * @param blend whether or not the stored frames will be retrieved by
- * calls to {@link #blendMeshFrames} as opposed to {@link #setMeshFrame}
- */
- public void storeMeshFrame (int frameId, boolean blend);
-
- /**
- * Recursively switches all skinned meshes to a stored animation frame for
- * the next update.
- */
- public void setMeshFrame (int frameId);
-
- /**
- * Recursively blends all skinned meshes between two stored animation
- * frames for the next update.
- */
- public void blendMeshFrames (int frameId1, int frameId2, float alpha);
-
- /**
- * Creates or populates and returns a clone of this object using the given
- * clone properties.
- *
- * @param store an instance of this class to populate, or null
- * to create a new instance
- */
- public Spatial putClone (Spatial store, Model.CloneCreator properties);
-}
diff --git a/src/java/com/threerings/jme/model/Rotator.java b/src/java/com/threerings/jme/model/Rotator.java
deleted file mode 100644
index 7bff0ced..00000000
--- a/src/java/com/threerings/jme/model/Rotator.java
+++ /dev/null
@@ -1,109 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.IOException;
-
-import java.util.Properties;
-
-import com.jme.math.Quaternion;
-import com.jme.math.Vector3f;
-import com.jme.scene.Controller;
-import com.jme.scene.Spatial;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-
-import com.threerings.jme.util.JmeUtil;
-
-/**
- * A procedural animation that rotates a node around at a constant angular
- * velocity.
- */
-public class Rotator extends ModelController
-{
- @Override
- public void configure (Properties props, Spatial target)
- {
- super.configure(props, target);
- _axis = JmeUtil.parseAxis(props.getProperty("axis", "x"));
- _velocity = Float.parseFloat(props.getProperty("velocity", "3.14"));
- }
-
- // documentation inherited
- public void update (float time)
- {
- if (!isActive()) {
- return;
- }
- _rot.fromAngleNormalAxis(time * _velocity, _axis);
- _target.getLocalRotation().multLocal(_rot);
- }
-
- @Override
- public Controller putClone (
- Controller store, Model.CloneCreator properties)
- {
- Rotator rstore;
- if (store == null) {
- rstore = new Rotator();
- } else {
- rstore = (Rotator)store;
- }
- super.putClone(rstore, properties);
- rstore._axis = _axis;
- rstore._velocity = _velocity;
- return rstore;
- }
-
- @Override
- public void read (JMEImporter im)
- throws IOException
- {
- super.read(im);
- InputCapsule capsule = im.getCapsule(this);
- _axis = (Vector3f)capsule.readSavable("axis", null);
- _velocity = capsule.readFloat("velocity", 0f);
- }
-
- @Override
- public void write (JMEExporter ex)
- throws IOException
- {
- super.write(ex);
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(_axis, "axis", null);
- capsule.write(_velocity, "velocity", 0f);
- }
-
- /** The axis about which to rotate. */
- protected Vector3f _axis;
-
- /** The velocity at which to rotate in radians per second. */
- protected float _velocity;
-
- /** A temporary quaternion. */
- protected Quaternion _rot = new Quaternion();
-
- private static final long serialVersionUID = 1;
-}
diff --git a/src/java/com/threerings/jme/model/SkinMesh.java b/src/java/com/threerings/jme/model/SkinMesh.java
deleted file mode 100644
index d6554880..00000000
--- a/src/java/com/threerings/jme/model/SkinMesh.java
+++ /dev/null
@@ -1,760 +0,0 @@
-//
-// $Id$
-//
-// Nenya library - tools for developing networked games
-// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
-// http://code.google.com/p/nenya/
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Lesser General Public License as published
-// by the Free Software Foundation; either version 2.1 of the License, or
-// (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-package com.threerings.jme.model;
-
-import java.io.IOException;
-
-import java.nio.ByteBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
-import org.lwjgl.opengl.GLContext;
-
-import com.jme.bounding.BoundingVolume;
-import com.jme.math.Matrix4f;
-import com.jme.renderer.Renderer;
-import com.jme.scene.Spatial;
-import com.jme.scene.TriMesh;
-import com.jme.scene.VBOInfo;
-import com.jme.scene.batch.SharedBatch;
-import com.jme.scene.batch.TriangleBatch;
-import com.jme.scene.state.GLSLShaderObjectsState;
-import com.jme.scene.state.RenderState;
-import com.jme.system.DisplaySystem;
-import com.jme.util.ShaderAttribute;
-import com.jme.util.export.JMEExporter;
-import com.jme.util.export.JMEImporter;
-import com.jme.util.export.InputCapsule;
-import com.jme.util.export.OutputCapsule;
-import com.jme.util.export.Savable;
-import com.jme.util.geom.BufferUtils;
-
-import com.samskivert.util.ArrayUtil;
-import com.samskivert.util.HashIntMap;
-import com.samskivert.util.ListUtil;
-
-import com.threerings.jme.util.JmeUtil;
-import com.threerings.jme.util.ShaderCache;
-import com.threerings.jme.util.ShaderConfig;
-
-/**
- * A triangle mesh that deforms according to a bone hierarchy.
- */
-public class SkinMesh extends ModelMesh
-{
- /** The maximum number of bone matrices that we can use for hardware skinning. */
- public static final int MAX_SHADER_BONE_COUNT = 31;
-
- /** The maximum number of bones influencing a single vertex for hardware skinning. */
- public static final int MAX_SHADER_BONES_PER_VERTEX = 4;
-
- /** Represents the vertex weights of a group of vertices influenced by the
- * same set of bones. */
- public static class WeightGroup
- implements Savable
- {
- /** The number of vertices in this weight group. */
- public int vertexCount;
-
- /** The bones influencing this group. */
- public Bone[] bones;
-
- /** The array of interleaved weights (of length vertexCount *
- * boneIndices.length): weights for first vertex, weights for
- * second, etc. */
- public float[] weights;
-
- /**
- * Rebinds this weight group for a prototype instance.
- *
- * @param bmap the mapping from prototype to instance bones
- */
- public WeightGroup rebind (Map bmap)
- {
- WeightGroup wgroup = new WeightGroup();
- wgroup.vertexCount = vertexCount;
- wgroup.bones = new Bone[bones.length];
- for (int ii = 0; ii < bones.length; ii++) {
- wgroup.bones[ii] = bmap.get(bones[ii]);
- }
- wgroup.weights = weights;
- return wgroup;
- }
-
- // documentation inherited
- public Class> getClassTag ()
- {
- return getClass();
- }
-
- // documentation inherited
- public void read (JMEImporter im)
- throws IOException
- {
- InputCapsule capsule = im.getCapsule(this);
- vertexCount = capsule.readInt("vertexCount", 0);
- bones = ArrayUtil.copy(capsule.readSavableArray("bones", null),
- new Bone[0]);
- weights = capsule.readFloatArray("weights", null);
- }
-
- // documentation inherited
- public void write (JMEExporter ex)
- throws IOException
- {
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(vertexCount, "vertexCount", 0);
- capsule.write(bones, "bones", null);
- capsule.write(weights, "weights", null);
- }
-
- private static final long serialVersionUID = 1;
- }
-
- /** Represents a bone that influences the mesh. */
- public static class Bone
- implements Savable
- {
- /** The node that defines the bone's position. */
- public ModelNode node;
-
- /** The inverse of the bone's model space reference transform. */
- public transient Matrix4f invRefTransform;
-
- /** The bone's current transform in model space. */
- public transient Matrix4f transform;
-
- public Bone (ModelNode node)
- {
- this();
- this.node = node;
- }
-
- public Bone ()
- {
- transform = new Matrix4f();
- }
-
- /**
- * Rebinds this bone for a prototype instance.
- *
- * @param pnodes a mapping from prototype nodes to instance nodes
- */
- public Bone rebind (Map pnodes)
- {
- Bone bone = new Bone((ModelNode)pnodes.get(node));
- bone.invRefTransform = invRefTransform;
- bone.transform = new Matrix4f();
- return bone;
- }
-
- // documentation inherited
- public Class> getClassTag ()
- {
- return getClass();
- }
-
- // documentation inherited
- public void read (JMEImporter im)
- throws IOException
- {
- InputCapsule capsule = im.getCapsule(this);
- node = (ModelNode)capsule.readSavable("node", null);
- }
-
- // documentation inherited
- public void write (JMEExporter ex)
- throws IOException
- {
- OutputCapsule capsule = ex.getCapsule(this);
- capsule.write(node, "node", null);
- }
-
- private static final long serialVersionUID = 1;
- }
-
- /**
- * No-arg constructor for deserialization.
- */
- public SkinMesh ()
- {
- }
-
- /**
- * Creates an empty mesh.
- */
- public SkinMesh (String name)
- {
- super(name);
- }
-
- /**
- * Sets the array of weight groups that determine how bones affect
- * each vertex.
- */
- public void setWeightGroups (WeightGroup[] weightGroups)
- {
- _weightGroups = weightGroups;
-
- // compile a list of all referenced bones
- HashSet bones = Sets.newHashSet();
- for (WeightGroup group : weightGroups) {
- Collections.addAll(bones, group.bones);
- }
- _bones = bones.toArray(new Bone[bones.size()]);
- }
-
- @Override
- public void addOverlay (RenderState[] overlay)
- {
- // add a cloned state config (with same uniforms) for the overlay
- super.addOverlay(overlay);
- if (_sconfig == null) {
- return;
- }
- if (_osconfigs == null) {
- _osconfigs = Lists.newArrayListWithCapacity(1);
- }
- SkinShaderConfig osconfig = (SkinShaderConfig)_sconfig.clone();
- osconfig.getState().uniforms = _sconfig.getState().uniforms;
- _osconfigs.add(osconfig);
- }
-
- @Override
- public void removeOverlay (RenderState[] overlay)
- {
- // remove the corresponding state config
- int idx = (_overlays == null) ? -1 : _overlays.indexOf(overlay);
- super.removeOverlay(overlay);
- if (_osconfigs != null && idx >= 0) {
- _osconfigs.remove(idx);
- if (_osconfigs.isEmpty()) {
- _osconfigs = null;
- }
- }
- }
-
- @Override
- public void reconstruct (
- FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors,
- FloatBuffer textures, IntBuffer indices)
- {
- super.reconstruct(vertices, normals, colors, textures, indices);
-
- // initialize the quantized frame table
- _frames = new HashIntMap