From 0221069740745f4357252b7bf4f652fd67f59566 Mon Sep 17 00:00:00 2001 From: stephengold Date: Tue, 7 Jan 2025 19:56:16 -0800 Subject: [PATCH] SoftBodyControl: use MyMesh.trianglesToLines() --- .../jme3/bullet/control/SoftBodyControl.java | 50 +------------------ 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/MinieLibrary/src/main/java/com/jme3/bullet/control/SoftBodyControl.java b/MinieLibrary/src/main/java/com/jme3/bullet/control/SoftBodyControl.java index 0b6832672..5815a090c 100644 --- a/MinieLibrary/src/main/java/com/jme3/bullet/control/SoftBodyControl.java +++ b/MinieLibrary/src/main/java/com/jme3/bullet/control/SoftBodyControl.java @@ -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; /** @@ -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(); @@ -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: @@ -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 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; - } }