use of artisynth.core.femmodels.FemModel3d in project artisynth_core by artisynth.
the class FemCollision method createFem.
private FemModel3d createFem(String name, double mySize) {
double myDensity = 1000;
double myYoungsModulus = 100000;
double myPoissonsRatio = 0.33;
double myParticleDamping = 2.0;
double myStiffnessDamping = 0.002;
FemModel3d fem = new FemModel3d(name);
fem.setDensity(myDensity);
fem.setParticleDamping(myParticleDamping);
fem.setStiffnessDamping(myStiffnessDamping);
// fem.setPoissonsRatio (myPoissonsRatio);
// fem.setYoungsModulus (myYoungsModulus);
fem.setLinearMaterial(myYoungsModulus, myPoissonsRatio, true);
RenderProps.setPointStyle(fem, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(fem, mySize / 50);
return fem;
}
use of artisynth.core.femmodels.FemModel3d in project artisynth_core by artisynth.
the class FemSkinDemo method build.
public void build(String[] args) {
myMech = new MechModel("mech");
RenderProps.setPointStyle(myMech, Renderer.PointStyle.SPHERE);
double midw = 0.6;
FemModel3d femMod1 = createFem("fem1", midw, 0.2, 0.2);
FemModel3d femMod2 = createFem("fem2", midw, 0.2, 0.2);
// fix the leftmost nodes
LinkedList<FemNode3d> leftNodes1 = getLeftNodes(femMod1);
LinkedList<FemNode3d> rightNodes1 = getRightNodes(femMod1);
LinkedList<FemNode3d> leftNodes2 = getLeftNodes(femMod2);
LinkedList<FemNode3d> rightNodes2 = getRightNodes(femMod2);
RigidTransform3d X = new RigidTransform3d();
double wx = 0.1;
double wy = 0.3;
double wz = 0.3;
double transx = wx / 2 + 1.5 * midw;
RigidBody leftBody = createBlock("leftBlock", wx, wy, wz);
leftBody.setPose(new RigidTransform3d(-transx, 0, 0));
RigidTransform3d TCW = new RigidTransform3d();
TCW.p.set(-transx - wx / 2, 0, wz / 2);
TCW.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
RevoluteJoint joint = new RevoluteJoint(leftBody, TCW);
RenderProps.setLineRadius(joint, 0.01);
joint.setAxisLength(0.4);
myMech.addBodyConnector(joint);
RigidBody middleBody = createBlock("middleBlock", midw, 0.21, 0.21);
RigidBody rightBody = createBlock("rightBlock", wx, wy, wz);
rightBody.setPose(new RigidTransform3d(transx, 0, 0));
TCW.p.set(transx + wx / 2, 0, wz / 2);
TCW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
joint = new RevoluteJoint(rightBody, TCW);
RenderProps.setLineRadius(joint, 0.01);
joint.setAxisLength(0.4);
myMech.addBodyConnector(joint);
femMod1.transformGeometry(new RigidTransform3d(-midw, 0, 0));
femMod2.transformGeometry(new RigidTransform3d(midw, 0, 0));
for (FemNode3d n : leftNodes1) {
myMech.attachPoint(n, leftBody);
}
for (FemNode3d n : rightNodes1) {
myMech.attachPoint(n, middleBody);
}
for (FemNode3d n : leftNodes2) {
myMech.attachPoint(n, middleBody);
}
for (FemNode3d n : rightNodes2) {
myMech.attachPoint(n, rightBody);
}
PolygonalMesh mesh = MeshFactory.createRoundedCylinder(/*r=*/
0.3, /*h=*/
1.8, /*nsclices=*/
12, /*nsegs=*/
10, /*flatbotton=*/
false);
// flip aout y axis
mesh.transform(new RigidTransform3d(0, 0, 0, 0, Math.PI / 2, 0));
SkinMeshBody skinBody = new SkinMeshBody(mesh);
skinBody.addFrame(rightBody);
skinBody.addFrame(middleBody);
skinBody.addFrame(leftBody);
skinBody.addFemModel(femMod1);
skinBody.addFemModel(femMod2);
skinBody.computeWeights();
skinBody.setName("skin");
RenderProps.setDrawEdges(skinBody, true);
RenderProps.setFaceStyle(skinBody, Renderer.FaceStyle.NONE);
myMech.addMeshBody(skinBody);
addModel(myMech);
}
use of artisynth.core.femmodels.FemModel3d in project artisynth_core by artisynth.
the class ArticulatedFem method build.
public void build(String[] args) {
int nlinks = 3;
int nelemsx = 6;
int nelemsz = 2;
double femLength = 0.6;
double femHeight = 0.2;
double boxLength = 0.1;
double boxHeight = 0.3;
double linkLength = femLength + 2 * boxLength;
myMechMod = new MechModel("mech");
RigidTransform3d X = new RigidTransform3d();
RigidBody lastBox = null;
double linkCenter;
RigidBody leftAnchorBox = makeBox();
linkCenter = linkLength * (-nlinks / 2.0 + 0.5);
X.p.set(linkCenter - (boxLength + femLength) / 2, 0, boxHeight);
leftAnchorBox.setPose(X);
leftAnchorBox.setDynamic(false);
// myMechMod.addRigidBody (leftAnchorBox);
RigidBody rightAnchorBox = makeBox();
linkCenter = linkLength * (-nlinks / 2.0 + (nlinks - 1) + 0.5);
X.p.set(linkCenter + (boxLength + femLength) / 2, 0, boxHeight);
rightAnchorBox.setPose(X);
rightAnchorBox.setDynamic(false);
for (int i = 0; i < nlinks; i++) {
linkCenter = linkLength * (-nlinks / 2.0 + i + 0.5);
LinkedList<FemNode3d> leftNodes = new LinkedList<FemNode3d>();
LinkedList<FemNode3d> rightNodes = new LinkedList<FemNode3d>();
FemModel3d femMod = FemFactory.createTetGrid(null, femLength, femHeight, femHeight, nelemsx, nelemsz, nelemsz);
femMod.setDensity(myDensity);
femMod.setLinearMaterial(200000, 0.4, true);
femMod.setGravity(0, 0, -9.8);
double eps = 0.000001;
for (FemNode3d n : femMod.getNodes()) {
double x = n.getPosition().x;
if (x <= -femLength / 2 + eps) {
leftNodes.add(n);
} else if (x >= femLength / 2 - eps) {
rightNodes.add(n);
}
}
femMod.setStiffnessDamping(0.002);
RenderProps.setLineWidth(femMod.getElements(), 2);
RenderProps.setLineColor(femMod.getElements(), Color.BLUE);
RenderProps.setPointStyle(femMod.getNodes(), Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(femMod.getNodes(), 0.005);
femMod.setSurfaceRendering(SurfaceRender.Shaded);
RenderProps.setFaceColor(femMod, new Color(0f, 0.7f, 0.7f));
RenderProps.setLineColor(femMod.getElements(), new Color(0f, 0.2f, 0.2f));
RenderProps.setLineWidth(femMod.getElements(), 3);
X.p.set(linkCenter, 0, 0);
femMod.transformGeometry(X);
myMechMod.addModel(femMod);
RigidBody leftBox = makeBox();
X.p.set(linkCenter - (boxLength + femLength) / 2, 0, 0);
leftBox.setPose(X);
myMechMod.addRigidBody(leftBox);
RigidBody rightBox = makeBox();
X.p.set(linkCenter + (boxLength + femLength) / 2, 0, 0);
rightBox.setPose(X);
myMechMod.addRigidBody(rightBox);
for (FemNode3d n : leftNodes) {
myMechMod.attachPoint(n, leftBox);
}
for (FemNode3d n : rightNodes) {
myMechMod.attachPoint(n, rightBox);
}
RigidTransform3d TCA = new RigidTransform3d();
RigidTransform3d TCB = new RigidTransform3d();
RevoluteJoint joint;
TCA.p.set(-boxLength / 2, 0, boxHeight / 2);
TCA.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
if (lastBox == null) {
TCB.mul(leftBox.getPose(), TCA);
// TCB.mulInverseLeft (leftAnchorBox.getPose(), TCB);
joint = new RevoluteJoint(leftBox, TCA, TCB);
} else {
TCB.p.set(boxLength / 2, 0, boxHeight / 2);
TCB.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
joint = new RevoluteJoint(leftBox, TCA, lastBox, TCB);
}
RenderProps.setLineRadius(joint, 0.01);
RenderProps.setLineColor(joint, new Color(0.15f, 0.15f, 1f));
joint.setAxisLength(0.5);
myMechMod.addBodyConnector(joint);
if (addLastJoint && i == nlinks - 1) {
TCA.p.set(boxLength / 2, 0, boxHeight / 2);
TCB.mul(rightBox.getPose(), TCA);
// TCB.mulInverseLeft (rightAnchorBox.getPose(), TCB);
joint = new RevoluteJoint(rightBox, TCA, TCB);
RenderProps.setLineRadius(joint, 0.01);
RenderProps.setLineColor(joint, new Color(0.15f, 0.15f, 1f));
joint.setAxisLength(0.5);
myMechMod.addBodyConnector(joint);
}
lastBox = rightBox;
}
if (!addLastJoint) {
lastBox.setDynamic(false);
}
myMechMod.setIntegrator(Integrator.BackwardEuler);
addModel(myMechMod);
addControlPanel(myMechMod);
}
use of artisynth.core.femmodels.FemModel3d in project artisynth_core by artisynth.
the class LinearAuxiliaryTest method createCylinder.
FemModel3d createCylinder(double h, double r) {
FemModel3d fem = FemFactory.createCylinder(null, h, r, 24, 40, 4);
fem.setDensity(1000);
fem.setSurfaceRendering(SurfaceRender.Shaded);
RenderProps.setFaceColor(fem, Color.ORANGE);
RenderProps.setVisible(fem.getElements(), false);
double eps = 1e-10;
for (FemNode3d node : fem.getNodes()) {
if (node.getPosition().z < -h / 2 + eps) {
node.setDynamic(false);
}
}
return fem;
}
use of artisynth.core.femmodels.FemModel3d in project artisynth_core by artisynth.
the class LinearAuxiliaryTest method build.
@Override
public void build(String[] args) throws IOException {
super.build(args);
MechModel mech = new MechModel("mech");
addModel(mech);
double h = 0.1;
double r = 0.005;
LinearMaterial lmat = new LinearMaterial(50000, 0.45, true);
FemModel3d fem1 = createCylinder(h, r);
fem1.setName("auxiliary");
mech.addModel(fem1);
fem1.setMaterial(new NullMaterial());
AuxMaterialBundle bundle = new AuxMaterialBundle("mat");
for (FemElement3d elem : fem1.getElements()) {
bundle.addElement(new AuxMaterialElementDesc(elem));
}
fem1.addMaterialBundle(bundle);
bundle.setMaterial(lmat);
FemModel3d fem2 = createCylinder(h, r);
fem2.setName("linear");
fem2.setMaterial(lmat);
mech.addModel(fem2);
RigidTransform3d rot = new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_Y_90);
fem1.transformGeometry(rot);
fem2.transformGeometry(rot);
fem2.transformGeometry(new RigidTransform3d(new Vector3d(0, 2 * r, 0), AxisAngle.IDENTITY));
RenderProps.setFaceColor(fem2, Color.MAGENTA);
addMonitor(new StiffnessErrorMonitor(fem1, fem2));
}
Aggregations