Bugfix: fixed a bug that caused subdivision surface modifier to crash if
at least one not connected vertex was in the mesh.
This commit is contained in:
parent
14349695a9
commit
f1a0125dc2
@ -2,6 +2,7 @@ package com.jme3.scene.plugins.blender.modifiers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -129,6 +130,8 @@ public class SubdivisionSurfaceModifier extends Modifier {
|
||||
for (int i = 0; i < temporalMesh.getVertexCount(); ++i) {
|
||||
// finding adjacent edges that were created by dividing original edges
|
||||
List<Edge> adjacentOriginalEdges = new ArrayList<Edge>();
|
||||
Collection<Edge> adjacentEdges = temporalMesh.getAdjacentEdges(i);
|
||||
if(adjacentEdges != null) {// this can be null if a vertex with index 'i' is not connected to any face nor edge
|
||||
for (Edge edge : temporalMesh.getAdjacentEdges(i)) {
|
||||
if (verticesOnOriginalEdges.contains(edge.getFirstIndex()) || verticesOnOriginalEdges.contains(edge.getSecondIndex())) {
|
||||
adjacentOriginalEdges.add(edge);
|
||||
@ -136,6 +139,9 @@ public class SubdivisionSurfaceModifier extends Modifier {
|
||||
}
|
||||
|
||||
creasePoints.add(new CreasePoint(i, boundaryVertices.contains(i), adjacentOriginalEdges, temporalMesh));
|
||||
} else {
|
||||
creasePoints.add(null);//the count of crease points must be equal to vertex count; otherwise we'll get IndexOutofBoundsException later
|
||||
}
|
||||
}
|
||||
|
||||
Vector3f[] averageVert = new Vector3f[temporalMesh.getVertexCount()];
|
||||
@ -174,6 +180,7 @@ public class SubdivisionSurfaceModifier extends Modifier {
|
||||
}
|
||||
|
||||
for (int i = 0; i < averageVert.length; ++i) {
|
||||
if(averageVert[i] != null && averageCount[i] > 0) {
|
||||
Vector3f v = temporalMesh.getVertices().get(i);
|
||||
averageVert[i].divideLocal(averageCount[i]);
|
||||
|
||||
@ -194,6 +201,7 @@ public class SubdivisionSurfaceModifier extends Modifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method performs a simple subdivision of the mesh.
|
||||
|
Loading…
x
Reference in New Issue
Block a user