Search in sources :

Example 36 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class FemBeamWithBlock method build.

public void build(String[] args) throws IOException {
    // Build simple FemBeam
    super.build(args);
    // Create a rigid block and move to the side of FEM
    RigidBody block = RigidBody.createBox("block", width / 2, 1.2 * width, 1.2 * width, 2 * density);
    mech.addRigidBody(block);
    block.setPose(new RigidTransform3d(length / 2 + width / 4, 0, 0));
    // Attach right-side nodes to rigid block
    for (FemNode3d node : fem.getNodes()) {
        if (node.getPosition().x >= length / 2 - EPS) {
            mech.addAttachment(new PointFrameAttachment(block, node));
        }
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemNode3d(artisynth.core.femmodels.FemNode3d) RigidBody(artisynth.core.mechmodels.RigidBody) PointFrameAttachment(artisynth.core.mechmodels.PointFrameAttachment)

Example 37 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class FemCollisions method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    // Reduce step size to better resolve collisions
    setMaxStepSize(0.0002);
    // Create and add main MechModel
    MechModel mech = new MechModel("mech");
    addModel(mech);
    // -------------------------------------------------------------
    // BEAM
    // -------------------------------------------------------------
    // Create FEM beam
    FemModel3d beam = new FemModel3d("beam");
    mech.addModel(beam);
    // widths
    double[] size = { 0.003, 0.0015, 0.0015 };
    // resolution
    int[] res = { 4, 2, 2 };
    FemFactory.createGrid(beam, FemElementType.Hex, size[0], size[1], size[2], res[0], res[1], res[2]);
    // Set properties
    beam.setDensity(1000);
    beam.setMaterial(new LinearMaterial(300, 0.33));
    // -------------------------------------------------------------
    // ELLIPSOID
    // -------------------------------------------------------------
    // Create FEM ellipsoid
    FemModel3d ellipsoid = new FemModel3d("ellipsoid");
    mech.addModel(ellipsoid);
    // radii (z, x, y)
    double[] radii = { 0.002, 0.001, 0.001 };
    // resolution (theta, phi, r)
    int[] eres = { 16, 4, 3 };
    FemFactory.createEllipsoid(ellipsoid, radii[0], radii[1], radii[2], eres[0], eres[1], eres[2]);
    // Set properties
    ellipsoid.setDensity(1000);
    ellipsoid.setMaterial(new LinearMaterial(300, 0.33));
    // Transform: rotate 90 degrees about X-Axis
    // translate up by 0.003
    RigidTransform3d trans = new RigidTransform3d();
    trans.setRotation(new AxisAngle(1, 0, 0, Math.PI / 2));
    trans.setTranslation(new Vector3d(0, 0.0005, 0.003));
    ellipsoid.transformGeometry(trans);
    // -------------------------------------------------------------
    // BLOCK WITH EMBEDDED SPHERE
    // -------------------------------------------------------------
    // Create FEM block
    FemModel3d block = new FemModel3d("block");
    mech.addModel(block);
    FemFactory.createHexGrid(block, 0.002, 0.002, 0.002, 3, 3, 3);
    // Set properties
    block.setDensity(1000);
    block.setMaterial(new LinearMaterial(300, 0.33));
    // Create embedded sphere
    double r = 0.0008;
    // level of refinement
    int ref = 2;
    PolygonalMesh sphere = MeshFactory.createOctahedralSphere(r, ref);
    FemMeshComp embeddedSphere = block.addMesh("embedded", sphere);
    // Transform: rotate 90 degrees about X-Axis
    // translate left by 0.003
    trans = new RigidTransform3d();
    trans.setTranslation(new Vector3d(0, 0.003, 0));
    block.transformGeometry(trans);
    // -------------------------------------------------------------
    // TABLE AND COLLISIONS
    // -------------------------------------------------------------
    RigidBody table = RigidBody.createBox("table", 0.005, 0.0075, 0.0008, 0);
    table.setDynamic(false);
    table.setPose(new RigidTransform3d(new Vector3d(0, 0.0015, -0.002), AxisAngle.IDENTITY));
    mech.addRigidBody(table);
    // Set up collisions
    mech.setCollisionBehavior(ellipsoid, beam, true, 0.1);
    mech.setCollisionBehavior(ellipsoid, table, true, 0.1);
    mech.setCollisionBehavior(embeddedSphere, table, true, 0.1);
    mech.setCollisionBehavior(ellipsoid, embeddedSphere, true, 0.1);
    mech.setCollisionBehavior(table, beam, true, 0.1);
    // -------------------------------------------------------------
    // RENDER PROPERTIES
    // -------------------------------------------------------------
    // Draw beam element widgets
    beam.setElementWidgetSize(0.8);
    RenderProps.setLineWidth(beam.getElements(), 0);
    // Make beam blue, and give it a transparent surface
    RenderProps.setFaceColor(beam, Color.BLUE);
    beam.setSurfaceRendering(SurfaceRender.Shaded);
    RenderProps.setAlpha(beam.getMeshComp("surface"), 0.4);
    // Make the ellipsoid red
    RenderProps.setFaceColor(ellipsoid, Color.RED);
    RenderProps.setLineColor(ellipsoid, Color.RED.darker());
    ellipsoid.setSurfaceRendering(SurfaceRender.Shaded);
    // Make the block green
    RenderProps.setFaceColor(block, Color.GREEN);
    RenderProps.setLineColor(block, Color.GREEN.darker());
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemModel3d(artisynth.core.femmodels.FemModel3d) FemMeshComp(artisynth.core.femmodels.FemMeshComp) LinearMaterial(artisynth.core.materials.LinearMaterial) PolygonalMesh(maspack.geometry.PolygonalMesh) MechModel(artisynth.core.mechmodels.MechModel) AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 38 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class FemMuscleHeart method build.

// Model builder
@Override
public void build(String[] args) throws IOException {
    super.build(args);
    setMaxStepSize(0.005);
    // Root mechanical model
    MechModel mech = new MechModel("mech");
    mech.setGravity(0, 0, -9.8);
    addModel(mech);
    // -------------------------------------------------------------
    // HEART LOAD / ADD GEOMETRY
    // -------------------------------------------------------------
    // Heart surface mesh, with texture
    String heartFile = ArtisynthPath.getSrcRelativePath(this, "data/HumanHeart.obj");
    WavefrontReader wfr = new WavefrontReader(new File(heartFile));
    PolygonalMesh heartMesh = new PolygonalMesh();
    wfr.readMesh(heartMesh);
    // triangulate for interaction
    heartMesh.triangulate();
    // FEM heart:
    // - FEM mesh of heart convex hull
    // - embedded heart surface geometry
    FemMuscleModel heart = new FemMuscleModel("heart");
    TetGenReader.read(heart, ArtisynthPath.getSrcRelativePath(this, "data/HumanHeartHull.node"), ArtisynthPath.getSrcRelativePath(this, "data/HumanHeartHull.ele"));
    // add real-looking mesh
    FemMeshComp embeddedHeart = heart.addMesh(heartMesh);
    embeddedHeart.setName("embedded");
    // Allow inverted elements (poor quality mesh)
    heart.setWarnOnInvertedElements(false);
    heart.setAbortOnInvertedElements(false);
    // Convert unites to metres (original was cm)
    heart.scaleDistance(0.01);
    heart.setGravity(0, 0, -9.8);
    heart.setStiffnessDamping(0.02);
    // Set material properties
    heart.setDensity(1000);
    FemMaterial femMat = new LinearMaterial(2500, 0.33, true);
    // simple muscle
    MuscleMaterial muscleMat = new SimpleForceMuscle(500.0);
    heart.setMaterial(femMat);
    // Add heart to model
    mech.addModel(heart);
    // -------------------------------------------------------------
    // MUSCLE BUNDLES
    // -------------------------------------------------------------
    // One "long" direction muscle bundle
    // One "radial" muscle bundle
    // LONG BUNDLE
    // Compute the "long" direction of the heart
    PolygonalMesh hull = heart.getSurfaceMesh();
    RigidTransform3d trans = hull.computePrincipalAxes();
    Vector3d longAxis = new Vector3d();
    // first column of rotation
    trans.R.getColumn(0, longAxis);
    // Create the long axis muscle bundle
    MuscleBundle longBundle = new MuscleBundle("long");
    for (FemElement3d elem : heart.getElements()) {
        longBundle.addElement(elem, longAxis);
    }
    longBundle.setMuscleMaterial(muscleMat);
    heart.addMuscleBundle(longBundle);
    // RADIAL BUNDLE
    // Compute a plane through centre of heart
    Plane plane = new Plane(longAxis, new Point3d(trans.p));
    Point3d centroid = new Point3d();
    Vector3d radialDir = new Vector3d();
    // Create the radial muscle bundle
    MuscleBundle radialBundle = new MuscleBundle("radial");
    for (FemElement3d elem : heart.getElements()) {
        elem.computeCentroid(centroid);
        // project to plane and compute radial direction
        plane.project(centroid, centroid);
        radialDir.sub(centroid, trans.p);
        radialDir.normalize();
        radialBundle.addElement(elem, radialDir);
    }
    radialBundle.setMuscleMaterial(muscleMat);
    heart.addMuscleBundle(radialBundle);
    // -------------------------------------------------------------
    // RIGID TABLE AND COLLISION
    // -------------------------------------------------------------
    // Create a rigid box for the heart to fall on
    RigidBody box = RigidBody.createBox("box", 0.2, 0.2, 0.02, 0, /*addnormals*/
    true);
    box.setPose(new RigidTransform3d(new Vector3d(0, 0, -0.2), AxisAngle.IDENTITY));
    box.setDynamic(false);
    mech.addRigidBody(box);
    // Enable collisions between the heart and table
    mech.setCollisionBehavior(heart, box, true);
    // -------------------------------------------------------------
    // RENDER PROPERTIES
    // -------------------------------------------------------------
    // Hide elements and nodes
    RenderProps.setVisible(heart.getElements(), false);
    RenderProps.setVisible(heart.getNodes(), false);
    RenderProps.setLineColor(radialBundle, Color.BLUE);
    RenderProps.setLineColor(longBundle, Color.RED);
    radialBundle.setDirectionRenderLen(0.1);
    longBundle.setDirectionRenderLen(0.1);
    RenderProps.setVisible(radialBundle, false);
    RenderProps.setVisible(longBundle, false);
    RenderProps.setVisible(heart.getSurfaceMeshComp(), false);
    // adjust table render properties
    RenderProps.setShading(box, Shading.METAL);
    RenderProps.setSpecular(box, new Color(0.8f, 0.8f, 0.8f));
    // adjust heart mesh render properties
    RenderProps rprops = embeddedHeart.getRenderProps();
    rprops.getBumpMap().setScaling(0.01f);
    // don't modify specular
    rprops.getColorMap().setSpecularColoring(false);
    rprops.setShading(Shading.SMOOTH);
    rprops.setFaceColor(new Color(0.8f, 0.8f, 0.8f));
    rprops.getColorMap().setColorMixing(ColorMixing.MODULATE);
    rprops.setSpecular(new Color(0.4f, 0.4f, 0.4f));
    rprops.setShininess(128);
    // -------------------------------------------------------------
    // INPUT PROBES
    // -------------------------------------------------------------
    // Add heart probe
    addHeartProbe(longBundle, radialBundle);
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) SimpleForceMuscle(artisynth.core.materials.SimpleForceMuscle) RigidTransform3d(maspack.matrix.RigidTransform3d) FemElement3d(artisynth.core.femmodels.FemElement3d) Plane(maspack.matrix.Plane) FemMeshComp(artisynth.core.femmodels.FemMeshComp) FemMaterial(artisynth.core.materials.FemMaterial) MuscleMaterial(artisynth.core.materials.MuscleMaterial) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) LinearMaterial(artisynth.core.materials.LinearMaterial) PolygonalMesh(maspack.geometry.PolygonalMesh) MechModel(artisynth.core.mechmodels.MechModel) MuscleBundle(artisynth.core.femmodels.MuscleBundle) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) FemMuscleModel(artisynth.core.femmodels.FemMuscleModel) RigidBody(artisynth.core.mechmodels.RigidBody) File(java.io.File)

