use of artisynth.core.mechmodels.MechModel 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);
}
use of artisynth.core.mechmodels.MechModel in project artisynth_core by artisynth.
the class FemBeamTest method build.
@Override
public void build(String[] args) throws IOException {
super.build(args);
mech = new MechModel("mech");
addModel(mech);
fems = new RenderableComponentList<>(FemModel3d.class);
FemModel3d tet = FemFactory.createTetGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
tet.setName("tet");
fems.add(tet);
FemModel3d pyr = FemFactory.createPyramidGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
pyr.setName("pyr");
fems.add(pyr);
FemModel3d wed = FemFactory.createWedgeGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
wed.setName("wed");
fems.add(wed);
FemModel3d hex = FemFactory.createHexGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
hex.setName("hex");
fems.add(hex);
FemModel3d qtet = FemFactory.createQuadtetGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
qtet.setName("qtet");
fems.add(qtet);
FemModel3d qpyr = FemFactory.createQuadpyramidGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
qpyr.setName("qpyr");
fems.add(qpyr);
FemModel3d qwed = FemFactory.createQuadwedgeGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
qwed.setName("qwed");
fems.add(qwed);
FemModel3d qhex = FemFactory.createQuadhexGrid(null, widthX, widthY, widthZ, numX, numY, numZ);
qhex.setName("qhex");
fems.add(qhex);
// freeze lhs nodes
double eps = 1e-10;
for (FemModel3d fem : fems) {
for (FemNode3d node : fem.getNodes()) {
if (node.getRestPosition().x < -widthX / 2 + eps) {
node.setDynamic(false);
}
}
}
// distribute
double delta = widthY * 0.25;
RigidTransform3d translate = new RigidTransform3d();
for (FemModel3d fem : fems) {
fem.transformGeometry(translate);
translate.p.y += widthY + delta;
}
mech.add(fems);
// render properties
int nfems = fems.size();
int ifem = 0;
for (FemModel3d fem : fems) {
fem.setSurfaceRendering(SurfaceRender.Shaded);
float h = (float) ifem / nfems;
RenderProps.setFaceColor(fem, Color.getHSBColor(h, 1.0f, 1.0f));
++ifem;
}
setMaterial(createDefaultMaterial());
}
use of artisynth.core.mechmodels.MechModel 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);
}
use of artisynth.core.mechmodels.MechModel in project artisynth_core by artisynth.
the class JointedFemBeams method build.
public void build(String[] args) {
MechModel mech = new MechModel("mechMod");
addModel(mech);
double stiffness = 5000;
// create first fem beam and fix the leftmost nodes
FemModel3d fem1 = addFem(mech, 2.4, 0.6, 0.4, stiffness);
for (FemNode3d n : fem1.getNodes()) {
if (n.getPosition().x <= -1.2) {
n.setDynamic(false);
}
}
// create the second fem beam and shift it 1.5 to the right
FemModel3d fem2 = addFem(mech, 2.4, 0.4, 0.4, 0.1 * stiffness);
fem2.transformGeometry(new RigidTransform3d(1.5, 0, 0));
// create a slotted revolute joint that connects the two fem beams
RigidTransform3d TDW = new RigidTransform3d(0.5, 0, 0, 0, 0, Math.PI / 2);
SlottedRevoluteJoint joint = new SlottedRevoluteJoint(fem2, fem1, TDW);
mech.addBodyConnector(joint);
// set ranges and rendering properties for the joint
joint.setAxisLength(0.8);
joint.setMinX(-0.5);
joint.setMaxX(0.5);
joint.setSlotWidth(0.61);
RenderProps.setLineColor(joint, myJointColor);
RenderProps.setLineWidth(joint, 3);
RenderProps.setLineRadius(joint, 0.04);
}
use of artisynth.core.mechmodels.MechModel in project artisynth_core by artisynth.
the class PenetrationRendererDemo method build.
public void build(String[] args) {
// create MechModel and add to RootModel
MechModel mech = new MechModel("mech");
addModel(mech);
// create and add the ball and plate
RigidBody ball = RigidBody.createIcosahedralSphere("ball", 0.8, 0.1, 1);
// ball.setPose (new RigidTransform3d (0, 0, 2, 0.4, 0.1, 0.1));
ball.setPose(new RigidTransform3d(0, 0, 0, 0.4, 0.1, 0.1));
ball.setDynamic(false);
mech.addRigidBody(ball);
RigidBody plate = RigidBody.createBox("plate", 5, 5, 5, 1);
plate.setPose(new RigidTransform3d(0, 0, 2.94, 1, 0, 0, 0));
plate.setDynamic(false);
mech.addRigidBody(plate);
// turn on collisions
mech.setDefaultCollisionBehavior(true, 0.20);
// make ball transparent so that contacts can be seen more clearly
RenderProps.setFaceStyle(ball, Renderer.FaceStyle.NONE);
RenderProps.setDrawEdges(ball, true);
RenderProps.setEdgeColor(ball, Color.WHITE);
RenderProps.setVisible(plate, false);
RenderProps.setAlpha(plate, 0.5);
// enable rendering of contacts normals and contours
CollisionManager cm = mech.getCollisionManager();
RenderProps.setVisible(cm, true);
RenderProps.setLineWidth(cm, 3);
RenderProps.setLineColor(cm, Color.RED);
RenderProps.setEdgeWidth(cm, 3);
RenderProps.setEdgeColor(cm, Color.BLUE);
cm.setContactNormalLen(0.5);
cm.setDrawContactNormals(true);
cm.setDrawIntersectionContours(true);
cm.setDrawIntersectionFaces(true);
cm.setDrawIntersectionPoints(true);
CollisionResponse resp = mech.setCollisionResponse(ball, plate);
addMonitor(new PenetrationRenderer(resp));
}
Aggregations