Added the ability to render meshes in multiple passes with different
render states. Cleaned up some formatting. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@25 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -33,6 +33,7 @@ import java.nio.IntBuffer;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.jme.bounding.BoundingVolume;
|
||||
@@ -45,6 +46,7 @@ import com.jme.scene.SharedMesh;
|
||||
import com.jme.scene.Spatial;
|
||||
import com.jme.scene.TriMesh;
|
||||
import com.jme.scene.VBOInfo;
|
||||
import com.jme.scene.batch.GeomBatch;
|
||||
import com.jme.scene.batch.TriangleBatch;
|
||||
import com.jme.scene.state.AlphaState;
|
||||
import com.jme.scene.state.CullState;
|
||||
@@ -151,6 +153,30 @@ public class ModelMesh extends TriMesh
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = new ArrayList<RenderState[]>(1);
|
||||
}
|
||||
_overlays.add(overlay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a layer from this mesh.
|
||||
*/
|
||||
public void removeOverlay (RenderState[] overlay)
|
||||
{
|
||||
_overlays.remove(overlay);
|
||||
if (_overlays.isEmpty()) {
|
||||
_overlays = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public void reconstruct (
|
||||
FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors,
|
||||
@@ -485,6 +511,15 @@ public class ModelMesh extends TriMesh
|
||||
reconstruct(vbbuf, nbbuf, cbbuf, tbbuf, ibbuf);
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
protected void setupBatchList ()
|
||||
{
|
||||
batchList = new ArrayList<GeomBatch>(1);
|
||||
TriangleBatch batch = new OverlayBatch();
|
||||
batch.setParentGeom(this);
|
||||
batchList.add(batch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks the transform and bounds of this mesh on the assumption that its
|
||||
* position will not change.
|
||||
@@ -526,6 +561,34 @@ public class ModelMesh extends TriMesh
|
||||
_overlayZBuffer.setWritable(false);
|
||||
}
|
||||
|
||||
/** Renders overlays as well as the base layer. */
|
||||
protected class OverlayBatch extends TriangleBatch
|
||||
{
|
||||
@Override // documentation inherited
|
||||
public void draw (Renderer r)
|
||||
{
|
||||
super.draw(r);
|
||||
if (_overlays != null && isEnabled() && r.isProcessingQueue()) {
|
||||
for (RenderState[] overlay : _overlays) {
|
||||
for (RenderState rstate : overlay) {
|
||||
int idx = rstate.getType();
|
||||
_ostates[idx] = states[idx];
|
||||
states[idx] = rstate;
|
||||
}
|
||||
r.draw(this);
|
||||
for (RenderState rstate : overlay) {
|
||||
int idx = rstate.getType();
|
||||
states[idx] = _ostates[idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Temporarily stores the original states. */
|
||||
protected RenderState[] _ostates =
|
||||
new RenderState[RenderState.RS_MAX_STATE];
|
||||
}
|
||||
|
||||
/** The sizes of the various buffers (zero for <code>null</code>). */
|
||||
protected int _vertexBufferSize, _normalBufferSize, _colorBufferSize,
|
||||
_textureBufferSize, _indexBufferSize;
|
||||
@@ -549,6 +612,9 @@ public class ModelMesh extends TriMesh
|
||||
/** Whether or not this mesh must be rendered as transparent. */
|
||||
protected boolean _transparent;
|
||||
|
||||
/** If non-null, additional layers to render over the base layer. */
|
||||
protected ArrayList<RenderState[]> _overlays;
|
||||
|
||||
/** For prototype meshes, the resolved texture states. */
|
||||
protected TextureState[] _tstates;
|
||||
|
||||
|
||||
@@ -164,13 +164,14 @@ public class AStarPathUtil
|
||||
if (n.x == bx && n.y == by) {
|
||||
// construct and return the acceptable path
|
||||
return getNodePath(n);
|
||||
|
||||
} else if (partial) {
|
||||
float pathdist = MathUtil.distance(n.x, n.y, bx, by);
|
||||
if (pathdist < bestdist) {
|
||||
bestdist = pathdist;
|
||||
bestpath = n;
|
||||
}
|
||||
float pathdist = MathUtil.distance(n.x, n.y, bx, by);
|
||||
if (pathdist < bestdist) {
|
||||
bestdist = pathdist;
|
||||
bestpath = n;
|
||||
}
|
||||
}
|
||||
|
||||
// consider each successor of the node
|
||||
stepper.init(info, n);
|
||||
@@ -185,8 +186,8 @@ public class AStarPathUtil
|
||||
return getNodePath(bestpath);
|
||||
}
|
||||
|
||||
// no path found
|
||||
return null;
|
||||
// no path found
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user