use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class RigidBody method getDistanceSurface.
protected PolygonalMesh getDistanceSurface() {
if (mySDSurface == null) {
if (hasDistanceGrid()) {
PolygonalMesh surf;
DistanceGrid grid = getDistanceGrid();
if (myRenderDistanceSurface == DistanceSurfaceRendering.QUADRATIC) {
surf = grid.createQuadDistanceSurface(myDistanceSurfaceIso, 4);
surf.setMeshToWorld(myState.XFrameToWorld);
} else {
surf = grid.createDistanceSurface(myDistanceSurfaceIso, 4);
surf.setMeshToWorld(myState.XFrameToWorld);
}
mySDSurface = surf;
}
}
return mySDSurface;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class RigidBody method scaleInternalGeometry.
// separated to prevent surface mesh from being scaled twice
protected void scaleInternalGeometry(double s) {
PolygonalMesh mesh = getMesh();
if (mesh != null) {
mesh.scale(s);
mesh.setMeshToWorld(myState.XFrameToWorld);
}
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class RigidBody method createEllipsoid.
/**
* Creates an ellipsoidal RigidBody with a prescribed uniform density.
* The ellipsoid is centered on the origin.
*
* @param bodyName name of the RigidBody
* @param a semi-axis length in the x direction
* @param b semi-axis length in the y direction
* @param c semi-axis length in the z direction
* @param density density of the body
* @param nslices number of slices used in creating the mesh
* @return ellipsoidal rigid body
*/
public static RigidBody createEllipsoid(String bodyName, double a, double b, double c, double density, int nslices) {
RigidBody body = new RigidBody(bodyName);
PolygonalMesh mesh = MeshFactory.createSphere(1.0, nslices);
AffineTransform3d XScale = new AffineTransform3d();
XScale.applyScaling(a, b, c);
mesh.transform(XScale);
body.setMesh(mesh, null);
double mass = 4 / 3.0 * Math.PI * a * b * c * density;
body.setInertia(SpatialInertia.createEllipsoidInertia(mass, a, b, c));
return body;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class RigidBody method setMeshFromInfo.
protected void setMeshFromInfo() {
PolygonalMesh mesh = getMesh();
if (mesh != null) {
mesh.setFixed(true);
mesh.setMeshToWorld(myState.XFrameToWorld);
if (myInertiaMethod == InertiaMethod.Density) {
setInertiaFromMesh(myDensity);
} else {
myDensity = mySpatialInertia.getMass() / mesh.computeVolume();
if (myInertiaMethod == InertiaMethod.Mass) {
setInertiaFromMesh(myDensity);
}
}
mySDGrid = null;
mySDSurface = null;
mySDGridValid = false;
} else {
mySDGrid = null;
mySDSurface = null;
mySDGridValid = true;
}
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MeshIntersectingProbe method trimFaces.
protected static PolygonalMesh trimFaces(PolygonalMesh mesh, HashMap<Vertex3d, Boolean> vtxIndicatorMap) {
PolygonalMesh out = new PolygonalMesh();
HashMap<Vertex3d, Vertex3d> vtxMap = new HashMap<Vertex3d, Vertex3d>(mesh.numVertices());
for (Vertex3d vtx : mesh.getVertices()) {
if (vtxIndicatorMap.get(vtx)) {
Vertex3d nvtx = new Vertex3d(new Point3d(vtx.getPosition()));
vtxMap.put(vtx, nvtx);
out.addVertex(nvtx);
}
}
for (Face face : mesh.getFaces()) {
boolean add = true;
for (Vertex3d vtx : face.getVertices()) {
if (vtxIndicatorMap.get(vtx) == false) {
add = false;
break;
}
}
if (add) {
Vertex3d[] oldVtxs = face.getVertices();
Vertex3d[] vtxs = new Vertex3d[face.numVertices()];
for (int i = 0; i < vtxs.length; i++) {
vtxs[i] = vtxMap.get(oldVtxs[i]);
}
out.addFace(vtxs);
}
}
return out;
}
Aggregations