use of maspack.geometry.Face in project artisynth_core by artisynth.
the class MayaAsciiReader method recursiveAddPolygonalMeshes.
private void recursiveAddPolygonalMeshes(Node<MayaNode> root, PolygonalMesh mesh, AffineTransform3d trans, UnitInfo units) {
// 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());
// only multiply if inherited
if (dtrans.inheritsTransform()) {
trans.mul(tu);
} else {
trans.set(tu);
}
} else if (data instanceof MayaMesh) {
MayaMesh mm = (MayaMesh) data;
PolygonalMesh mmesh = mm.getMesh();
if (mmesh != null) {
// transform mesh
HashMap<Vertex3d, Vertex3d> vtxMap = new HashMap<Vertex3d, Vertex3d>();
for (Vertex3d vtx : mmesh.getVertices()) {
Vertex3d nvtx = new Vertex3d(vtx.pnt);
// XXX prevent transform
nvtx.pnt.scale(mm.units.length.getSI() / units.length.getSI());
nvtx.pnt.transform(trans);
vtxMap.put(vtx, nvtx);
mesh.addVertex(nvtx);
}
for (Face face : mmesh.getFaces()) {
Vertex3d[] oface = face.getVertices();
Vertex3d[] nface = new Vertex3d[oface.length];
for (int i = 0; i < oface.length; i++) {
nface[i] = vtxMap.get(oface[i]);
}
mesh.addFace(nface);
}
}
}
for (Node<MayaNode> child : root.getChildren()) {
recursiveAddPolygonalMeshes(child, mesh, trans, units);
}
}
use of maspack.geometry.Face in project artisynth_core by artisynth.
the class AmiraMeshWriter method writeMesh.
public void writeMesh(PolygonalMesh mesh) {
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
if (!mesh.isTriangular()) {
throw new IllegalArgumentException("Mesh must be triangular");
}
int nVerts = mesh.numVertices();
int nFaces = mesh.numFaces();
pw.println(FILE_HEADER);
// mesh name
if (mesh.getName() != null) {
pw.println("# " + mesh.getName());
}
pw.println();
pw.println("define Nodes " + nVerts);
pw.println("define Triangles " + nFaces);
pw.println();
pw.println("Parameters {");
// pw.println(" ContentType \"HxLineSet\"");
// XXX confirm with amira about valid parameter set
pw.println("}");
pw.println();
pw.println("Nodes { float[3] Coordinates } = @1");
pw.println("Triangles { int[3] Nodes } = @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 # triangular face indices");
for (Face face : mesh.getFaces()) {
HalfEdge he = face.firstHalfEdge();
Vertex3d vtx = he.getHead();
pw.print(vtx.getIndex());
he = he.getNext();
vtx = he.getHead();
pw.print(" " + vtx.getIndex());
he = he.getNext();
vtx = he.getHead();
pw.println(" " + vtx.getIndex());
}
// end loop through faces
pw.flush();
}
use of maspack.geometry.Face in project artisynth_core by artisynth.
the class FemModel3d method findNearestSurfaceElement.
/**
* Returns the nearest surface element to a specified point,
* which is found by projecting the point onto the FEM surface.
* The location of the projection is returned in <code>loc</code>.
*
* @param loc Projected location of the point onto the surface.
* @param pnt Point for which nearest surface element is desired.
* @return Nearest surface element.
*/
public FemElement3d findNearestSurfaceElement(Point3d loc, Point3d pnt) {
Vector2d coords = new Vector2d();
PolygonalMesh surf = getSurfaceMesh();
if (surf == null || surf.numFaces() == 0) {
surf = getInternalSurfaceMesh();
}
if (surf != null) {
Face face = BVFeatureQuery.getNearestFaceToPoint(loc, coords, surf, pnt);
FemElement3d elem = getSurfaceElement(face);
if (elem == null) {
throw new InternalErrorException("surface element not found for face");
}
return elem;
} else {
return null;
}
}
use of maspack.geometry.Face in project artisynth_core by artisynth.
the class SimpleFemWriter method writeSurfaceFile.
public void writeSurfaceFile(FemModel3d fem, PrintWriter surfaceWriter) {
PolygonalMesh mesh = fem.getSurfaceMesh();
for (Face face : mesh.getFaces()) {
surfaceWriter.print(faceToken);
for (Vertex3d vtx : face.getVertices()) {
FemNode3d node = fem.getSurfaceNode(vtx);
if (node != null) {
surfaceWriter.print(" " + (node.getNumber() + nodeOffset));
}
}
surfaceWriter.println();
}
}
use of maspack.geometry.Face in project artisynth_core by artisynth.
the class SkinMeshBody method createPointAttachment.
public PointSkinAttachment createPointAttachment(Point pnt) {
if (!(getMesh() instanceof PolygonalMesh)) {
return null;
}
PolygonalMesh mesh = (PolygonalMesh) getMesh();
if (!mesh.isTriangular()) {
return null;
}
// Find nearest face to the point; we'll need this to
// estimate a basePosition for the attachments from the
// start by find
BVFeatureQuery query = new BVFeatureQuery();
Point3d near = new Point3d();
Vector2d uv = new Vector2d();
Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
// Create a new PointSkinAttachment
MeshDistCalc dcalc = new MeshDistCalc();
dcalc.computeDistancesAndWeights(pnt.getPosition(), myLastSigma);
PointSkinAttachment a = dcalc.computeDisplacementAttachment();
a.setSkinMesh(this);
// Now estimate the basePosition from the face vertices
Point3d basePos = new Point3d();
Vertex3d[] vtxs = face.getTriVertices();
double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
for (int i = 0; i < vtxs.length; i++) {
PointSkinAttachment va = (PointSkinAttachment) myVertexAttachments.get(vtxs[i].getIndex());
basePos.scaledAdd(wgts[i], va.getBasePosition());
}
a.setBasePosition(basePos);
a.setPoint(pnt);
return a;
}
Aggregations