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

master
Stephen Gold 5 years ago
parent bee3d36f16
commit 851793cde6
  1. 31
      jme3-core/src/main/java/com/jme3/scene/Geometry.java
  2. 61
      jme3-core/src/main/java/com/jme3/scene/Mesh.java
  3. 59
      jme3-core/src/main/java/com/jme3/scene/Node.java
  4. 27
      jme3-core/src/main/java/com/jme3/scene/Spatial.java
  5. 71
      jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java

@ -61,7 +61,6 @@ import java.util.logging.Logger;
* @author Kirill Vainer * @author Kirill Vainer
*/ */
public class Geometry extends Spatial { public class Geometry extends Spatial {
// Version #1: removed shared meshes. // Version #1: removed shared meshes.
// models loaded with shared mesh will be automatically fixed. // models loaded with shared mesh will be automatically fixed.
public static final int SAVABLE_VERSION = 1; public static final int SAVABLE_VERSION = 1;
@ -74,19 +73,16 @@ public class Geometry extends Spatial {
*/ */
protected boolean ignoreTransform = false; protected boolean ignoreTransform = false;
protected transient Matrix4f cachedWorldMat = new Matrix4f(); protected transient Matrix4f cachedWorldMat = new Matrix4f();
/** /**
* Specifies which {@link GeometryGroupNode} this <code>Geometry</code> * Specifies which {@link GeometryGroupNode} this <code>Geometry</code>
* is managed by. * is managed by.
*/ */
protected GeometryGroupNode groupNode; protected GeometryGroupNode groupNode;
/** /**
* The start index of this <code>Geometry's</code> inside * The start index of this <code>Geometry's</code> inside
* the {@link GeometryGroupNode}. * the {@link GeometryGroupNode}.
*/ */
protected int startIndex = -1; protected int startIndex = -1;
/** /**
* Morph state variable for morph animation * 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 * Indicate that the transform of this spatial has changed and that
* a refresh is required. * a refresh is required.
*/ */
@ -624,6 +619,7 @@ public class Geometry extends Spatial {
/** /**
* returns true if the morph state has changed on the last frame. * returns true if the morph state has changed on the last frame.
*
* @return true if changed, otherwise false * @return true if changed, otherwise false
*/ */
public boolean isDirtyMorph() { 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, * Seting this to true will stop this geometry morph buffer to be updated,
* unless the morph state changes * unless the morph state changes
*
* @param dirtyMorph * @param dirtyMorph
*/ */
public void setDirtyMorph(boolean dirtyMorph) { public void setDirtyMorph(boolean dirtyMorph) {
@ -642,6 +639,7 @@ public class Geometry extends Spatial {
/** /**
* returns the morph state of this Geometry. * returns the morph state of this Geometry.
* Used internally by the MorphControl. * Used internally by the MorphControl.
*
* @return an array * @return an array
*/ */
public float[] getMorphState() { public float[] getMorphState() {
@ -653,6 +651,7 @@ public class Geometry extends Spatial {
/** /**
* Get the state of a morph * Get the state of a morph
*
* @param morphTarget the name of the morph to get the state of * @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 * @return the state of the morph, or -1 if the morph is not found
*/ */
@ -666,10 +665,13 @@ public class Geometry extends Spatial {
} }
/** /**
* 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. * 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. * Else it's set to -1.
*
* @return the number of simultaneous morph targets handled on the GPU * @return the number of simultaneous morph targets handled on the GPU
*/ */
public int getNbSimultaneousGPUMorph() { 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. * 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. * 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. * @param nbSimultaneousGPUMorph the number of simultaneous morph targets to be handled on the GPU.
*/ */
public void setNbSimultaneousGPUMorph(int nbSimultaneousGPUMorph) { public void setNbSimultaneousGPUMorph(int nbSimultaneousGPUMorph) {
@ -723,7 +729,8 @@ public class Geometry extends Spatial {
material = im.getAssetManager().loadMaterial(matName); material = im.getAssetManager().loadMaterial(matName);
} catch (AssetNotFoundException ex) { } catch (AssetNotFoundException ex) {
// Cannot find J3M file. // 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 // If material is NULL, try to load it from the geometry

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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.IntMap.Entry;
import com.jme3.util.clone.Cloner; import com.jme3.util.clone.Cloner;
import com.jme3.util.clone.JmeCloneable; import com.jme3.util.clone.JmeCloneable;
import java.io.IOException; import java.io.IOException;
import java.nio.*; import java.nio.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -79,50 +78,46 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* determined via the vertex shader's <code>gl_PointSize</code> output. * determined via the vertex shader's <code>gl_PointSize</code> output.
*/ */
Points(true), Points(true),
/** /**
* A primitive is a line segment. Every two vertices specify * A primitive is a line segment. Every two vertices specify
* a single line. {@link 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. * to set the width of the lines.
*/ */
Lines(true), Lines(true),
/** /**
* A primitive is a line segment. The first two vertices specify * A primitive is a line segment. The first two vertices specify
* a single line, while subsequent vertices are combined with the * 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. * be used to set the width of the lines.
*/ */
LineStrip(false), LineStrip(false),
/** /**
* Identical to {@link #LineStrip} except that at the end * Identical to {@link #LineStrip} except that at the end
* the last vertex is connected with the first to form a line. * the last vertex is connected with the first to form a line.
* {@link 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. * to set the width of the lines.
*/ */
LineLoop(false), LineLoop(false),
/** /**
* A primitive is a triangle. Each 3 vertices specify a single * A primitive is a triangle. Each 3 vertices specify a single
* triangle. * triangle.
*/ */
Triangles(true), Triangles(true),
/** /**
* Similar to {@link #Triangles}, the first 3 vertices * Similar to {@link #Triangles}, the first 3 vertices
* specify a triangle, while subsequent vertices are combined with * specify a triangle, while subsequent vertices are combined with
* the previous two to form a triangle. * the previous two to form a triangle.
*/ */
TriangleStrip(false), TriangleStrip(false),
/** /**
* Similar to {@link #Triangles}, the first 3 vertices * Similar to {@link #Triangles}, the first 3 vertices
* specify a triangle, each 2 subsequent vertices are combined * specify a triangle, each 2 subsequent vertices are combined
* with the very first vertex to make a triangle. * with the very first vertex to make a triangle.
*/ */
TriangleFan(false), TriangleFan(false),
/** /**
* A combination of various triangle modes. It is best to avoid * A combination of various triangle modes. It is best to avoid
* using this mode as it may not be supported by all renderers. * using this mode as it may not be supported by all renderers.
@ -315,7 +310,6 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
*/ */
@Override @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. // Probably could clone this now but it will get regenerated anyway.
this.collisionTree = null; this.collisionTree = null;
@ -445,29 +439,34 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
VertexBuffer indices = getBuffer(Type.BoneIndex); VertexBuffer indices = getBuffer(Type.BoneIndex);
if (indices.getFormat() == Format.UnsignedByte) { if (indices.getFormat() == Format.UnsignedByte) {
ByteBuffer originalIndex = (ByteBuffer) indices.getData(); ByteBuffer originalIndex = (ByteBuffer) indices.getData();
ByteBuffer directIndex = BufferUtils.createByteBuffer(originalIndex.capacity()); ByteBuffer directIndex
= BufferUtils.createByteBuffer(originalIndex.capacity());
originalIndex.clear(); originalIndex.clear();
directIndex.put(originalIndex); directIndex.put(originalIndex);
result = directIndex; result = directIndex;
} else { } else {
//bone indices can be stored in an UnsignedShort buffer //bone indices can be stored in an UnsignedShort buffer
ShortBuffer originalIndex = (ShortBuffer) indices.getData(); ShortBuffer originalIndex = (ShortBuffer) indices.getData();
ShortBuffer directIndex = BufferUtils.createShortBuffer(originalIndex.capacity()); ShortBuffer directIndex
= BufferUtils.createShortBuffer(originalIndex.capacity());
originalIndex.clear(); originalIndex.clear();
directIndex.put(originalIndex); directIndex.put(originalIndex);
result = directIndex; 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); VertexBuffer weightsHW = getBuffer(Type.HWBoneWeight);
if (weightsHW.getData() == null) { if (weightsHW.getData() == null) {
VertexBuffer weights = getBuffer(Type.BoneWeight); VertexBuffer weights = getBuffer(Type.BoneWeight);
FloatBuffer originalWeight = (FloatBuffer) weights.getData(); FloatBuffer originalWeight = (FloatBuffer) weights.getData();
FloatBuffer directWeight = BufferUtils.createFloatBuffer(originalWeight.capacity()); FloatBuffer directWeight
= BufferUtils.createFloatBuffer(originalWeight.capacity());
originalWeight.clear(); originalWeight.clear();
directWeight.put(originalWeight); directWeight.put(originalWeight);
weightsHW.setupData(Usage.Static, weights.getNumComponents(), weights.getFormat(), directWeight); weightsHW.setupData(Usage.Static, weights.getNumComponents(),
weights.getFormat(), directWeight);
} }
// position, normal, and tanget buffers to be in "Static" mode // position, normal, and tanget buffers to be in "Static" mode
@ -636,7 +635,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* Returns the line width for line meshes. * Returns the line width for line meshes.
* *
* @return the line width * @return the line width
* @deprecated use {@link Material#getAdditionalRenderState()} and {@link RenderState#getLineWidth()} * @deprecated use {@link Material#getAdditionalRenderState()}
* and {@link RenderState#getLineWidth()}
*/ */
@Deprecated @Deprecated
public float getLineWidth() { public float getLineWidth() {
@ -649,7 +649,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* the default value is 1.0. * the default value is 1.0.
* *
* @param lineWidth The line width * @param lineWidth The line width
* @deprecated use {@link Material#getAdditionalRenderState()} and {@link RenderState#setLineWidth(float)} * @deprecated use {@link Material#getAdditionalRenderState()}
* and {@link RenderState#setLineWidth(float)}
*/ */
@Deprecated @Deprecated
public void setLineWidth(float lineWidth) { public void setLineWidth(float lineWidth) {
@ -1311,8 +1312,10 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
if (oldVb.getData() != null) { if (oldVb.getData() != null) {
// Create a new vertex buffer with similar configuration, but // Create a new vertex buffer with similar configuration, but
// with the capacity of number of unique vertices // with the capacity of number of unique vertices
Buffer buffer = VertexBuffer.createBuffer(oldVb.getFormat(), oldVb.getNumComponents(), newNumVerts); Buffer buffer = VertexBuffer.createBuffer(oldVb.getFormat(),
newVb.setupData(oldVb.getUsage(), oldVb.getNumComponents(), oldVb.getFormat(), buffer); oldVb.getNumComponents(), newNumVerts);
newVb.setupData(oldVb.getUsage(), oldVb.getNumComponents(),
oldVb.getFormat(), buffer);
// Copy the vertex data from the old buffer into the new buffer // Copy the vertex data from the old buffer into the new buffer
for (int i = 0; i < newNumVerts; i++) { 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 * Scales the texture coordinate buffer on this mesh by the given scale
* scale factor. * factor.
* <p> * <p>
* Note that values above 1 will cause the * Note that values above 1 will cause the
* texture to tile, while values below 1 will cause the texture * texture to tile, while values below 1 will cause the texture
@ -1449,8 +1452,8 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* @return true if the mesh uses bone animation, false otherwise * @return true if the mesh uses bone animation, false otherwise
*/ */
public boolean isAnimated() { public boolean isAnimated() {
return getBuffer(Type.BoneIndex) != null || return getBuffer(Type.BoneIndex) != null
getBuffer(Type.HWBoneIndex) != null; || getBuffer(Type.HWBoneIndex) != null;
} }
/** /**
@ -1504,6 +1507,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
/** /**
* Sets the count of vertices used for each tessellation patch * Sets the count of vertices used for each tessellation patch
*
* @param patchVertexCount * @param patchVertexCount
*/ */
public void setPatchVertexCount(int 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; * Gets the amount of vertices used for each patch;
*
* @return the count (&ge;0) * @return the count (&ge;0)
*/ */
public int getPatchVertexCount() { public int getPatchVertexCount() {
return patchVertexCount; return patchVertexCount;
} }
public void addMorphTarget(MorphTarget target) { public void addMorphTarget(MorphTarget target) {
if (morphTargets == null) { if (morphTargets == null) {
morphTargets = new SafeArrayList<>(MorphTarget.class); morphTargets = new SafeArrayList<>(MorphTarget.class);
@ -1540,7 +1544,6 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
* @return an array * @return an array
*/ */
public String[] getMorphTargetNames() { public String[] getMorphTargetNames() {
MorphTarget[] nbMorphTargets = getMorphTargets(); MorphTarget[] nbMorphTargets = getMorphTargets();
if (nbMorphTargets.length == 0) { if (nbMorphTargets.length == 0) {
return new String[0]; return new String[0];
@ -1559,6 +1562,7 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
/** /**
* Get the index of the morph that has the given name. * Get the index of the morph that has the given name.
*
* @param morphName The name of the morph to search for * @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.
*/ */
@ -1662,5 +1666,4 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
morphTargets = new SafeArrayList(MorphTarget.class, l); morphTargets = new SafeArrayList(MorphTarget.class, l);
} }
} }
} }

@ -47,7 +47,6 @@ import java.util.Queue;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* <code>Node</code> defines an internal node of a scene graph. The internal * <code>Node</code> defines an internal node of a scene graph. The internal
* node maintains a collection of children and handles merging said children * node maintains a collection of children and handles merging said children
@ -59,14 +58,11 @@ import java.util.logging.Logger;
* @author Joshua Slack * @author Joshua Slack
*/ */
public class Node extends Spatial { public class Node extends Spatial {
private static final Logger logger = Logger.getLogger(Node.class.getName()); private static final Logger logger = Logger.getLogger(Node.class.getName());
/** /**
* This node's children. * This node's children.
*/ */
protected SafeArrayList<Spatial> children = new SafeArrayList<Spatial>(Spatial.class); protected SafeArrayList<Spatial> children = new SafeArrayList<Spatial>(Spatial.class);
/** /**
* If this node is a root, this list will contain the current * If this node is a root, this list will contain the current
* set of children (and children of children) that require * 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 * <code>getQuantity</code> returns the number of children this node
* maintains. * maintains.
* *
@ -119,8 +114,9 @@ public class Node extends Spatial {
protected void setTransformRefresh() { protected void setTransformRefresh() {
super.setTransformRefresh(); super.setTransformRefresh();
for (Spatial child : children.getArray()) { for (Spatial child : children.getArray()) {
if ((child.refreshFlags & RF_TRANSFORM) != 0) if ((child.refreshFlags & RF_TRANSFORM) != 0) {
continue; continue;
}
child.setTransformRefresh(); child.setTransformRefresh();
} }
@ -130,8 +126,9 @@ public class Node extends Spatial {
protected void setLightListRefresh() { protected void setLightListRefresh() {
super.setLightListRefresh(); super.setLightListRefresh();
for (Spatial child : children.getArray()) { for (Spatial child : children.getArray()) {
if ((child.refreshFlags & RF_LIGHTLIST) != 0) if ((child.refreshFlags & RF_LIGHTLIST) != 0) {
continue; continue;
}
child.setLightListRefresh(); child.setLightListRefresh();
} }
@ -297,6 +294,7 @@ public class Node extends Spatial {
return count; return count;
} }
/** /**
* <code>getVertexCount</code> returns the number of vertices contained * <code>getVertexCount</code> returns the number of vertices contained
* in all sub-branches of this node that contain geometry. * in all sub-branches of this node that contain geometry.
@ -330,8 +328,8 @@ public class Node extends Spatial {
public int attachChild(Spatial child) { public int attachChild(Spatial child) {
return attachChildAt(child, children.size()); return attachChildAt(child, children.size());
} }
/** /**
*
* <code>attachChildAt</code> attaches a child to this node at an index. This node * <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 * becomes the child's parent. The current number of children maintained is
* returned. * returned.
@ -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. * @return the index the child was at. -1 if the child was not in the list.
*/ */
public int detachChild(Spatial child) { public int detachChild(Spatial child) {
if (child == null) if (child == null) {
throw new NullPointerException(); throw new NullPointerException();
}
if (child.getParent() == this) { if (child.getParent() == this) {
int index = children.indexOf(child); int index = children.indexOf(child);
@ -404,8 +403,9 @@ public class Node extends Spatial {
* @return the index the child was at. -1 if the child was not in the list. * @return the index the child was at. -1 if the child was not in the list.
*/ */
public int detachChildNamed(String childName) { public int detachChildNamed(String childName) {
if (childName == null) if (childName == null) {
throw new NullPointerException(); throw new NullPointerException();
}
for (int x = 0, max = children.size(); x < max; x++) { for (int x = 0, max = children.size(); x < max; x++) {
Spatial child = children.get(x); Spatial child = children.get(x);
@ -418,7 +418,6 @@ public class Node extends Spatial {
} }
/** /**
*
* <code>detachChildAt</code> removes a child at a given index. That child * <code>detachChildAt</code> removes a child at a given index. That child
* is returned for saving purposes. * is returned for saving purposes.
* *
@ -450,7 +449,6 @@ public class Node extends Spatial {
} }
/** /**
*
* <code>detachAllChildren</code> removes all children attached to this * <code>detachAllChildren</code> removes all children attached to this
* node. * node.
*/ */
@ -469,8 +467,7 @@ public class Node extends Spatial {
* in this node's list of children. * in this node's list of children.
* @param sp * @param sp
* The spatial to look up * The spatial to look up
* @return * @return The index of the spatial in the node's children, or -1
* The index of the spatial in the node's children, or -1
* if the spatial is not attached to this node * if the spatial is not attached to this node
*/ */
public int getChildIndex(Spatial sp) { public int getChildIndex(Spatial sp) {
@ -492,11 +489,9 @@ public class Node extends Spatial {
} }
/** /**
*
* <code>getChild</code> returns a child at a given index. * <code>getChild</code> returns a child at a given index.
* *
* @param i * @param i the index to retrieve the child from.
* the index to retrieve the child from.
* @return the child at a specified index. * @return the child at a specified index.
*/ */
public Spatial getChild(int i) { public Spatial getChild(int i) {
@ -514,8 +509,9 @@ public class Node extends Spatial {
* @return the child if found, or null. * @return the child if found, or null.
*/ */
public Spatial getChild(String name) { public Spatial getChild(String name) {
if (name == null) if (name == null) {
return null; return null;
}
for (Spatial child : children.getArray()) { for (Spatial child : children.getArray()) {
if (name.equals(child.getName())) { if (name.equals(child.getName())) {
@ -529,6 +525,7 @@ public class Node extends Spatial {
} }
return null; return null;
} }
/** /**
* determines if the provided Spatial is contained in the children list of * determines if the provided Spatial is contained in the children list of
* this node. * this node.
@ -538,13 +535,15 @@ public class Node extends Spatial {
* @return true if the object is contained, false otherwise. * @return true if the object is contained, false otherwise.
*/ */
public boolean hasChild(Spatial spat) { public boolean hasChild(Spatial spat) {
if (children.contains(spat)) if (children.contains(spat)) {
return true; return true;
}
for (Spatial child : children.getArray()) { for (Spatial child : children.getArray()) {
if (child instanceof Node && ((Node) child).hasChild(spat)) if (child instanceof Node && ((Node) child).hasChild(spat)) {
return true; return true;
} }
}
return false; return false;
} }
@ -578,8 +577,10 @@ public class Node extends Spatial {
public int collideWith(Collidable other, CollisionResults results) { public int collideWith(Collidable other, CollisionResults results) {
int total = 0; int total = 0;
// optimization: try collideWith BoundingVolume to avoid possibly redundant tests on children // 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. // number 4 in condition is somewhat arbitrary.
// The idea is when there are few children, it can be too expensive to test boundingVolume first. // 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 I'm removing this change until some issues can be addressed and I really
think it needs to be implemented a better way anyway. think it needs to be implemented a better way anyway.
@ -643,7 +644,8 @@ public class Node extends Spatial {
* Null causes all Spatials to qualify. * Null causes all Spatials to qualify.
* @param nameRegex Regular expression to match Spatial name against. * @param nameRegex Regular expression to match Spatial name against.
* Null causes all Names to qualify. * 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 java.util.regex.Pattern
* @see Spatial#matches(java.lang.Class, java.lang.String) * @see Spatial#matches(java.lang.Class, java.lang.String)
@ -652,14 +654,18 @@ public class Node extends Spatial {
public <T extends Spatial> List<T> descendantMatches( public <T extends Spatial> List<T> descendantMatches(
Class<T> spatialSubclass, String nameRegex) { Class<T> spatialSubclass, String nameRegex) {
List<T> newList = new ArrayList<T>(); List<T> newList = new ArrayList<T>();
if (getQuantity() < 1) return newList; if (getQuantity() < 1) {
return newList;
}
for (Spatial child : getChildren()) { for (Spatial child : getChildren()) {
if (child.matches(spatialSubclass, nameRegex)) if (child.matches(spatialSubclass, nameRegex)) {
newList.add((T) child); newList.add((T) child);
if (child instanceof Node) }
if (child instanceof Node) {
newList.addAll(((Node) child).descendantMatches( newList.addAll(((Node) child).descendantMatches(
spatialSubclass, nameRegex)); spatialSubclass, nameRegex));
} }
}
return newList; return newList;
} }
@ -734,6 +740,7 @@ public class Node extends Spatial {
// cloning this list is fine. // cloning this list is fine.
this.updateList = cloner.clone(updateList); this.updateList = cloner.clone(updateList);
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void write(JmeExporter e) throws IOException { public void write(JmeExporter e) throws IOException {

@ -68,8 +68,8 @@ import java.util.logging.Logger;
* @author Joshua Slack * @author Joshua Slack
* @version $Revision: 4075 $, $Data$ * @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()); 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. * this spatial.
*/ */
public enum CullHint { public enum CullHint {
/** /**
* Do whatever our parent does. If no parent, default to {@link #Dynamic}. * 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 * Specifies if this spatial should be batched
*/ */
public enum BatchHint { public enum BatchHint {
/** /**
* Do whatever our parent does. If no parent, default to {@link #Always}. * Do whatever our parent does. If no parent, default to {@link #Always}.
*/ */
@ -121,7 +119,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
/** /**
* Refresh flag types * Refresh flag types
*/ */
protected static final int RF_TRANSFORM = 0x01, // need light resort + combine transforms protected static final int
RF_TRANSFORM = 0x01, // need light resort + combine transforms
RF_BOUND = 0x02, RF_BOUND = 0x02,
RF_LIGHTLIST = 0x04, // changes in light lists RF_LIGHTLIST = 0x04, // changes in light lists
RF_CHILD_LIGHTLIST = 0x08, // some child need geometry update RF_CHILD_LIGHTLIST = 0x08, // some child need geometry update
@ -147,7 +146,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
*/ */
protected String name; protected String name;
// scale values // 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 RenderQueue.Bucket queueBucket = RenderQueue.Bucket.Inherit;
protected ShadowMode shadowMode = RenderQueue.ShadowMode.Inherit; protected ShadowMode shadowMode = RenderQueue.ShadowMode.Inherit;
public transient float queueDistance = Float.NEGATIVE_INFINITY; public transient float queueDistance = Float.NEGATIVE_INFINITY;
@ -232,6 +232,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
boolean requiresUpdates() { boolean requiresUpdates() {
return requiresUpdates | !controls.isEmpty(); return requiresUpdates | !controls.isEmpty();
} }
/** /**
* Subclasses can call this with true to denote that they require * Subclasses can call this with true to denote that they require
* updateLogicalState() to be called even if they contain no controls. * updateLogicalState() to be called even if they contain no controls.
@ -325,6 +326,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
p = p.parent; p = p.parent;
} }
} }
/** /**
* (Internal use only) Forces a refresh of the given types of data. * (Internal use only) Forces a refresh of the given types of data.
* *
@ -762,6 +764,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
/** /**
* Add a control to the list of controls. * Add a control to the list of controls.
*
* @param control The control to add. * @param control The control to add.
* *
* @see Spatial#removeControl(java.lang.Class) * @see Spatial#removeControl(java.lang.Class)
@ -1229,6 +1232,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
/** /**
* Centers the spatial in the origin of the world bound. * Centers the spatial in the origin of the world bound.
*
* @return The spatial on which this method is called, e.g <code>this</code>. * @return The spatial on which this method is called, e.g <code>this</code>.
*/ */
public Spatial center() { public Spatial center() {
@ -1342,7 +1346,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
* @see Mesh#cloneForAnim() * @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. // Setup the cloner for the type of cloning we want to do.
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
@ -1438,7 +1441,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
@Override @Override
@SuppressWarnings("unchecked") @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 // Clone all of the fields that need fix-ups and/or potential
// sharing. // sharing.
this.parent = cloner.clone(parent); this.parent = cloner.clone(parent);
@ -1588,9 +1590,11 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
} }
worldOverrides = new SafeArrayList<>(MatParamOverride.class); 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 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 : //When backward compatibility won't be needed anymore this can be replaced by :
//controls = ic.readSavableArrayList("controlsList", null)); //controls = ic.readSavableArrayList("controlsList", null));
controls.addAll(0, ic.readSavableArrayList("controlsList", null)); controls.addAll(0, ic.readSavableArrayList("controlsList", null));
@ -1759,6 +1763,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
/** /**
* Visit each scene graph element ordered by DFS with the default post order mode. * Visit each scene graph element ordered by DFS with the default post order mode.
*
* @param visitor * @param visitor
* @see #depthFirstTraversal(com.jme3.scene.SceneGraphVisitor, com.jme3.scene.Spatial.DFSMode) * @see #depthFirstTraversal(com.jme3.scene.SceneGraphVisitor, com.jme3.scene.Spatial.DFSMode)
*/ */
@ -1783,6 +1788,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
/** /**
* Visit each scene graph element ordered by DFS. * Visit each scene graph element ordered by DFS.
* There are two modes: pre order and post order. * There are two modes: pre order and post order.
*
* @param visitor * @param visitor
* @param mode the traversal mode: pre order or post order * @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 * Visit each scene graph element ordered by BFS
*
* @param visitor * @param visitor
*/ */
public void breadthFirstTraversal(SceneGraphVisitor visitor) { public void breadthFirstTraversal(SceneGraphVisitor visitor) {

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -54,7 +54,6 @@ import java.nio.*;
* </ul> * </ul>
*/ */
public class VertexBuffer extends NativeObject implements Savable, Cloneable { public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/** /**
* Type of buffer. Specifies the actual attribute it defines. * Type of buffer. Specifies the actual attribute it defines.
*/ */
@ -63,27 +62,22 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* Position of the vertex (3 floats) * Position of the vertex (3 floats)
*/ */
Position, Position,
/** /**
* The size of the point when using point buffers (float). * The size of the point when using point buffers (float).
*/ */
Size, Size,
/** /**
* Normal vector, normalized (3 floats). * Normal vector, normalized (3 floats).
*/ */
Normal, Normal,
/** /**
* Texture coordinate (2 float) * Texture coordinate (2 float)
*/ */
TexCoord, TexCoord,
/** /**
* Color and Alpha (4 floats) * Color and Alpha (4 floats)
*/ */
Color, Color,
/** /**
* Tangent vector, normalized (4 floats) (x,y,z,w). The w component is * Tangent vector, normalized (4 floats) (x,y,z,w). The w component is
* called the binormal parity, is not normalized, and is either 1f or * called the binormal parity, is not normalized, and is either 1f or
@ -91,19 +85,16 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* GPU at render time. * GPU at render time.
*/ */
Tangent, Tangent,
/** /**
* Binormal vector, normalized (3 floats, optional) * Binormal vector, normalized (3 floats, optional)
*/ */
Binormal, Binormal,
/** /**
* Specifies the source data for various vertex buffers * Specifies the source data for various vertex buffers
* when interleaving is used. By default the format is * when interleaving is used. By default the format is
* byte. * byte.
*/ */
InterleavedData, InterleavedData,
/** /**
* Do not use. * Do not use.
*/ */
@ -114,7 +105,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* (ubyte, ushort, or uint). * (ubyte, ushort, or uint).
*/ */
Index, Index,
/** /**
* Initial vertex position, used with animation. * Initial vertex position, used with animation.
* Should have the same format and size as {@link Type#Position}. * Should have the same format and size as {@link Type#Position}.
@ -123,7 +113,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* on the heap. * on the heap.
*/ */
BindPosePosition, BindPosePosition,
/** /**
* Initial vertex normals, used with animation. * Initial vertex normals, used with animation.
* Should have the same format and size as {@link Type#Normal}. * Should have the same format and size as {@link Type#Normal}.
@ -132,7 +121,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* on the heap. * on the heap.
*/ */
BindPoseNormal, BindPoseNormal,
/** /**
* Bone weights, used with animation (4 floats). * Bone weights, used with animation (4 floats).
* Only used for software skinning, the usage should be * Only used for software skinning, the usage should be
@ -140,7 +128,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* on the heap. * on the heap.
*/ */
BoneWeight, BoneWeight,
/** /**
* Bone indices, used with animation (4 ubytes). * Bone indices, used with animation (4 ubytes).
* Only used for software skinning, the usage should be * Only used for software skinning, the usage should be
@ -148,42 +135,34 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* on the heap as a ubytes buffer. * on the heap as a ubytes buffer.
*/ */
BoneIndex, BoneIndex,
/** /**
* Texture coordinate #2 * Texture coordinate #2
*/ */
TexCoord2, TexCoord2,
/** /**
* Texture coordinate #3 * Texture coordinate #3
*/ */
TexCoord3, TexCoord3,
/** /**
* Texture coordinate #4 * Texture coordinate #4
*/ */
TexCoord4, TexCoord4,
/** /**
* Texture coordinate #5 * Texture coordinate #5
*/ */
TexCoord5, TexCoord5,
/** /**
* Texture coordinate #6 * Texture coordinate #6
*/ */
TexCoord6, TexCoord6,
/** /**
* Texture coordinate #7 * Texture coordinate #7
*/ */
TexCoord7, TexCoord7,
/** /**
* Texture coordinate #8 * Texture coordinate #8
*/ */
TexCoord8, TexCoord8,
/** /**
* Initial vertex tangents, used with animation. * Initial vertex tangents, used with animation.
* Should have the same format and size as {@link Type#Tangent}. * Should have the same format and size as {@link Type#Tangent}.
@ -192,20 +171,17 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* on the heap. * on the heap.
*/ */
BindPoseTangent, BindPoseTangent,
/** /**
* Bone weights, used with animation (4 floats). * Bone weights, used with animation (4 floats).
* for Hardware Skinning only * for Hardware Skinning only
*/ */
HWBoneWeight, HWBoneWeight,
/** /**
* Bone indices, used with animation (4 ubytes). * Bone indices, used with animation (4 ubytes).
* for Hardware Skinning only * for Hardware Skinning only
* either an int or float buffer due to shader attribute types restrictions. * either an int or float buffer due to shader attribute types restrictions.
*/ */
HWBoneIndex, HWBoneIndex,
/** /**
* Information about this instance. * Information about this instance.
* *
@ -213,7 +189,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* should be 16. * should be 16.
*/ */
InstanceData, InstanceData,
/** /**
* Morph animations targets. * Morph animations targets.
* Supports up tp 14 morph target buffers at the same time * Supports up tp 14 morph target buffers at the same time
@ -225,11 +200,15 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* 7 simultaneous POSITION and NORMAL targets * 7 simultaneous POSITION and NORMAL targets
* 4 simultaneous POSTION, NORMAL and TANGENT targets. * 4 simultaneous POSTION, NORMAL and TANGENT targets.
* <p> * <p>
* Note that the MorphControl will find how many buffers can be supported for each mesh/material combination. * Note that the MorphControl will find how many buffers
* Note that all buffers have 3 components (Vector3f) even the Tangent buffer that * can be supported for each mesh/material combination.
* does not contain the w (handedness) component that will not be interpolated for morph animation. * 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.
* <p> * <p>
* 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 * So that you can interpolate with a MADD operation in the vertex shader
* position = weight * diffPosition + basePosition; * position = weight * diffPosition + basePosition;
*/ */
@ -247,7 +226,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
MorphTarget11, MorphTarget11,
MorphTarget12, MorphTarget12,
MorphTarget13, 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. * or held in video memory, but no guarantees are made- it's only a hint.
*/ */
public static enum Usage { public static enum Usage {
/** /**
* Mesh data is sent once and very rarely updated. * Mesh data is sent once and very rarely updated.
*/ */
Static, Static,
/** /**
* Mesh data is updated occasionally (once per frame or less). * Mesh data is updated occasionally (once per frame or less).
*/ */
Dynamic, Dynamic,
/** /**
* Mesh data is updated every frame. * Mesh data is updated every frame.
*/ */
Stream, Stream,
/** /**
* Mesh data is <em>not</em> sent to GPU at all. It is only * Mesh data is <em>not</em> sent to GPU at all. It is only
* used by the CPU. * used by the CPU.
@ -289,49 +263,38 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
*/ */
public static enum Format { public static enum Format {
/** /**
* Half precision floating point. * Half precision floating point. 2 bytes, signed.
* 2 bytes, signed.
*/ */
Half(2), Half(2),
/** /**
* Single precision floating point. * Single precision floating point. 4 bytes, signed
* 4 bytes, signed
*/ */
Float(4), Float(4),
/** /**
* Double precision floating point. * Double precision floating point. 8 bytes, signed. May not be
* 8 bytes, signed. May not * supported by all GPUs.
* be supported by all GPUs.
*/ */
Double(8), Double(8),
/** /**
* 1 byte integer, signed. * 1 byte integer, signed.
*/ */
Byte(1), Byte(1),
/** /**
* 1 byte integer, unsigned. * 1 byte integer, unsigned.
*/ */
UnsignedByte(1), UnsignedByte(1),
/** /**
* 2 byte integer, signed. * 2 byte integer, signed.
*/ */
Short(2), Short(2),
/** /**
* 2 byte integer, unsigned. * 2 byte integer, unsigned.
*/ */
UnsignedShort(2), UnsignedShort(2),
/** /**
* 4 byte integer, signed. * 4 byte integer, signed.
*/ */
Int(4), Int(4),
/** /**
* 4 byte integer, unsigned. * 4 byte integer, unsigned.
*/ */
@ -507,7 +470,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* 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() { public Buffer getDataReadOnly() {
if (data == null) { if (data == null) {
return null; return null;
} }
@ -515,7 +477,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
// Create a read-only duplicate(). Note: this does not copy // Create a read-only duplicate(). Note: this does not copy
// the underlying memory, it just creates a new read-only wrapper // the underlying memory, it just creates a new read-only wrapper
// with its own buffer position state. // with its own buffer position state.
// Unfortunately, this is not 100% straight forward since Buffer // Unfortunately, this is not 100% straight forward since Buffer
// does not have an asReadOnlyBuffer() method. // does not have an asReadOnlyBuffer() method.
Buffer result; Buffer result;
@ -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 * 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 * 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 * 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 * set the proper update flag indicating the data should be sent to the GPU
@ -743,6 +705,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/** /**
* Returns true if the data size of the VertexBuffer has changed. * Returns true if the data size of the VertexBuffer has changed.
* Internal use only. * Internal use only.
*
* @return true if the data size has changed * @return true if the data size has changed
*/ */
public boolean hasDataSizeChanged() { public boolean hasDataSizeChanged() {
@ -1145,7 +1108,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
@Override @Override
public void write(JmeExporter ex) throws IOException { public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = ex.getCapsule(this); OutputCapsule oc = ex.getCapsule(this);
oc.write(components, "components", 0); oc.write(components, "components", 0);
oc.write(usage, "usage", Usage.Dynamic); oc.write(usage, "usage", Usage.Dynamic);
@ -1215,5 +1177,4 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
throw new IOException("Unsupported import buffer format: " + format); throw new IOException("Unsupported import buffer format: " + format);
} }
} }
} }

Loading…
Cancel
Save