diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Edge.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Edge.java index 48f9b8990..32a0b88c2 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Edge.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/Edge.java @@ -19,12 +19,17 @@ import com.jme3.scene.plugins.blender.meshes.IndexesLoop.IndexPredicate; * @author Marcin Roguski (Kaelthas) */ public class Edge extends Line { - private static final long serialVersionUID = 7172714692126675311L; + private static final long serialVersionUID = 7172714692126675311L; + private static final Logger LOGGER = Logger.getLogger(Edge.class.getName()); - private static final Logger LOGGER = Logger.getLogger(Edge.class.getName()); + private static final int FLAG_EDGE_NOT_IN_FACE = 0x80; /** The vertices indexes. */ private int index1, index2; + /** The weight of the edge. */ + private float crease; + /** A variable that indicates if this edge belongs to any face or not. */ + private boolean inFace; public Edge() { } @@ -36,10 +41,16 @@ public class Edge extends Line { * the first index of the edge * @param index2 * the second index of the edge + * @param crease + * the weight of the face + * @param inFace + * a variable that indicates if this edge belongs to any face or not */ - private Edge(int index1, int index2) { + private Edge(int index1, int index2, float crease, boolean inFace) { this.index1 = index1; this.index2 = index2; + this.crease = crease; + this.inFace = inFace; } /** @@ -49,17 +60,21 @@ public class Edge extends Line { * the first index of the edge * @param index2 * the second index of the edge + * @param crease + * the weight of the face + * @param inFace + * a variable that indicates if this edge belongs to any face or not * @param vertices * the vertices of the mesh */ - public Edge(int index1, int index2, List vertices) { - this(index1, index2); + public Edge(int index1, int index2, float crease, boolean inFace, List vertices) { + this(index1, index2, crease, inFace); this.set(vertices.get(index1), vertices.get(index2)); } @Override public Edge clone() { - Edge result = new Edge(index1, index2); + Edge result = new Edge(index1, index2, crease, inFace); result.setOrigin(this.getOrigin()); result.setDirection(this.getDirection()); return result; @@ -79,6 +94,20 @@ public class Edge extends Line { return index2; } + /** + * @return the crease value of the edge (its weight) + */ + public float getCrease() { + return crease; + } + + /** + * @return true if the edge is used by at least one face and false otherwise + */ + public boolean isInFace() { + return inFace; + } + /** * Shifts indexes by a given amount. * @param shift @@ -168,10 +197,13 @@ public class Edge extends Line { @Override public String toString() { - String result = "Edge [" + index1 + ", " + index2 + "]"; + String result = "Edge [" + index1 + ", " + index2 + "] {" + crease + "}"; if (this.getOrigin() != null && this.getDirection() != null) { result += " -> {" + this.getOrigin() + ", " + this.getOrigin().add(this.getDirection()) + "}"; } + if (inFace) { + result += "[F]"; + } return result; } @@ -217,11 +249,12 @@ public class Edge extends Line { List edges = pMEdge.fetchData(); for (Structure edge : edges) { int flag = ((Number) edge.getFieldValue("flag")).intValue(); - if ((flag & MeshHelper.EDGE_NOT_IN_FACE_FLAG) != 0) { - int v1 = ((Number) edge.getFieldValue("v1")).intValue(); - int v2 = ((Number) edge.getFieldValue("v2")).intValue(); - result.add(new Edge(v1, v2)); - } + + int v1 = ((Number) edge.getFieldValue("v1")).intValue(); + int v2 = ((Number) edge.getFieldValue("v2")).intValue(); + float crease = ((Number) edge.getFieldValue("crease")).floatValue(); + boolean edgeInFace = (flag & Edge.FLAG_EDGE_NOT_IN_FACE) == 0; + result.add(new Edge(v1, v2, crease, edgeInFace)); } } LOGGER.log(Level.FINE, "Loaded {0} edges.", result.size()); 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 f4a417daa..da37a88eb 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 @@ -343,7 +343,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, vertices))) { + if (d < distance && this.contains(new Edge(index, i, 0, true, vertices))) { result = i; distance = d; } diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java index 994ac23f3..92b236f4c 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java @@ -68,8 +68,6 @@ public class MeshHelper extends AbstractBlenderHelper { public static final int UV_DATA_LAYER_TYPE_FMESH = 5; /** A type of UV data layer in bmesh type. */ public static final int UV_DATA_LAYER_TYPE_BMESH = 16; - /** The flag mask indicating if the edge belongs to a face or not. */ - public static final int EDGE_NOT_IN_FACE_FLAG = 0x80; /** A material used for single lines and points. */ private Material blackUnshadedMaterial; @@ -340,7 +338,7 @@ public class MeshHelper extends AbstractBlenderHelper { } return result; } - + /** * Selects the proper subsets of vertex colors for the given sublist of indexes. * @param face diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java index 1770b2770..bbf4fd976 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java @@ -105,7 +105,7 @@ public class TemporalMesh extends Geometry { if (loadData) { name = meshStructure.getName(); - + MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class); meshHelper.loadVerticesAndNormals(meshStructure, vertices, normals); @@ -495,7 +495,12 @@ public class TemporalMesh extends Geometry { LOGGER.fine("Preparing lines geometries."); List> separateEdges = new ArrayList>(); - List edges = new ArrayList(this.edges); + List edges = new ArrayList(this.edges.size()); + for (Edge edge : this.edges) { + if (!edge.isInFace()) { + edges.add(edge); + } + } while (edges.size() > 0) { boolean edgeAppended = false; int edgeIndex = 0;