Search in sources :

Example 1 with FrameMarker

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

the class RigidBodyEditor method applyAction.

public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
    if (containsMultipleSelection(selection, RigidBody.class)) {
        if (actionCommand == "Select markers") {
            LinkedList<ModelComponent> list = (LinkedList<ModelComponent>) selection.clone();
            for (ModelComponent c : list) {
                FrameMarker[] mkrs = ((RigidBody) c).getFrameMarkers();
                for (int i = 0; i < mkrs.length; i++) {
                    myMain.getSelectionManager().addSelected(mkrs[i]);
                }
                myMain.getSelectionManager().removeSelected(c);
            }
        }
        if (containsSingleSelection(selection, RigidBody.class)) {
            if (actionCommand == "Edit geometry and inertia ...") {
                if (myEditManager.acquireEditLock()) {
                    RigidBody body = (RigidBody) selection.get(0);
                    RigidBodyGeometryAgent agent = new RigidBodyGeometryAgent(myMain, body);
                    agent.show(popupBounds);
                }
            } else if (actionCommand == "Save mesh as ...") {
                RigidBody body = (RigidBody) selection.get(0);
                PolygonalMesh mesh = body.getMesh();
                EditorUtils.saveMesh(mesh, mesh != null ? mesh.getMeshToWorld() : null);
            } else if (actionCommand == "Attach particles ...") {
                if (myEditManager.acquireEditLock()) {
                    RigidBody body = (RigidBody) selection.get(0);
                    // XXX should be more general than this ... what if mechModel
                    // is a sub model?
                    MechModel mech = (MechModel) body.getGrandParent();
                    myMain.getSelectionManager().clearSelections();
                    AttachParticleBodyAgent agent = new AttachParticleBodyAgent(myMain, mech, body);
                    agent.show(popupBounds);
                }
            } else if (actionCommand == "Add mesh inspector") {
                RigidBody body = (RigidBody) selection.get(0);
                MechModel mech = (MechModel) body.getGrandParent();
                EditablePolygonalMeshComp editMesh = new EditablePolygonalMeshComp(body.getSurfaceMesh());
                double size = RenderableUtils.getRadius(editMesh);
                RenderProps.setVisible(editMesh, true);
                RenderProps.setPointStyle(editMesh, Renderer.PointStyle.SPHERE);
                RenderProps.setPointRadius(editMesh, 0.05 * size);
                mech.addRenderable(editMesh);
            }
        }
    }
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) EditablePolygonalMeshComp(artisynth.core.renderables.EditablePolygonalMeshComp) FrameMarker(artisynth.core.mechmodels.FrameMarker) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 2 with FrameMarker

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

the class ForceTargetDemo method build.

