Skip to content

Commit

Permalink
Mesh: add 5 new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Aug 7, 2023
1 parent 81dea79 commit fd5dc65
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions lib/src/main/java/com/github/stephengold/vsport/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ public int countVertices() {
return vertexCount;
}

/**
* Remove the normals from the mesh.
*/
public void dropNormals() {
this.normalBuffer = null;
this.normalFloats = null;
}

/**
* Generate an attribute-description buffer.
*
Expand Down Expand Up @@ -489,6 +497,99 @@ protected FloatBuffer createUvs() {

return texCoordsFloats;
}

/**
* Assign new vertex indices.
*
* @param indexArray the vertex indices to use (not null, unaffected)
*/
protected void setIndices(int... indexArray) {
this.indexBuffer = IndexBuffer.newInstance(indexArray);
}

/**
* Assign new normals to the vertices.
*
* @param normalArray the desired vertex normals (not null,
* length=3*vertexCount, unaffected)
*/
protected void setNormals(float... normalArray) {
int numFloats = normalArray.length;
Validate.require(numFloats == vertexCount * numAxes, "correct length");

int numBytes = numFloats * Float.BYTES;
int usage = VK10.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
boolean staging = false;
this.normalBuffer = new BufferResource(numBytes, usage, staging) {
@Override
protected void fill(ByteBuffer destinationBuffer) {
for (int floatI = 0; floatI < numFloats; ++floatI) {
float fValue = normalArray[floatI];
destinationBuffer.putFloat(fValue);
}
}
};

ByteBuffer byteBuffer = normalBuffer.getData();
byteBuffer.flip();
this.normalFloats = byteBuffer.asFloatBuffer();
}

/**
* Assign new positions to the vertices.
*
* @param positionArray the desired vertex positions (not null,
* length=3*vertexCount, unaffected)
*/
protected void setPositions(float... positionArray) {
int numFloats = positionArray.length;
Validate.require(numFloats == vertexCount * numAxes, "correct length");

int numBytes = numFloats * Float.BYTES;
int usage = VK10.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
boolean staging = false;
this.positionBuffer = new BufferResource(numBytes, usage, staging) {
@Override
protected void fill(ByteBuffer destinationBuffer) {
for (int floatI = 0; floatI < numFloats; ++floatI) {
float fValue = positionArray[floatI];
destinationBuffer.putFloat(fValue);
}
}
};

ByteBuffer byteBuffer = positionBuffer.getData();
byteBuffer.flip();
this.positionFloats = byteBuffer.asFloatBuffer();
}

/**
* Assign new texture coordinates to the vertices.
*
* @param uvArray the desired vertex texture coordinates (not null,
* length=2*vertexCount, unaffected)
*/
protected void setUvs(float... uvArray) {
int numFloats = uvArray.length;
Validate.require(numFloats == 2 * vertexCount, "correct length");

int numBytes = numFloats * Float.BYTES;
int usage = VK10.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
boolean staging = false;
this.texCoordsBuffer = new BufferResource(numBytes, usage, staging) {
@Override
protected void fill(ByteBuffer destinationBuffer) {
for (int floatI = 0; floatI < numFloats; ++floatI) {
float fValue = uvArray[floatI];
destinationBuffer.putFloat(fValue);
}
}
};

ByteBuffer byteBuffer = texCoordsBuffer.getData();
byteBuffer.flip();
this.texCoordsFloats = byteBuffer.asFloatBuffer();
}
// *************************************************************************
// jme3utilities.lbj.Mesh methods

Expand Down

0 comments on commit fd5dc65

Please sign in to comment.