use of maspack.geometry.MeshBase 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.MeshBase in project artisynth_core by artisynth.
the class SkinMeshBody method resetBasePositions.
/**
* Resets the base positions for all attachments in this SkinMeshBody
* to the current vertex position.
*/
protected void resetBasePositions() {
MeshBase mesh = getMesh();
for (int i = 0; i < myVertexAttachments.size(); i++) {
PointSkinAttachment a = myVertexAttachments.get(i);
Vertex3d vtx = mesh.getVertices().get(a.getNumber());
a.setBasePosition(vtx.getPosition());
}
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class SkinMeshBody method initializeAttachments.
private void initializeAttachments() {
MeshBase mesh = getMesh();
int numVtxs = mesh.numVertices();
myVertexAttachments.removeAll();
myVertexAttachments.ensureCapacity(numVtxs);
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class SkinMeshBody method computeDisplacementAttachments.
/**
* Computes displacement-based attachments for each vertex attachment in
* this skin mesh. For each vertex, the weights are determined using the
* relative distances from the vertex to the surface meshes of each of the
* controlling bodies (Frame, FemModel, etc.). Controlling bodies which
* don't have a surface mesh are ignored.
*
* <p>
* Bodies further away have a lower weighting. If <code>sigma</code>
* is non-positive, the weighting is determined using an inverse-square
* attenuation. Otherwise, the weighting is determined using a
* Gaussian attention controlled by <code>sigma</code>.
*
* @param sigma if greater than 0, specifies a Gaussian weighting
* attenuation.
*/
public void computeDisplacementAttachments(double sigma) {
MeshBase mesh = getMesh();
MeshDistCalc dcalc = new MeshDistCalc();
clearAttachments();
for (int i = 0; i < mesh.numVertices(); i++) {
Vertex3d vtx = mesh.getVertices().get(i);
dcalc.computeDistancesAndWeights(vtx.getPosition(), sigma);
PointSkinAttachment a = dcalc.computeDisplacementAttachment();
addAttachment(a);
}
myLastSigma = sigma;
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class FemMeshComp method setSurfaceRendering.
@Override
public void setSurfaceRendering(SurfaceRender mode) {
SurfaceRender oldMode = getSurfaceRendering();
super.setSurfaceRendering(mode);
if (oldMode != mode) {
if (myFem != null) {
// paranoid: myFem should always be non-null here
switch(mode) {
case Strain:
myFem.setComputeNodalStrain(true);
myFem.updateStressAndStiffness();
break;
case Stress:
myFem.setComputeNodalStress(true);
myFem.updateStressAndStiffness();
break;
default:
{
myFem.setComputeNodalStrain(false);
myFem.setComputeNodalStress(false);
break;
}
}
}
// save/restore original vertex colors
MeshBase mesh = getMesh();
if (mesh != null) {
boolean oldStressOrStrain = isStressOrStrainRendering(oldMode);
boolean newStressOrStrain = isStressOrStrainRendering(mode);
if (newStressOrStrain != oldStressOrStrain) {
if (newStressOrStrain) {
saveShading();
saveMeshColoring(mesh);
mesh.setVertexColoringEnabled();
mesh.setVertexColorMixing(ColorMixing.REPLACE);
myRenderProps.setShading(Shading.NONE);
// enable stress/strain rendering *after* vertex coloring set
// not sure we need this here
updateVertexColors();
} else {
// disable stress/strain rendering *before* restoring colors
restoreMeshColoring(mesh);
restoreShading();
}
}
}
}
}
Aggregations