public void build(String[] args) throws IOException {
    // create MechModel and add to RootModel
    mech = new MechModel("mech");
    addModel(mech);
    // create the components
    p1 = new Particle("p1", /*mass=*/
    2, /*x,y,z=*/
    0, 0, 0.15);
    p2 = new Particle("p2", 2, 10, 0, 0.15);
    p3 = new Particle("p3", 2, 5, 5, 0);
    p4 = new Particle("p4", 2, 5, -5, 0);
    p5 = new Particle("p5", 0, 5, 0, 5);
    p6 = new Particle("p6", 0, 5, 0, -5);
    box = RigidBody.createBox("box", /*wx,wy,wz=*/
    0.5, 0.3, 0.3, /*density=*/
    1);
    box.setPose(new RigidTransform3d(/*x,y,z=*/
    5, 0, -0.15));
    // create marker point and connect it to the box:
    FrameMarker mkr = new FrameMarker(/*x,y,z=*/
    0, 0, 0.15);
    mkr.setFrame(box);
    // create the muscle:
    muscle = new Muscle("mus1", /*restLength=*/
    5);
    muscle.setPoints(p1, mkr);
    muscle.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
    0, /*damping=*/
    10, /*maxf=*/
    1000));
    muscle2 = new Muscle("mus2", /*restLength=*/
    5);
    muscle2.setPoints(p2, mkr);
    muscle2.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
    0, /*damping=*/
    10, /*maxf=*/
    1000));
    muscle3 = new Muscle("mus3", /*restLength=*/
    5);
    muscle3.setPoints(p3, mkr);
    muscle3.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
    0, /*damping=*/
    10, /*maxf=*/
    4000));
    muscle4 = new Muscle("mus4", /*restLength=*/
    5);
    muscle4.setPoints(p4, mkr);
    muscle4.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
    0, /*damping=*/
    10, /*maxf=*/
    4000));
    muscle5 = new Muscle("mus5", /*restLength=*/
    5);
    muscle5.setPoints(p5, mkr);
    muscle5.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
    0, /*damping=*/
    10, /*maxf=*/
    4000));
    muscle6 = new Muscle("mus6", /*restLength=*/
    5);
    muscle6.setPoints(p6, mkr);
    muscle6.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
    0, /*damping=*/
    10, /*maxf=*/
    4000));
    if (two_cons == true) {
        RigidTransform3d XPW = new RigidTransform3d(5, 0, 0);
        XPW.R.mulAxisAngle(1, 0, 0, Math.toRadians(90));
        // Connection on the corner
        // PlanarConnector connector =
        // new PlanarConnector (box, new Vector3d (lenx/2, -2.5, 1.5), XPW);
        // Connection in the center
        con = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW);
        con.setUnilateral(false);
        con.setPlaneSize(2);
        RenderProps props = con.createRenderProps();
        props.setPointColor(Color.blue);
        props.setPointStyle(Renderer.PointStyle.SPHERE);
        props.setPointRadius(0.06);
        con.setRenderProps(props);
        // con = new ParticlePlaneConstraint(p5, pl);
        // RenderProps.setDrawEdges (con, true);
        // RenderProps.setVisible (con, true);
        RigidTransform3d XPW2 = new RigidTransform3d(5, 0, 0);
        XPW2.R.mulAxisAngle(1, 0, 0, 0);
        // Connection on the corner
        // PlanarConnector connector =
        // new PlanarConnector (box, new Vector3d (lenx/2, -2.5, 1.5), XPW);
        // Connection in the center
        con2 = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW2);
        con2.setUnilateral(false);
        con2.setPlaneSize(2);
        con2.setRenderProps(props);
    } else {
        RigidTransform3d XPW = new RigidTransform3d(5, 0, 0);
        XPW.R.mulAxisAngle(1, 0, 0, Math.toRadians(45));
        con = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW);
        con.setUnilateral(false);
        con.setPlaneSize(2);
        RenderProps props = con.createRenderProps();
        props.setPointColor(Color.blue);
        props.setPointStyle(Renderer.PointStyle.SPHERE);
        props.setPointRadius(0.06);
        con.setRenderProps(props);
    }
    // con.setRenderProps (myRenderProps);
    // add components to the mech model
    mech.addParticle(p1);
    mech.addParticle(p2);
    mech.addParticle(p3);
    mech.addParticle(p4);
    mech.addParticle(p5);
    mech.addParticle(p6);
    mech.addRigidBody(box);
    mech.addFrameMarker(mkr);
    // mech.addParticle (p5);
    mech.addAxialSpring(muscle);
    mech.addAxialSpring(muscle2);
    mech.addAxialSpring(muscle3);
    mech.addAxialSpring(muscle4);
    mech.addAxialSpring(muscle5);
    mech.addAxialSpring(muscle6);
    con.setName("con1");
    if (two_cons == true) {
        con2.setName("con2");
    }
    if (cons == true) {
        mech.addBodyConnector(con);
        ConnectorForceRenderer rend = new ConnectorForceRenderer(con);
        myRenderProps = rend.createRenderProps();
        myRenderProps.setLineStyle(LineStyle.CYLINDER);
        myRenderProps.setLineRadius(0.175);
        myRenderProps.setLineColor(Color.BLUE);
        rend.setRenderProps(myRenderProps);
        rend.setArrowSize(0.1);
        addMonitor(rend);
    }
    if (two_cons == true) {
        mech.addBodyConnector(con2);
    }
    // first particle set to be fixed
    p1.setDynamic(false);
    p2.setDynamic(false);
    p3.setDynamic(false);
    p4.setDynamic(false);
    p5.setDynamic(false);
    p6.setDynamic(false);
    // increase model bounding box for the viewer
    mech.setBounds(/*min=*/
    -1, 0, -1, /*max=*/
    1, 0, 0);
    // set render properties for the components
    setPointRenderProps(p1);
    setPointRenderProps(p2);
    setPointRenderProps(p3);
    setPointRenderProps(p4);
    setPointRenderProps(p5);
    setPointRenderProps(p6);
    setPointRenderProps(mkr);
    setLineRenderProps(muscle);
    setLineRenderProps(muscle2);
    setLineRenderProps(muscle3);
    setLineRenderProps(muscle4);
    setLineRenderProps(muscle5);
    setLineRenderProps(muscle6);
    addTrackingController(mkr);
    if (cons = true) {
        addConForceProbe(10, 0.1);
    }
}
Also used : Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) ConnectorForceRenderer(artisynth.core.inverse.ConnectorForceRenderer) FrameMarker(artisynth.core.mechmodels.FrameMarker) Vector3d(maspack.matrix.Vector3d) PlanarConnector(artisynth.core.mechmodels.PlanarConnector) RenderProps(maspack.render.RenderProps) SimpleAxialMuscle(artisynth.core.materials.SimpleAxialMuscle) Muscle(artisynth.core.mechmodels.Muscle) SimpleAxialMuscle(artisynth.core.materials.SimpleAxialMuscle)

