aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-core
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2021-03-04 00:45:53 +0100
committerJulien Gouesse <[email protected]>2021-03-04 00:45:53 +0100
commit6eb68ea594195f5032222ac151570aa63bdedf1f (patch)
tree72ab04cb8eebd4fda19b0734f7ec96575b457f72 /ardor3d-core
parentf810c7d58099db8e5c75bc9b1035ae393d84abbd (diff)
Adds a method to retrieve the normals of a primitive
Diffstat (limited to 'ardor3d-core')
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java44
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.