|
|
|
@ -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. |
|
|
|
@ -315,7 +310,6 @@ public class Mesh implements Savable, Cloneable, JmeCloneable { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void cloneFields(Cloner cloner, Object original) { |
|
|
|
|
|
|
|
|
|
// Probably could clone this now but it will get regenerated anyway.
|
|
|
|
|
this.collisionTree = null; |
|
|
|
|
|
|
|
|
@ -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
|
|
|
|
@ -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) { |
|
|
|
@ -1311,8 +1312,10 @@ public class Mesh implements Savable, Cloneable, JmeCloneable { |
|
|
|
|
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 |
|
|
|
@ -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 (≥0) |
|
|
|
|
*/ |
|
|
|
|
public int getPatchVertexCount() { |
|
|
|
|
return patchVertexCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addMorphTarget(MorphTarget target) { |
|
|
|
|
if (morphTargets == null) { |
|
|
|
|
morphTargets = new SafeArrayList<>(MorphTarget.class); |
|
|
|
@ -1540,7 +1544,6 @@ public class Mesh implements Savable, Cloneable, JmeCloneable { |
|
|
|
|
* @return an array |
|
|
|
|
*/ |
|
|
|
|
public String[] getMorphTargetNames() { |
|
|
|
|
|
|
|
|
|
MorphTarget[] nbMorphTargets = getMorphTargets(); |
|
|
|
|
if (nbMorphTargets.length == 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. |
|
|
|
|
* |
|
|
|
|
* @param morphName The name of the morph to search for |
|
|
|
|
* @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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|