use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MeshColliderTest method testRegions.
boolean testRegions() {
PolygonalMesh mesh0 = MeshFactory.createBox(1, 1, 1);
PolygonalMesh mesh1 = MeshFactory.createBox(1, 1, 1);
mesh0.scale(0.9);
RigidTransform3d trans1 = new RigidTransform3d();
trans1.mulAxisAngle(new AxisAngle(0, 1, 0, Math.PI / 4));
trans1.mulAxisAngle(new AxisAngle(1, 0, 0, Math.PI / 4));
mesh1.setMeshToWorld(trans1);
MeshCollider collider = new MeshCollider();
// first way
ContactInfo info = collider.getContacts(mesh0, mesh1);
if (info == null) {
return false;
}
if (info.getContactPlanes().size() != 6) {
return false;
}
// second way
info = collider.getContacts(mesh1, mesh0);
if (info == null) {
return false;
}
if (info.getContactPlanes().size() != 6) {
return false;
}
return true;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MeshColliderTest method testVertexVertex.
boolean testVertexVertex() {
PolygonalMesh mesh0 = MeshFactory.createBox(1, 1, 1);
PolygonalMesh mesh1 = MeshFactory.createBox(1, 1, 1);
RigidTransform3d trans0 = new RigidTransform3d(new Vector3d(Math.sqrt(3), 0, 0), new AxisAngle());
trans0.mulAxisAngle(new AxisAngle(0, 1, 0, Math.atan(Math.sqrt(2))));
trans0.mulAxisAngle(new AxisAngle(1, 0, 0, Math.PI / 4));
mesh0.setMeshToWorld(trans0);
RigidTransform3d trans1 = new RigidTransform3d();
trans1.mulAxisAngle(new AxisAngle(0, 1, 0, Math.atan(Math.sqrt(2))));
trans1.mulAxisAngle(new AxisAngle(1, 0, 0, Math.PI / 4));
mesh1.setMeshToWorld(trans1);
MeshCollider collider = new MeshCollider();
// first way
ContactInfo info = collider.getContacts(mesh0, mesh1);
if (info == null) {
return false;
}
ArrayList<ContactPlane> regions = info.getContactPlanes();
if (regions.size() != 1) {
return false;
}
ContactPlane region = regions.get(0);
if (region.points.size() != 1)
return false;
if (!region.points.get(0).epsilonEquals(new Vector3d(Math.sqrt(3.0) / 2.0, 0, 0), epsilon))
return false;
if (!region.normal.epsilonEquals(new Vector3d(0.9994849337479609, 0, -0.03209154422638611), epsilon))
return false;
// second way
info = collider.getContacts(mesh1, mesh0);
if (info == null) {
return false;
}
regions = info.getContactPlanes();
if (regions.size() != 1)
return false;
region = regions.get(0);
if (region.points.size() != 1)
return false;
if (!region.points.get(0).epsilonEquals(new Vector3d(Math.sqrt(3.0) / 2.0, 0, 0), epsilon))
return false;
if (!region.normal.epsilonEquals(new Vector3d(-0.9994849337479609, 0, 0.03209154422638611), epsilon))
return false;
return true;
}
use of maspack.geometry.PolygonalMesh 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.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class NagataDistanceTest method main.
public static void main(String[] args) {
NagataDistanceTest tester = new NagataDistanceTest();
ArrayList<PolygonalMesh> meshes = new ArrayList<PolygonalMesh>();
// meshes.add (tester.myBaseMesh);
meshes.add(tester.myFineMesh);
MeshViewer frame = new MeshViewer(meshes, 640, 480);
frame.addRenderable(tester);
GLViewer viewer = frame.getViewer();
viewer.autoFitOrtho();
frame.setVisible(true);
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class VtkMeshToWavefrontConverter method convert.
public static void convert(String input, String output, NumberFormat fmt) {
PrintStream out = null;
// output stream
if (output == null) {
out = System.out;
} else {
try {
out = new PrintStream(output);
} catch (IOException e) {
e.printStackTrace();
return;
}
}
PolygonalMesh mesh;
try {
mesh = VtkXmlReader.read(input);
} catch (IOException e1) {
e1.printStackTrace();
return;
}
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");
out.println("# Exported OBJ file from '" + input + "', " + dateFormat.format(date));
out.println();
if (mesh != null) {
try {
mesh.write(new PrintWriter(out), fmt, false);
} catch (IOException e) {
e.printStackTrace();
return;
}
}
}
Aggregations