use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class GLSparkleDebug method addContent.
protected void addContent(MultiViewer mv) {
Color[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.CYAN, Color.GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.YELLOW, Color.RED.darker().darker(), Color.GREEN.darker().darker(), Color.BLUE.darker().darker(), Color.CYAN.darker().darker(), Color.GRAY.darker().darker(), Color.MAGENTA.darker().darker(), Color.ORANGE.darker().darker(), Color.PINK.darker().darker(), Color.YELLOW.darker().darker(), Color.RED.brighter().brighter(), Color.GREEN.brighter().brighter(), Color.BLUE.brighter().brighter(), Color.CYAN.brighter().brighter(), Color.GRAY.brighter().brighter(), Color.MAGENTA.brighter().brighter(), Color.ORANGE.brighter().brighter(), Color.PINK.brighter().brighter(), Color.YELLOW.brighter().brighter() };
PolygonalMesh mesh = MeshFactory.createIcosahedralSphere(1, 0);
mesh.setFeatureColoringEnabled();
for (int i = 0; i < mesh.numColors(); ++i) {
mesh.setColor(i, colors[i % colors.length]);
}
mesh.setRenderProps(new MeshRenderProps());
mesh.getRenderProps().setShading(Shading.FLAT);
mv.addRenderable(mesh);
}
use of maspack.geometry.PolygonalMesh 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.PolygonalMesh in project artisynth_core by artisynth.
the class FemModel3d method getSurfaceMeshComp.
// Returns the FemMeshComp component for the surface mesh. If appropriate, the
// surface is generated on demand
public FemMeshComp getSurfaceMeshComp() {
if (myMeshList.size() < 1) {
throw new IllegalArgumentException("Default surface mesh component has been removed");
}
// if auto, take first. If not, take first one marked as a surface mesh;
if (!mySurfaceMeshValid) {
if (myAutoGenerateSurface) {
FemMeshComp meshc = doGetSurfaceMeshComp();
createDefaultSurfaceMesh(meshc);
mySurfaceMeshValid = true;
myInternalSurfaceMeshComp = null;
// grab newly created mesh
MeshBase mesh = meshc.getMesh();
// paranoid: call in case mesh is rendered directly before
// prerender()
PolygonalMesh smesh = (PolygonalMesh) mesh;
smesh.saveRenderInfo(myRenderProps);
return meshc;
} else {
return null;
}
} else {
return myMeshList.get(0);
}
}
use of maspack.geometry.PolygonalMesh 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.PolygonalMesh 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