Search in sources :

Example 21 with PolygonalMesh

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);
}
Also used : MeshRenderProps(maspack.render.MeshRenderProps) Color(java.awt.Color) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 22 with PolygonalMesh

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

Example 23 with PolygonalMesh

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

Example 24 with PolygonalMesh

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

Example 25 with PolygonalMesh

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

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