|
@@ -37,12 +37,12 @@ import com.jme3.collision.Collidable;
|
|
import com.jme3.collision.CollisionResults;
|
|
import com.jme3.collision.CollisionResults;
|
|
import com.jme3.collision.bih.BIHTree;
|
|
import com.jme3.collision.bih.BIHTree;
|
|
import com.jme3.export.*;
|
|
import com.jme3.export.*;
|
|
|
|
+import com.jme3.material.Material;
|
|
import com.jme3.material.RenderState;
|
|
import com.jme3.material.RenderState;
|
|
import com.jme3.math.Matrix4f;
|
|
import com.jme3.math.Matrix4f;
|
|
import com.jme3.math.Triangle;
|
|
import com.jme3.math.Triangle;
|
|
import com.jme3.math.Vector2f;
|
|
import com.jme3.math.Vector2f;
|
|
import com.jme3.math.Vector3f;
|
|
import com.jme3.math.Vector3f;
|
|
-import com.jme3.renderer.Renderer;
|
|
|
|
import com.jme3.scene.VertexBuffer.Format;
|
|
import com.jme3.scene.VertexBuffer.Format;
|
|
import com.jme3.scene.VertexBuffer.Type;
|
|
import com.jme3.scene.VertexBuffer.Type;
|
|
import com.jme3.scene.VertexBuffer.Usage;
|
|
import com.jme3.scene.VertexBuffer.Usage;
|
|
@@ -50,8 +50,9 @@ import com.jme3.scene.mesh.*;
|
|
import com.jme3.util.BufferUtils;
|
|
import com.jme3.util.BufferUtils;
|
|
import com.jme3.util.IntMap;
|
|
import com.jme3.util.IntMap;
|
|
import com.jme3.util.IntMap.Entry;
|
|
import com.jme3.util.IntMap.Entry;
|
|
-import com.jme3.util.NativeObject;
|
|
|
|
import com.jme3.util.SafeArrayList;
|
|
import com.jme3.util.SafeArrayList;
|
|
|
|
+import com.jme3.util.clone.Cloner;
|
|
|
|
+import com.jme3.util.clone.JmeCloneable;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.nio.*;
|
|
import java.nio.*;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -62,18 +63,18 @@ import java.util.ArrayList;
|
|
* All visible elements in a scene are represented by meshes.
|
|
* All visible elements in a scene are represented by meshes.
|
|
* Meshes may contain three types of geometric primitives:
|
|
* Meshes may contain three types of geometric primitives:
|
|
* <ul>
|
|
* <ul>
|
|
- * <li>Points - Every vertex represents a single point in space,
|
|
|
|
|
|
+ * <li>Points - Every vertex represents a single point in space,
|
|
* the size of each point is specified via {@link Mesh#setPointSize(float) }.
|
|
* the size of each point is specified via {@link Mesh#setPointSize(float) }.
|
|
* Points can also be used for {@link RenderState#setPointSprite(boolean) point
|
|
* Points can also be used for {@link RenderState#setPointSprite(boolean) point
|
|
* sprite} mode.</li>
|
|
* sprite} mode.</li>
|
|
* <li>Lines - 2 vertices represent a line segment, with the width specified
|
|
* <li>Lines - 2 vertices represent a line segment, with the width specified
|
|
- * via {@link Mesh#setLineWidth(float) }.</li>
|
|
|
|
|
|
+ * via {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)}.</li>
|
|
* <li>Triangles - 3 vertices represent a solid triangle primitive. </li>
|
|
* <li>Triangles - 3 vertices represent a solid triangle primitive. </li>
|
|
* </ul>
|
|
* </ul>
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author Kirill Vainer
|
|
* @author Kirill Vainer
|
|
*/
|
|
*/
|
|
-public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
+public class Mesh extends NativeObject implements Savable, Cloneable, JmeCloneable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* The mode of the Mesh specifies both the type of primitive represented
|
|
* The mode of the Mesh specifies both the type of primitive represented
|
|
@@ -81,49 +82,49 @@ public class Mesh extends NativeObject implements Savable {
|
|
*/
|
|
*/
|
|
public enum Mode {
|
|
public enum Mode {
|
|
/**
|
|
/**
|
|
- * A primitive is a single point in space. The size of the points
|
|
|
|
|
|
+ * A primitive is a single point in space. The size of the points
|
|
* can be specified with {@link Mesh#setPointSize(float) }.
|
|
* can be specified with {@link Mesh#setPointSize(float) }.
|
|
*/
|
|
*/
|
|
Points(true),
|
|
Points(true),
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* A primitive is a line segment. Every two vertices specify
|
|
* A primitive is a line segment. Every two vertices specify
|
|
- * a single line. {@link Mesh#setLineWidth(float) } can be used
|
|
|
|
|
|
+ * a single line. {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)} can be used
|
|
* to set the width of the lines.
|
|
* to set the width of the lines.
|
|
*/
|
|
*/
|
|
Lines(true),
|
|
Lines(true),
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* A primitive is a line segment. The first two vertices specify
|
|
* A primitive is a line segment. The first two vertices specify
|
|
- * a single line, while subsequent vertices are combined with the
|
|
|
|
- * previous vertex to make a line. {@link Mesh#setLineWidth(float) } can
|
|
|
|
|
|
+ * a single line, while subsequent vertices are combined with the
|
|
|
|
+ * previous vertex to make a line. {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)} can
|
|
* be used to set the width of the lines.
|
|
* be used to set the width of the lines.
|
|
*/
|
|
*/
|
|
LineStrip(false),
|
|
LineStrip(false),
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Identical to {@link #LineStrip} except that at the end
|
|
* Identical to {@link #LineStrip} except that at the end
|
|
* the last vertex is connected with the first to form a line.
|
|
* the last vertex is connected with the first to form a line.
|
|
- * {@link Mesh#setLineWidth(float) } can be used
|
|
|
|
|
|
+ * {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)} can be used
|
|
* to set the width of the lines.
|
|
* to set the width of the lines.
|
|
*/
|
|
*/
|
|
LineLoop(false),
|
|
LineLoop(false),
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* A primitive is a triangle. Each 3 vertices specify a single
|
|
* A primitive is a triangle. Each 3 vertices specify a single
|
|
* triangle.
|
|
* triangle.
|
|
*/
|
|
*/
|
|
Triangles(true),
|
|
Triangles(true),
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Similar to {@link #Triangles}, the first 3 vertices
|
|
|
|
|
|
+ * Similar to {@link #Triangles}, the first 3 vertices
|
|
* specify a triangle, while subsequent vertices are combined with
|
|
* specify a triangle, while subsequent vertices are combined with
|
|
- * the previous two to form a triangle.
|
|
|
|
|
|
+ * the previous two to form a triangle.
|
|
*/
|
|
*/
|
|
TriangleStrip(false),
|
|
TriangleStrip(false),
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Similar to {@link #Triangles}, the first 3 vertices
|
|
|
|
|
|
+ * Similar to {@link #Triangles}, the first 3 vertices
|
|
* specify a triangle, each 2 subsequent vertices are combined
|
|
* specify a triangle, each 2 subsequent vertices are combined
|
|
* with the very first vertex to make a triangle.
|
|
* with the very first vertex to make a triangle.
|
|
*/
|
|
*/
|
|
@@ -136,20 +137,19 @@ public class Mesh extends NativeObject implements Savable {
|
|
* for each patch (default is 3 for triangle tesselation)
|
|
* for each patch (default is 3 for triangle tesselation)
|
|
*/
|
|
*/
|
|
Patch(true);
|
|
Patch(true);
|
|
-
|
|
|
|
private boolean listMode = false;
|
|
private boolean listMode = false;
|
|
-
|
|
|
|
|
|
+
|
|
private Mode(boolean listMode){
|
|
private Mode(boolean listMode){
|
|
this.listMode = listMode;
|
|
this.listMode = listMode;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns true if the specified mode is a list mode (meaning
|
|
* Returns true if the specified mode is a list mode (meaning
|
|
- * ,it specifies the indices as a linear list and not some special
|
|
|
|
|
|
+ * ,it specifies the indices as a linear list and not some special
|
|
* format).
|
|
* format).
|
|
* Will return true for the types {@link #Points}, {@link #Lines} and
|
|
* Will return true for the types {@link #Points}, {@link #Lines} and
|
|
* {@link #Triangles}.
|
|
* {@link #Triangles}.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return true if the mode is a list type mode
|
|
* @return true if the mode is a list type mode
|
|
*/
|
|
*/
|
|
public boolean isListMode(){
|
|
public boolean isListMode(){
|
|
@@ -169,7 +169,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
private IntMap<VertexBuffer> buffers = new IntMap<VertexBuffer>();
|
|
private IntMap<VertexBuffer> buffers = new IntMap<VertexBuffer>();
|
|
private VertexBuffer[] lodLevels;
|
|
private VertexBuffer[] lodLevels;
|
|
private float pointSize = 1;
|
|
private float pointSize = 1;
|
|
- private float lineWidth = 1;
|
|
|
|
|
|
+ private float lineWidth = -1;
|
|
|
|
|
|
private transient int vertexArrayID = -1;
|
|
private transient int vertexArrayID = -1;
|
|
|
|
|
|
@@ -195,7 +195,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
* Create a shallow clone of this Mesh. The {@link VertexBuffer vertex
|
|
* Create a shallow clone of this Mesh. The {@link VertexBuffer vertex
|
|
* buffers} are shared between this and the clone mesh, the rest
|
|
* buffers} are shared between this and the clone mesh, the rest
|
|
* of the data is cloned.
|
|
* of the data is cloned.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return A shallow clone of the mesh
|
|
* @return A shallow clone of the mesh
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@@ -209,10 +209,10 @@ public class Mesh extends NativeObject implements Savable {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Creates a deep clone of this mesh.
|
|
|
|
|
|
+ * Creates a deep clone of this mesh.
|
|
* The {@link VertexBuffer vertex buffers} and the data inside them
|
|
* The {@link VertexBuffer vertex buffers} and the data inside them
|
|
* is cloned.
|
|
* is cloned.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return a deep clone of this mesh.
|
|
* @return a deep clone of this mesh.
|
|
*/
|
|
*/
|
|
public Mesh deepClone(){
|
|
public Mesh deepClone(){
|
|
@@ -248,14 +248,14 @@ public class Mesh extends NativeObject implements Savable {
|
|
* of the {@link VertexBuffer vertex buffer} data, however the
|
|
* of the {@link VertexBuffer vertex buffer} data, however the
|
|
* {@link Type#Position}, {@link Type#Normal}, and {@link Type#Tangent} buffers
|
|
* {@link Type#Position}, {@link Type#Normal}, and {@link Type#Tangent} buffers
|
|
* are deeply cloned.
|
|
* are deeply cloned.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return A clone of the mesh for animation use.
|
|
* @return A clone of the mesh for animation use.
|
|
*/
|
|
*/
|
|
public Mesh cloneForAnim(){
|
|
public Mesh cloneForAnim(){
|
|
Mesh clone = clone();
|
|
Mesh clone = clone();
|
|
if (getBuffer(Type.BindPosePosition) != null){
|
|
if (getBuffer(Type.BindPosePosition) != null){
|
|
VertexBuffer oldPos = getBuffer(Type.Position);
|
|
VertexBuffer oldPos = getBuffer(Type.Position);
|
|
-
|
|
|
|
|
|
+
|
|
// NOTE: creates deep clone
|
|
// NOTE: creates deep clone
|
|
VertexBuffer newPos = oldPos.clone();
|
|
VertexBuffer newPos = oldPos.clone();
|
|
clone.clearBuffer(Type.Position);
|
|
clone.clearBuffer(Type.Position);
|
|
@@ -266,7 +266,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
VertexBuffer newNorm = oldNorm.clone();
|
|
VertexBuffer newNorm = oldNorm.clone();
|
|
clone.clearBuffer(Type.Normal);
|
|
clone.clearBuffer(Type.Normal);
|
|
clone.setBuffer(newNorm);
|
|
clone.setBuffer(newNorm);
|
|
-
|
|
|
|
|
|
+
|
|
if (getBuffer(Type.BindPoseTangent) != null){
|
|
if (getBuffer(Type.BindPoseTangent) != null){
|
|
VertexBuffer oldTang = getBuffer(Type.Tangent);
|
|
VertexBuffer oldTang = getBuffer(Type.Tangent);
|
|
VertexBuffer newTang = oldTang.clone();
|
|
VertexBuffer newTang = oldTang.clone();
|
|
@@ -278,14 +278,42 @@ public class Mesh extends NativeObject implements Savable {
|
|
return clone;
|
|
return clone;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Called internally by com.jme3.util.clone.Cloner. Do not call directly.
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Mesh jmeClone() {
|
|
|
|
+ try {
|
|
|
|
+ Mesh clone = (Mesh)super.clone();
|
|
|
|
+ return clone;
|
|
|
|
+ } catch (CloneNotSupportedException ex) {
|
|
|
|
+ throw new AssertionError();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Called internally by com.jme3.util.clone.Cloner. Do not call directly.
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void cloneFields( Cloner cloner, Object original ) {
|
|
|
|
+
|
|
|
|
+ // Probably could clone this now but it will get regenerated anyway.
|
|
|
|
+ this.collisionTree = null;
|
|
|
|
+
|
|
|
|
+ this.meshBound = cloner.clone(meshBound);
|
|
|
|
+ this.buffersList = cloner.clone(buffersList);
|
|
|
|
+ this.buffers = cloner.clone(buffers);
|
|
|
|
+ this.lodLevels = cloner.clone(lodLevels);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Generates the {@link Type#BindPosePosition}, {@link Type#BindPoseNormal},
|
|
* Generates the {@link Type#BindPosePosition}, {@link Type#BindPoseNormal},
|
|
- * and {@link Type#BindPoseTangent}
|
|
|
|
|
|
+ * and {@link Type#BindPoseTangent}
|
|
* buffers for this mesh by duplicating them based on the position and normal
|
|
* buffers for this mesh by duplicating them based on the position and normal
|
|
* buffers already set on the mesh.
|
|
* buffers already set on the mesh.
|
|
* This method does nothing if the mesh has no bone weight or index
|
|
* This method does nothing if the mesh has no bone weight or index
|
|
* buffers.
|
|
* buffers.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param forSoftwareAnim Should be true if the bind pose is to be generated.
|
|
* @param forSoftwareAnim Should be true if the bind pose is to be generated.
|
|
*/
|
|
*/
|
|
public void generateBindPose(boolean forSoftwareAnim){
|
|
public void generateBindPose(boolean forSoftwareAnim){
|
|
@@ -318,7 +346,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
setBuffer(bindNorm);
|
|
setBuffer(bindNorm);
|
|
norm.setUsage(Usage.Stream);
|
|
norm.setUsage(Usage.Stream);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
VertexBuffer tangents = getBuffer(Type.Tangent);
|
|
VertexBuffer tangents = getBuffer(Type.Tangent);
|
|
if (tangents != null) {
|
|
if (tangents != null) {
|
|
VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent);
|
|
VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent);
|
|
@@ -334,8 +362,8 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Prepares the mesh for software skinning by converting the bone index
|
|
* Prepares the mesh for software skinning by converting the bone index
|
|
- * and weight buffers to heap buffers.
|
|
|
|
- *
|
|
|
|
|
|
+ * and weight buffers to heap buffers.
|
|
|
|
+ *
|
|
* @param forSoftwareAnim Should be true to enable the conversion.
|
|
* @param forSoftwareAnim Should be true to enable the conversion.
|
|
*/
|
|
*/
|
|
public void prepareForAnim(boolean forSoftwareAnim){
|
|
public void prepareForAnim(boolean forSoftwareAnim){
|
|
@@ -379,7 +407,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
//if HWBoneIndex and HWBoneWeight are empty, we setup them as direct
|
|
//if HWBoneIndex and HWBoneWeight are empty, we setup them as direct
|
|
- //buffers with software anim buffers data
|
|
|
|
|
|
+ //buffers with software anim buffers data
|
|
VertexBuffer indicesHW = getBuffer(Type.HWBoneIndex);
|
|
VertexBuffer indicesHW = getBuffer(Type.HWBoneIndex);
|
|
if (indicesHW.getData() == null) {
|
|
if (indicesHW.getData() == null) {
|
|
VertexBuffer indices = getBuffer(Type.BoneIndex);
|
|
VertexBuffer indices = getBuffer(Type.BoneIndex);
|
|
@@ -389,7 +417,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
directIndex.put(originalIndex);
|
|
directIndex.put(originalIndex);
|
|
indicesHW.setupData(Usage.Static, indices.getNumComponents(), indices.getFormat(), directIndex);
|
|
indicesHW.setupData(Usage.Static, indices.getNumComponents(), indices.getFormat(), directIndex);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
VertexBuffer weightsHW = getBuffer(Type.HWBoneWeight);
|
|
VertexBuffer weightsHW = getBuffer(Type.HWBoneWeight);
|
|
if (weightsHW.getData() == null) {
|
|
if (weightsHW.getData() == null) {
|
|
VertexBuffer weights = getBuffer(Type.BoneWeight);
|
|
VertexBuffer weights = getBuffer(Type.BoneWeight);
|
|
@@ -399,26 +427,26 @@ public class Mesh extends NativeObject implements Savable {
|
|
directWeight.put(originalWeight);
|
|
directWeight.put(originalWeight);
|
|
weightsHW.setupData(Usage.Static, weights.getNumComponents(), weights.getFormat(), directWeight);
|
|
weightsHW.setupData(Usage.Static, weights.getNumComponents(), weights.getFormat(), directWeight);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// position, normal, and tanget buffers to be in "Static" mode
|
|
// position, normal, and tanget buffers to be in "Static" mode
|
|
VertexBuffer positions = getBuffer(Type.Position);
|
|
VertexBuffer positions = getBuffer(Type.Position);
|
|
VertexBuffer normals = getBuffer(Type.Normal);
|
|
VertexBuffer normals = getBuffer(Type.Normal);
|
|
VertexBuffer tangents = getBuffer(Type.Tangent);
|
|
VertexBuffer tangents = getBuffer(Type.Tangent);
|
|
-
|
|
|
|
|
|
+
|
|
VertexBuffer positionsBP = getBuffer(Type.BindPosePosition);
|
|
VertexBuffer positionsBP = getBuffer(Type.BindPosePosition);
|
|
VertexBuffer normalsBP = getBuffer(Type.BindPoseNormal);
|
|
VertexBuffer normalsBP = getBuffer(Type.BindPoseNormal);
|
|
VertexBuffer tangentsBP = getBuffer(Type.BindPoseTangent);
|
|
VertexBuffer tangentsBP = getBuffer(Type.BindPoseTangent);
|
|
-
|
|
|
|
|
|
+
|
|
positions.setUsage(Usage.Static);
|
|
positions.setUsage(Usage.Static);
|
|
positionsBP.copyElements(0, positions, 0, positionsBP.getNumElements());
|
|
positionsBP.copyElements(0, positions, 0, positionsBP.getNumElements());
|
|
positions.setUpdateNeeded();
|
|
positions.setUpdateNeeded();
|
|
-
|
|
|
|
|
|
+
|
|
if (normals != null) {
|
|
if (normals != null) {
|
|
normals.setUsage(Usage.Static);
|
|
normals.setUsage(Usage.Static);
|
|
normalsBP.copyElements(0, normals, 0, normalsBP.getNumElements());
|
|
normalsBP.copyElements(0, normals, 0, normalsBP.getNumElements());
|
|
normals.setUpdateNeeded();
|
|
normals.setUpdateNeeded();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (tangents != null) {
|
|
if (tangents != null) {
|
|
tangents.setUsage(Usage.Static);
|
|
tangents.setUsage(Usage.Static);
|
|
tangentsBP.copyElements(0, tangents, 0, tangentsBP.getNumElements());
|
|
tangentsBP.copyElements(0, tangents, 0, tangentsBP.getNumElements());
|
|
@@ -429,7 +457,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Set the LOD (level of detail) index buffers on this mesh.
|
|
* Set the LOD (level of detail) index buffers on this mesh.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param lodLevels The LOD levels to set
|
|
* @param lodLevels The LOD levels to set
|
|
*/
|
|
*/
|
|
public void setLodLevels(VertexBuffer[] lodLevels){
|
|
public void setLodLevels(VertexBuffer[] lodLevels){
|
|
@@ -446,15 +474,15 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the lod level at the given index.
|
|
* Returns the lod level at the given index.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param lod The lod level index, this does not include
|
|
* @param lod The lod level index, this does not include
|
|
* the main index buffer.
|
|
* the main index buffer.
|
|
* @return The LOD index buffer at the index
|
|
* @return The LOD index buffer at the index
|
|
- *
|
|
|
|
- * @throws IndexOutOfBoundsException If the index is outside of the
|
|
|
|
|
|
+ *
|
|
|
|
+ * @throws IndexOutOfBoundsException If the index is outside of the
|
|
* range [0, {@link #getNumLodLevels()}].
|
|
* range [0, {@link #getNumLodLevels()}].
|
|
- *
|
|
|
|
- * @see #setLodLevels(com.jme3.scene.VertexBuffer[])
|
|
|
|
|
|
+ *
|
|
|
|
+ * @see #setLodLevels(com.jme3.scene.VertexBuffer[])
|
|
*/
|
|
*/
|
|
public VertexBuffer getLodLevel(int lod){
|
|
public VertexBuffer getLodLevel(int lod){
|
|
return lodLevels[lod];
|
|
return lodLevels[lod];
|
|
@@ -462,10 +490,10 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the mesh mode
|
|
* Returns the mesh mode
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return the mesh mode
|
|
* @return the mesh mode
|
|
- *
|
|
|
|
- * @see #setMode(com.jme3.scene.Mesh.Mode)
|
|
|
|
|
|
+ *
|
|
|
|
+ * @see #setMode(com.jme3.scene.Mesh.Mode)
|
|
*/
|
|
*/
|
|
public Mode getMode() {
|
|
public Mode getMode() {
|
|
return mode;
|
|
return mode;
|
|
@@ -473,9 +501,9 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Change the Mesh's mode. By default the mode is {@link Mode#Triangles}.
|
|
* Change the Mesh's mode. By default the mode is {@link Mode#Triangles}.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param mode The new mode to set
|
|
* @param mode The new mode to set
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @see Mode
|
|
* @see Mode
|
|
*/
|
|
*/
|
|
public void setMode(Mode mode) {
|
|
public void setMode(Mode mode) {
|
|
@@ -485,10 +513,10 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the maximum number of weights per vertex on this mesh.
|
|
* Returns the maximum number of weights per vertex on this mesh.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return maximum number of weights per vertex
|
|
* @return maximum number of weights per vertex
|
|
- *
|
|
|
|
- * @see #setMaxNumWeights(int)
|
|
|
|
|
|
+ *
|
|
|
|
+ * @see #setMaxNumWeights(int)
|
|
*/
|
|
*/
|
|
public int getMaxNumWeights() {
|
|
public int getMaxNumWeights() {
|
|
return maxNumWeights;
|
|
return maxNumWeights;
|
|
@@ -498,8 +526,8 @@ public class Mesh extends NativeObject implements Savable {
|
|
* Set the maximum number of weights per vertex on this mesh.
|
|
* Set the maximum number of weights per vertex on this mesh.
|
|
* Only relevant if this mesh has bone index/weight buffers.
|
|
* Only relevant if this mesh has bone index/weight buffers.
|
|
* This value should be between 0 and 4.
|
|
* This value should be between 0 and 4.
|
|
- *
|
|
|
|
- * @param maxNumWeights
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param maxNumWeights
|
|
*/
|
|
*/
|
|
public void setMaxNumWeights(int maxNumWeights) {
|
|
public void setMaxNumWeights(int maxNumWeights) {
|
|
this.maxNumWeights = maxNumWeights;
|
|
this.maxNumWeights = maxNumWeights;
|
|
@@ -507,23 +535,23 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the size of points for point meshes
|
|
* Returns the size of points for point meshes
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return the size of points
|
|
* @return the size of points
|
|
- *
|
|
|
|
- * @see #setPointSize(float)
|
|
|
|
|
|
+ *
|
|
|
|
+ * @see #setPointSize(float)
|
|
*/
|
|
*/
|
|
public float getPointSize() {
|
|
public float getPointSize() {
|
|
return pointSize;
|
|
return pointSize;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Set the size of points for meshes of mode {@link Mode#Points}.
|
|
|
|
|
|
+ * Set the size of points for meshes of mode {@link Mode#Points}.
|
|
* The point size is specified as on-screen pixels, the default
|
|
* The point size is specified as on-screen pixels, the default
|
|
* value is 1.0. The point size
|
|
* value is 1.0. The point size
|
|
* does nothing if {@link RenderState#setPointSprite(boolean) point sprite}
|
|
* does nothing if {@link RenderState#setPointSprite(boolean) point sprite}
|
|
- * render state is enabled, in that case, the vertex shader must specify the
|
|
|
|
|
|
+ * render state is enabled, in that case, the vertex shader must specify the
|
|
* point size by writing to <code>gl_PointSize</code>.
|
|
* point size by writing to <code>gl_PointSize</code>.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param pointSize The size of points
|
|
* @param pointSize The size of points
|
|
*/
|
|
*/
|
|
public void setPointSize(float pointSize) {
|
|
public void setPointSize(float pointSize) {
|
|
@@ -532,26 +560,30 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the line width for line meshes.
|
|
* Returns the line width for line meshes.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return the line width
|
|
* @return the line width
|
|
|
|
+ * @deprecated use {@link Material#getAdditionalRenderState()} and {@link RenderState#getLineWidth()}
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public float getLineWidth() {
|
|
public float getLineWidth() {
|
|
return lineWidth;
|
|
return lineWidth;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Specify the line width for meshes of the line modes, such
|
|
* Specify the line width for meshes of the line modes, such
|
|
- * as {@link Mode#Lines}. The line width is specified as on-screen pixels,
|
|
|
|
|
|
+ * as {@link Mode#Lines}. The line width is specified as on-screen pixels,
|
|
* the default value is 1.0.
|
|
* the default value is 1.0.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param lineWidth The line width
|
|
* @param lineWidth The line width
|
|
|
|
+ * @deprecated use {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)}
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public void setLineWidth(float lineWidth) {
|
|
public void setLineWidth(float lineWidth) {
|
|
this.lineWidth = lineWidth;
|
|
this.lineWidth = lineWidth;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Indicates to the GPU that this mesh will not be modified (a hint).
|
|
|
|
|
|
+ * Indicates to the GPU that this mesh will not be modified (a hint).
|
|
* Sets the usage mode to {@link Usage#Static}
|
|
* Sets the usage mode to {@link Usage#Static}
|
|
* for all {@link VertexBuffer vertex buffers} on this Mesh.
|
|
* for all {@link VertexBuffer vertex buffers} on this Mesh.
|
|
*/
|
|
*/
|
|
@@ -592,7 +624,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
public void setInterleaved(){
|
|
public void setInterleaved(){
|
|
ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>();
|
|
ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>();
|
|
vbs.addAll(buffersList);
|
|
vbs.addAll(buffersList);
|
|
-
|
|
|
|
|
|
+
|
|
// ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(buffers.values());
|
|
// ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(buffers.values());
|
|
// index buffer not included when interleaving
|
|
// index buffer not included when interleaving
|
|
vbs.remove(getBuffer(Type.Index));
|
|
vbs.remove(getBuffer(Type.Index));
|
|
@@ -611,7 +643,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
VertexBuffer allData = new VertexBuffer(Type.InterleavedData);
|
|
VertexBuffer allData = new VertexBuffer(Type.InterleavedData);
|
|
ByteBuffer dataBuf = BufferUtils.createByteBuffer(stride * getVertexCount());
|
|
ByteBuffer dataBuf = BufferUtils.createByteBuffer(stride * getVertexCount());
|
|
allData.setupData(Usage.Static, 1, Format.UnsignedByte, dataBuf);
|
|
allData.setupData(Usage.Static, 1, Format.UnsignedByte, dataBuf);
|
|
-
|
|
|
|
|
|
+
|
|
// adding buffer directly so that no update counts is forced
|
|
// adding buffer directly so that no update counts is forced
|
|
buffers.put(Type.InterleavedData.ordinal(), allData);
|
|
buffers.put(Type.InterleavedData.ordinal(), allData);
|
|
buffersList.add(allData);
|
|
buffersList.add(allData);
|
|
@@ -662,7 +694,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
for (VertexBuffer vb : vbs){
|
|
for (VertexBuffer vb : vbs){
|
|
vb.setOffset(offset);
|
|
vb.setOffset(offset);
|
|
vb.setStride(stride);
|
|
vb.setStride(stride);
|
|
-
|
|
|
|
|
|
+
|
|
vb.updateData(null);
|
|
vb.updateData(null);
|
|
//vb.setupData(vb.usage, vb.components, vb.format, null);
|
|
//vb.setupData(vb.usage, vb.components, vb.format, null);
|
|
offset += vb.componentsLength;
|
|
offset += vb.componentsLength;
|
|
@@ -696,20 +728,20 @@ public class Mesh extends NativeObject implements Savable {
|
|
int max = 0;
|
|
int max = 0;
|
|
for( VertexBuffer vb : buffersList ) {
|
|
for( VertexBuffer vb : buffersList ) {
|
|
if( vb.getBaseInstanceCount() > max ) {
|
|
if( vb.getBaseInstanceCount() > max ) {
|
|
- max = vb.getBaseInstanceCount();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ max = vb.getBaseInstanceCount();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return max;
|
|
return max;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Update the {@link #getVertexCount() vertex} and
|
|
|
|
|
|
+ * Update the {@link #getVertexCount() vertex} and
|
|
* {@link #getTriangleCount() triangle} counts for this mesh
|
|
* {@link #getTriangleCount() triangle} counts for this mesh
|
|
* based on the current data. This method should be called
|
|
* based on the current data. This method should be called
|
|
* after the {@link Buffer#capacity() capacities} of the mesh's
|
|
* after the {@link Buffer#capacity() capacities} of the mesh's
|
|
* {@link VertexBuffer vertex buffers} has been altered.
|
|
* {@link VertexBuffer vertex buffers} has been altered.
|
|
- *
|
|
|
|
- * @throws IllegalStateException If this mesh is in
|
|
|
|
|
|
+ *
|
|
|
|
+ * @throws IllegalStateException If this mesh is in
|
|
* {@link #setInterleaved() interleaved} format.
|
|
* {@link #setInterleaved() interleaved} format.
|
|
*/
|
|
*/
|
|
public void updateCounts(){
|
|
public void updateCounts(){
|
|
@@ -739,7 +771,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the triangle count for the given LOD level.
|
|
* Returns the triangle count for the given LOD level.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param lod The lod level to look up
|
|
* @param lod The lod level to look up
|
|
* @return The triangle count for that LOD level
|
|
* @return The triangle count for that LOD level
|
|
*/
|
|
*/
|
|
@@ -762,10 +794,10 @@ public class Mesh extends NativeObject implements Savable {
|
|
/**
|
|
/**
|
|
* Returns how many triangles or elements are on this Mesh.
|
|
* Returns how many triangles or elements are on this Mesh.
|
|
* This value is only updated when {@link #updateCounts() } is called.
|
|
* This value is only updated when {@link #updateCounts() } is called.
|
|
- * If the mesh mode is not a triangle mode, then this returns the
|
|
|
|
|
|
+ * If the mesh mode is not a triangle mode, then this returns the
|
|
* number of elements/primitives, e.g. how many lines or how many points,
|
|
* number of elements/primitives, e.g. how many lines or how many points,
|
|
* instead of how many triangles.
|
|
* instead of how many triangles.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return how many triangles/elements are on this Mesh.
|
|
* @return how many triangles/elements are on this Mesh.
|
|
*/
|
|
*/
|
|
public int getTriangleCount(){
|
|
public int getTriangleCount(){
|
|
@@ -774,30 +806,30 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the number of vertices on this mesh.
|
|
* Returns the number of vertices on this mesh.
|
|
- * The value is computed based on the position buffer, which
|
|
|
|
|
|
+ * The value is computed based on the position buffer, which
|
|
* must be set on all meshes.
|
|
* must be set on all meshes.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return Number of vertices on the mesh
|
|
* @return Number of vertices on the mesh
|
|
*/
|
|
*/
|
|
public int getVertexCount(){
|
|
public int getVertexCount(){
|
|
return vertCount;
|
|
return vertCount;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns the number of instances this mesh contains. The instance
|
|
* Returns the number of instances this mesh contains. The instance
|
|
* count is based on any VertexBuffers with instancing set.
|
|
* count is based on any VertexBuffers with instancing set.
|
|
*/
|
|
*/
|
|
public int getInstanceCount() {
|
|
public int getInstanceCount() {
|
|
return instanceCount;
|
|
return instanceCount;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Gets the triangle vertex positions at the given triangle index
|
|
|
|
|
|
+ * Gets the triangle vertex positions at the given triangle index
|
|
* and stores them into the v1, v2, v3 arguments.
|
|
* and stores them into the v1, v2, v3 arguments.
|
|
- *
|
|
|
|
- * @param index The index of the triangle.
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param index The index of the triangle.
|
|
* Should be between 0 and {@link #getTriangleCount()}.
|
|
* Should be between 0 and {@link #getTriangleCount()}.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param v1 Vector to contain first vertex position
|
|
* @param v1 Vector to contain first vertex position
|
|
* @param v2 Vector to contain second vertex position
|
|
* @param v2 Vector to contain second vertex position
|
|
* @param v3 Vector to contain third vertex position
|
|
* @param v3 Vector to contain third vertex position
|
|
@@ -822,15 +854,15 @@ public class Mesh extends NativeObject implements Savable {
|
|
+ " has incompatible format");
|
|
+ " has incompatible format");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Gets the triangle vertex positions at the given triangle index
|
|
|
|
|
|
+ * Gets the triangle vertex positions at the given triangle index
|
|
* and stores them into the {@link Triangle} argument.
|
|
* and stores them into the {@link Triangle} argument.
|
|
* Also sets the triangle index to the <code>index</code> argument.
|
|
* Also sets the triangle index to the <code>index</code> argument.
|
|
- *
|
|
|
|
- * @param index The index of the triangle.
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param index The index of the triangle.
|
|
* Should be between 0 and {@link #getTriangleCount()}.
|
|
* Should be between 0 and {@link #getTriangleCount()}.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param tri The triangle to store the positions in
|
|
* @param tri The triangle to store the positions in
|
|
*/
|
|
*/
|
|
public void getTriangle(int index, Triangle tri){
|
|
public void getTriangle(int index, Triangle tri){
|
|
@@ -840,12 +872,12 @@ public class Mesh extends NativeObject implements Savable {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Gets the triangle vertex indices at the given triangle index
|
|
|
|
|
|
+ * Gets the triangle vertex indices at the given triangle index
|
|
* and stores them into the given int array.
|
|
* and stores them into the given int array.
|
|
- *
|
|
|
|
- * @param index The index of the triangle.
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param index The index of the triangle.
|
|
* Should be between 0 and {@link #getTriangleCount()}.
|
|
* Should be between 0 and {@link #getTriangleCount()}.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param indices Indices of the triangle's vertices
|
|
* @param indices Indices of the triangle's vertices
|
|
*/
|
|
*/
|
|
public void getTriangle(int index, int[] indices){
|
|
public void getTriangle(int index, int[] indices){
|
|
@@ -860,9 +892,9 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Generates a collision tree for the mesh.
|
|
* Generates a collision tree for the mesh.
|
|
- * Called automatically by {@link #collideWith(com.jme3.collision.Collidable,
|
|
|
|
- * com.jme3.math.Matrix4f,
|
|
|
|
- * com.jme3.bounding.BoundingVolume,
|
|
|
|
|
|
+ * Called automatically by {@link #collideWith(com.jme3.collision.Collidable,
|
|
|
|
+ * com.jme3.math.Matrix4f,
|
|
|
|
+ * com.jme3.bounding.BoundingVolume,
|
|
* com.jme3.collision.CollisionResults) }.
|
|
* com.jme3.collision.CollisionResults) }.
|
|
*/
|
|
*/
|
|
public void createCollisionData(){
|
|
public void createCollisionData(){
|
|
@@ -885,7 +917,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
* User code should only use collideWith() on scene
|
|
* User code should only use collideWith() on scene
|
|
* graph elements such as {@link Spatial}s.
|
|
* graph elements such as {@link Spatial}s.
|
|
*/
|
|
*/
|
|
- public int collideWith(Collidable other,
|
|
|
|
|
|
+ public int collideWith(Collidable other,
|
|
Matrix4f worldMatrix,
|
|
Matrix4f worldMatrix,
|
|
BoundingVolume worldBound,
|
|
BoundingVolume worldBound,
|
|
CollisionResults results){
|
|
CollisionResults results){
|
|
@@ -893,18 +925,18 @@ public class Mesh extends NativeObject implements Savable {
|
|
if (getVertexCount() == 0) {
|
|
if (getVertexCount() == 0) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (collisionTree == null){
|
|
if (collisionTree == null){
|
|
createCollisionData();
|
|
createCollisionData();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return collisionTree.collideWith(other, worldMatrix, worldBound, results);
|
|
return collisionTree.collideWith(other, worldMatrix, worldBound, results);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sets the {@link VertexBuffer} on the mesh.
|
|
* Sets the {@link VertexBuffer} on the mesh.
|
|
* This will update the vertex/triangle counts if needed.
|
|
* This will update the vertex/triangle counts if needed.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param vb The buffer to set
|
|
* @param vb The buffer to set
|
|
* @throws IllegalArgumentException If the buffer type is already set
|
|
* @throws IllegalArgumentException If the buffer type is already set
|
|
*/
|
|
*/
|
|
@@ -916,12 +948,12 @@ public class Mesh extends NativeObject implements Savable {
|
|
buffersList.add(vb);
|
|
buffersList.add(vb);
|
|
updateCounts();
|
|
updateCounts();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Unsets the {@link VertexBuffer} set on this mesh
|
|
* Unsets the {@link VertexBuffer} set on this mesh
|
|
- * with the given type. Does nothing if the vertex buffer type is not set
|
|
|
|
|
|
+ * with the given type. Does nothing if the vertex buffer type is not set
|
|
* initially.
|
|
* initially.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param type The buffer type to remove
|
|
* @param type The buffer type to remove
|
|
*/
|
|
*/
|
|
public void clearBuffer(VertexBuffer.Type type){
|
|
public void clearBuffer(VertexBuffer.Type type){
|
|
@@ -931,17 +963,17 @@ public class Mesh extends NativeObject implements Savable {
|
|
updateCounts();
|
|
updateCounts();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Creates a {@link VertexBuffer} for the mesh or modifies
|
|
* Creates a {@link VertexBuffer} for the mesh or modifies
|
|
* the existing one per the parameters given.
|
|
* the existing one per the parameters given.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param type The type of the buffer
|
|
* @param type The type of the buffer
|
|
* @param components Number of components
|
|
* @param components Number of components
|
|
* @param format Data format
|
|
* @param format Data format
|
|
* @param buf The buffer data
|
|
* @param buf The buffer data
|
|
- *
|
|
|
|
- * @throws UnsupportedOperationException If the buffer already set is
|
|
|
|
|
|
+ *
|
|
|
|
+ * @throws UnsupportedOperationException If the buffer already set is
|
|
* incompatible with the parameters given.
|
|
* incompatible with the parameters given.
|
|
*/
|
|
*/
|
|
public void setBuffer(Type type, int components, Format format, Buffer buf){
|
|
public void setBuffer(Type type, int components, Format format, Buffer buf){
|
|
@@ -959,16 +991,16 @@ public class Mesh extends NativeObject implements Savable {
|
|
updateCounts();
|
|
updateCounts();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Set a floating point {@link VertexBuffer} on the mesh.
|
|
|
|
- *
|
|
|
|
- * @param type The type of {@link VertexBuffer},
|
|
|
|
|
|
+ * Set a floating point {@link VertexBuffer} on the mesh.
|
|
|
|
+ *
|
|
|
|
+ * @param type The type of {@link VertexBuffer},
|
|
* e.g. {@link Type#Position}, {@link Type#Normal}, etc.
|
|
* e.g. {@link Type#Position}, {@link Type#Normal}, etc.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param components Number of components on the vertex buffer, should
|
|
* @param components Number of components on the vertex buffer, should
|
|
* be between 1 and 4.
|
|
* be between 1 and 4.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param buf The floating point data to contain
|
|
* @param buf The floating point data to contain
|
|
*/
|
|
*/
|
|
public void setBuffer(Type type, int components, FloatBuffer buf) {
|
|
public void setBuffer(Type type, int components, FloatBuffer buf) {
|
|
@@ -1006,9 +1038,9 @@ public class Mesh extends NativeObject implements Savable {
|
|
/**
|
|
/**
|
|
* Get the {@link VertexBuffer} stored on this mesh with the given
|
|
* Get the {@link VertexBuffer} stored on this mesh with the given
|
|
* type.
|
|
* type.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param type The type of VertexBuffer
|
|
* @param type The type of VertexBuffer
|
|
- * @return the VertexBuffer data, or null if not set
|
|
|
|
|
|
+ * @return the VertexBuffer data, or null if not set
|
|
*/
|
|
*/
|
|
public VertexBuffer getBuffer(Type type){
|
|
public VertexBuffer getBuffer(Type type){
|
|
return buffers.get(type.ordinal());
|
|
return buffers.get(type.ordinal());
|
|
@@ -1017,7 +1049,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
/**
|
|
/**
|
|
* Get the {@link VertexBuffer} data stored on this mesh in float
|
|
* Get the {@link VertexBuffer} data stored on this mesh in float
|
|
* format.
|
|
* format.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param type The type of VertexBuffer
|
|
* @param type The type of VertexBuffer
|
|
* @return the VertexBuffer data, or null if not set
|
|
* @return the VertexBuffer data, or null if not set
|
|
*/
|
|
*/
|
|
@@ -1028,11 +1060,11 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
return (FloatBuffer) vb.getData();
|
|
return (FloatBuffer) vb.getData();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Get the {@link VertexBuffer} data stored on this mesh in short
|
|
* Get the {@link VertexBuffer} data stored on this mesh in short
|
|
* format.
|
|
* format.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param type The type of VertexBuffer
|
|
* @param type The type of VertexBuffer
|
|
* @return the VertexBuffer data, or null if not set
|
|
* @return the VertexBuffer data, or null if not set
|
|
*/
|
|
*/
|
|
@@ -1047,40 +1079,40 @@ public class Mesh extends NativeObject implements Savable {
|
|
/**
|
|
/**
|
|
* Acquires an index buffer that will read the vertices on the mesh
|
|
* Acquires an index buffer that will read the vertices on the mesh
|
|
* as a list.
|
|
* as a list.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return A virtual or wrapped index buffer to read the data as a list
|
|
* @return A virtual or wrapped index buffer to read the data as a list
|
|
*/
|
|
*/
|
|
public IndexBuffer getIndicesAsList(){
|
|
public IndexBuffer getIndicesAsList(){
|
|
IndexBuffer ib = getIndexBuffer();
|
|
IndexBuffer ib = getIndexBuffer();
|
|
- if (ib != null) {
|
|
|
|
- if (mode.isListMode()) {
|
|
|
|
|
|
+ if (ib != null){
|
|
|
|
+ if (mode.isListMode()){
|
|
// already in list mode
|
|
// already in list mode
|
|
return ib;
|
|
return ib;
|
|
- } else {
|
|
|
|
|
|
+ }else{
|
|
// not in list mode but it does have an index buffer
|
|
// not in list mode but it does have an index buffer
|
|
// wrap it so the data is converted to list format
|
|
// wrap it so the data is converted to list format
|
|
return new WrappedIndexBuffer(this);
|
|
return new WrappedIndexBuffer(this);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ }else{
|
|
// return a virtual index buffer that will supply
|
|
// return a virtual index buffer that will supply
|
|
// "fake" indices in list format
|
|
// "fake" indices in list format
|
|
return new VirtualIndexBuffer(vertCount, mode);
|
|
return new VirtualIndexBuffer(vertCount, mode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Get the index buffer for this mesh.
|
|
|
|
|
|
+ * Get the index buffer for this mesh.
|
|
* Will return <code>null</code> if no index buffer is set.
|
|
* Will return <code>null</code> if no index buffer is set.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return The index buffer of this mesh.
|
|
* @return The index buffer of this mesh.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @see Type#Index
|
|
* @see Type#Index
|
|
*/
|
|
*/
|
|
public IndexBuffer getIndexBuffer() {
|
|
public IndexBuffer getIndexBuffer() {
|
|
VertexBuffer vb = getBuffer(Type.Index);
|
|
VertexBuffer vb = getBuffer(Type.Index);
|
|
if (vb == null)
|
|
if (vb == null)
|
|
return null;
|
|
return null;
|
|
-
|
|
|
|
|
|
+
|
|
return IndexBuffer.wrapIndexBuffer(vb.getData());
|
|
return IndexBuffer.wrapIndexBuffer(vb.getData());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1090,7 +1122,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
* to index into the attributes of the other mesh.
|
|
* to index into the attributes of the other mesh.
|
|
* Note that this will also change this mesh's index buffer so that
|
|
* Note that this will also change this mesh's index buffer so that
|
|
* the references to the vertex data match the new indices.
|
|
* the references to the vertex data match the new indices.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param other The mesh to extract the vertex data from
|
|
* @param other The mesh to extract the vertex data from
|
|
*/
|
|
*/
|
|
public void extractVertexData(Mesh other) {
|
|
public void extractVertexData(Mesh other) {
|
|
@@ -1110,7 +1142,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
int oldIndex = indexBuf.get(i);
|
|
int oldIndex = indexBuf.get(i);
|
|
|
|
|
|
if (!oldIndicesToNewIndices.containsKey(oldIndex)) {
|
|
if (!oldIndicesToNewIndices.containsKey(oldIndex)) {
|
|
- // this vertex has not been added, so allocate a
|
|
|
|
|
|
+ // this vertex has not been added, so allocate a
|
|
// new index for it and add it to the map
|
|
// new index for it and add it to the map
|
|
oldIndicesToNewIndices.put(oldIndex, newIndex);
|
|
oldIndicesToNewIndices.put(oldIndex, newIndex);
|
|
newIndicesToOldIndices.add(oldIndex);
|
|
newIndicesToOldIndices.add(oldIndex);
|
|
@@ -1127,8 +1159,8 @@ public class Mesh extends NativeObject implements Savable {
|
|
throw new AssertionError();
|
|
throw new AssertionError();
|
|
}
|
|
}
|
|
|
|
|
|
- // Create the new index buffer.
|
|
|
|
- // Do not overwrite the old one because we might be able to
|
|
|
|
|
|
+ // Create the new index buffer.
|
|
|
|
+ // Do not overwrite the old one because we might be able to
|
|
// convert from int index buffer to short index buffer
|
|
// convert from int index buffer to short index buffer
|
|
IndexBuffer newIndexBuf;
|
|
IndexBuffer newIndexBuf;
|
|
if (newNumVerts >= 65536) {
|
|
if (newNumVerts >= 65536) {
|
|
@@ -1144,10 +1176,10 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
newIndexBuf.put(i, newIndex);
|
|
newIndexBuf.put(i, newIndex);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
VertexBuffer newIdxBuf = new VertexBuffer(Type.Index);
|
|
VertexBuffer newIdxBuf = new VertexBuffer(Type.Index);
|
|
- newIdxBuf.setupData(oldIdxBuf.getUsage(),
|
|
|
|
- oldIdxBuf.getNumComponents(),
|
|
|
|
|
|
+ newIdxBuf.setupData(oldIdxBuf.getUsage(),
|
|
|
|
+ oldIdxBuf.getNumComponents(),
|
|
newIndexBuf instanceof IndexIntBuffer ? Format.UnsignedInt : Format.UnsignedShort,
|
|
newIndexBuf instanceof IndexIntBuffer ? Format.UnsignedInt : Format.UnsignedShort,
|
|
newIndexBuf.getBuffer());
|
|
newIndexBuf.getBuffer());
|
|
clearBuffer(Type.Index);
|
|
clearBuffer(Type.Index);
|
|
@@ -1163,7 +1195,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
|
|
|
|
VertexBuffer newVb = new VertexBuffer(oldVb.getBufferType());
|
|
VertexBuffer newVb = new VertexBuffer(oldVb.getBufferType());
|
|
newVb.setNormalized(oldVb.isNormalized());
|
|
newVb.setNormalized(oldVb.isNormalized());
|
|
- //check for data before copying, some buffers are just empty shells
|
|
|
|
|
|
+ //check for data before copying, some buffers are just empty shells
|
|
//for caching purpose (HW skinning buffers), and will be filled when
|
|
//for caching purpose (HW skinning buffers), and will be filled when
|
|
//needed
|
|
//needed
|
|
if(oldVb.getData()!=null){
|
|
if(oldVb.getData()!=null){
|
|
@@ -1181,32 +1213,32 @@ public class Mesh extends NativeObject implements Savable {
|
|
oldVb.copyElement(oldIndex, newVb, i);
|
|
oldVb.copyElement(oldIndex, newVb, i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// Set the buffer on the mesh
|
|
// Set the buffer on the mesh
|
|
clearBuffer(newVb.getBufferType());
|
|
clearBuffer(newVb.getBufferType());
|
|
setBuffer(newVb);
|
|
setBuffer(newVb);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// Copy max weights per vertex as well
|
|
// Copy max weights per vertex as well
|
|
setMaxNumWeights(other.getMaxNumWeights());
|
|
setMaxNumWeights(other.getMaxNumWeights());
|
|
-
|
|
|
|
|
|
+
|
|
// The data has been copied over, update informations
|
|
// The data has been copied over, update informations
|
|
updateCounts();
|
|
updateCounts();
|
|
updateBound();
|
|
updateBound();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Scales the texture coordinate buffer on this mesh by the given
|
|
* Scales the texture coordinate buffer on this mesh by the given
|
|
- * scale factor.
|
|
|
|
|
|
+ * scale factor.
|
|
* <p>
|
|
* <p>
|
|
- * Note that values above 1 will cause the
|
|
|
|
- * texture to tile, while values below 1 will cause the texture
|
|
|
|
|
|
+ * Note that values above 1 will cause the
|
|
|
|
+ * texture to tile, while values below 1 will cause the texture
|
|
* to stretch.
|
|
* to stretch.
|
|
* </p>
|
|
* </p>
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param scaleFactor The scale factor to scale by. Every texture
|
|
* @param scaleFactor The scale factor to scale by. Every texture
|
|
* coordinate is multiplied by this vector to get the result.
|
|
* coordinate is multiplied by this vector to get the result.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @throws IllegalStateException If there's no texture coordinate
|
|
* @throws IllegalStateException If there's no texture coordinate
|
|
* buffer on the mesh
|
|
* buffer on the mesh
|
|
* @throws UnsupportedOperationException If the texture coordinate
|
|
* @throws UnsupportedOperationException If the texture coordinate
|
|
@@ -1238,7 +1270,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Updates the bounding volume of this mesh.
|
|
|
|
|
|
+ * Updates the bounding volume of this mesh.
|
|
* The method does nothing if the mesh has no {@link Type#Position} buffer.
|
|
* The method does nothing if the mesh has no {@link Type#Position} buffer.
|
|
* It is expected that the position buffer is a float buffer with 3 components.
|
|
* It is expected that the position buffer is a float buffer with 3 components.
|
|
*/
|
|
*/
|
|
@@ -1252,7 +1284,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
/**
|
|
/**
|
|
* Returns the {@link BoundingVolume} of this Mesh.
|
|
* Returns the {@link BoundingVolume} of this Mesh.
|
|
* By default the bounding volume is a {@link BoundingBox}.
|
|
* By default the bounding volume is a {@link BoundingBox}.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return the bounding volume of this mesh
|
|
* @return the bounding volume of this mesh
|
|
*/
|
|
*/
|
|
public BoundingVolume getBound() {
|
|
public BoundingVolume getBound() {
|
|
@@ -1262,7 +1294,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
/**
|
|
/**
|
|
* Sets the {@link BoundingVolume} for this Mesh.
|
|
* Sets the {@link BoundingVolume} for this Mesh.
|
|
* The bounding volume is recomputed by calling {@link #updateBound() }.
|
|
* The bounding volume is recomputed by calling {@link #updateBound() }.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param modelBound The model bound to set
|
|
* @param modelBound The model bound to set
|
|
*/
|
|
*/
|
|
public void setBound(BoundingVolume modelBound) {
|
|
public void setBound(BoundingVolume modelBound) {
|
|
@@ -1273,38 +1305,38 @@ public class Mesh extends NativeObject implements Savable {
|
|
* Returns a map of all {@link VertexBuffer vertex buffers} on this Mesh.
|
|
* Returns a map of all {@link VertexBuffer vertex buffers} on this Mesh.
|
|
* The integer key for the map is the {@link Enum#ordinal() ordinal}
|
|
* The integer key for the map is the {@link Enum#ordinal() ordinal}
|
|
* of the vertex buffer's {@link Type}.
|
|
* of the vertex buffer's {@link Type}.
|
|
- * Note that the returned map is a reference to the map used internally,
|
|
|
|
|
|
+ * Note that the returned map is a reference to the map used internally,
|
|
* modifying it will cause undefined results.
|
|
* modifying it will cause undefined results.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return map of vertex buffers on this mesh.
|
|
* @return map of vertex buffers on this mesh.
|
|
*/
|
|
*/
|
|
public IntMap<VertexBuffer> getBuffers(){
|
|
public IntMap<VertexBuffer> getBuffers(){
|
|
return buffers;
|
|
return buffers;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns a list of all {@link VertexBuffer vertex buffers} on this Mesh.
|
|
* Returns a list of all {@link VertexBuffer vertex buffers} on this Mesh.
|
|
* Using a list instead an IntMap via the {@link #getBuffers() } method is
|
|
* Using a list instead an IntMap via the {@link #getBuffers() } method is
|
|
* better for iteration as there's no need to create an iterator instance.
|
|
* better for iteration as there's no need to create an iterator instance.
|
|
* Note that the returned list is a reference to the list used internally,
|
|
* Note that the returned list is a reference to the list used internally,
|
|
* modifying it will cause undefined results.
|
|
* modifying it will cause undefined results.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return list of vertex buffers on this mesh.
|
|
* @return list of vertex buffers on this mesh.
|
|
*/
|
|
*/
|
|
public SafeArrayList<VertexBuffer> getBufferList(){
|
|
public SafeArrayList<VertexBuffer> getBufferList(){
|
|
return buffersList;
|
|
return buffersList;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Determines if the mesh uses bone animation.
|
|
* Determines if the mesh uses bone animation.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* A mesh uses bone animation if it has bone index / weight buffers
|
|
* A mesh uses bone animation if it has bone index / weight buffers
|
|
* such as {@link Type#BoneIndex} or {@link Type#HWBoneIndex}.
|
|
* such as {@link Type#BoneIndex} or {@link Type#HWBoneIndex}.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return true if the mesh uses bone animation, false otherwise
|
|
* @return true if the mesh uses bone animation, false otherwise
|
|
*/
|
|
*/
|
|
public boolean isAnimated() {
|
|
public boolean isAnimated() {
|
|
- return getBuffer(Type.BoneIndex) != null ||
|
|
|
|
|
|
+ return getBuffer(Type.BoneIndex) != null ||
|
|
getBuffer(Type.HWBoneIndex) != null;
|
|
getBuffer(Type.HWBoneIndex) != null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1399,7 +1431,7 @@ public class Mesh extends NativeObject implements Savable {
|
|
}
|
|
}
|
|
|
|
|
|
//creating hw animation buffers empty so that they are put in the cache
|
|
//creating hw animation buffers empty so that they are put in the cache
|
|
- if (isAnimated()) {
|
|
|
|
|
|
+ if(isAnimated()){
|
|
VertexBuffer hwBoneIndex = new VertexBuffer(Type.HWBoneIndex);
|
|
VertexBuffer hwBoneIndex = new VertexBuffer(Type.HWBoneIndex);
|
|
hwBoneIndex.setUsage(Usage.CpuOnly);
|
|
hwBoneIndex.setUsage(Usage.CpuOnly);
|
|
setBuffer(hwBoneIndex);
|
|
setBuffer(hwBoneIndex);
|