Search in sources :

Example 41 with PolygonalMesh

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;
}
Also used : DistanceGrid(maspack.geometry.DistanceGrid) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 42 with PolygonalMesh

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);
    }
}
Also used : PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 43 with PolygonalMesh

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;
}
Also used : PolygonalMesh(maspack.geometry.PolygonalMesh) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 44 with PolygonalMesh

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;
    }
}
Also used : PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 45 with PolygonalMesh

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

PolygonalMesh (maspack.geometry.PolygonalMesh)128 Point3d (maspack.matrix.Point3d)30 Vertex3d (maspack.geometry.Vertex3d)24 Vector3d (maspack.matrix.Vector3d)23 RigidTransform3d (maspack.matrix.RigidTransform3d)21 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 File (java.io.File)14 Face (maspack.geometry.Face)14 ContactPoint (artisynth.core.mechmodels.ContactPoint)11 Point (artisynth.core.mechmodels.Point)11 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)10 Color (java.awt.Color)10 MeshBase (maspack.geometry.MeshBase)10 RigidBody (artisynth.core.mechmodels.RigidBody)9 MechModel (artisynth.core.mechmodels.MechModel)8 BufferedReader (java.io.BufferedReader)8 AxisAngle (maspack.matrix.AxisAngle)8 RenderProps (maspack.render.RenderProps)8 HashMap (java.util.HashMap)7