Skip to content

Commit

Permalink
SoftBodyControl: use MyMesh.trianglesToLines()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 8, 2025
1 parent 589e86b commit 0221069
Showing 1 changed file with 2 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@
import com.jme3.util.BufferUtils;
import com.jme3.util.clone.Cloner;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import jme3utilities.MyMesh;
import jme3utilities.MySpatial;
import jme3utilities.Validate;
import jme3utilities.math.IntPair;
import jme3utilities.math.MyMath;

/**
Expand Down Expand Up @@ -406,7 +402,7 @@ private void appendFromGeometry() {
switch (useTriangles) {
case FacesAndLinks:
faces = mesh.getIndicesAsList();
links = trianglesToLines(faces, numVertices);
links = MyMesh.trianglesToLines(faces, numVertices);
break;
case FacesOnly:
faces = mesh.getIndicesAsList();
Expand All @@ -415,7 +411,7 @@ private void appendFromGeometry() {
break;
case LinksOnly:
faces = mesh.getIndicesAsList();
links = trianglesToLines(faces, numVertices);
links = MyMesh.trianglesToLines(faces, numVertices);
faces = null;
break;
default:
Expand Down Expand Up @@ -462,46 +458,4 @@ private void appendFromGeometry() {
}
body.applyTransform(meshToPhysics);
}

/**
* Convert IndexBuffer triangles to lines. TODO move to the MyMesh class
*
* @param indexList the IndexBuffer to convert (not null, size a multiple of
* 3, unaffected)
* @param numVertices the number of vertices in the mesh (>0)
* @return a new buffer
*/
private static IndexBuffer trianglesToLines(
IndexBuffer indexList, int numVertices) {
Validate.nonNull(indexList, "index list");
Validate.require(
(indexList.size() % MyMesh.vpt) == 0, "size a multiple of 3");
Validate.positive(numVertices, "number of vertices");

int numTriangles = indexList.size() / MyMesh.vpt;
Set<IntPair> edgeSet = new HashSet<>(MyMesh.vpt * numTriangles);
for (int triIndex = 0; triIndex < numTriangles; ++triIndex) {
int intOffset = MyMesh.vpt * triIndex;
int ti0 = indexList.get(intOffset);
int ti1 = indexList.get(intOffset + 1);
int ti2 = indexList.get(intOffset + 2);

edgeSet.add(new IntPair(ti0, ti1));
edgeSet.add(new IntPair(ti0, ti2));
edgeSet.add(new IntPair(ti1, ti2));
}
int numEdges = edgeSet.size();
int numIndices = MyMesh.vpe * numEdges;

IndexBuffer result
= IndexBuffer.createIndexBuffer(numVertices, numIndices);
for (IntPair edge : edgeSet) {
result.put(edge.smaller());
result.put(edge.larger());
}
Buffer ibData = result.getBuffer();
ibData.flip();

return result;
}
}

0 comments on commit 0221069

Please sign in to comment.