Geometry
* is managed by.
*/
protected GeometryGroupNode groupNode;
-
/**
* The start index of this Geometry's
inside
* the {@link GeometryGroupNode}.
*/
protected int startIndex = -1;
-
/**
* Morph state variable for morph animation
*/
@@ -391,8 +387,7 @@ public class Geometry extends Spatial {
}
}
-
- /**
+ /*
* Indicate that the transform of this spatial has changed and that
* a refresh is required.
*/
@@ -519,7 +514,7 @@ public class Geometry extends Spatial {
*/
@Override
public Geometry clone(boolean cloneMaterial) {
- return (Geometry)super.clone(cloneMaterial);
+ return (Geometry) super.clone(cloneMaterial);
}
/**
@@ -553,13 +548,13 @@ public class Geometry extends Spatial {
* Called internally by com.jme3.util.clone.Cloner. Do not call directly.
*/
@Override
- public void cloneFields( Cloner cloner, Object original ) {
+ public void cloneFields(Cloner cloner, Object original) {
super.cloneFields(cloner, original);
// If this is a grouped node and if our group node is
// also cloned then we'll grab its reference.
- if( groupNode != null ) {
- if( cloner.isCloned(groupNode) ) {
+ if (groupNode != null) {
+ if (cloner.isCloned(groupNode)) {
// Then resolve the reference
this.groupNode = cloner.clone(groupNode);
} else {
@@ -581,7 +576,7 @@ public class Geometry extends Spatial {
// See if we clone the mesh using the special animation
// semi-deep cloning
- if( shallowClone && mesh != null && mesh.getBuffer(Type.BindPosePosition) != null ) {
+ if (shallowClone && mesh != null && mesh.getBuffer(Type.BindPosePosition) != null) {
// Then we need to clone the mesh a little deeper
this.mesh = mesh.cloneForAnim();
} else {
@@ -593,7 +588,7 @@ public class Geometry extends Spatial {
}
public void setMorphState(float[] state) {
- if (mesh == null || mesh.getMorphTargets().length == 0){
+ if (mesh == null || mesh.getMorphTargets().length == 0) {
return;
}
@@ -608,9 +603,9 @@ public class Geometry extends Spatial {
/**
* Set the state of the morph with the given name.
- *
+ *
* If the name of the morph is not found, no state will be set.
- *
+ *
* @param morphTarget The name of the morph to set the state of
* @param state The state to set the morph to
*/
@@ -624,6 +619,7 @@ public class Geometry extends Spatial {
/**
* returns true if the morph state has changed on the last frame.
+ *
* @return true if changed, otherwise false
*/
public boolean isDirtyMorph() {
@@ -633,6 +629,7 @@ public class Geometry extends Spatial {
/**
* Seting this to true will stop this geometry morph buffer to be updated,
* unless the morph state changes
+ *
* @param dirtyMorph
*/
public void setDirtyMorph(boolean dirtyMorph) {
@@ -642,6 +639,7 @@ public class Geometry extends Spatial {
/**
* returns the morph state of this Geometry.
* Used internally by the MorphControl.
+ *
* @return an array
*/
public float[] getMorphState() {
@@ -650,9 +648,10 @@ public class Geometry extends Spatial {
}
return morphState;
}
-
+
/**
* Get the state of a morph
+ *
* @param morphTarget the name of the morph to get the state of
* @return the state of the morph, or -1 if the morph is not found
*/
@@ -660,16 +659,19 @@ public class Geometry extends Spatial {
int index = mesh.getMorphIndex(morphTarget);
if (index < 0) {
return -1;
- } else {
+ } else {
return morphState[index];
}
}
/**
- * Return the number of morph targets that can be handled on the GPU simultaneously for this geometry.
+ * Return the number of morph targets that can be handled
+ * on the GPU simultaneously for this geometry.
* Note that it depends on the material set on this geometry.
- * This number is computed and set by the MorphControl, so it might be available only after the first frame.
+ * This number is computed and set by the MorphControl,
+ * so it might be available only after the first frame.
* Else it's set to -1.
+ *
* @return the number of simultaneous morph targets handled on the GPU
*/
public int getNbSimultaneousGPUMorph() {
@@ -677,11 +679,15 @@ public class Geometry extends Spatial {
}
/**
- * Sets the number of morph targets that can be handled on the GPU simultaneously for this geometry.
+ * Sets the number of morph targets that can be handled
+ * on the GPU simultaneously for this geometry.
* Note that it depends on the material set on this geometry.
- * This number is computed and set by the MorphControl, so it might be available only after the first frame.
+ * This number is computed and set by the MorphControl,
+ * so it might be available only after the first frame.
* Else it's set to -1.
- * WARNING: setting this manually might crash the shader compilation if set too high. Do it at your own risk.
+ * WARNING: setting this manually might crash the shader compilation if set too high.
+ * Do it at your own risk.
+ *
* @param nbSimultaneousGPUMorph the number of simultaneous morph targets to be handled on the GPU.
*/
public void setNbSimultaneousGPUMorph(int nbSimultaneousGPUMorph) {
@@ -723,7 +729,8 @@ public class Geometry extends Spatial {
material = im.getAssetManager().loadMaterial(matName);
} catch (AssetNotFoundException ex) {
// Cannot find J3M file.
- logger.log(Level.FINE, "Cannot locate {0} for geometry {1}", new Object[]{matName, key});
+ logger.log(Level.FINE, "Cannot locate {0} for geometry {1}",
+ new Object[]{matName, key});
}
}
// If material is NULL, try to load it from the geometry
diff --git a/jme3-core/src/main/java/com/jme3/scene/Mesh.java b/jme3-core/src/main/java/com/jme3/scene/Mesh.java
index 2b86cbd12..6248f4430 100644
--- a/jme3-core/src/main/java/com/jme3/scene/Mesh.java
+++ b/jme3-core/src/main/java/com/jme3/scene/Mesh.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009-2019 jMonkeyEngine
+ * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -46,7 +46,6 @@ import com.jme3.util.*;
import com.jme3.util.IntMap.Entry;
import com.jme3.util.clone.Cloner;
import com.jme3.util.clone.JmeCloneable;
-
import java.io.IOException;
import java.nio.*;
import java.util.ArrayList;
@@ -79,50 +78,46 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* determined via the vertex shader's gl_PointSize
output.
*/
Points(true),
-
/**
* A primitive is a line segment. Every two vertices specify
- * a single line. {@link Material#getAdditionalRenderState()} and {@link RenderState#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.
*/
Lines(true),
-
/**
* 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 Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)} can
+ * previous vertex to make a line. {@link Material#getAdditionalRenderState()}
+ * and {@link RenderState#setLineWidth(float)} can
* be used to set the width of the lines.
*/
LineStrip(false),
-
/**
* Identical to {@link #LineStrip} except that at the end
* the last vertex is connected with the first to form a line.
- * {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)} can be used
+ * {@link Material#getAdditionalRenderState()}
+ * and {@link RenderState#setLineWidth(float)} can be used
* to set the width of the lines.
*/
LineLoop(false),
-
/**
* A primitive is a triangle. Each 3 vertices specify a single
* triangle.
*/
Triangles(true),
-
/**
* Similar to {@link #Triangles}, the first 3 vertices
* specify a triangle, while subsequent vertices are combined with
* the previous two to form a triangle.
*/
TriangleStrip(false),
-
/**
* Similar to {@link #Triangles}, the first 3 vertices
* specify a triangle, each 2 subsequent vertices are combined
* with the very first vertex to make a triangle.
*/
TriangleFan(false),
-
/**
* A combination of various triangle modes. It is best to avoid
* using this mode as it may not be supported by all renderers.
@@ -138,7 +133,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
Patch(true);
private boolean listMode = false;
- private Mode(boolean listMode){
+ private Mode(boolean listMode) {
this.listMode = listMode;
}
@@ -151,7 +146,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*
* @return true if the mode is a list type mode
*/
- public boolean isListMode(){
+ public boolean isListMode() {
return listMode;
}
}
@@ -160,7 +155,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* The bounding volume that contains the mesh entirely.
* By default a BoundingBox (AABB).
*/
- private BoundingVolume meshBound = new BoundingBox();
+ private BoundingVolume meshBound = new BoundingBox();
private CollisionData collisionTree = null;
@@ -175,7 +170,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
private int vertCount = -1;
private int elementCount = -1;
private int instanceCount = -1;
- private int patchVertexCount=3; //only used for tessellation
+ private int patchVertexCount = 3; //only used for tessellation
private int maxNumWeights = -1; // only if using skeletal animation
private int[] elementLengths;
@@ -188,7 +183,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
/**
* Creates a new mesh with no {@link VertexBuffer vertex buffers}.
*/
- public Mesh(){
+ public Mesh() {
}
/**
@@ -226,8 +221,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*
* @return a deep clone of this mesh.
*/
- public Mesh deepClone(){
- try{
+ public Mesh deepClone() {
+ try {
Mesh clone = (Mesh) super.clone();
clone.meshBound = meshBound != null ? meshBound.clone() : null;
@@ -237,7 +232,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
clone.buffers = new IntMap<>();
clone.buffersList = new SafeArrayList<>(VertexBuffer.class);
- for (VertexBuffer vb : buffersList.getArray()){
+ for (VertexBuffer vb : buffersList.getArray()) {
VertexBuffer bufClone = vb.clone();
clone.buffers.put(vb.getBufferType().ordinal(), bufClone);
clone.buffersList.add(bufClone);
@@ -255,7 +250,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
clone.elementLengths = elementLengths != null ? elementLengths.clone() : null;
clone.modeStart = modeStart != null ? modeStart.clone() : null;
return clone;
- }catch (CloneNotSupportedException ex){
+ } catch (CloneNotSupportedException ex) {
throw new AssertionError();
}
}
@@ -269,9 +264,9 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*
* @return A clone of the mesh for animation use.
*/
- public Mesh cloneForAnim(){
+ public Mesh cloneForAnim() {
Mesh clone = clone();
- if (getBuffer(Type.BindPosePosition) != null){
+ if (getBuffer(Type.BindPosePosition) != null) {
VertexBuffer oldPos = getBuffer(Type.Position);
// NOTE: creates deep clone
@@ -279,13 +274,13 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
clone.clearBuffer(Type.Position);
clone.setBuffer(newPos);
- if (getBuffer(Type.BindPoseNormal) != null){
+ if (getBuffer(Type.BindPoseNormal) != null) {
VertexBuffer oldNorm = getBuffer(Type.Normal);
VertexBuffer newNorm = oldNorm.clone();
clone.clearBuffer(Type.Normal);
clone.setBuffer(newNorm);
- if (getBuffer(Type.BindPoseTangent) != null){
+ if (getBuffer(Type.BindPoseTangent) != null) {
VertexBuffer oldTang = getBuffer(Type.Tangent);
VertexBuffer newTang = oldTang.clone();
clone.clearBuffer(Type.Tangent);
@@ -302,7 +297,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
@Override
public Mesh jmeClone() {
try {
- Mesh clone = (Mesh)super.clone();
+ Mesh clone = (Mesh) super.clone();
clone.vertexArrayID = -1;
return clone;
} catch (CloneNotSupportedException ex) {
@@ -314,8 +309,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* Called internally by com.jme3.util.clone.Cloner. Do not call directly.
*/
@Override
- public void cloneFields( Cloner cloner, Object original ) {
-
+ public void cloneFields(Cloner cloner, Object original) {
// Probably could clone this now but it will get regenerated anyway.
this.collisionTree = null;
@@ -393,7 +387,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*
* @param forSoftwareAnim Should be true to enable the conversion.
*/
- public void prepareForAnim(boolean forSoftwareAnim){
+ public void prepareForAnim(boolean forSoftwareAnim) {
if (forSoftwareAnim) {
// convert indices to ubytes on the heap
VertexBuffer indices = getBuffer(Type.BoneIndex);
@@ -445,29 +439,34 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
VertexBuffer indices = getBuffer(Type.BoneIndex);
if (indices.getFormat() == Format.UnsignedByte) {
ByteBuffer originalIndex = (ByteBuffer) indices.getData();
- ByteBuffer directIndex = BufferUtils.createByteBuffer(originalIndex.capacity());
+ ByteBuffer directIndex
+ = BufferUtils.createByteBuffer(originalIndex.capacity());
originalIndex.clear();
directIndex.put(originalIndex);
result = directIndex;
} else {
//bone indices can be stored in an UnsignedShort buffer
ShortBuffer originalIndex = (ShortBuffer) indices.getData();
- ShortBuffer directIndex = BufferUtils.createShortBuffer(originalIndex.capacity());
+ ShortBuffer directIndex
+ = BufferUtils.createShortBuffer(originalIndex.capacity());
originalIndex.clear();
directIndex.put(originalIndex);
result = directIndex;
}
- indicesHW.setupData(Usage.Static, indices.getNumComponents(), indices.getFormat(), result);
+ indicesHW.setupData(Usage.Static, indices.getNumComponents(),
+ indices.getFormat(), result);
}
VertexBuffer weightsHW = getBuffer(Type.HWBoneWeight);
if (weightsHW.getData() == null) {
VertexBuffer weights = getBuffer(Type.BoneWeight);
FloatBuffer originalWeight = (FloatBuffer) weights.getData();
- FloatBuffer directWeight = BufferUtils.createFloatBuffer(originalWeight.capacity());
+ FloatBuffer directWeight
+ = BufferUtils.createFloatBuffer(originalWeight.capacity());
originalWeight.clear();
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
@@ -502,7 +501,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*
* @param lodLevels The LOD levels to set
*/
- public void setLodLevels(VertexBuffer[] lodLevels){
+ public void setLodLevels(VertexBuffer[] lodLevels) {
this.lodLevels = lodLevels;
}
@@ -510,7 +509,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* @return The number of LOD levels set on this mesh, including the main
* index buffer, returns zero if there are no lod levels.
*/
- public int getNumLodLevels(){
+ public int getNumLodLevels() {
return lodLevels != null ? lodLevels.length : 0;
}
@@ -526,7 +525,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*
* @see #setLodLevels(com.jme3.scene.VertexBuffer[])
*/
- public VertexBuffer getLodLevel(int lod){
+ public VertexBuffer getLodLevel(int lod) {
return lodLevels[lod];
}
@@ -636,7 +635,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* Returns the line width for line meshes.
*
* @return the line width
- * @deprecated use {@link Material#getAdditionalRenderState()} and {@link RenderState#getLineWidth()}
+ * @deprecated use {@link Material#getAdditionalRenderState()}
+ * and {@link RenderState#getLineWidth()}
*/
@Deprecated
public float getLineWidth() {
@@ -649,7 +649,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* the default value is 1.0.
*
* @param lineWidth The line width
- * @deprecated use {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)}
+ * @deprecated use {@link Material#getAdditionalRenderState()}
+ * and {@link RenderState#setLineWidth(float)}
*/
@Deprecated
public void setLineWidth(float lineWidth) {
@@ -665,7 +666,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* for all {@link VertexBuffer vertex buffers} on this Mesh.
*/
public void setStatic() {
- for (VertexBuffer vb : buffersList.getArray()){
+ for (VertexBuffer vb : buffersList.getArray()) {
vb.setUsage(Usage.Static);
}
}
@@ -676,7 +677,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* for all {@link VertexBuffer vertex buffers} on this Mesh.
*/
public void setDynamic() {
- for (VertexBuffer vb : buffersList.getArray()){
+ for (VertexBuffer vb : buffersList.getArray()) {
vb.setUsage(Usage.Dynamic);
}
}
@@ -686,8 +687,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* Sets the usage mode to {@link Usage#Stream}
* for all {@link VertexBuffer vertex buffers} on this Mesh.
*/
- public void setStreamed(){
- for (VertexBuffer vb : buffersList.getArray()){
+ public void setStreamed() {
+ for (VertexBuffer vb : buffersList.getArray()) {
vb.setUsage(Usage.Stream);
}
}
@@ -698,7 +699,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* to avoid using this method as it disables some engine features.
*/
@Deprecated
- public void setInterleaved(){
+ public void setInterleaved() {
ArrayList
* Note that values above 1 will cause the
* texture to tile, while values below 1 will cause the texture
@@ -1354,7 +1357,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* @throws UnsupportedOperationException If the texture coordinate
* buffer is not in 2D float format.
*/
- public void scaleTextureCoordinates(Vector2f scaleFactor){
+ public void scaleTextureCoordinates(Vector2f scaleFactor) {
VertexBuffer tc = getBuffer(Type.TexCoord);
if (tc == null) {
throw new IllegalStateException("The mesh has no texture coordinates");
@@ -1370,10 +1373,10 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
FloatBuffer fb = (FloatBuffer) tc.getData();
fb.clear();
- for (int i = 0; i < fb.limit() / 2; i++){
+ for (int i = 0; i < fb.limit() / 2; i++) {
float x = fb.get();
float y = fb.get();
- fb.position(fb.position()-2);
+ fb.position(fb.position() - 2);
x *= scaleFactor.getX();
y *= scaleFactor.getY();
fb.put(x).put(y);
@@ -1387,10 +1390,10 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* 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.
*/
- public void updateBound(){
+ public void updateBound() {
VertexBuffer posBuf = getBuffer(VertexBuffer.Type.Position);
- if (meshBound != null && posBuf != null){
- meshBound.computeFromPoints((FloatBuffer)posBuf.getData());
+ if (meshBound != null && posBuf != null) {
+ meshBound.computeFromPoints((FloatBuffer) posBuf.getData());
}
}
@@ -1423,7 +1426,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*
* @return map of vertex buffers on this mesh.
*/
- public IntMap
- * Note that the MorphControl will find how many buffers can be supported for each mesh/material combination.
- * Note that all buffers have 3 components (Vector3f) even the Tangent buffer that
- * does not contain the w (handedness) component that will not be interpolated for morph animation.
+ * Note that the MorphControl will find how many buffers
+ * can be supported for each mesh/material combination.
+ * Note that all buffers have 3 components (Vector3f)
+ * even the Tangent buffer that
+ * does not contain the w (handedness) component
+ * that will not be interpolated for morph animation.
*
- * Note that those buffers contain the difference between the base buffer (POSITION, NORMAL or TANGENT) and the target value
+ * Note that those buffers contain the difference between
+ * the base buffer (POSITION, NORMAL or TANGENT) and the target value
* So that you can interpolate with a MADD operation in the vertex shader
* position = weight * diffPosition + basePosition;
*/
@@ -247,7 +226,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
MorphTarget11,
MorphTarget12,
MorphTarget13,
-
}
/**
@@ -256,22 +234,18 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* or held in video memory, but no guarantees are made- it's only a hint.
*/
public static enum Usage {
-
/**
* Mesh data is sent once and very rarely updated.
*/
Static,
-
/**
* Mesh data is updated occasionally (once per frame or less).
*/
Dynamic,
-
/**
* Mesh data is updated every frame.
*/
Stream,
-
/**
* Mesh data is not sent to GPU at all. It is only
* used by the CPU.
@@ -289,49 +263,38 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
*/
public static enum Format {
/**
- * Half precision floating point.
- * 2 bytes, signed.
+ * Half precision floating point. 2 bytes, signed.
*/
Half(2),
-
/**
- * Single precision floating point.
- * 4 bytes, signed
+ * Single precision floating point. 4 bytes, signed
*/
Float(4),
-
/**
- * Double precision floating point.
- * 8 bytes, signed. May not
- * be supported by all GPUs.
+ * Double precision floating point. 8 bytes, signed. May not be
+ * supported by all GPUs.
*/
Double(8),
-
/**
* 1 byte integer, signed.
*/
Byte(1),
-
/**
* 1 byte integer, unsigned.
*/
UnsignedByte(1),
-
/**
* 2 byte integer, signed.
*/
Short(2),
-
/**
* 2 byte integer, unsigned.
*/
UnsignedShort(2),
-
/**
* 4 byte integer, signed.
*/
Int(4),
-
/**
* 4 byte integer, unsigned.
*/
@@ -339,16 +302,16 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
private int componentSize = 0;
- Format(int componentSize){
+ Format(int componentSize) {
this.componentSize = componentSize;
}
/**
* Returns the size in bytes of this data type.
- *
+ *
* @return Size in bytes of this data type.
*/
- public int getComponentSize(){
+ public int getComponentSize() {
return componentSize;
}
}
@@ -374,7 +337,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* Creates an empty, uninitialized buffer.
* Must call setupData() to initialize.
*/
- public VertexBuffer(Type type){
+ public VertexBuffer(Type type) {
super();
this.bufType = type;
}
@@ -382,11 +345,11 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/**
* Serialization only. Do not use.
*/
- protected VertexBuffer(){
+ protected VertexBuffer() {
super();
}
- protected VertexBuffer(int id){
+ protected VertexBuffer(int id) {
super(id);
}
@@ -408,7 +371,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
throw new AssertionError();
}
// Are components between 1 and 4?
-
+
// Are components between 1 and 4 and not InstanceData?
if (bufType != Type.InstanceData) {
if (components < 1 || components > 4) {
@@ -442,11 +405,11 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
}
return true;
}
-
+
/**
* @return The offset after which the data is sent to the GPU.
- *
- * @see #setOffset(int)
+ *
+ * @see #setOffset(int)
*/
public int getOffset() {
return offset;
@@ -461,21 +424,21 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
}
/**
- * @return The stride (in bytes) for the data.
- *
- * @see #setStride(int)
+ * @return The stride (in bytes) for the data.
+ *
+ * @see #setStride(int)
*/
public int getStride() {
return stride;
}
/**
- * Set the stride (in bytes) for the data.
+ * Set the stride (in bytes) for the data.
*
- * If the data is packed in the buffer, then stride is 0, if there's other
- * data that is between the current component and the next component in the
+ * If the data is packed in the buffer, then stride is 0, if there's other
+ * data that is between the current component and the next component in the
* buffer, then this specifies the size in bytes of that additional data.
- *
+ *
* @param stride the stride (in bytes) for the data
*/
public void setStride(int stride) {
@@ -486,17 +449,17 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* Returns the raw internal data buffer used by this VertexBuffer.
* This buffer is not safe to call from multiple threads since buffers
* have their own internal position state that cannot be shared.
- * Call getData().duplicate(), getData().asReadOnlyBuffer(), or
- * the more convenient getDataReadOnly() if the buffer may be accessed
+ * Call getData().duplicate(), getData().asReadOnlyBuffer(), or
+ * the more convenient getDataReadOnly() if the buffer may be accessed
* from multiple threads.
- *
+ *
* @return A native buffer, in the specified {@link Format format}.
*/
- public Buffer getData(){
+ public Buffer getData() {
return data;
}
-
- /**
+
+ /**
* Returns a safe read-only version of this VertexBuffer's data. The
* contents of the buffer will reflect whatever changes are made on
* other threads (eventually) but these should not be used in that way.
@@ -504,38 +467,36 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* a separate thread since it has its own book-keeping state (position, limit, etc.)
*
* @return A rewound native buffer in the specified {@link Format format}
- * that is safe to read from a separate thread from other readers.
+ * that is safe to read from a separate thread from other readers.
*/
public Buffer getDataReadOnly() {
-
if (data == null) {
return null;
}
-
+
// Create a read-only duplicate(). Note: this does not copy
// the underlying memory, it just creates a new read-only wrapper
// with its own buffer position state.
-
// Unfortunately, this is not 100% straight forward since Buffer
// does not have an asReadOnlyBuffer() method.
Buffer result;
- if( data instanceof ByteBuffer ) {
- result = ((ByteBuffer)data).asReadOnlyBuffer();
- } else if( data instanceof FloatBuffer ) {
- result = ((FloatBuffer)data).asReadOnlyBuffer();
- } else if( data instanceof ShortBuffer ) {
- result = ((ShortBuffer)data).asReadOnlyBuffer();
- } else if( data instanceof IntBuffer ) {
- result = ((IntBuffer)data).asReadOnlyBuffer();
+ if (data instanceof ByteBuffer) {
+ result = ((ByteBuffer) data).asReadOnlyBuffer();
+ } else if (data instanceof FloatBuffer) {
+ result = ((FloatBuffer) data).asReadOnlyBuffer();
+ } else if (data instanceof ShortBuffer) {
+ result = ((ShortBuffer) data).asReadOnlyBuffer();
+ } else if (data instanceof IntBuffer) {
+ result = ((IntBuffer) data).asReadOnlyBuffer();
} else {
- throw new UnsupportedOperationException( "Cannot get read-only view of buffer type:" + data );
+ throw new UnsupportedOperationException("Cannot get read-only view of buffer type:" + data);
}
-
+
// Make sure the caller gets a consistent view since we may
// have grabbed this buffer while another thread was reading
// the raw data.
result.rewind();
-
+
return result;
}
@@ -543,7 +504,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* @return The usage of this buffer. See {@link Usage} for more
* information.
*/
- public Usage getUsage(){
+ public Usage getUsage() {
return usage;
}
@@ -551,7 +512,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* @param usage The usage of this buffer. See {@link Usage} for more
* information.
*/
- public void setUsage(Usage usage){
+ public void setUsage(Usage usage) {
// if (id != -1)
// throw new UnsupportedOperationException("Data has already been sent. Cannot set usage.");
@@ -567,15 +528,15 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* the components will be converted to the range 0.0 - 1.0 by dividing
* every integer by 2^32.
*/
- public void setNormalized(boolean normalized){
+ public void setNormalized(boolean normalized) {
this.normalized = normalized;
}
/**
* @return True if integer components should be converted to the range 0-1.
- * @see VertexBuffer#setNormalized(boolean)
+ * @see VertexBuffer#setNormalized(boolean)
*/
- public boolean isNormalized(){
+ public boolean isNormalized() {
return normalized;
}
@@ -585,9 +546,9 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* instanceSpan.
*/
public void setInstanced(boolean instanced) {
- if( instanced && instanceSpan == 0 ) {
+ if (instanced && instanceSpan == 0) {
instanceSpan = 1;
- } else if( !instanced ) {
+ } else if (!instanced) {
instanceSpan = 0;
}
}
@@ -599,7 +560,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
public boolean isInstanced() {
return instanceSpan > 0;
}
-
+
/**
* Sets how this vertex buffer matches with rendered instances
* where 0 means no instancing at all, ie: all elements are
@@ -610,22 +571,22 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
public void setInstanceSpan(int i) {
this.instanceSpan = i;
}
-
+
public int getInstanceSpan() {
return instanceSpan;
}
-
+
/**
* @return The type of information that this buffer has.
*/
- public Type getBufferType(){
+ public Type getBufferType() {
return bufType;
}
/**
* @return The {@link Format format}, or data type of the data.
*/
- public Format getFormat(){
+ public Format getFormat() {
return format;
}
@@ -633,15 +594,15 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* @return The number of components of the given {@link Format format} per
* element.
*/
- public int getNumComponents(){
+ public int getNumComponents() {
return components;
}
/**
* @return The total number of data elements in the data buffer.
*/
- public int getNumElements(){
- if( data == null ) {
+ public int getNumElements() {
+ if (data == null) {
return 0;
}
int elements = data.limit() / components;
@@ -659,7 +620,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* but the instance data begins to repeat.
*/
public int getBaseInstanceCount() {
- if( instanceSpan == 0 ) {
+ if (instanceSpan == 0) {
return 1;
}
return getNumElements() * instanceSpan;
@@ -668,7 +629,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/**
* Called to initialize the data in the Node
defines an internal node of a scene graph. The internal
* node maintains a collection of children and handles merging said children
@@ -59,14 +58,11 @@ import java.util.logging.Logger;
* @author Joshua Slack
*/
public class Node extends Spatial {
-
private static final Logger logger = Logger.getLogger(Node.class.getName());
-
/**
* This node's children.
*/
protected SafeArrayListgetQuantity
returns the number of children this node
* maintains.
*
@@ -116,22 +111,24 @@ public class Node extends Spatial {
}
@Override
- protected void setTransformRefresh(){
+ protected void setTransformRefresh() {
super.setTransformRefresh();
- for (Spatial child : children.getArray()){
- if ((child.refreshFlags & RF_TRANSFORM) != 0)
+ for (Spatial child : children.getArray()) {
+ if ((child.refreshFlags & RF_TRANSFORM) != 0) {
continue;
+ }
child.setTransformRefresh();
}
}
@Override
- protected void setLightListRefresh(){
+ protected void setLightListRefresh() {
super.setLightListRefresh();
- for (Spatial child : children.getArray()){
- if ((child.refreshFlags & RF_LIGHTLIST) != 0)
+ for (Spatial child : children.getArray()) {
+ if ((child.refreshFlags & RF_LIGHTLIST) != 0) {
continue;
+ }
child.setLightListRefresh();
}
@@ -150,7 +147,7 @@ public class Node extends Spatial {
}
@Override
- protected void updateWorldBound(){
+ protected void updateWorldBound() {
super.updateWorldBound();
// for a node, the world bound is a combination of all its children
// bounds
@@ -176,7 +173,7 @@ public class Node extends Spatial {
@Override
protected void setParent(Node parent) {
- if( this.parent == null && parent != null ) {
+ if (this.parent == null && parent != null) {
// We were a root before and now we aren't... make sure if
// we had an updateList then we clear it completely to
// avoid holding the dead array.
@@ -186,13 +183,13 @@ public class Node extends Spatial {
super.setParent(parent);
}
- private void addUpdateChildren( SafeArrayListgetVertexCount
returns the number of vertices contained
* in all sub-branches of this node that contain geometry.
@@ -306,9 +304,9 @@ public class Node extends Spatial {
@Override
public int getVertexCount() {
int count = 0;
- if(children != null) {
- for(int i = 0; i < children.size(); i++) {
- count += children.get(i).getVertexCount();
+ if (children != null) {
+ for (int i = 0; i < children.size(); i++) {
+ count += children.get(i).getVertexCount();
}
}
@@ -330,8 +328,8 @@ public class Node extends Spatial {
public int attachChild(Spatial child) {
return attachChildAt(child, children.size());
}
+
/**
- *
* attachChildAt
attaches a child to this node at an index. This node
* becomes the child's parent. The current number of children maintained is
* returned.
@@ -349,7 +347,7 @@ public class Node extends Spatial {
}
if (child == this) {
throw new IllegalArgumentException("Cannot add child to itself");
- }
+ }
if (child.getParent() != this) {
if (child.getParent() != null) {
child.getParent().detachChild(child);
@@ -363,7 +361,7 @@ public class Node extends Spatial {
child.setLightListRefresh();
child.setMatParamOverrideRefresh();
if (logger.isLoggable(Level.FINE)) {
- logger.log(Level.FINE,"Child ({0}) attached to this node ({1})",
+ logger.log(Level.FINE, "Child ({0}) attached to this node ({1})",
new Object[]{child.getName(), getName()});
}
invalidateUpdateList();
@@ -380,8 +378,9 @@ public class Node extends Spatial {
* @return the index the child was at. -1 if the child was not in the list.
*/
public int detachChild(Spatial child) {
- if (child == null)
+ if (child == null) {
throw new NullPointerException();
+ }
if (child.getParent() == this) {
int index = children.indexOf(child);
@@ -404,13 +403,14 @@ public class Node extends Spatial {
* @return the index the child was at. -1 if the child was not in the list.
*/
public int detachChildNamed(String childName) {
- if (childName == null)
+ if (childName == null) {
throw new NullPointerException();
+ }
for (int x = 0, max = children.size(); x < max; x++) {
- Spatial child = children.get(x);
+ Spatial child = children.get(x);
if (childName.equals(child.getName())) {
- detachChildAt( x );
+ detachChildAt(x);
return x;
}
}
@@ -418,7 +418,6 @@ public class Node extends Spatial {
}
/**
- *
* detachChildAt
removes a child at a given index. That child
* is returned for saving purposes.
*
@@ -427,9 +426,9 @@ public class Node extends Spatial {
* @return the child at the supplied index.
*/
public Spatial detachChildAt(int index) {
- Spatial child = children.remove(index);
- if ( child != null ) {
- child.setParent( null );
+ Spatial child = children.remove(index);
+ if (child != null) {
+ child.setParent(null);
logger.log(Level.FINE, "{0}: Child removed.", this.toString());
// since a child with a bound was detached;
@@ -443,14 +442,13 @@ public class Node extends Spatial {
// lights are also inherited from parent
child.setLightListRefresh();
child.setMatParamOverrideRefresh();
-
+
invalidateUpdateList();
}
return child;
}
/**
- *
* detachAllChildren
removes all children attached to this
* node.
*/
@@ -458,7 +456,7 @@ public class Node extends Spatial {
// Note: this could be a bit more efficient if it delegated
// to a private method that avoided setBoundRefresh(), etc.
// for every child and instead did one in here at the end.
- for ( int i = children.size() - 1; i >= 0; i-- ) {
+ for (int i = children.size() - 1; i >= 0; i--) {
detachChildAt(i);
}
logger.log(Level.FINE, "{0}: All children removed.", this.toString());
@@ -469,8 +467,7 @@ public class Node extends Spatial {
* in this node's list of children.
* @param sp
* The spatial to look up
- * @return
- * The index of the spatial in the node's children, or -1
+ * @return The index of the spatial in the node's children, or -1
* if the spatial is not attached to this node
*/
public int getChildIndex(Spatial sp) {
@@ -484,19 +481,17 @@ public class Node extends Spatial {
* @param index2 The index of the second child to swap
*/
public void swapChildren(int index1, int index2) {
- Spatial c2 = children.get(index2);
- Spatial c1 = children.remove(index1);
+ Spatial c2 = children.get(index2);
+ Spatial c1 = children.remove(index1);
children.add(index1, c2);
children.remove(index2);
children.add(index2, c1);
}
/**
- *
* getChild
returns a child at a given index.
*
- * @param i
- * the index to retrieve the child from.
+ * @param i the index to retrieve the child from.
* @return the child at a specified index.
*/
public Spatial getChild(int i) {
@@ -514,21 +509,23 @@ public class Node extends Spatial {
* @return the child if found, or null.
*/
public Spatial getChild(String name) {
- if (name == null)
+ if (name == null) {
return null;
+ }
for (Spatial child : children.getArray()) {
if (name.equals(child.getName())) {
return child;
- } else if(child instanceof Node) {
- Spatial out = ((Node)child).getChild(name);
- if(out != null) {
+ } else if (child instanceof Node) {
+ Spatial out = ((Node) child).getChild(name);
+ if (out != null) {
return out;
}
}
}
return null;
}
+
/**
* determines if the provided Spatial is contained in the children list of
* this node.
@@ -538,12 +535,14 @@ public class Node extends Spatial {
* @return true if the object is contained, false otherwise.
*/
public boolean hasChild(Spatial spat) {
- if (children.contains(spat))
+ if (children.contains(spat)) {
return true;
+ }
for (Spatial child : children.getArray()) {
- if (child instanceof Node && ((Node) child).hasChild(spat))
+ if (child instanceof Node && ((Node) child).hasChild(spat)) {
return true;
+ }
}
return false;
@@ -560,14 +559,14 @@ public class Node extends Spatial {
}
@Override
- public void setMaterial(Material mat){
- for (int i = 0; i < children.size(); i++){
+ public void setMaterial(Material mat) {
+ for (int i = 0; i < children.size(); i++) {
children.get(i).setMaterial(mat);
}
}
@Override
- public void setLodLevel(int lod){
+ public void setLodLevel(int lod) {
super.setLodLevel(lod);
for (Spatial child : children.getArray()) {
child.setLodLevel(lod);
@@ -575,11 +574,13 @@ public class Node extends Spatial {
}
@Override
- public int collideWith(Collidable other, CollisionResults results){
+ public int collideWith(Collidable other, CollisionResults results) {
int total = 0;
// optimization: try collideWith BoundingVolume to avoid possibly redundant tests on children
- // number 4 in condition is somewhat arbitrary. When there is only one child, the boundingVolume test is redundant at all.
- // The idea is when there are few children, it can be too expensive to test boundingVolume first.
+ // number 4 in condition is somewhat arbitrary.
+ // When there is only one child, the boundingVolume test is redundant at all.
+ // The idea is when there are few children,
+ // it can be too expensive to test boundingVolume first.
/*
I'm removing this change until some issues can be addressed and I really
think it needs to be implemented a better way anyway.
@@ -612,7 +613,7 @@ public class Node extends Spatial {
if (bv.collideWith(other) == 0) return 0;
}
*/
- for (Spatial child : children.getArray()){
+ for (Spatial child : children.getArray()) {
total += child.collideWith(other, results);
}
return total;
@@ -643,22 +644,27 @@ public class Node extends Spatial {
* Null causes all Spatials to qualify.
* @param nameRegex Regular expression to match Spatial name against.
* Null causes all Names to qualify.
- * @return Non-null, but possibly 0-element, list of matching Spatials (also Instances extending Spatials).
+ * @return Non-null, but possibly 0-element, list of matching Spatials
+ * (also Instances extending Spatials).
*
* @see java.util.regex.Pattern
* @see Spatial#matches(java.lang.Class, java.lang.String)
*/
@SuppressWarnings("unchecked")
- public this
.
*/
public Spatial center() {
@@ -1341,8 +1345,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
*
* @see Mesh#cloneForAnim()
*/
- public Spatial clone( boolean cloneMaterial ) {
-
+ public Spatial clone(boolean cloneMaterial) {
// Setup the cloner for the type of cloning we want to do.
Cloner cloner = new Cloner();
@@ -1351,7 +1354,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
// If we aren't cloning materials then we will make sure those
// aren't cloned also
- if( !cloneMaterial ) {
+ if (!cloneMaterial) {
cloner.setCloneFunction(Material.class, new IdentityCloneFunctionVertexBuffer
. Must only
* be called once.
- *
+ *
* @param usage The usage for the data, or how often will the data
* be updated per frame. See the {@link Usage} enum.
* @param components The number of components per element.
@@ -677,7 +638,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* @param data A native buffer, the format of which matches the {@link Format}
* argument.
*/
- public void setupData(Usage usage, int components, Format format, Buffer data){
+ public void setupData(Usage usage, int components, Format format, Buffer data) {
if (id != -1) {
throw new UnsupportedOperationException("Data has already been sent. Cannot setupData again.");
}
@@ -695,7 +656,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
throw new IllegalArgumentException("components must be between 1 and 4");
}
}
-
+
this.data = data;
this.components = components;
this.usage = usage;
@@ -707,7 +668,8 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/**
* Called to update the data in the buffer with new data. Can only
- * be called after {@link VertexBuffer#setupData(com.jme3.scene.VertexBuffer.Usage, int, com.jme3.scene.VertexBuffer.Format, java.nio.Buffer) }
+ * be called after {@link VertexBuffer#setupData(
+ * com.jme3.scene.VertexBuffer.Usage, int, com.jme3.scene.VertexBuffer.Format, java.nio.Buffer) }
* has been called. Note that it is fine to call this method on the
* data already set, e.g. vb.updateData(vb.getData()), this will just
* set the proper update flag indicating the data should be sent to the GPU
@@ -716,26 +678,26 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* It is allowed to specify a buffer with different capacity than the
* originally set buffer, HOWEVER, if you do so, you must
* call Mesh.updateCounts() otherwise bizarre errors can occur.
- *
+ *
* @param data The data buffer to set
*/
- public void updateData(Buffer data){
- if (id != -1){
+ public void updateData(Buffer data) {
+ if (id != -1) {
// request to update data is okay
}
// Check if the data buffer is read-only which is a sign
// of a bug on the part of the caller
if (data != null && data.isReadOnly()) {
- throw new IllegalArgumentException( "VertexBuffer data cannot be read-only." );
+ throw new IllegalArgumentException("VertexBuffer data cannot be read-only.");
}
// will force renderer to call glBufferData again
- if (data != null && (this.data.getClass() != data.getClass() || data.limit() != lastLimit)){
+ if (data != null && (this.data.getClass() != data.getClass() || data.limit() != lastLimit)) {
dataSizeChanged = true;
lastLimit = data.limit();
}
-
+
this.data = data;
setUpdateNeeded();
}
@@ -743,6 +705,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/**
* Returns true if the data size of the VertexBuffer has changed.
* Internal use only.
+ *
* @return true if the data size has changed
*/
public boolean hasDataSizeChanged() {
@@ -750,7 +713,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
}
@Override
- public void clearUpdateNeeded(){
+ public void clearUpdateNeeded() {
super.clearUpdateNeeded();
dataSizeChanged = false;
}
@@ -758,7 +721,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/**
* Converts single floating-point data to {@link Format#Half half} floating-point data.
*/
- public void convertToHalf(){
+ public void convertToHalf() {
if (id != -1) {
throw new UnsupportedOperationException("Data has already been sent.");
}
@@ -770,14 +733,14 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
int numElements = data.limit() / components;
format = Format.Half;
this.componentsLength = components * format.getComponentSize();
-
+
ByteBuffer halfData = BufferUtils.createByteBuffer(componentsLength * numElements);
halfData.rewind();
FloatBuffer floatData = (FloatBuffer) data;
floatData.rewind();
- for (int i = 0; i < floatData.limit(); i++){
+ for (int i = 0; i < floatData.limit(); i++) {
float f = floatData.get(i);
short half = FastMath.convertFloatToHalf(f);
halfData.putShort(half);
@@ -794,10 +757,10 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
*
* @param numElements The number of elements to reduce to.
*/
- public void compact(int numElements){
+ public void compact(int numElements) {
int total = components * numElements;
data.clear();
- switch (format){
+ switch (format) {
case Byte:
case UnsignedByte:
case Half:
@@ -831,7 +794,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
data = fnewBuf;
break;
default:
- throw new UnsupportedOperationException("Unrecognized buffer format: "+format);
+ throw new UnsupportedOperationException("Unrecognized buffer format: " + format);
}
data.clear();
setUpdateNeeded();
@@ -842,69 +805,69 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* Modify a component inside an element.
* The val
parameter must be in the buffer's format:
* {@link Format}.
- *
+ *
* @param elementIndex The element index to modify
* @param componentIndex The component index to modify
* @param val The value to set, either byte, short, int or float depending
* on the {@link Format}.
*/
- public void setElementComponent(int elementIndex, int componentIndex, Object val){
+ public void setElementComponent(int elementIndex, int componentIndex, Object val) {
int inPos = elementIndex * components;
int elementPos = componentIndex;
- if (format == Format.Half){
+ if (format == Format.Half) {
inPos *= 2;
elementPos *= 2;
}
data.clear();
- switch (format){
+ switch (format) {
case Byte:
case UnsignedByte:
case Half:
ByteBuffer bin = (ByteBuffer) data;
- bin.put(inPos + elementPos, (Byte)val);
+ bin.put(inPos + elementPos, (Byte) val);
break;
case Short:
case UnsignedShort:
ShortBuffer sin = (ShortBuffer) data;
- sin.put(inPos + elementPos, (Short)val);
+ sin.put(inPos + elementPos, (Short) val);
break;
case Int:
case UnsignedInt:
IntBuffer iin = (IntBuffer) data;
- iin.put(inPos + elementPos, (Integer)val);
+ iin.put(inPos + elementPos, (Integer) val);
break;
case Float:
FloatBuffer fin = (FloatBuffer) data;
- fin.put(inPos + elementPos, (Float)val);
+ fin.put(inPos + elementPos, (Float) val);
break;
default:
- throw new UnsupportedOperationException("Unrecognized buffer format: "+format);
+ throw new UnsupportedOperationException("Unrecognized buffer format: " + format);
}
}
/**
* Get the component inside an element.
- *
+ *
* @param elementIndex The element index
* @param componentIndex The component index
* @return The component, as one of the primitive types, byte, short,
* int or float.
*/
- public Object getElementComponent(int elementIndex, int componentIndex){
+ public Object getElementComponent(int elementIndex, int componentIndex) {
int inPos = elementIndex * components;
int elementPos = componentIndex;
- if (format == Format.Half){
+ if (format == Format.Half) {
inPos *= 2;
elementPos *= 2;
}
Buffer srcData = getDataReadOnly();
- switch (format){
+ switch (format) {
case Byte:
case UnsignedByte:
case Half:
@@ -922,46 +885,46 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
FloatBuffer fin = (FloatBuffer) srcData;
return fin.get(inPos + elementPos);
default:
- throw new UnsupportedOperationException("Unrecognized buffer format: "+format);
+ throw new UnsupportedOperationException("Unrecognized buffer format: " + format);
}
}
/**
* Copies a single element of data from this VertexBuffer
* to the given output VertexBuffer.
- *
+ *
* @param inIndex The input element index
* @param outVb The buffer to copy to
* @param outIndex The output element index
- *
+ *
* @throws IllegalArgumentException If the formats of the buffers do not
* match.
*/
- public void copyElement(int inIndex, VertexBuffer outVb, int outIndex){
+ public void copyElement(int inIndex, VertexBuffer outVb, int outIndex) {
copyElements(inIndex, outVb, outIndex, 1);
}
/**
* Copies a sequence of elements of data from this VertexBuffer
* to the given output VertexBuffer.
- *
+ *
* @param inIndex The input element index
* @param outVb The buffer to copy to
* @param outIndex The output element index
* @param len The number of elements to copy
- *
+ *
* @throws IllegalArgumentException If the formats of the buffers do not
* match.
*/
- public void copyElements(int inIndex, VertexBuffer outVb, int outIndex, int len){
+ public void copyElements(int inIndex, VertexBuffer outVb, int outIndex, int len) {
if (outVb.format != format || outVb.components != components) {
throw new IllegalArgumentException("Buffer format mismatch. Cannot copy");
}
- int inPos = inIndex * components;
+ int inPos = inIndex * components;
int outPos = outIndex * components;
int elementSz = components;
- if (format == Format.Half){
+ if (format == Format.Half) {
// because half is stored as bytebuf but its 2 bytes long
inPos *= 2;
outPos *= 2;
@@ -974,7 +937,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
Buffer srcData = getDataReadOnly();
outVb.data.clear();
- switch (format){
+ switch (format) {
case Byte:
case UnsignedByte:
case Half:
@@ -982,7 +945,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
ByteBuffer bout = (ByteBuffer) outVb.data;
bin.position(inPos).limit(inPos + elementSz * len);
bout.position(outPos).limit(outPos + elementSz * len);
- bout.put(bin);
+ bout.put(bin);
break;
case Short:
case UnsignedShort:
@@ -1008,7 +971,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
fout.put(fin);
break;
default:
- throw new UnsupportedOperationException("Unrecognized buffer format: "+format);
+ throw new UnsupportedOperationException("Unrecognized buffer format: " + format);
}
// Clear the output buffer to rewind it and reset its
@@ -1022,14 +985,14 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* {@link Format format} and would be able to contain the given number
* of elements with the given number of components in each element.
*/
- public static Buffer createBuffer(Format format, int components, int numElements){
+ public static Buffer createBuffer(Format format, int components, int numElements) {
if (components < 1 || components > 4) {
throw new IllegalArgumentException("Num components must be between 1 and 4");
}
int total = numElements * components;
- switch (format){
+ switch (format) {
case Byte:
case UnsignedByte:
return BufferUtils.createByteBuffer(total);
@@ -1046,17 +1009,17 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
case Double:
return BufferUtils.createDoubleBuffer(total);
default:
- throw new UnsupportedOperationException("Unrecoginized buffer format: "+format);
+ throw new UnsupportedOperationException("Unrecoginized buffer format: " + format);
}
}
/**
* Creates a deep clone of the {@link VertexBuffer}.
- *
+ *
* @return Deep clone of this buffer
*/
@Override
- public VertexBuffer clone(){
+ public VertexBuffer clone() {
// NOTE: Superclass GLObject automatically creates shallow clone
// e.g re-use ID.
VertexBuffer vb = (VertexBuffer) super.clone();
@@ -1069,22 +1032,22 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
// a purely read-only operation.
vb.updateData(BufferUtils.clone(getDataReadOnly()));
}
-
+
return vb;
}
/**
* Creates a deep clone of this VertexBuffer but overrides the
* {@link Type}.
- *
+ *
* @param overrideType The type of the cloned VertexBuffer
* @return A deep clone of the buffer
*/
- public VertexBuffer clone(Type overrideType){
+ public VertexBuffer clone(Type overrideType) {
VertexBuffer vb = new VertexBuffer(overrideType);
vb.components = components;
vb.componentsLength = componentsLength;
-
+
// Make sure to pass a read-only buffer to clone so that
// the position information doesn't get clobbered by another
// reading thread during cloning (and vice versa) since this is
@@ -1103,15 +1066,15 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
}
@Override
- public String toString(){
+ public String toString() {
String dataTxt = null;
- if (data != null){
- dataTxt = ", elements="+data.limit();
+ if (data != null) {
+ dataTxt = ", elements=" + data.limit();
}
- return getClass().getSimpleName() + "[fmt="+format.name()
- +", type="+bufType.name()
- +", usage="+usage.name()
- +dataTxt+"]";
+ return getClass().getSimpleName() + "[fmt=" + format.name()
+ + ", type=" + bufType.name()
+ + ", usage=" + usage.name()
+ + dataTxt + "]";
}
@Override
@@ -1123,29 +1086,28 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
@Override
public void deleteObject(Object rendererObject) {
- ((Renderer)rendererObject).deleteBuffer(this);
+ ((Renderer) rendererObject).deleteBuffer(this);
}
-
+
@Override
protected void deleteNativeBuffers() {
if (data != null) {
BufferUtils.destroyDirectBuffer(data);
}
}
-
+
@Override
- public NativeObject createDestructableClone(){
+ public NativeObject createDestructableClone() {
return new VertexBuffer(id);
}
@Override
public long getUniqueId() {
- return ((long)OBJTYPE_VERTEXBUFFER << 32) | ((long)id);
+ return ((long) OBJTYPE_VERTEXBUFFER << 32) | ((long) id);
}
-
+
@Override
public void write(JmeExporter ex) throws IOException {
-
OutputCapsule oc = ex.getCapsule(this);
oc.write(components, "components", 0);
oc.write(usage, "usage", Usage.Dynamic);
@@ -1158,7 +1120,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
String dataName = "data" + format.name();
Buffer roData = getDataReadOnly();
- switch (format){
+ switch (format) {
case Float:
oc.write((FloatBuffer) roData, dataName, null);
break;
@@ -1176,7 +1138,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
oc.write((IntBuffer) roData, dataName, null);
break;
default:
- throw new IOException("Unsupported export buffer format: "+format);
+ throw new IOException("Unsupported export buffer format: " + format);
}
}
@@ -1194,7 +1156,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
componentsLength = components * format.getComponentSize();
String dataName = "data" + format.name();
- switch (format){
+ switch (format) {
case Float:
data = ic.readFloatBuffer(dataName, null);
break;
@@ -1212,8 +1174,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
data = ic.readIntBuffer(dataName, null);
break;
default:
- throw new IOException("Unsupported import buffer format: "+format);
+ throw new IOException("Unsupported import buffer format: " + format);
}
}
-
}