diff options
-rw-r--r-- | ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java index c195339..2b3785b 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java +++ b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java @@ -892,6 +892,50 @@ public class MeshData implements Savable { } return result; } + + /** + * Gets the normals of the primitive. + * + * @param primitiveIndex + * the primitive index + * @param section + * the section + * @param store + * the store + * + * @return the normals of the primitive + */ + public Vector3[] getPrimitiveNormals(final int primitiveIndex, final int section, final Vector3[] store) { + final Vector3[] result; + if (getNormalBuffer() == null) { + result = null; + } else { + final int count = getPrimitiveCount(section); + if (primitiveIndex >= count || primitiveIndex < 0) { + throw new IndexOutOfBoundsException("Invalid primitiveIndex '" + primitiveIndex + "'. Count is " + count); + } + final IndexMode mode = getIndexMode(section); + final int rSize = mode.getVertexCount(); + if (store == null || store.length < rSize) { + result = new Vector3[rSize]; + } else { + result = store; + } + for (int i = 0; i < rSize; i++) { + if (result[i] == null) { + result[i] = new Vector3(); + } + if (getIndexBuffer() != null) {// indexed geometry + BufferUtils.populateFromBuffer(result[i], getNormalBuffer(), + getIndices().get(getVertexIndex(primitiveIndex, i, section))); + } else {// non-indexed geometry + BufferUtils.populateFromBuffer(result[i], getNormalBuffer(), + getVertexIndex(primitiveIndex, i, section)); + } + } + } + return result; + } /** * Gets the vertex index. |