Example 39 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class SpinControlProbe method build.

public void build(String[] args) {
    MechModel mech = new MechModel("mech");
    addModel(mech);
    // Create a parametrically controlled rigid body to spin:
    RigidBody body = RigidBody.createBox("box", 1.0, 1.0, 0.5, 1000.0);
    mech.addRigidBody(body);
    body.setDynamic(false);
    // Create a NumericControlProbe with size 1, initial spin data
    // with time step 2.0, start time 0, and stop time 8.
    NumericControlProbe spinProbe = new NumericControlProbe(/*vsize=*/
    1, new double[] { 0.0, 90.0, 0.0, -90.0, 0.0 }, 2.0, 0.0, 8.0);
    // set cubic interpolation for a smoother result
    spinProbe.setInterpolationOrder(Interpolation.Order.Cubic);
    // then set the data function:
    spinProbe.setDataFunction(new SpinFunction(body));
    addInputProbe(spinProbe);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) NumericControlProbe(artisynth.core.probes.NumericControlProbe) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 40 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class FullPlanarJointDemo method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    MechModel mech = (MechModel) models().get("mech");
    RigidBody lumbar1 = mech.rigidBodies().get("lumbar1");
    // constrain to mid-sagittal plane: medio-lateral direction is in world y-axis
    FullPlanarJoint planarJoint = new FullPlanarJoint(lumbar1, Vector3d.Y_UNIT);
    mech.addBodyConnector(planarJoint);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) FullPlanarJoint(artisynth.core.mechmodels.FullPlanarJoint) RigidBody(artisynth.core.mechmodels.RigidBody)

Aggregations

RigidBody (artisynth.core.mechmodels.RigidBody)55 MechModel (artisynth.core.mechmodels.MechModel)25 RigidTransform3d (maspack.matrix.RigidTransform3d)18 FrameMarker (artisynth.core.mechmodels.FrameMarker)11 RenderProps (maspack.render.RenderProps)11 Point3d (maspack.matrix.Point3d)10 PolygonalMesh (maspack.geometry.PolygonalMesh)9 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)8 Vector3d (maspack.matrix.Vector3d)8 FemModel3d (artisynth.core.femmodels.FemModel3d)7 FemNode3d (artisynth.core.femmodels.FemNode3d)7 SphericalJoint (artisynth.core.mechmodels.SphericalJoint)7 WayPoint (artisynth.core.probes.WayPoint)6 AxialSpring (artisynth.core.mechmodels.AxialSpring)5 Particle (artisynth.core.mechmodels.Particle)5 Color (java.awt.Color)5 CollisionManager (artisynth.core.mechmodels.CollisionManager)4 File (java.io.File)4 IOException (java.io.IOException)4 AxisAngle (maspack.matrix.AxisAngle)4