Skip to content

Commit

Permalink
IndexedMesh: trivial refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 25, 2025
1 parent 2580ea3 commit 159b8aa
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2024 jMonkeyEngine
* Copyright (c) 2019-2025 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -80,10 +80,6 @@ public class IndexedMesh
// *************************************************************************
// constants and loggers

/**
* number of bytes in a float
*/
final private static int floatBytes = 4;
/**
* number of axes in a vector
*/
Expand Down Expand Up @@ -216,7 +212,7 @@ public IndexedMesh(Vector3f[] positionArray, int[] indexArray) {

this.numVertices = positionArray.length;
this.vertexPositions = BufferUtils.createFloatBuffer(positionArray);
this.vertexStride = numAxes * floatBytes;
this.vertexStride = numAxes * Float.BYTES;

this.numTriangles = numIndices / vpt;
IntBuffer buffer = BufferUtils.createIntBuffer(indexArray);
Expand Down Expand Up @@ -246,7 +242,7 @@ public IndexedMesh(FloatBuffer buffer) {
this.numVertices = dvv.countDistinct();
this.vertexPositions
= BufferUtils.createFloatBuffer(numAxes * numVertices);
this.vertexStride = numAxes * floatBytes;
this.vertexStride = numAxes * Float.BYTES;

int numIndices = numFloats / numAxes;
this.numTriangles = numIndices / vpt;
Expand Down Expand Up @@ -288,7 +284,7 @@ public IndexedMesh(FloatBuffer positionBuffer, IntBuffer indexBuffer) {

this.numVertices = numFloats / numAxes;
this.vertexPositions = positionBuffer;
this.vertexStride = numAxes * floatBytes;
this.vertexStride = numAxes * Float.BYTES;

this.numTriangles = numIndices / vpt;
this.indices = IndexBuffer.wrapIndexBuffer(indexBuffer);
Expand Down Expand Up @@ -321,7 +317,7 @@ public IndexedMesh(CollisionShape shape, int meshResolution) {
this.numVertices = countVertices(meshId);
int numFloats = numVertices * numAxes;
this.vertexPositions = BufferUtils.createFloatBuffer(numFloats);
this.vertexStride = numAxes * floatBytes;
this.vertexStride = numAxes * Float.BYTES;

this.numTriangles = countTriangles(meshId);
int numIndices = numTriangles * vpt;
Expand Down Expand Up @@ -699,7 +695,7 @@ public void read(JmeImporter importer) throws IOException {
this.numVertices = capsule.readInt(tagNumVertices, 0);

this.vertexStride = capsule.readInt(tagVertexStride, 12);
assert vertexStride == numAxes * floatBytes : vertexStride;
assert vertexStride == numAxes * Float.BYTES : vertexStride;

int[] intArray = capsule.readIntArray(tagIndexInts, new int[0]);
int numIndices = intArray.length;
Expand Down Expand Up @@ -790,7 +786,7 @@ private void create(Mesh jmeMesh, Transform transform) {
float temp = meshVs.get(offset);
vertexPositions.put(offset, temp);
}
this.vertexStride = numAxes * floatBytes;
this.vertexStride = numAxes * Float.BYTES;

if (transform != null && !MyMath.isIdentity(transform)) {
MyBuffer.transform(vertexPositions, 0, numFloats, transform);
Expand Down

0 comments on commit 159b8aa

Please sign in to comment.