use of artisynth.core.mechmodels.CollisionManager in project artisynth_core by artisynth.
the class JointedCollide method build.
public void build(String[] args) {
super.build(args);
// allow bodyB to fall freely
bodyB.setDynamic(true);
// create and add the inclined plane
RigidBody base = RigidBody.createBox("base", 25, 25, 2, 0.2);
base.setPose(new RigidTransform3d(5, 0, 0, 0, 1, 0, -Math.PI / 8));
base.setDynamic(false);
mech.addRigidBody(base);
// turn on collisions
CollisionBehavior behav = new CollisionBehavior(true, 0);
// behav.setColliderType (ColliderType.SIGNED_DISTANCE);
CollisionManager cm = mech.getCollisionManager();
cm.setColliderType(ColliderType.SIGNED_DISTANCE);
mech.setDefaultCollisionBehavior(behav);
behav.setMethod(CollisionBehavior.Method.VERTEX_PENETRATION);
// turn on collisions
// mech.setDefaultCollisionBehavior (true, 0.20);
mech.setCollisionBehavior(bodyA, bodyB, false);
}
use of artisynth.core.mechmodels.CollisionManager in project artisynth_core by artisynth.
the class FemCollision method build.
public void build(String[] args) throws IOException {
try {
MechModel mechmod = new MechModel();
// mechmod.setIntegrator (Integrator.ConstrainedBackwardEuler);
mechmod.setIntegrator(Integrator.BackwardEuler);
// mechmod.setProfiling (true);
CollisionManager collisions = mechmod.getCollisionManager();
RenderProps.setVisible(collisions, true);
RenderProps.setEdgeWidth(collisions, 4);
RenderProps.setEdgeColor(collisions, Color.YELLOW);
RenderProps.setLineWidth(collisions, 3);
RenderProps.setLineColor(collisions, Color.GREEN);
collisions.setDrawContactNormals(true);
RigidBody table = new RigidBody("table");
table.setDynamic(false);
// table.setMesh (new PolygonalMesh (new File (rbpath+ "box.obj")), null);
table.setMesh(MeshFactory.createBox(2, 2, 2));
AffineTransform3d trans = new AffineTransform3d();
trans.setIdentity();
trans.applyScaling(4, 2, 0.5);
table.transformGeometry(trans);
table.setPose(new RigidTransform3d(new Vector3d(1, 0, 0.8077474533228615), new AxisAngle(1, 0, 0, Math.toRadians(mu == 0 ? 0.0 : 1.5))));
if (wireFrame) {
RenderProps.setFaceStyle(table, Renderer.FaceStyle.NONE);
RenderProps.setDrawEdges(table, true);
}
mechmod.addRigidBody(table);
if (incBox0) {
box0 = new RigidBody("box0");
// box0.setMesh (
// new PolygonalMesh (new File (rbpath + "box.obj")), null);
box0.setMesh(MeshFactory.createBox(2, 2, 2));
trans.setIdentity();
trans.applyScaling(1.5, 1.5, 0.5);
box0.transformGeometry(trans);
box0.setInertia(SpatialInertia.createBoxInertia(10000, 4, 4, 1));
box0.setPose(new RigidTransform3d(new Vector3d(-0.5, 0, 3.5), new AxisAngle()));
RenderProps.setFaceColor(box0, Color.GREEN.darker());
if (wireFrame) {
RenderProps.setFaceStyle(box0, Renderer.FaceStyle.NONE);
RenderProps.setDrawEdges(box0, true);
}
mechmod.addRigidBody(box0);
}
if (incFem0) {
String fem0Name = // "torus546";
"sphere2";
// "box0023";
// "box0048";
// "box0144";
// "box0604";
// "box1056";
// "box2463";
// "box4257";
fem0 = TetGenReader.read("fem0", 5000, fempath + fem0Name + ".1.node", fempath + fem0Name + ".1.ele", new Vector3d(0.8, 0.8, 0.8));
fem0.transformGeometry(new RigidTransform3d(new Vector3d(2, 0, 3.5), new AxisAngle()));
fem0.setLinearMaterial(1000000, 0.33, true);
if (!wireFrame)
fem0.setSurfaceRendering(SurfaceRender.Shaded);
fem0.setParticleDamping(0.1);
RenderProps.setFaceColor(fem0, new Color(0.5f, 0f, 0f));
// RenderProps.setAlpha(fem0, 0.33);
RenderProps.setAlpha(fem0, 0.5);
RenderProps.setShading(fem0, Shading.NONE);
RenderProps.setDrawEdges(fem0, true);
RenderProps.setVisible(fem0.getElements(), false);
RenderProps.setVisible(fem0.getNodes(), false);
// RenderProps.setLineColor(fem0, Color.GRAY);
mechmod.addModel(fem0);
}
if (incFem1) {
// Use this code for a box
/*
* double mySize = 1; fem1 = createFem (name, mySize);
* FemFactory.createTetGrid ( fem1, 1*mySize, 4*mySize, mySize, 1,
* 1, 1);
*/
// end box code
// Use this code for a ball
String fem1Name = "sphere2";
fem1 = TetGenReader.read("fem1", 5000, fempath + fem1Name + ".1.node", fempath + fem1Name + ".1.ele", new Vector3d(0.8, 0.8, 0.8));
fem1.setLinearMaterial(1000000, 0.33, true);
fem1.setParticleDamping(0.1);
// end ball code
fem1.setIncompressible(FemModel3d.IncompMethod.AUTO);
fem1.transformGeometry(new RigidTransform3d(new Vector3d(1.25, 0, 2), new AxisAngle()));
fem1.setSurfaceRendering(wireFrame ? SurfaceRender.None : SurfaceRender.Shaded);
RenderProps.setAlpha(fem1, 0.5);
RenderProps.setShading(fem1, Shading.NONE);
RenderProps.setDrawEdges(fem1, true);
RenderProps.setVisible(fem1.getElements(), false);
RenderProps.setVisible(fem1.getNodes(), false);
RenderProps.setFaceColor(fem1, new Color(0f, 0f, 0.8f));
mechmod.addModel(fem1);
}
if (incFem0) {
mechmod.setCollisionBehavior(fem0, table, true, mu);
mechmod.setCollisionResponse(fem0, Collidable.Deformable);
mechmod.setCollisionResponse(fem0, table);
}
if (incFem1 & incFem0) {
mechmod.setCollisionBehavior(fem0, fem1, true, mu);
}
if (incBox0 & incFem0) {
mechmod.setCollisionBehavior(box0, fem0, true, mu);
}
if (incFem1) {
mechmod.setCollisionBehavior(fem1, table, true, mu);
mechmod.setCollisionResponse(fem1, Collidable.AllBodies);
}
if (incBox0 & incFem1) {
mechmod.setCollisionBehavior(box0, fem1, true, mu);
}
if (incBox0) {
mechmod.setCollisionBehavior(box0, table, true, mu);
mechmod.setCollisionResponse(box0, table);
}
addModel(mechmod);
// mechmod.setIntegrator (Integrator.BackwardEuler);
// addBreakPoint (2.36);
// reset();
} catch (IOException e) {
throw e;
}
}
use of artisynth.core.mechmodels.CollisionManager in project artisynth_core by artisynth.
the class SimpleCollide method build.
public void build(String[] args) {
MechModel mechMod = new MechModel("mechModel");
mechMod.setMaxStepSize(0.01);
mechMod.setIntegrator(Integrator.ConstrainedBackwardEuler);
addModel(mechMod);
// for block/block friction test
// mySeparation = 1.09;
// mySeparation = .615;
CollisionManager cm = mechMod.getCollisionManager();
cm.setColliderType(ColliderType.SIGNED_DISTANCE);
cm.setDrawIntersectionContours(true);
RenderProps.setEdgeWidth(cm, 2);
RenderProps.setEdgeColor(cm, Color.YELLOW);
RenderProps.setVisible(cm, true);
setTopObject(ObjectType.FemEllipsoid);
setBottomObject(ObjectType.Box);
// for block/block friction test
// mechMod.transformGeometry (
// new RigidTransform3d (0, 0, 0, 0, 1, 0, Math.toRadians(20)));
mechMod.setProfiling(false);
ControlPanel panel = new ControlPanel("controls");
panel.addWidget(this, "topObject");
panel.addWidget(this, "bottomObject");
panel.addWidget(mechMod, "integrator");
panel.addWidget(this, "friction");
panel.addWidget(mechMod, "collisionManager:compliance");
panel.addWidget(mechMod, "collisionManager:damping");
addControlPanel(panel, 0);
// mechMod.transformGeometry (
// new RigidTransform3d (0, 0, 0, 0, 1, 0, Math.PI));
Main.getMain().arrangeControlPanels(this);
// panel.pack();
// panel.setVisible (true);
// java.awt.Point loc = Main.getMainFrame().getLocation();
// panel.setLocation(loc.x + Main.getMainFrame().getWidth(), loc.y);
// addControlPanel (panel);
NumericInputProbe iprobe = new NumericInputProbe(mechMod, "rigidBodies/bottomObject:targetOrientation", 0, 6);
// new NumericInputProbe (
// mechMod, "rigidBodies/bottomObject:targetPosition", 0, 6);
iprobe.addData(new double[] { 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 3, 0, 1, 0, 90, 5, 0, 1, 0, 180, 6, 0, 1, 0, 180 }, NumericInputProbe.EXPLICIT_TIME);
// iprobe.addData (
// new double[] { 0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 0, 0, 3, 0, 0,
// 2, 4, 0, 0, 0,},
// NumericInputProbe.EXPLICIT_TIME);
//
//
iprobe.setActive(true);
addInputProbe(iprobe);
addBreakPoint(1.34);
}
use of artisynth.core.mechmodels.CollisionManager in project artisynth_core by artisynth.
the class MechModelCollide method build.
public void build(String[] args) {
MechModel mechMod = new MechModel("mechMod");
// mechMod.setProfiling (true);
mechMod.setGravity(0, 0, -98);
// mechMod.setRigidBodyDamper (new FrameDamper (1.0, 4.0));
mechMod.setFrameDamping(1.0);
mechMod.setRotaryDamping(4.0);
RigidTransform3d XMB = new RigidTransform3d();
RigidTransform3d XLW = new RigidTransform3d();
RigidTransform3d TCA = new RigidTransform3d();
RigidTransform3d TCB = new RigidTransform3d();
RigidTransform3d XAB = new RigidTransform3d();
PolygonalMesh mesh;
// number of slices for approximating a circle
int nslices = 16;
// // set view so tha points upwards
// X.R.setAxisAngle (1, 0, 0, -Math.PI/2);
// viewer.setTransform (X);
double lenx0 = 30;
double leny0 = 30;
double lenz0 = 2;
RigidBody base = RigidBody.createBox("base", lenx0, leny0, lenz0, 0.2);
base.setDynamic(false);
mechMod.setDefaultCollisionBehavior(true, 0.20);
RenderProps props;
// first link
double lenx1 = 10;
double leny1 = 2;
double lenz1 = 3;
RigidBody link1 = new RigidBody("link1");
link1.setInertia(SpatialInertia.createBoxInertia(10, lenx1, leny1, lenz1));
mesh = MeshFactory.createRoundedBox(lenx1, leny1, lenz1, nslices / 2);
XMB.setIdentity();
XMB.R.setAxisAngle(1, 1, 1, 2 * Math.PI / 3);
mesh.transform(XMB);
// mesh.setRenderMaterial (Material.createSpecial (Material.GRAY));
link1.setMesh(mesh, /* fileName= */
null);
XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
// XLW.R.mulAxisAngle (0, 1, 0, Math.PI/4);
XLW.p.set(0, 0, 1.5 * lenx1);
link1.setPose(XLW);
mechMod.addRigidBody(link1);
// second link
double lenx2 = 10;
double leny2 = 2;
double lenz2 = 2;
RigidBody link2 = new RigidBody("link2");
if (// useSphericalJoint)
false) {
mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, nslices, /*nsegs=*/
1, /*flatBottom=*/
false);
link2.setInertia(SpatialInertia.createBoxInertia(10, leny2, leny2, lenx2));
XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
XLW.p.set(lenx1 / 2, lenx2 / 2, lenx1);
link2.setPose(XLW);
}
mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, nslices, /*nsegs=*/
1, /*flatBottom=*/
false);
mesh.transform(XMB);
link2.setInertia(SpatialInertia.createBoxInertia(10, lenx2, leny2, lenz2));
XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
XLW.p.set(lenx1 / 2 + lenx2 / 2, 0, 1.5 * lenx1);
if (useSphericalJoint) {
// Math.PI/4;
double ang = 0;
XLW.R.mulAxisAngle(0, 1, 0, ang);
XLW.p.y += Math.sin(ang) * lenx2 / 2;
XLW.p.x -= (1 - Math.cos(ang)) * lenx2 / 2;
}
link2.setPose(XLW);
link2.setMesh(mesh, /* fileName= */
null);
mechMod.addRigidBody(link2);
if (transparentLinks) {
RenderProps.setFaceStyle(link1, Renderer.FaceStyle.NONE);
RenderProps.setDrawEdges(link1, true);
RenderProps.setFaceStyle(link2, Renderer.FaceStyle.NONE);
RenderProps.setDrawEdges(link2, true);
}
BodyConnector joint2 = null;
// joint 2
if (useSphericalJoint) {
TCA.setIdentity();
TCA.p.set(-lenx2 / 2, 0, 0);
XAB.mulInverseLeft(link1.getPose(), link2.getPose());
TCB.mul(XAB, TCA);
SphericalJoint sjoint = new SphericalJoint(link2, TCA, link1, TCB);
// RevoluteJoint joint2 = new RevoluteJoint (link2, TCA, TCB);
sjoint.setName("joint2");
// RenderProps.setLineRadius(sjoint, 0.2);
sjoint.setAxisLength(4);
mechMod.addBodyConnector(sjoint);
joint2 = sjoint;
} else {
TCA.setIdentity();
TCA.p.set(-lenx2 / 2, 0, 0);
// TCA.R.mulAxisAngle (1, 0, 0, -Math.toRadians(90));
XAB.mulInverseLeft(link1.getPose(), link2.getPose());
TCB.mul(XAB, TCA);
RevoluteJoint rjoint = new RevoluteJoint(link2, TCA, link1, TCB);
rjoint.setName("joint2");
rjoint.setAxisLength(4);
RenderProps.setLineRadius(rjoint, 0.2);
mechMod.addBodyConnector(rjoint);
rjoint.setTheta(35);
joint2 = rjoint;
}
mechMod.transformGeometry(new RigidTransform3d(-5, 0, 10, 1, 1, 0, Math.toRadians(30)));
mechMod.addRigidBody(base);
mechMod.setCollisionBehavior(link1, link2, false);
CollisionManager cm = mechMod.getCollisionManager();
RenderProps.setVisible(cm, true);
RenderProps.setLineWidth(cm, 3);
RenderProps.setLineColor(cm, Color.RED);
cm.setDrawContactNormals(true);
mechMod.setPenetrationTol(1e-3);
// try {
// MechSystemSolver.setLogWriter (
// ArtisynthIO.newIndentingPrintWriter ("solve.txt"));
// }
// catch (Exception e) {
// }
addModel(mechMod);
// mechMod.setIntegrator (Integrator.ForwardEuler);
// addBreakPoint (0.51);
// mechMod.setProfiling (true);
addControlPanel(mechMod);
}
use of artisynth.core.mechmodels.CollisionManager in project artisynth_core by artisynth.
the class RigidBodyCollision method build.
public void build(String[] args) throws IOException {
try {
mechmod = new MechModel();
mechmod.setMaxStepSize(0.005);
boxes = new ArrayList<RigidBody>();
table = new RigidBody("table");
table.setDynamic(false);
table.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
AffineTransform3d trans = new AffineTransform3d();
trans.setIdentity();
trans.applyScaling(4, 2, 0.5);
table.transformGeometry(trans);
table.setPose(new RigidTransform3d(new Vector3d(0, 0, 0.8077474533228615), new AxisAngle()));
table.setInertia(SpatialInertia.createBoxInertia(1, 1, 1, 1));
mechmod.addRigidBody(table);
boxes.add(table);
if (wireFrame) {
setWireFrame(table);
}
// middle box in pile
box0 = new RigidBody("box0");
box0.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.5, 0.5, 0.5);
box0.transformGeometry(trans);
box0.setInertia(SpatialInertia.createBoxInertia(4, 1, 1, 1));
addBox(box0, Color.GREEN);
if (wireFrame) {
setWireFrame(box0);
}
// long thin box, bottom of pile
box1 = new RigidBody("box1");
box1.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.6, 0.1, 1.9);
box1.transformGeometry(trans);
box1.setInertia(SpatialInertia.createBoxInertia(1, 1, 0.1, 4));
addBox(box1, Color.YELLOW);
if (wireFrame) {
setWireFrame(box1);
}
// left hand box falling on unsupported end of
box2 = new RigidBody("box2");
// box1
box2.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.5, 0.5, 0.5);
box2.transformGeometry(trans);
box2.setInertia(SpatialInertia.createBoxInertia(20, 1, 1, 1));
addBox(box2, Color.BLUE);
if (wireFrame) {
setWireFrame(box2);
}
// top box in pile
box3 = new RigidBody("box3");
box3.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.4, 0.4, 0.4);
box3.transformGeometry(trans);
box3.setInertia(SpatialInertia.createBoxInertia(0.5, 0.5, 0.5, 4));
addBox(box3, Color.CYAN);
// box3.getMesh().name = "box3";
if (wireFrame) {
setWireFrame(box3);
}
// solo box off to the right.
box4 = new RigidBody("box4");
box4.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.6, 0.6, 0.3);
box4.transformGeometry(trans);
box4.setInertia(SpatialInertia.createBoxInertia(0.5, 0.5, 0.5, 4));
box4.setPose(new RigidTransform3d(new Vector3d(1, 0.0, 5), new AxisAngle(0, 0, 0, 0)));
addBox(box4, Color.RED);
// box4.getMesh().name = "box4";
if (wireFrame) {
setWireFrame(box4);
}
mechmod.setDefaultCollisionBehavior(true, 0.05);
reset();
addModel(mechmod);
ControlPanel panel = new ControlPanel();
panel.addWidget(mechmod, "integrator");
panel.addWidget(mechmod, "maxStepSize");
addControlPanel(panel);
Main.getMain().arrangeControlPanels(this);
CollisionManager cm = mechmod.getCollisionManager();
RenderProps.setVisible(cm, true);
RenderProps.setLineWidth(cm, 3);
RenderProps.setLineColor(cm, Color.RED);
cm.setDrawContactNormals(true);
// addBreakPoint (0.74);
for (int i = 1; i <= 10; i++) {
addWayPoint(0.1 * i);
}
// setWaypointChecking (true);
} catch (IOException e) {
throw e;
}
}
Aggregations