Feature: added reading edge crease and if it belongs to a face or not
(this will be used by some modifiers soon).
This commit is contained in:
parent
6dc8ff521a
commit
90d62218ed
@ -20,11 +20,16 @@ import com.jme3.scene.plugins.blender.meshes.IndexesLoop.IndexPredicate;
|
|||||||
*/
|
*/
|
||||||
public class Edge extends Line {
|
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. */
|
/** The vertices indexes. */
|
||||||
private int index1, index2;
|
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() {
|
public Edge() {
|
||||||
}
|
}
|
||||||
@ -36,10 +41,16 @@ public class Edge extends Line {
|
|||||||
* the first index of the edge
|
* the first index of the edge
|
||||||
* @param index2
|
* @param index2
|
||||||
* the second index of the edge
|
* 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.index1 = index1;
|
||||||
this.index2 = index2;
|
this.index2 = index2;
|
||||||
|
this.crease = crease;
|
||||||
|
this.inFace = inFace;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,17 +60,21 @@ public class Edge extends Line {
|
|||||||
* the first index of the edge
|
* the first index of the edge
|
||||||
* @param index2
|
* @param index2
|
||||||
* the second index of the edge
|
* 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
|
* @param vertices
|
||||||
* the vertices of the mesh
|
* the vertices of the mesh
|
||||||
*/
|
*/
|
||||||
public Edge(int index1, int index2, List<Vector3f> vertices) {
|
public Edge(int index1, int index2, float crease, boolean inFace, List<Vector3f> vertices) {
|
||||||
this(index1, index2);
|
this(index1, index2, crease, inFace);
|
||||||
this.set(vertices.get(index1), vertices.get(index2));
|
this.set(vertices.get(index1), vertices.get(index2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Edge clone() {
|
public Edge clone() {
|
||||||
Edge result = new Edge(index1, index2);
|
Edge result = new Edge(index1, index2, crease, inFace);
|
||||||
result.setOrigin(this.getOrigin());
|
result.setOrigin(this.getOrigin());
|
||||||
result.setDirection(this.getDirection());
|
result.setDirection(this.getDirection());
|
||||||
return result;
|
return result;
|
||||||
@ -79,6 +94,20 @@ public class Edge extends Line {
|
|||||||
return index2;
|
return index2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the crease value of the edge (its weight)
|
||||||
|
*/
|
||||||
|
public float getCrease() {
|
||||||
|
return crease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return <b>true</b> if the edge is used by at least one face and <b>false</b> otherwise
|
||||||
|
*/
|
||||||
|
public boolean isInFace() {
|
||||||
|
return inFace;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shifts indexes by a given amount.
|
* Shifts indexes by a given amount.
|
||||||
* @param shift
|
* @param shift
|
||||||
@ -168,10 +197,13 @@ public class Edge extends Line {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String result = "Edge [" + index1 + ", " + index2 + "]";
|
String result = "Edge [" + index1 + ", " + index2 + "] {" + crease + "}";
|
||||||
if (this.getOrigin() != null && this.getDirection() != null) {
|
if (this.getOrigin() != null && this.getDirection() != null) {
|
||||||
result += " -> {" + this.getOrigin() + ", " + this.getOrigin().add(this.getDirection()) + "}";
|
result += " -> {" + this.getOrigin() + ", " + this.getOrigin().add(this.getDirection()) + "}";
|
||||||
}
|
}
|
||||||
|
if (inFace) {
|
||||||
|
result += "[F]";
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,11 +249,12 @@ public class Edge extends Line {
|
|||||||
List<Structure> edges = pMEdge.fetchData();
|
List<Structure> edges = pMEdge.fetchData();
|
||||||
for (Structure edge : edges) {
|
for (Structure edge : edges) {
|
||||||
int flag = ((Number) edge.getFieldValue("flag")).intValue();
|
int flag = ((Number) edge.getFieldValue("flag")).intValue();
|
||||||
if ((flag & MeshHelper.EDGE_NOT_IN_FACE_FLAG) != 0) {
|
|
||||||
int v1 = ((Number) edge.getFieldValue("v1")).intValue();
|
int v1 = ((Number) edge.getFieldValue("v1")).intValue();
|
||||||
int v2 = ((Number) edge.getFieldValue("v2")).intValue();
|
int v2 = ((Number) edge.getFieldValue("v2")).intValue();
|
||||||
result.add(new Edge(v1, v2));
|
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());
|
LOGGER.log(Level.FINE, "Loaded {0} edges.", result.size());
|
||||||
|
@ -343,7 +343,7 @@ public class Face implements Comparator<Integer> {
|
|||||||
if (i != index && i != indexToIgnore) {
|
if (i != index && i != indexToIgnore) {
|
||||||
Vector3f v2 = vertices.get(i);
|
Vector3f v2 = vertices.get(i);
|
||||||
float d = v2.distance(v1);
|
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;
|
result = i;
|
||||||
distance = d;
|
distance = d;
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,6 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
public static final int UV_DATA_LAYER_TYPE_FMESH = 5;
|
public static final int UV_DATA_LAYER_TYPE_FMESH = 5;
|
||||||
/** A type of UV data layer in bmesh type. */
|
/** A type of UV data layer in bmesh type. */
|
||||||
public static final int UV_DATA_LAYER_TYPE_BMESH = 16;
|
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. */
|
/** A material used for single lines and points. */
|
||||||
private Material blackUnshadedMaterial;
|
private Material blackUnshadedMaterial;
|
||||||
|
@ -495,7 +495,12 @@ public class TemporalMesh extends Geometry {
|
|||||||
LOGGER.fine("Preparing lines geometries.");
|
LOGGER.fine("Preparing lines geometries.");
|
||||||
|
|
||||||
List<List<Integer>> separateEdges = new ArrayList<List<Integer>>();
|
List<List<Integer>> separateEdges = new ArrayList<List<Integer>>();
|
||||||
List<Edge> edges = new ArrayList<Edge>(this.edges);
|
List<Edge> edges = new ArrayList<Edge>(this.edges.size());
|
||||||
|
for (Edge edge : this.edges) {
|
||||||
|
if (!edge.isInFace()) {
|
||||||
|
edges.add(edge);
|
||||||
|
}
|
||||||
|
}
|
||||||
while (edges.size() > 0) {
|
while (edges.size() > 0) {
|
||||||
boolean edgeAppended = false;
|
boolean edgeAppended = false;
|
||||||
int edgeIndex = 0;
|
int edgeIndex = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user