From 84a38d13635fcf82aa2da83396dbd86c7761ab6a Mon Sep 17 00:00:00 2001 From: jmekaelthas Date: Wed, 13 Jan 2016 20:02:32 +0100 Subject: [PATCH] Bugfix: fixed an error that caused bad faces triangulation in some cases. --- .../scene/plugins/blender/meshes/Face.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Face.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Face.java index 9dc851a58..34db4598d 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Face.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Face.java @@ -335,17 +335,23 @@ public class Face implements Comparator { return "Face " + indexes; } - /** - * The method finds the closest vertex to the one specified by index. - * If the vertexToIgnore is positive than it will be ignored in the result. - * The closes vertex must be able to create an edge that is fully contained within the face and does not cross - * any other edges. - * @param index - * the index of the vertex that needs to have found the nearest neighbour - * @param indexToIgnore - * the index to ignore in the result (pass -1 if none is to be ignored) - * @return the index of the closest vertex to the given one - */ + /** + * The method finds the closest vertex to the one specified by index. + * If the vertexToIgnore is positive than it will be ignored in the result. + * The closest vertex must be able to create an edge that is fully contained + * within the face and does not cross any other edges. Also if the + * vertexToIgnore is not negative then the condition that the edge between + * the found index and the one to ignore is inside the face must also be + * met. + * + * @param index + * the index of the vertex that needs to have found the nearest + * neighbour + * @param indexToIgnore + * the index to ignore in the result (pass -1 if none is to be + * ignored) + * @return the index of the closest vertex to the given one + */ private int findClosestVertex(int index, int indexToIgnore) { int result = -1; List vertices = temporalMesh.getVertices(); @@ -355,7 +361,7 @@ public class Face implements Comparator { if (i != index && i != indexToIgnore) { Vector3f v2 = vertices.get(i); float d = v2.distance(v1); - if (d < distance && this.contains(new Edge(index, i, 0, true, temporalMesh))) { + if (d < distance && this.contains(new Edge(index, i, 0, true, temporalMesh)) && (indexToIgnore < 0 || this.contains(new Edge(indexToIgnore, i, 0, true, temporalMesh)))) { result = i; distance = d; }