Example 3 with FrameMarker

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

the class PointModel method addCenter.

public void addCenter() {
    RigidBody body = new RigidBody("body");
    body.setInertia(SpatialInertia.createSphereInertia(mass, len / 25));
    model.addRigidBody(body);
    RenderProps.setVisible(body, false);
    RigidBody fixed = new RigidBody("fixed");
    fixed.setInertia(SpatialInertia.createSphereInertia(mass, len / 25));
    fixed.setDynamic(false);
    model.addRigidBody(fixed);
    RenderProps.setVisible(fixed, false);
    if (useReactionForceTargetP) {
        // add spherical joint for reaction force target testing
        SphericalJoint joint = new SphericalJoint(body, fixed, Point3d.ZERO);
        joint.setName("center_constraint");
        model.addBodyConnector(joint);
        addMonitor(new ConnectorForceRenderer(joint));
    }
    center = new FrameMarker();
    center.setName("center");
    center.setPointDamping(pointDamping);
    model.addFrameMarker(center, body, Point3d.ZERO);
}
Also used : SphericalJoint(artisynth.core.mechmodels.SphericalJoint) ConnectorForceRenderer(artisynth.core.inverse.ConnectorForceRenderer) FrameMarker(artisynth.core.mechmodels.FrameMarker) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 4 with FrameMarker

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

the class DoubleArmDemo method addEndPoint.

public void addEndPoint() {
    RigidBody thirdArm = model.rigidBodies().get("third");
    if (thirdArm == null) {
        return;
    }
    FrameMarker endPoint = new FrameMarker();
    endPoint.setName("endPoint");
    endPoint.setFrame(thirdArm);
    endPoint.setLocation(new Point3d(0, 0, len / 2));
    model.addFrameMarker(endPoint);
    // lowerArm.addMarker(endPoint);
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setShading(Renderer.Shading.SMOOTH);
    rp.setPointColor(Color.ORANGE);
    rp.setPointRadius(len / 20);
    endPoint.setRenderProps(rp);
}
Also used : FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 5 with FrameMarker

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

the class DoubleArmDemo method addMuscles.

