Browse Source

improve formatting & rm trailing whitespace (5 files in com.jme3.scene)

Stephen Gold 5 years ago
parent
commit
851793cde6

+ 29 - 22
jme3-core/src/main/java/com/jme3/scene/Geometry.java

@@ -61,7 +61,6 @@ import java.util.logging.Logger;
  * @author Kirill Vainer
  */
 public class Geometry extends Spatial {
-
     // Version #1: removed shared meshes.
     // models loaded with shared mesh will be automatically fixed.
     public static final int SAVABLE_VERSION = 1;
@@ -74,19 +73,16 @@ public class Geometry extends Spatial {
      */
     protected boolean ignoreTransform = false;
     protected transient Matrix4f cachedWorldMat = new Matrix4f();
-
     /**
      * Specifies which {@link GeometryGroupNode} this <code>Geometry</code>
      * is managed by.
      */
     protected GeometryGroupNode groupNode;
-
     /**
      * The start index of this <code>Geometry's</code> 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

+ 133 - 130
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 <code>gl_PointSize</code> 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 <em>avoid</em> using this method as it disables some engine features.
      */
     @Deprecated
-    public void setInterleaved(){
+    public void setInterleaved() {
         ArrayList<VertexBuffer> vbs = new ArrayList<>();
         vbs.addAll(buffersList);
 
@@ -707,7 +708,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         vbs.remove(getBuffer(Type.Index));
 
         int stride = 0; // aka bytes per vertex
-        for (int i = 0; i < vbs.size(); i++){
+        for (int i = 0; i < vbs.size(); i++) {
             VertexBuffer vb = vbs.get(i);
 //            if (vb.getFormat() != Format.Float){
 //                throw new UnsupportedOperationException("Cannot interleave vertex buffer.\n" +
@@ -725,20 +726,20 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         buffers.put(Type.InterleavedData.ordinal(), allData);
         buffersList.add(allData);
 
-        for (int vert = 0; vert < getVertexCount(); vert++){
-            for (int i = 0; i < vbs.size(); i++){
+        for (int vert = 0; vert < getVertexCount(); vert++) {
+            for (int i = 0; i < vbs.size(); i++) {
                 VertexBuffer vb = vbs.get(i);
-                switch (vb.getFormat()){
+                switch (vb.getFormat()) {
                     case Float:
                         FloatBuffer fb = (FloatBuffer) vb.getData();
-                        for (int comp = 0; comp < vb.components; comp++){
+                        for (int comp = 0; comp < vb.components; comp++) {
                             dataBuf.putFloat(fb.get());
                         }
                         break;
                     case Byte:
                     case UnsignedByte:
                         ByteBuffer bb = (ByteBuffer) vb.getData();
-                        for (int comp = 0; comp < vb.components; comp++){
+                        for (int comp = 0; comp < vb.components; comp++) {
                             dataBuf.put(bb.get());
                         }
                         break;
@@ -746,20 +747,20 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
                     case Short:
                     case UnsignedShort:
                         ShortBuffer sb = (ShortBuffer) vb.getData();
-                        for (int comp = 0; comp < vb.components; comp++){
+                        for (int comp = 0; comp < vb.components; comp++) {
                             dataBuf.putShort(sb.get());
                         }
                         break;
                     case Int:
                     case UnsignedInt:
                         IntBuffer ib = (IntBuffer) vb.getData();
-                        for (int comp = 0; comp < vb.components; comp++){
+                        for (int comp = 0; comp < vb.components; comp++) {
                             dataBuf.putInt(ib.get());
                         }
                         break;
                     case Double:
                         DoubleBuffer db = (DoubleBuffer) vb.getData();
-                        for (int comp = 0; comp < vb.components; comp++){
+                        for (int comp = 0; comp < vb.components; comp++) {
                             dataBuf.putDouble(db.get());
                         }
                         break;
@@ -768,7 +769,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         }
 
         int offset = 0;
-        for (VertexBuffer vb : vbs){
+        for (VertexBuffer vb : vbs) {
             vb.setOffset(offset);
             vb.setStride(stride);
 
@@ -778,8 +779,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         }
     }
 
-    private int computeNumElements(int bufSize){
-        switch (mode){
+    private int computeNumElements(int bufSize) {
+        switch (mode) {
             case Triangles:
                 return bufSize / 3;
             case TriangleFan:
@@ -794,7 +795,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
             case LineStrip:
                 return bufSize - 1;
             case Patch:
-                return bufSize/patchVertexCount;
+                return bufSize / patchVertexCount;
             default:
                 throw new UnsupportedOperationException();
         }
@@ -803,8 +804,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
     private int computeInstanceCount() {
         // Whatever the max of the base instance counts
         int max = 0;
-        for( VertexBuffer vb : buffersList ) {
-            if( vb.getBaseInstanceCount() > max ) {
+        for (VertexBuffer vb : buffersList) {
+            if (vb.getBaseInstanceCount() > max) {
                 max = vb.getBaseInstanceCount();
             }
         }
@@ -821,19 +822,19 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * @throws IllegalStateException If this mesh is in
      * {@link #setInterleaved() interleaved} format.
      */
-    public void updateCounts(){
+    public void updateCounts() {
         if (getBuffer(Type.InterleavedData) != null) {
             throw new IllegalStateException("Should update counts before interleave");
         }
 
         VertexBuffer pb = getBuffer(Type.Position);
         VertexBuffer ib = getBuffer(Type.Index);
-        if (pb != null){
+        if (pb != null) {
             vertCount = pb.getData().limit() / pb.getNumComponents();
         }
-        if (ib != null){
+        if (ib != null) {
             elementCount = computeNumElements(ib.getData().limit());
-        }else{
+        } else {
             elementCount = computeNumElements(vertCount);
         }
         instanceCount = computeInstanceCount();
@@ -845,8 +846,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * @param lod The lod level to look up
      * @return The triangle count for that LOD level
      */
-    public int getTriangleCount(int lod){
-        if (lodLevels != null){
+    public int getTriangleCount(int lod) {
+        if (lodLevels != null) {
             if (lod < 0) {
                 throw new IllegalArgumentException("LOD level cannot be < 0");
             }
@@ -856,9 +857,9 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
             }
 
             return computeNumElements(lodLevels[lod].getData().limit());
-        }else if (lod == 0){
+        } else if (lod == 0) {
             return elementCount;
-        }else{
+        } else {
             throw new IllegalArgumentException("There are no LOD levels on the mesh!");
         }
     }
@@ -872,7 +873,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      *
      * @return how many triangles/elements are on this Mesh.
      */
-    public int getTriangleCount(){
+    public int getTriangleCount() {
         return elementCount;
     }
 
@@ -883,7 +884,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      *
      * @return Number of vertices on the mesh
      */
-    public int getVertexCount(){
+    public int getVertexCount() {
         return vertCount;
     }
 
@@ -906,24 +907,24 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * @param v2 Vector to contain second vertex position
      * @param v3 Vector to contain third vertex position
      */
-    public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
+    public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3) {
         VertexBuffer pb = getBuffer(Type.Position);
         IndexBuffer ib = getIndicesAsList();
-        if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3){
+        if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3) {
             FloatBuffer fpb = (FloatBuffer) pb.getData();
 
             // aquire triangle's vertex indices
             int vertIndex = index * 3;
             int vert1 = ib.get(vertIndex);
-            int vert2 = ib.get(vertIndex+1);
-            int vert3 = ib.get(vertIndex+2);
+            int vert2 = ib.get(vertIndex + 1);
+            int vert3 = ib.get(vertIndex + 2);
 
             BufferUtils.populateFromBuffer(v1, fpb, vert1);
             BufferUtils.populateFromBuffer(v2, fpb, vert2);
             BufferUtils.populateFromBuffer(v3, fpb, vert3);
-        }else{
+        } else {
             throw new UnsupportedOperationException("Position buffer not set or "
-                                                  + " has incompatible format");
+                    + " has incompatible format");
         }
     }
 
@@ -937,7 +938,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      *
      * @param tri The triangle to store the positions in
      */
-    public void getTriangle(int index, Triangle tri){
+    public void getTriangle(int index, Triangle tri) {
         getTriangle(index, tri.get1(), tri.get2(), tri.get3());
         tri.setIndex(index);
         tri.setNormal(null);
@@ -952,27 +953,27 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      *
      * @param indices Indices of the triangle's vertices
      */
-    public void getTriangle(int index, int[] indices){
+    public void getTriangle(int index, int[] indices) {
         IndexBuffer ib = getIndicesAsList();
 
         // acquire triangle's vertex indices
         int vertIndex = index * 3;
         indices[0] = ib.get(vertIndex);
-        indices[1] = ib.get(vertIndex+1);
-        indices[2] = ib.get(vertIndex+2);
+        indices[1] = ib.get(vertIndex + 1);
+        indices[2] = ib.get(vertIndex + 2);
     }
 
     /**
      * Returns the mesh's VAO ID. Internal use only.
      */
-    public int getId(){
+    public int getId() {
         return vertexArrayID;
     }
 
     /**
      * Sets the mesh's VAO ID. Internal use only.
      */
-    public void setId(int id){
+    public void setId(int id) {
         if (vertexArrayID != -1) {
             throw new IllegalStateException("ID has already been set.");
         }
@@ -987,7 +988,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * com.jme3.bounding.BoundingVolume,
      * com.jme3.collision.CollisionResults) }.
      */
-    public void createCollisionData(){
+    public void createCollisionData() {
         BIHTree tree = new BIHTree(this);
         tree.construct();
         collisionTree = tree;
@@ -1008,9 +1009,9 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * graph elements such as {@link Spatial}s.
      */
     public int collideWith(Collidable other,
-                           Matrix4f worldMatrix,
-                           BoundingVolume worldBound,
-                           CollisionResults results){
+            Matrix4f worldMatrix,
+            BoundingVolume worldBound,
+            CollisionResults results) {
 
         switch (mode) {
             case Points:
@@ -1028,7 +1029,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
             return 0;
         }
 
-        if (collisionTree == null){
+        if (collisionTree == null) {
             createCollisionData();
         }
 
@@ -1042,7 +1043,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * @param vb The buffer to set
      * @throws IllegalArgumentException If the buffer type is already set
      */
-    public void setBuffer(VertexBuffer vb){
+    public void setBuffer(VertexBuffer vb) {
         if (buffers.containsKey(vb.getBufferType().ordinal())) {
             throw new IllegalArgumentException("Buffer type already set: " + vb.getBufferType());
         }
@@ -1059,9 +1060,9 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      *
      * @param type The buffer type to remove
      */
-    public void clearBuffer(VertexBuffer.Type type){
+    public void clearBuffer(VertexBuffer.Type type) {
         VertexBuffer vb = buffers.remove(type.ordinal());
-        if (vb != null){
+        if (vb != null) {
             buffersList.remove(vb);
             updateCounts();
         }
@@ -1079,14 +1080,14 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * @throws UnsupportedOperationException If the buffer already set is
      * 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) {
         VertexBuffer vb = buffers.get(type.ordinal());
-        if (vb == null){
+        if (vb == null) {
             vb = new VertexBuffer(type);
             vb.setupData(Usage.Dynamic, components, format, buf);
             setBuffer(vb);
-        }else{
-            if (vb.getNumComponents() != components || vb.getFormat() != format){
+        } else {
+            if (vb.getNumComponents() != components || vb.getFormat() != format) {
                 throw new UnsupportedOperationException("The buffer already set "
                         + "is incompatible with the given parameters");
             }
@@ -1110,7 +1111,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         setBuffer(type, components, Format.Float, buf);
     }
 
-    public void setBuffer(Type type, int components, float[] buf){
+    public void setBuffer(Type type, int components, float[] buf) {
         setBuffer(type, components, BufferUtils.createFloatBuffer(buf));
     }
 
@@ -1118,7 +1119,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         setBuffer(type, components, Format.UnsignedInt, buf);
     }
 
-    public void setBuffer(Type type, int components, int[] buf){
+    public void setBuffer(Type type, int components, int[] buf) {
         setBuffer(type, components, BufferUtils.createIntBuffer(buf));
     }
 
@@ -1126,7 +1127,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         setBuffer(type, components, Format.UnsignedShort, buf);
     }
 
-    public void setBuffer(Type type, int components, byte[] buf){
+    public void setBuffer(Type type, int components, byte[] buf) {
         setBuffer(type, components, BufferUtils.createByteBuffer(buf));
     }
 
@@ -1134,7 +1135,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         setBuffer(type, components, Format.UnsignedByte, buf);
     }
 
-    public void setBuffer(Type type, int components, short[] buf){
+    public void setBuffer(Type type, int components, short[] buf) {
         setBuffer(type, components, BufferUtils.createShortBuffer(buf));
     }
 
@@ -1145,7 +1146,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * @param type The type of VertexBuffer
      * @return the VertexBuffer data, or null if not set
      */
-    public VertexBuffer getBuffer(Type type){
+    public VertexBuffer getBuffer(Type type) {
         return buffers.get(type.ordinal());
     }
 
@@ -1187,22 +1188,22 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      *
      * @return A virtual or wrapped index buffer to read the data as a list
      */
-    public IndexBuffer getIndicesAsList(){
+    public IndexBuffer getIndicesAsList() {
         if (mode == Mode.Hybrid) {
             throw new UnsupportedOperationException("Hybrid mode not supported");
         }
 
         IndexBuffer ib = getIndexBuffer();
-        if (ib != null){
-            if (mode.isListMode()){
+        if (ib != null) {
+            if (mode.isListMode()) {
                 // already in list mode
                 return ib;
-            }else{
+            } else {
                 // not in list mode but it does have an index buffer
                 // wrap it so the data is converted to list format
                 return new WrappedIndexBuffer(this);
             }
-        }else{
+        } else {
             // return a virtual index buffer that will supply
             // "fake" indices in list format
             return new VirtualIndexBuffer(vertCount, mode);
@@ -1289,9 +1290,9 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
 
         VertexBuffer newIdxBuf = new VertexBuffer(Type.Index);
         newIdxBuf.setupData(oldIdxBuf.getUsage(),
-                            oldIdxBuf.getNumComponents(),
-                            newIndexBuf instanceof IndexIntBuffer ? Format.UnsignedInt : Format.UnsignedShort,
-                            newIndexBuf.getBuffer());
+                oldIdxBuf.getNumComponents(),
+                newIndexBuf instanceof IndexIntBuffer ? Format.UnsignedInt : Format.UnsignedShort,
+                newIndexBuf.getBuffer());
         clearBuffer(Type.Index);
         setBuffer(newIdxBuf);
 
@@ -1308,11 +1309,13 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
             //check for data before copying, some buffers are just empty shells
             //for caching purpose (HW skinning buffers), and will be filled when
             //needed
-            if(oldVb.getData()!=null){
+            if (oldVb.getData() != null) {
                 // Create a new vertex buffer with similar configuration, but
                 // with the capacity of number of unique vertices
-                Buffer buffer = VertexBuffer.createBuffer(oldVb.getFormat(), oldVb.getNumComponents(), newNumVerts);
-                newVb.setupData(oldVb.getUsage(), oldVb.getNumComponents(), oldVb.getFormat(), buffer);
+                Buffer buffer = VertexBuffer.createBuffer(oldVb.getFormat(),
+                        oldVb.getNumComponents(), newNumVerts);
+                newVb.setupData(oldVb.getUsage(), oldVb.getNumComponents(),
+                        oldVb.getFormat(), buffer);
 
                 // Copy the vertex data from the old buffer into the new buffer
                 for (int i = 0; i < newNumVerts; i++) {
@@ -1338,8 +1341,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
     }
 
     /**
-     * Scales the texture coordinate buffer on this mesh by the given
-     * scale factor.
+     * Scales the texture coordinate buffer on this mesh by the given scale
+     * factor.
      * <p>
      * 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<VertexBuffer> getBuffers(){
+    public IntMap<VertexBuffer> getBuffers() {
         return buffers;
     }
 
@@ -1436,7 +1439,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      *
      * @return list of vertex buffers on this mesh.
      */
-    public SafeArrayList<VertexBuffer> getBufferList(){
+    public SafeArrayList<VertexBuffer> getBufferList() {
         return buffersList;
     }
 
@@ -1449,8 +1452,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
      * @return true if the mesh uses bone animation, false otherwise
      */
     public boolean isAnimated() {
-        return getBuffer(Type.BoneIndex) != null ||
-               getBuffer(Type.HWBoneIndex) != null;
+        return getBuffer(Type.BoneIndex) != null
+                || getBuffer(Type.HWBoneIndex) != null;
     }
 
     /**
@@ -1504,6 +1507,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
 
     /**
      * Sets the count of vertices used for each tessellation patch
+     *
      * @param patchVertexCount
      */
     public void setPatchVertexCount(int patchVertexCount) {
@@ -1512,13 +1516,13 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
 
     /**
      * Gets the amount of vertices used for each patch;
+     *
      * @return the count (&ge;0)
      */
     public int getPatchVertexCount() {
         return patchVertexCount;
     }
 
-
     public void addMorphTarget(MorphTarget target) {
         if (morphTargets == null) {
             morphTargets = new SafeArrayList<>(MorphTarget.class);
@@ -1533,14 +1537,13 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
             return morphTargets.getArray();
         }
     }
-    
+
     /**
      * Get the name of all morphs in order.
      * Morphs without names will be null
      * @return an array
      */
     public String[] getMorphTargetNames() {
-        
         MorphTarget[] nbMorphTargets = getMorphTargets();
         if (nbMorphTargets.length == 0) {
             return new String[0];
@@ -1556,11 +1559,12 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
     public boolean hasMorphTargets() {
         return morphTargets != null && !morphTargets.isEmpty();
     }
-    
+
     /**
      * Get the index of the morph that has the given name.
+     *
      * @param morphName The name of the morph to search for
-     * @return The index of the morph, or -1 if not found. 
+     * @return The index of the morph, or -1 if not found.
      */
     public int getMorphIndex(String morphName) {
         int index = -1;
@@ -1637,12 +1641,12 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
 
 //        in.readStringSavableMap("buffers", null);
         buffers = (IntMap<VertexBuffer>) in.readIntSavableMap("buffers", null);
-        for (Entry<VertexBuffer> entry : buffers){
+        for (Entry<VertexBuffer> entry : buffers) {
             buffersList.add(entry.getValue());
         }
 
         //creating hw animation buffers empty so that they are put in the cache
-        if(isAnimated()){
+        if (isAnimated()) {
             VertexBuffer hwBoneIndex = new VertexBuffer(Type.HWBoneIndex);
             hwBoneIndex.setUsage(Usage.CpuOnly);
             setBuffer(hwBoneIndex);
@@ -1654,7 +1658,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
         Savable[] lodLevelsSavable = in.readSavableArray("lodLevels", null);
         if (lodLevelsSavable != null) {
             lodLevels = new VertexBuffer[lodLevelsSavable.length];
-            System.arraycopy( lodLevelsSavable, 0, lodLevels, 0, lodLevels.length);
+            System.arraycopy(lodLevelsSavable, 0, lodLevels, 0, lodLevels.length);
         }
 
         ArrayList<Savable> l = in.readSavableArrayList("morphTargets", null);
@@ -1662,5 +1666,4 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
             morphTargets = new SafeArrayList(MorphTarget.class, l);
         }
     }
-
 }

+ 91 - 84
jme3-core/src/main/java/com/jme3/scene/Node.java

@@ -47,7 +47,6 @@ import java.util.Queue;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-
 /**
  * <code>Node</code> 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 SafeArrayList<Spatial> children = new SafeArrayList<Spatial>(Spatial.class);
-
     /**
      * If this node is a root, this list will contain the current
      * set of children (and children of children) that require
@@ -105,7 +101,6 @@ public class Node extends Spatial {
     }
 
     /**
-     *
      * <code>getQuantity</code> 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( SafeArrayList<Spatial> results ) {
-        for( Spatial child : children.getArray() ) {
-            if( child.requiresUpdates() ) {
+    private void addUpdateChildren(SafeArrayList<Spatial> results) {
+        for (Spatial child : children.getArray()) {
+            if (child.requiresUpdates()) {
                 results.add(child);
             }
-            if( child instanceof Node ) {
-                ((Node)child).addUpdateChildren(results);
+            if (child instanceof Node) {
+                ((Node) child).addUpdateChildren(results);
             }
         }
     }
@@ -205,16 +202,16 @@ public class Node extends Spatial {
      */
     void invalidateUpdateList() {
         updateListValid = false;
-        if ( parent != null ) {
+        if (parent != null) {
             parent.invalidateUpdateList();
         }
     }
 
     private SafeArrayList<Spatial> getUpdateList() {
-        if( updateListValid ) {
+        if (updateListValid) {
             return updateList;
         }
-        if( updateList == null ) {
+        if (updateList == null) {
             updateList = new SafeArrayList<Spatial>(Spatial.class);
         } else {
             updateList.clear();
@@ -227,32 +224,32 @@ public class Node extends Spatial {
     }
 
     @Override
-    public void updateLogicalState(float tpf){
+    public void updateLogicalState(float tpf) {
         super.updateLogicalState(tpf);
 
         // Only perform updates on children if we are the
         // root and then only peform updates on children we
         // know to require updates.
         // So if this isn't the root, abort.
-        if( parent != null ) {
+        if (parent != null) {
             return;
         }
 
-        for( Spatial s : getUpdateList().getArray() ) {
+        for (Spatial s : getUpdateList().getArray()) {
             s.updateLogicalState(tpf);
         }
     }
 
     @Override
-    public void updateGeometricState(){
+    public void updateGeometricState() {
         if (refreshFlags == 0) {
             // This branch has no geometric state that requires updates.
             return;
         }
-        if ((refreshFlags & RF_LIGHTLIST) != 0){
+        if ((refreshFlags & RF_LIGHTLIST) != 0) {
             updateWorldLightList();
         }
-        if ((refreshFlags & RF_TRANSFORM) != 0){
+        if ((refreshFlags & RF_TRANSFORM) != 0) {
             // combine with parent transforms- same for all spatial
             // subclasses.
             updateWorldTransforms();
@@ -273,7 +270,7 @@ public class Node extends Spatial {
             }
         }
 
-        if ((refreshFlags & RF_BOUND) != 0){
+        if ((refreshFlags & RF_BOUND) != 0) {
             updateWorldBound();
         }
 
@@ -289,14 +286,15 @@ public class Node extends Spatial {
     @Override
     public int getTriangleCount() {
         int count = 0;
-        if(children != null) {
-            for(int i = 0; i < children.size(); i++) {
+        if (children != null) {
+            for (int i = 0; i < children.size(); i++) {
                 count += children.get(i).getTriangleCount();
             }
         }
 
         return count;
     }
+
     /**
      * <code>getVertexCount</code> 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());
     }
+
     /**
-     *
      * <code>attachChildAt</code> 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 {
     }
 
     /**
-     *
      * <code>detachChildAt</code> 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;
     }
 
     /**
-     *
      * <code>detachAllChildren</code> 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);
     }
 
     /**
-     *
      * <code>getChild</code> 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 <T extends Spatial>List<T> descendantMatches(
+    public <T extends Spatial> List<T> descendantMatches(
             Class<T> spatialSubclass, String nameRegex) {
         List<T> newList = new ArrayList<T>();
-        if (getQuantity() < 1) return newList;
+        if (getQuantity() < 1) {
+            return newList;
+        }
         for (Spatial child : getChildren()) {
-            if (child.matches(spatialSubclass, nameRegex))
-                newList.add((T)child);
-            if (child instanceof Node)
+            if (child.matches(spatialSubclass, nameRegex)) {
+                newList.add((T) child);
+            }
+            if (child instanceof Node) {
                 newList.addAll(((Node) child).descendantMatches(
                         spatialSubclass, nameRegex));
+            }
         }
         return newList;
     }
@@ -668,7 +674,7 @@ public class Node extends Spatial {
      *
      * @see #descendantMatches(java.lang.Class, java.lang.String)
      */
-    public <T extends Spatial>List<T> descendantMatches(
+    public <T extends Spatial> List<T> descendantMatches(
             Class<T> spatialSubclass) {
         return descendantMatches(spatialSubclass, null);
     }
@@ -678,12 +684,12 @@ public class Node extends Spatial {
      *
      * @see #descendantMatches(java.lang.Class, java.lang.String)
      */
-    public <T extends Spatial>List<T> descendantMatches(String nameRegex) {
+    public <T extends Spatial> List<T> descendantMatches(String nameRegex) {
         return descendantMatches(null, nameRegex);
     }
 
     @Override
-    public Node clone(boolean cloneMaterials){
+    public Node clone(boolean cloneMaterials) {
         Node nodeClone = (Node) super.clone(cloneMaterials);
 //        nodeClone.children = new ArrayList<Spatial>();
 //        for (Spatial child : children){
@@ -700,7 +706,7 @@ public class Node extends Spatial {
 
     @Override
     public Spatial deepClone() {
-        Node nodeClone = (Node)super.deepClone();
+        Node nodeClone = (Node) super.deepClone();
 
         // Reset the fields of the clone that should be in a 'new' state.
         nodeClone.updateList = null;
@@ -709,10 +715,10 @@ public class Node extends Spatial {
         return nodeClone;
     }
 
-    public Spatial oldDeepClone(){
+    public Spatial oldDeepClone() {
         Node nodeClone = (Node) super.clone();
         nodeClone.children = new SafeArrayList<Spatial>(Spatial.class);
-        for (Spatial child : children){
+        for (Spatial child : children) {
             Spatial childClone = child.deepClone();
             childClone.parent = nodeClone;
             nodeClone.children.add(childClone);
@@ -724,7 +730,7 @@ public class Node 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);
 
         this.children = cloner.clone(children);
@@ -734,6 +740,7 @@ public class Node extends Spatial {
         // cloning this list is fine.
         this.updateList = cloner.clone(updateList);
     }
+
     @Override
     @SuppressWarnings("unchecked")
     public void write(JmeExporter e) throws IOException {
@@ -747,8 +754,8 @@ public class Node extends Spatial {
         // XXX: Load children before loading itself!!
         // This prevents empty children list if controls query
         // it in Control.setSpatial().
-        children = new SafeArrayList( Spatial.class,
-                                      e.getCapsule(this).readSavableArrayList("children", null) );
+        children = new SafeArrayList(Spatial.class,
+                e.getCapsule(this).readSavableArrayList("children", null));
 
         // go through children and set parent to this node
         if (children != null) {
@@ -761,7 +768,7 @@ public class Node extends Spatial {
 
     @Override
     public void setModelBound(BoundingVolume modelBound) {
-        if(children != null) {
+        if (children != null) {
             for (Spatial child : children.getArray()) {
                 child.setModelBound(modelBound != null ? modelBound.clone(null) : null);
             }
@@ -770,7 +777,7 @@ public class Node extends Spatial {
 
     @Override
     public void updateModelBound() {
-        if(children != null) {
+        if (children != null) {
             for (Spatial child : children.getArray()) {
                 child.updateModelBound();
             }

+ 42 - 35
jme3-core/src/main/java/com/jme3/scene/Spatial.java

@@ -68,8 +68,8 @@ import java.util.logging.Logger;
  * @author Joshua Slack
  * @version $Revision: 4075 $, $Data$
  */
-public abstract class Spatial implements Savable, Cloneable, Collidable, CloneableSmartAsset, JmeCloneable, HasLocalTransform {
-
+public abstract class Spatial implements Savable, Cloneable, Collidable,
+        CloneableSmartAsset, JmeCloneable, HasLocalTransform {
     private static final Logger logger = Logger.getLogger(Spatial.class.getName());
 
     /**
@@ -77,7 +77,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
      * this spatial.
      */
     public enum CullHint {
-
         /**
          * Do whatever our parent does. If no parent, default to {@link #Dynamic}.
          */
@@ -104,7 +103,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
      * Specifies if this spatial should be batched
      */
     public enum BatchHint {
-
         /**
          * Do whatever our parent does. If no parent, default to {@link #Always}.
          */
@@ -121,12 +119,13 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
     /**
      * Refresh flag types
      */
-    protected static final int RF_TRANSFORM = 0x01, // need light resort + combine transforms
-                               RF_BOUND = 0x02,
-                               RF_LIGHTLIST = 0x04, // changes in light lists 
-                               RF_CHILD_LIGHTLIST = 0x08, // some child need geometry update
-                               RF_MATPARAM_OVERRIDE = 0x10;
-    
+    protected static final int
+            RF_TRANSFORM = 0x01, // need light resort + combine transforms
+            RF_BOUND = 0x02,
+            RF_LIGHTLIST = 0x04, // changes in light lists
+            RF_CHILD_LIGHTLIST = 0x08, // some child need geometry update
+            RF_MATPARAM_OVERRIDE = 0x10;
+
     protected CullHint cullHint = CullHint.Inherit;
     protected BatchHint batchHint = BatchHint.Inherit;
     /**
@@ -147,7 +146,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
      */
     protected String name;
     // scale values
-    protected transient Camera.FrustumIntersect frustrumIntersects = Camera.FrustumIntersect.Intersects;
+    protected transient Camera.FrustumIntersect frustrumIntersects
+            = Camera.FrustumIntersect.Intersects;
     protected RenderQueue.Bucket queueBucket = RenderQueue.Bucket.Inherit;
     protected ShadowMode shadowMode = RenderQueue.ShadowMode.Inherit;
     public transient float queueDistance = Float.NEGATIVE_INFINITY;
@@ -232,6 +232,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
     boolean requiresUpdates() {
         return requiresUpdates | !controls.isEmpty();
     }
+
     /**
      * Subclasses can call this with true to denote that they require
      * updateLogicalState() to be called even if they contain no controls.
@@ -247,7 +248,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
      * optimal behavior if they don't require updateLogicalState() to be
      * called even if there are no controls.
      */
-    protected void setRequiresUpdates( boolean f ) {
+    protected void setRequiresUpdates(boolean f) {
         // Note to explorers, the reason this was done as a protected setter
         // instead of passed on construction is because it frees all subclasses
         // from having to make sure to always pass the value up in case they
@@ -264,7 +265,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         // it to false if the class is Node.class or Geometry.class.
         // This means that all subclasses will default to the old behavior
         // unless they opt in.
-        if( parent != null ) {
+        if (parent != null) {
             throw new IllegalStateException("setRequiresUpdates() cannot be called once attached.");
         }
         this.requiresUpdates = f;
@@ -325,6 +326,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
             p = p.parent;
         }
     }
+
     /**
      * (Internal use only) Forces a refresh of the given types of data.
      *
@@ -556,9 +558,9 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         Vector3f compVecA = vars.vect4;
         compVecA.set(position).subtractLocal(worldTranslation);
         getLocalRotation().lookAt(compVecA, upVector);
-        if ( getParent() != null ) {
-            Quaternion rot=vars.quat1;
-            rot =  rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation());
+        if (getParent() != null) {
+            Quaternion rot = vars.quat1;
+            rot = rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation());
             rot.normalizeLocal();
             setLocalRotation(rot);
         }
@@ -762,6 +764,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
 
     /**
      * Add a control to the list of controls.
+     *
      * @param control The control to add.
      *
      * @see Spatial#removeControl(java.lang.Class)
@@ -774,7 +777,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         // If the requirement to be updated has changed
         // then we need to let the parent node know so it
         // can rebuild its update list.
-        if( parent != null && before != after ) {
+        if (parent != null && before != after) {
             parent.invalidateUpdateList();
         }
     }
@@ -797,7 +800,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         // If the requirement to be updated has changed
         // then we need to let the parent node know so it
         // can rebuild its update list.
-        if( parent != null && before != after ) {
+        if (parent != null && before != after) {
             parent.invalidateUpdateList();
         }
     }
@@ -822,7 +825,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         // If the requirement to be updated has changed
         // then we need to let the parent node know so it
         // can rebuild its update list.
-        if( parent != null && before != after ) {
+        if (parent != null && before != after) {
             parent.invalidateUpdateList();
         }
         return result;
@@ -1229,6 +1232,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
 
     /**
      * Centers the spatial in the origin of the world bound.
+     *
      * @return The spatial on which this method is called, e.g <code>this</code>.
      */
     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 IdentityCloneFunction<Material>());
         }
 
@@ -1425,7 +1428,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
     @Override
     public Spatial jmeClone() {
         try {
-            Spatial clone = (Spatial)super.clone();
+            Spatial clone = (Spatial) super.clone();
             return clone;
         } catch (CloneNotSupportedException ex) {
             throw new AssertionError();
@@ -1437,8 +1440,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
      */
     @Override
     @SuppressWarnings("unchecked")
-    public void cloneFields( Cloner cloner, Object original ) {
-
+    public void cloneFields(Cloner cloner, Object original) {
         // Clone all of the fields that need fix-ups and/or potential
         // sharing.
         this.parent = cloner.clone(parent);
@@ -1457,11 +1459,11 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         // to avoid all of the nasty cloneForSpatial() fixup style code that
         // used to inject stuff into the clone's user data.  By using cloner
         // to clone the user data we get this automatically.
-        if( userData != null ) {
-            userData = (HashMap<String, Savable>)userData.clone();
-            for( Map.Entry<String, Savable> e : userData.entrySet() ) {
+        if (userData != null) {
+            userData = (HashMap<String, Savable>) userData.clone();
+            for (Map.Entry<String, Savable> e : userData.entrySet()) {
                 Savable value = e.getValue();
-                if( value instanceof Cloneable ) {
+                if (value instanceof Cloneable) {
                     // Note: all JmeCloneable objects are also Cloneable so this
                     // catches both cases.
                     e.setValue(cloner.clone(value));
@@ -1474,7 +1476,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         if (data == null) {
             if (userData != null) {
                 userData.remove(key);
-                if(userData.isEmpty()) {
+                if (userData.isEmpty()) {
                     userData = null;
                 }
             }
@@ -1588,9 +1590,11 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         }
         worldOverrides = new SafeArrayList<>(MatParamOverride.class);
 
-        //changed for backward compatibility with j3o files generated before the AnimControl/SkeletonControl split
+        //changed for backward compatibility with j3o files
+        //generated before the AnimControl/SkeletonControl split
         //the AnimControl creates the SkeletonControl for old files and add it to the spatial.
-        //The SkeletonControl must be the last in the stack so we add the list of all other control before it.
+        //The SkeletonControl must be the last in the stack
+        //so we add the list of all other control before it.
         //When backward compatibility won't be needed anymore this can be replaced by :
         //controls = ic.readSavableArrayList("controlsList", null));
         controls.addAll(0, ic.readSavableArrayList("controlsList", null));
@@ -1759,13 +1763,14 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
 
     /**
      * Visit each scene graph element ordered by DFS with the default post order mode.
+     *
      * @param visitor
-     * @see #depthFirstTraversal(com.jme3.scene.SceneGraphVisitor, com.jme3.scene.Spatial.DFSMode) 
+     * @see #depthFirstTraversal(com.jme3.scene.SceneGraphVisitor, com.jme3.scene.Spatial.DFSMode)
      */
     public void depthFirstTraversal(SceneGraphVisitor visitor) {
         depthFirstTraversal(visitor, DFSMode.POST_ORDER);
     }
-    
+
     /**
      * Specifies the mode of the depth first search.
      */
@@ -1779,10 +1784,11 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
          */
         POST_ORDER;
     }
-    
+
     /**
      * Visit each scene graph element ordered by DFS.
      * There are two modes: pre order and post order.
+     *
      * @param visitor
      * @param mode the traversal mode: pre order or post order
      */
@@ -1790,6 +1796,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
 
     /**
      * Visit each scene graph element ordered by BFS
+     *
      * @param visitor
      */
     public void breadthFirstTraversal(SceneGraphVisitor visitor) {

File diff suppressed because it is too large
+ 146 - 184
jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java


Some files were not shown because too many files changed in this diff