use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class FemBeamWithFemSphere method build.
public void build(String[] args) throws IOException {
// Build simple FemBeam
super.build(args);
// Create a FEM sphere
FemModel3d femSphere = new FemModel3d("sphere");
mech.addModel(femSphere);
// Read from TetGen file
TetGenReader.read(femSphere, ArtisynthPath.getSrcRelativePath(FemModel3d.class, "meshes/sphere2.1.node"), ArtisynthPath.getSrcRelativePath(FemModel3d.class, "meshes/sphere2.1.ele"));
femSphere.scaleDistance(0.22);
// FEM properties
femSphere.setDensity(10);
femSphere.setParticleDamping(2);
femSphere.setMaterial(new LinearMaterial(4000, 0.33));
// Reposition FEM to side of beam
femSphere.transformGeometry(new RigidTransform3d(length / 2 + width / 2, 0, 0));
// Attach sphere nodes that are inside beam
for (FemNode3d node : femSphere.getNodes()) {
// Find element containing node (if exists)
FemElement3d elem = fem.findContainingElement(node.getPosition());
// Add attachment if node is inside "fem"
if (elem != null) {
mech.attachPoint(node, elem);
}
}
// Set render properties
setRenderProps(femSphere);
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class FrameBodyAttachment method build.
public void build(String[] args) {
// create MechModel and add to RootModel
mech = new MechModel("mech");
mech.setGravity(0, 0, -98);
mech.setFrameDamping(1.0);
mech.setRotaryDamping(4.0);
addModel(mech);
// bodies will be defined using a mesh
PolygonalMesh mesh;
// create bodyB and set its pose
mesh = MeshFactory.createRoundedBox(lenx1, leny1, lenz1, /*nslices=*/
8);
RigidTransform3d TMB = new RigidTransform3d(0, 0, 0, /*axisAng=*/
1, 1, 1, 2 * Math.PI / 3);
mesh.transform(TMB);
bodyB = RigidBody.createFromMesh("bodyB", mesh, /*density=*/
0.2, 1.0);
bodyB.setPose(new RigidTransform3d(0, 0, 1.5 * lenx1, 1, 0, 0, Math.PI / 2));
// create bodyA and set its pose
mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, /*nslices=*/
16, /*nsegs=*/
1, /*flatBottom=*/
false);
mesh.transform(TMB);
bodyA = RigidBody.createFromMesh("bodyA", mesh, 0.2, 1.0);
bodyA.setPose(new RigidTransform3d((lenx1 + leny2) / 2, 0, 1.5 * lenx1, 0, Math.PI / 2, 0));
// create the joint
RigidTransform3d TDW = new RigidTransform3d(-lenx1 / 2, 0, 1.5 * lenx1, 1, 0, 0, Math.PI / 2);
RevoluteJoint joint = new RevoluteJoint(bodyB, TDW);
// add components to the mech model
mech.addRigidBody(bodyB);
mech.addRigidBody(bodyA);
mech.addBodyConnector(joint);
// set render properties for components
RenderProps.setLineRadius(joint, 0.2);
joint.setAxisLength(4);
// now connect bodyA to bodyB using a FrameAttachment
mech.attachFrame(bodyA, bodyB);
// create an auxiliary frame and add it to the mech model
Frame frame = new Frame();
mech.addFrame(frame);
// set the frames axis length > 0 so we can see it
frame.setAxisLength(4.0);
// set the attached frame's pose to that of bodyA ...
RigidTransform3d TFW = new RigidTransform3d(bodyA.getPose());
// ... plus a translation of lenx2/2 along the x axis:
TFW.mulXyz(lenx2 / 2, 0, 0);
// finally, attach the frame to bodyA
mech.attachFrame(frame, bodyA, TFW);
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class FrameFemAttachment method build.
public void build(String[] args) {
MechModel mech = new MechModel("mech");
addModel(mech);
// create and add FEM beam
FemModel3d fem = FemFactory.createHexGrid(null, 1.0, 0.2, 0.2, 6, 3, 3);
fem.setMaterial(new LinearMaterial(500000, 0.33));
RenderProps.setLineColor(fem, Color.BLUE);
RenderProps.setLineWidth(mech, 2);
mech.addModel(fem);
// fix leftmost nodes of the FEM
for (FemNode3d n : fem.getNodes()) {
if ((n.getPosition().x - (-0.5)) < 1e-8) {
n.setDynamic(false);
}
}
// create and add rigid body box
RigidBody box = RigidBody.createBox("box", 0.25, 0.1, 0.1, /*density=*/
1000);
mech.add(box);
// create a basic frame and and set its pose and axis length
Frame frame = new Frame();
frame.setPose(new RigidTransform3d(0.4, 0, 0, 0, Math.PI / 4, 0));
frame.setAxisLength(0.3);
mech.addFrame(frame);
// attach using element-based attachment
mech.attachFrame(frame, fem);
// attach the box to the FEM, using all the nodes of elements 31 and 32
HashSet<FemNode3d> nodes = collectNodes(fem, new int[] { 22, 31 });
FrameFem3dAttachment attachment = new FrameFem3dAttachment(box);
attachment.setFromNodes(box.getPose(), nodes);
mech.addAttachment(attachment);
// render the attachment nodes for the box as spheres
for (FemNode n : attachment.getNodes()) {
RenderProps.setSphericalPoints(n, 0.007, Color.GREEN);
}
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class PenetrationRender method build.
public void build(String[] args) {
MechModel mech = new MechModel("mech");
addModel(mech);
// create first body and set its rendering properties
RigidBody body0 = createHemiBody(mech, "body0", 2, -0.5, false);
RenderProps.setFaceStyle(body0, FaceStyle.FRONT_AND_BACK);
RenderProps.setFaceColor(body0, CREAM);
// create second body and set its pose and rendering properties
RigidBody body1 = createHemiBody(mech, "body1", 1, 2.0, true);
body1.setPose(new RigidTransform3d(0, 0, 0.75));
// set up
RenderProps.setFaceStyle(body1, FaceStyle.NONE);
// wireframe
RenderProps.setShading(body1, Shading.NONE);
// rendering
RenderProps.setDrawEdges(body1, true);
RenderProps.setEdgeColor(body1, GOLD);
// create and set a collision behavior between body0 and body1, and make
// collisions INACTIVE since we only care about graphical display
CollisionBehavior behav = new CollisionBehavior(true, 0);
behav.setMethod(CollisionBehavior.Method.INACTIVE);
// show penetration of mesh 0
behav.setDrawPenetrationDepth(0);
behav.getPenetrationDepthRange().setUpdating(ScalarRange.Updating.AUTO_FIT);
mech.setCollisionBehavior(body0, body1, behav);
CollisionManager cm = mech.getCollisionManager();
// penetration rendering only works with contour-based collisions
cm.setColliderType(ColliderType.AJL_CONTOUR);
// set other rendering properities in the collision manager:
// enable collision rendering
RenderProps.setVisible(cm, true);
// draw contours ...
cm.setDrawIntersectionContours(true);
// with a line width of 3
RenderProps.setEdgeWidth(cm, 3);
// and a blue color
RenderProps.setEdgeColor(cm, Color.BLUE);
// create a custom color map for rendering the penetration depth
JetColorMap map = new JetColorMap();
map.setColorArray(new Color[] { // no penetration
CREAM, createColor(255, 204, 153), createColor(255, 153, 102), createColor(255, 102, 51), createColor(255, 51, 0), // most penetration
createColor(204, 0, 0) });
cm.setColorMap(map);
// create a separate color bar to show depth values associated with the
// color map
ColorBar cbar = createColorBar();
cbar.setColorMap(map);
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class PenetrationRender method createHemiBody.
// Creates and returns a rigid body built from a hemispherical mesh. The
// body is centered at the origin, has a radius of 'rad', and the z axis is
// scaled by 'zscale'.
RigidBody createHemiBody(MechModel mech, String name, double rad, double zscale, boolean flipMesh) {
PolygonalMesh mesh = MeshFactory.createHemisphere(rad, /*slices=*/
20, /*levels=*/
10);
// scale mesh in the z direction
mesh.scale(1, 1, zscale);
if (flipMesh) {
// flip upside down is requested
mesh.transform(new RigidTransform3d(0, 0, 0, 0, 0, Math.PI));
}
RigidBody body = RigidBody.createFromMesh(name, mesh, /*density=*/
1000, /*scale=*/
1.0);
mech.addRigidBody(body);
// body is only parametrically controlled
body.setDynamic(false);
return body;
}
Aggregations