use of artisynth.core.femmodels.FemModel3d 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.femmodels.FemModel3d 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.femmodels.FemModel3d 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.femmodels.FemModel3d in project artisynth_core by artisynth.
the class FemModel3dAgent method handleLocationEvent.
public void handleLocationEvent(GLViewer viewer, MouseRayEvent rayEvent) {
Point3d isect;
if (myUsePlaneToggle.isSelected() && viewer.getNumClipPlanes() > 0) {
isect = intersectClipPlane(rayEvent.getRay(), viewer.getClipPlane(0));
} else {
isect = intersectViewPlane(rayEvent.getRay(), getCenter(new FemModel3d()), viewer);
}
positionField.setValue(isect);
}
use of artisynth.core.femmodels.FemModel3d in project artisynth_core by artisynth.
the class FemModel3dAgent method createPreviewModel.
private void createPreviewModel() {
fem = new FemModel3d();
setProperties(fem, getPrototypeComponent(myComponentType));
setProperties(myPrototype, myPrototype);
FemElementType elemType = null;
FemMeshType meshType = (FemMeshType) meshSelector.getValue();
if (elemSelector.isEnabledAll()) {
elemType = (FemElementType) elemSelector.getValue();
}
switch(meshType) {
case Grid:
{
VectorBase dims = gridDimField.getVectorValue();
int[] divs = gridDivField.getVectorValue();
FemFactory.createGrid(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
break;
}
case Tube:
{
VectorBase dims = tubeDimField.getVectorValue();
int[] divs = tubeDivField.getVectorValue();
FemFactory.createTube(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
break;
}
case Torus:
{
VectorBase dims = torusDimField.getVectorValue();
int[] divs = torusDivField.getVectorValue();
FemFactory.createTorus(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
break;
}
case Sphere:
{
int nodes = (Integer) sphereNodesField.getValue();
String meshPath;
if (nodes == SPHERE_NODE_OPTIONS[0]) {
meshPath = ArtisynthPath.getHomeRelativePath(SPHERE_54_MESH_PATH, ".");
} else if (nodes == SPHERE_NODE_OPTIONS[1]) {
meshPath = ArtisynthPath.getHomeRelativePath(SPHERE_196_MESH_PATH, ".");
} else {
EditorUtils.showError(myDisplay, "Invalid number of nodes for sphere");
return;
}
try {
TetGenReader.read(fem, 1000, meshPath + ".node", meshPath + ".ele", new Vector3d(1, 1, 1));
} catch (Exception e) {
EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
return;
}
break;
}
case Extrusion:
{
double d = extrusDepthField.getDoubleValue();
int n = extrusLayersField.getIntValue();
String meshFileName = extrusFileField.getStringValue();
try {
PolygonalMesh mesh = new PolygonalMesh(new File(meshFileName));
FemFactory.createExtrusion(fem, elemType, n, d, 0, mesh);
} catch (Exception e) {
EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
return;
}
break;
}
case AnsysMesh:
{
String nodeFileName = ansysNodeFileField.getStringValue();
String elemFileName = ansysElemFileField.getStringValue();
try {
AnsysReader.read(fem, nodeFileName, elemFileName, 1000, null, /*options=*/
0);
} catch (Exception e) {
EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
return;
}
break;
}
case TetgenMesh:
{
String nodeFileName = tetgenNodeFileField.getStringValue();
String eleFileName = tetgenEleFileField.getStringValue();
try {
TetGenReader.read(fem, 1000, nodeFileName, eleFileName, new Vector3d(1, 1, 1));
} catch (Exception e) {
EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
return;
}
break;
}
case UCDMesh:
{
String ucdFileName = ucdMeshFileField.getStringValue();
try {
UCDReader.read(fem, ucdFileName, 1000);
} catch (Exception e) {
EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
return;
}
break;
}
case SurfaceMesh:
{
String objFileName = surfaceMeshFileField.getStringValue();
PolygonalMesh surfaceMesh = null;
try {
surfaceMesh = new PolygonalMesh(new File(objFileName));
} catch (Exception e) {
EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
return;
}
try {
FemFactory.createFromMesh(fem, surfaceMesh, /*quality=*/
2.0);
} catch (Exception e) {
e.printStackTrace();
EditorUtils.showError(myDisplay, "Error tessellating mesh: " + e.getMessage());
return;
}
break;
}
default:
{
throw new InternalErrorException("Unimplemented mesh type");
}
}
RigidTransform3d X = new RigidTransform3d();
X.p.set(positionField.getVectorValue());
X.R.setAxisAngle(orientationField.getAxisAngleValue());
PolygonalMesh mesh = fem.getSurfaceMesh();
RenderProps props = mesh.createRenderProps();
props.setFaceStyle(Renderer.FaceStyle.NONE);
props.setDrawEdges(true);
props.setLineColor(Color.LIGHT_GRAY);
mesh.setRenderProps(props);
mesh.setMeshToWorld(X);
mesh.setFixed(false);
mesh.setRenderBuffered(false);
if (meshPropPanel.getComponentIndex(scaleField) != -1) {
scaleField.maskValueChangeListeners(true);
scaleField.setValue(1.0);
scaleField.maskValueChangeListeners(false);
lastScale = 1.0;
}
myMain.getWorkspace().getViewerManager().addRenderable(mesh);
rotator = new Transrotator3d();
GLViewer viewer = myMain.getMain().getViewer();
rotator.setDraggerToWorld(X);
rotator.setSize(viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6);
rotator.addListener(new FemModelDraggerListener());
myMain.getWorkspace().getViewerManager().addDragger(rotator);
myMain.rerender();
}
Aggregations