use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class MFreeMeshComp method markSurfaceMesh.
protected void markSurfaceMesh(boolean set) {
MeshBase mesh = getMesh();
if (mesh != null && !(mesh instanceof PolygonalMesh)) {
throw new IllegalArgumentException("Mesh must be a PolygonalMesh to be set as a surface");
}
isSurfaceMesh = set;
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class RigidCompositeBody method setInertiaFromMass.
/**
* Causes the inertia to be automatically computed from the mesh volume
* and a given mass (with the density computed by dividing the mass
* by the mesh volume). If the mesh is currently <code>null</code> the mass
* of the inertia is updated but the otherwise the inertia and density
* are left unchanged. Subsequent (non-<code>null</code>) changes
* to the mesh will cause the inertia to be recomputed.
* The inertia method is set to {@link RigidBody.InertiaMethod#Mass Mass}.
*
* @param mass desired body mass
*/
public void setInertiaFromMass(double mass) {
if (mass < 0) {
throw new IllegalArgumentException("mass must be non-negative");
}
double volume = 0;
for (RigidMeshComp mc : myMeshList) {
MeshBase mesh = mc.getMesh();
if (mesh != null && mc.isPhysical()) {
volume += getMeshVolume(mesh);
}
}
if (volume > 0) {
myDensity = getMass() / volume;
} else {
myDensity = 0;
}
for (RigidMeshComp mc : myMeshList) {
MeshBase mesh = mc.getMesh();
if (mesh != null && mc.isPhysical()) {
addMeshInertia(mesh, myDensity);
}
}
mySpatialInertia.setMass(mass);
myInertiaMethod = InertiaMethod.Mass;
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class RigidCompositeBody method setDensity.
/**
* Sets the density for the mesh, which is defined at the mass divided
* by the mesh volume. If the mesh is currently non-null, the mass
* will be updated accordingly. If the current InertiaMethod
* is either {@link RigidBody.InertiaMethod#Density Density} or
* {@link RigidBody.InertiaMethod#Mass Mass}, the other components of
* the spatial inertia will also be updated.
*
* @param density
* new density value
*/
public void setDensity(double density) {
if (density < 0) {
throw new IllegalArgumentException("density must be non-negative");
}
double mass = 0;
for (RigidMeshComp mc : myMeshList) {
MeshBase mesh = mc.getMesh();
if (mesh != null && mc.isPhysical()) {
mass += getMeshMass(mesh, density);
}
}
if (myInertiaMethod == InertiaMethod.Mass) {
setInertiaFromMass(mass);
} else if (myInertiaMethod == InertiaMethod.Density) {
setInertiaFromDensity(density);
}
myDensity = density;
mySpatialInertia.setMass(mass);
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class RigidMeshComp method transformGeometry.
public void transformGeometry(GeometryTransformer gtr, TransformGeometryContext context, int flags) {
if ((flags & TransformableGeometry.TG_SIMULATING) == 0) {
myMeshInfo.transformGeometryAndPose(gtr, null);
} else {
MeshBase mesh = myMeshInfo.getMesh();
mesh.setMeshToWorld(getRigidBody().getPose());
}
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class VertexComponent method setPosition.
public void setPosition(Point3d pnt) {
MeshBase mesh = myVertex.getMesh();
if (mesh == null || mesh.meshToWorldIsIdentity()) {
myVertex.setPosition(pnt);
} else {
Point3d pos = new Point3d(pnt);
pos.inverseTransform(mesh.XMeshToWorld);
myVertex.setPosition(pos);
}
notifyVertexPositionModified();
}
Aggregations