public void addMuscles() {
    RigidBody upperArm = model.rigidBodies().get("upper");
    RigidBody lowerArm = model.rigidBodies().get("lower");
    RigidBody thirdArm = model.rigidBodies().get("third");
    if (upperArm == null || lowerArm == null || thirdArm == null) {
        return;
    }
    Point3d markerBodyPos = new Point3d(-size.x / 2, 0, (size.z / 2.0) / 1.2);
    FrameMarker u = new FrameMarker();
    model.addFrameMarker(u, upperArm, markerBodyPos);
    u.setName("upperAttachment");
    markerBodyPos = new Point3d(size.x / 2, 0, (size.z / 2.0) / 1.2);
    FrameMarker tu = new FrameMarker();
    model.addFrameMarker(tu, thirdArm, markerBodyPos);
    tu.setName("thirdUpperAttachment");
    markerBodyPos = new Point3d(size.x / 2, 0, -(size.z / 2.0) / 2);
    FrameMarker l = new FrameMarker();
    model.addFrameMarker(l, lowerArm, markerBodyPos);
    l.setName("lowerAttachment");
    markerBodyPos = new Point3d(size.x / 2, 0, (size.z / 2.0) / 2);
    FrameMarker tl = new FrameMarker();
    model.addFrameMarker(tl, lowerArm, markerBodyPos);
    tl.setName("thirdLowerAttachment");
    Muscle muscle = new Muscle("muscle");
    muscle.setPeckMuscleMaterial(20.0, 22.0, 30, 0.2, 0.5, 0.1);
    Muscle muscle2 = new Muscle("muscle2");
    muscle2.setPeckMuscleMaterial(8, 20, 30, 0.2, 0.5, 0.1);
    muscle.setFirstPoint(u);
    muscle2.setFirstPoint(tu);
    muscle.setSecondPoint(l);
    muscle2.setSecondPoint(tl);
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setLineStyle(Renderer.LineStyle.SPINDLE);
    rp.setLineRadius(len / 20);
    // rp.setLineSlices(10);
    rp.setShading(Renderer.Shading.SMOOTH);
    rp.setLineColor(Color.RED);
    muscle.setRenderProps(rp);
    muscle2.setRenderProps(rp);
    model.addAxialSpring(muscle);
    model.addAxialSpring(muscle2);
    if (addCompression) {
        markerBodyPos = new Point3d(size.x / 2, 0, +size.z / 2.0);
        FrameMarker l2 = new FrameMarker();
        model.addFrameMarker(l2, lowerArm, markerBodyPos);
        l2.setName("lowerAttachmentCompressor");
        double len = u.getPosition().distance(l2.getPosition());
        AxialSpring s = new AxialSpring(10, 0, 50);
        s.setFirstPoint(u);
        s.setSecondPoint(l2);
        model.addAxialSpring(s);
        RenderProps props = new RenderProps();
        props.setLineStyle(Renderer.LineStyle.CYLINDER);
        props.setLineRadius(0.0);
        s.setRenderProps(props);
        // restoring spring
        len = tu.getPosition().distance(tl.getPosition());
        s = new AxialSpring(10, 0, 2 * len);
        s.setFirstPoint(tu);
        s.setSecondPoint(tl);
        model.addAxialSpring(s);
        s.setRenderProps(props);
    }
}
Also used : FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) Muscle(artisynth.core.mechmodels.Muscle) RigidBody(artisynth.core.mechmodels.RigidBody) AxialSpring(artisynth.core.mechmodels.AxialSpring)

Aggregations

FrameMarker (artisynth.core.mechmodels.FrameMarker)14 RigidBody (artisynth.core.mechmodels.RigidBody)11 Point3d (maspack.matrix.Point3d)9 MechModel (artisynth.core.mechmodels.MechModel)6 RenderProps (maspack.render.RenderProps)6 AxialSpring (artisynth.core.mechmodels.AxialSpring)4 Particle (artisynth.core.mechmodels.Particle)4 RigidTransform3d (maspack.matrix.RigidTransform3d)4 Muscle (artisynth.core.mechmodels.Muscle)3 PlanarConnector (artisynth.core.mechmodels.PlanarConnector)3 ConnectorForceRenderer (artisynth.core.inverse.ConnectorForceRenderer)2 SphericalJoint (artisynth.core.mechmodels.SphericalJoint)2 WayPoint (artisynth.core.probes.WayPoint)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 Vector3d (maspack.matrix.Vector3d)2 LinearAxialMuscle (artisynth.core.materials.LinearAxialMuscle)1 SimpleAxialMuscle (artisynth.core.materials.SimpleAxialMuscle)1 BodyConnector (artisynth.core.mechmodels.BodyConnector)1 Frame (artisynth.core.mechmodels.Frame)1 MultiPointMuscle (artisynth.core.mechmodels.MultiPointMuscle)1