use of artisynth.core.mechmodels.MechModel 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;
}
}
use of artisynth.core.mechmodels.MechModel in project artisynth_core by artisynth.
the class SegmentedPlaneDemo method build.
public void build(String[] args) {
// set up the mechmodel
MechModel mechMod = new MechModel("mechMod");
mechMod.setGravity(0, 0, -9.8);
mechMod.setFrameDamping(1.0);
mechMod.setRotaryDamping(4.0);
mechMod.setIntegrator(MechSystemSolver.Integrator.BackwardEuler);
// set up the rigid body and the plane constraint
double lenx = 10;
double leny = 5;
double lenz = 3;
RigidBody box = new RigidBody("box");
RigidTransform3d XBoxToWorld = new RigidTransform3d();
box.setInertia(SpatialInertia.createBoxInertia(10, lenx, leny, lenz));
PolygonalMesh mesh = MeshFactory.createBox(lenx, leny, lenz);
box.setMesh(mesh, /* fileName= */
null);
XBoxToWorld.p.set(0, 0, lenz / 2);
box.setPose(XBoxToWorld);
mechMod.addRigidBody(box);
// FrameMarker mkr = new FrameMarker (box, -5, 2.5, 1.5);
// mechMod.addFrameMarker (mkr);
// RenderProps props = mkr.createRenderProps();
// props.setPointColor (Color.blue);
// props.setPointStyle (RenderProps.PointStyle.SPHERE);
// props.setPointRadius (0.25);
// mkr.setRenderProps (props);
RigidTransform3d XPlanesToWorld = new RigidTransform3d();
// XPlanesToWorld.R.setAxisAngle(0,1,0,Math.PI);
SegmentedPlanarConnector segPlanes = new SegmentedPlanarConnector(box, new Vector3d(-5, 2.5, 1.5), XPlanesToWorld, new double[] { -6, 4, -3, 1, -1, 0, 1, 0, 3, 1, 6, 4 });
segPlanes.setUnilateral(true);
segPlanes.setPlaneSize(10);
RenderProps props = segPlanes.createRenderProps();
props.setPointColor(Color.blue);
props.setPointStyle(PointStyle.SPHERE);
props.setPointRadius(0.25);
segPlanes.setRenderProps(props);
// mechMod.addRigidBody (box);
mechMod.addBodyConnector(segPlanes);
addModel(mechMod);
addControlPanel(mechMod);
// AffineTransform3d X = new AffineTransform3d ();
// X.applyScaling (1, 1, 2);
// mechMod.transformGeometry (X);
// RigidTransform3d X = new RigidTransform3d (0, 0, 1.5);
// box.transformGeometry (X);
}
use of artisynth.core.mechmodels.MechModel in project artisynth_core by artisynth.
the class SpringMeshDemo method setCollision.
public void setCollision(boolean enable) {
if (models().size() > 0) {
MechModel model = (MechModel) models().getByNumber(0);
if (model.forceEffectors().size() > 0 && !enable) {
model.clearForceEffectors();
rerender();
} else if (model.forceEffectors().size() == 0 && enable) {
model.addForceEffector(getCollider(model));
rerender();
}
}
}
use of artisynth.core.mechmodels.MechModel 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());
}
use of artisynth.core.mechmodels.MechModel 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);
}
Aggregations