Search in sources :

Example 46 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class FemBeamMech method build.

public void build(String[] args) {
    femPath = "models/mech/models/fem/";
    modPath = "models/mech/";
    int nn = 2;
    myFemMod = FemFactory.createTetGrid(null, 0.6, 0.2, 0.2, nn * 3, nn * 1, nn * 1);
    myFemMod.setName("fem");
    myFemMod.setDensity(myDensity);
    myFemMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
    myFemMod.setLinearMaterial(60000, 0.33, true);
    myFemMod.setStiffnessDamping(0.002);
    myFemMod.setImplicitIterations(100);
    myFemMod.setImplicitPrecision(0.001);
    myFemMod.setSurfaceRendering(SurfaceRender.Shaded);
    Renderable elems = myFemMod.getElements();
    RenderProps.setLineWidth(elems, 2);
    RenderProps.setLineColor(elems, Color.BLUE);
    Renderable nodes = myFemMod.getNodes();
    RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(nodes, 0.005);
    RenderProps.setPointColor(nodes, Color.GREEN);
    // fix the leftmost nodes
    double EPS = 1e-9;
    for (FemNode3d n : myFemMod.getNodes()) {
        if (n.getPosition().x < -0.3 + EPS) {
            myLeftNodes.add(n);
        }
    }
    System.out.println("fixed nodes:");
    for (FemNode3d n : myLeftNodes) {
        n.setDynamic(false);
    }
    RenderProps.setFaceColor(myFemMod, new Color(0.4f, 0.4f, 1.0f));
    myFemMod.setProfiling(true);
    RigidBody anchorBox = new RigidBody("anchorBox");
    PolygonalMesh mesh = MeshFactory.createBox(0.1, 0.3, 0.3);
    anchorBox.setMesh(mesh, /* fileName= */
    null);
    RigidTransform3d X = new RigidTransform3d();
    X.p.set(-0.35, 0, 0);
    anchorBox.setPose(X);
    anchorBox.setDynamic(false);
    myMechMod = new MechModel("mech");
    myMechMod.addModel(myFemMod);
    myMechMod.addRigidBody(anchorBox);
    System.out.println("models: " + myMechMod.findComponent("models"));
    System.out.println("models/fem: " + myMechMod.findComponent("models/fem"));
    myMechMod.setIntegrator(Integrator.BackwardEuler);
    addModel(myMechMod);
    myMechMod.setProfiling(true);
    // add marker to lower right corner element
    Point3d corner = new Point3d(0.3, -0.1, -0.1);
    FemElement cornerElem = null;
    for (FemElement e : myFemMod.getElements()) {
        FemNode[] nodeList = e.getNodes();
        for (int i = 0; i < nodeList.length; i++) {
            if (nodeList[i].getPosition().epsilonEquals(corner, 1e-8)) {
                cornerElem = e;
                break;
            }
        }
    }
    if (cornerElem != null) {
        FemMarker mkr = new FemMarker(0.3, -0.07, -0.03);
        myFemMod.addMarker(mkr, cornerElem);
        RenderProps.setPointStyle(mkr, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(mkr, 0.01);
        RenderProps.setPointColor(mkr, Color.WHITE);
        Particle part = new Particle(1, 0.5, -0.07, -0.03);
        RenderProps.setPointStyle(part, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(part, 0.01);
        part.setDynamic(false);
        myMechMod.addParticle(part);
        AxialSpring spr = new AxialSpring(1000, 0, 0);
        myMechMod.attachAxialSpring(part, mkr, spr);
        RenderProps.setLineStyle(spr, Renderer.LineStyle.SPINDLE);
        RenderProps.setLineRadius(spr, 0.01);
        RenderProps.setLineColor(spr, Color.GREEN);
    }
    int numWays = 0;
    double res = 0.2;
    for (int i = 0; i < numWays; i++) {
        addWayPoint(new WayPoint((i + 1) * res, true));
    }
    addControlPanel(myMechMod, myFemMod);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemNode(artisynth.core.femmodels.FemNode) Color(java.awt.Color) PolygonalMesh(maspack.geometry.PolygonalMesh) FemMarker(artisynth.core.femmodels.FemMarker) WayPoint(artisynth.core.probes.WayPoint) AxialSpring(artisynth.core.mechmodels.AxialSpring) Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) Renderable(maspack.render.Renderable) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d) WayPoint(artisynth.core.probes.WayPoint) RigidBody(artisynth.core.mechmodels.RigidBody) FemElement(artisynth.core.femmodels.FemElement)

Example 47 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class ColoredFemBeam3d method build.

public void build(String[] args) {
    super.build(args);
    PolygonalMesh surf = myFemMod.getSurfaceMesh();
    surf.setVertexColoringEnabled();
    RainbowColorMap rcm = new RainbowColorMap();
    Point3d pmin = new Point3d(Point3d.POSITIVE_INFINITY);
    Point3d pmax = new Point3d(Point3d.NEGATIVE_INFINITY);
    myFemMod.updateBounds(pmin, pmax);
    for (int i = 0; i < surf.numVertices(); i++) {
        Point3d vpos = surf.getVertex(i).getPosition();
        surf.setColor(i, rcm.getColor((vpos.x - pmin.x) / (pmax.x - pmin.x)));
    }
}
Also used : Point3d(maspack.matrix.Point3d) RainbowColorMap(maspack.render.color.RainbowColorMap) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 48 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class CoupledSolveDemo method addCollider.

public void addCollider() {
    MechModel mod = (MechModel) models().get(0);
    collider = new RigidBody("Collider");
    PolygonalMesh colliderMesh = null;
    String meshFileName = null;
    colliderMesh = MeshFactory.createBox(0.05, 0.05, 0.03);
    collider.setPose(new RigidTransform3d(0, 0, 0.05));
    collider.setMesh(colliderMesh, meshFileName);
    collider.setInertiaFromDensity(10000);
    collider.setDynamic(false);
    RenderProps.setShading(collider, Renderer.Shading.SMOOTH);
    RenderProps.setVisible(collider, true);
    RenderProps.setFaceStyle(collider, Renderer.FaceStyle.FRONT_AND_BACK);
    RenderProps.setFaceColor(collider, new Color(0.7f, 0f, 0f));
    RenderProps.setAlpha(collider, 1);
    RenderProps.setShading(collider, Renderer.Shading.FLAT);
    mod.addRigidBody(collider);
    FemModel3d femMod = (FemModel3d) mod.models().get("FemMod");
    mod.setCollisionBehavior(femMod, collider, true);
}
Also used : Color(java.awt.Color) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 49 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MdlToObj method main.

public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("usage: java artisynth.models.badin.MdlToObj inputMdlMeshName outputObjMeshName");
        return;
    }
    try {
        PolygonalMesh mesh = MDLMeshIO.read(args[0], null);
        PrintWriter pw = new PrintWriter(new File(args[1]));
        mesh.write(pw, new NumberFormat("%g"), /*zeroindexed=*/
        false);
        pw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) File(java.io.File) PrintWriter(java.io.PrintWriter) NumberFormat(maspack.util.NumberFormat)

Example 50 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class WrappedMuscleArm method addBody.

public void addBody(String name, RigidTransform3d pose, String meshName) {
    // add a simple rigid body to the simulation
    RigidBody rb = new RigidBody();
    rb.setName(name);
    rb.setPose(pose);
    model.addRigidBody(rb);
    PolygonalMesh mesh;
    try {
        String meshFilename = meshDir + meshName;
        mesh = new PolygonalMesh();
        mesh.read(new BufferedReader(new FileReader(new File(meshFilename))));
        rb.setMesh(mesh, meshFilename);
    } catch (IOException e) {
        System.out.println(e.getMessage());
        mesh = MeshFactory.createBox(size.x, size.y, size.z);
        rb.setMesh(mesh, null);
    }
    rb.setInertia(SpatialInertia.createBoxInertia(10.0, size.x, size.y, size.z));
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setFaceColor(Color.GRAY);
    rp.setShading(Renderer.Shading.FLAT);
    rb.setRenderProps(rp);
    rb.setFrameDamping(10);
    rb.setRotaryDamping(10000.0);
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) File(java.io.File)

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