use of maspack.geometry.Polyline in project artisynth_core by artisynth.
the class MayaAsciiReader method recursiveAddPolylines.
private void recursiveAddPolylines(Node<MayaNode> root, PolylineMesh mesh, AffineTransform3d trans, UnitInfo units, Pattern pregex) {
// make copy so can traverse
trans = new AffineTransform3d(trans);
// children independently
MayaNode data = root.getData();
if (data instanceof MayaTransform) {
MayaTransform dtrans = (MayaTransform) data;
AffineTransform3d tu = new AffineTransform3d();
dtrans.getTransform(tu);
// convert units
tu.p.scale(dtrans.units.length.getSI() / units.length.getSI());
if (dtrans.inheritsTransform()) {
trans.mul(tu);
} else {
trans.set(tu);
}
} else if (data instanceof MayaNurbsCurve) {
MayaNurbsCurve mnc = (MayaNurbsCurve) data;
if (pregex == null || pregex.matcher(mnc.getName()).matches()) {
Polyline line = new Polyline(mnc.curve);
if (line != null) {
// transform line
for (Vertex3d vtx : line.getVertices()) {
vtx.pnt.scale(mnc.units.length.getSI() / units.length.getSI());
vtx.pnt.transform(trans);
}
mesh.addLine(line);
}
}
}
for (Node<MayaNode> child : root.getChildren()) {
recursiveAddPolylines(child, mesh, trans, units, pregex);
}
}
use of maspack.geometry.Polyline in project artisynth_core by artisynth.
the class AmiraMeshWriter method writeMesh.
public void writeMesh(PolylineMesh mesh) {
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
int nLineSize = 0;
for (Polyline line : mesh.getLines()) {
int nlineVerts = line.numVertices();
if (nlineVerts > 0) {
nLineSize += nlineVerts + 1;
}
}
int nVerts = mesh.numVertices();
pw.println(FILE_HEADER);
// mesh name
if (mesh.getName() != null) {
pw.println("# " + mesh.getName());
}
pw.println();
pw.println("define Lines " + nLineSize);
pw.println("define Vertices " + nVerts);
pw.println();
pw.println("Parameters {");
pw.println(" ContentType \"HxLineSet\"");
pw.println("}");
pw.println();
pw.println("Vertices { float[3] Coordinates } = @1");
pw.println("Lines { int LineIdx } = @2");
pw.println();
pw.println("@1 # xyz vertex coordinates");
int idx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
vtx.setIndex(idx++);
pw.println(vtx.getPosition().toString(myFmt));
}
pw.println();
pw.println("@2 # line indices, terminating with -1");
for (Polyline line : mesh.getLines()) {
idx = 0;
Vertex3d[] vtxs = line.getVertices();
if (vtxs.length > 0) {
pw.print(vtxs[0].getIndex());
for (int i = 1; i < vtxs.length; i++) {
if ((i % maxLineIndexSize) == 0) {
pw.println();
} else {
pw.print(" ");
}
pw.print(vtxs[i].getIndex());
}
if ((vtxs.length % maxLineIndexSize) == 0) {
pw.println();
} else {
pw.print(" ");
}
pw.println(-1);
}
// end if non-null line
}
// end loop through lines
pw.flush();
}
Aggregations