Search in sources :

Example 6 with PolygonalMesh

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;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 7 with PolygonalMesh

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;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 8 with PolygonalMesh

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);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) Frame(artisynth.core.mechmodels.Frame) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 9 with PolygonalMesh

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);
}
Also used : GLViewer(maspack.render.GL.GLViewer) ArrayList(java.util.ArrayList) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 10 with PolygonalMesh

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;
        }
    }
}
Also used : PrintStream(java.io.PrintStream) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

PolygonalMesh (maspack.geometry.PolygonalMesh)128 Point3d (maspack.matrix.Point3d)30 Vertex3d (maspack.geometry.Vertex3d)24 Vector3d (maspack.matrix.Vector3d)23 RigidTransform3d (maspack.matrix.RigidTransform3d)21 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 File (java.io.File)14 Face (maspack.geometry.Face)14 ContactPoint (artisynth.core.mechmodels.ContactPoint)11 Point (artisynth.core.mechmodels.Point)11 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)10 Color (java.awt.Color)10 MeshBase (maspack.geometry.MeshBase)10 RigidBody (artisynth.core.mechmodels.RigidBody)9 MechModel (artisynth.core.mechmodels.MechModel)8 BufferedReader (java.io.BufferedReader)8 AxisAngle (maspack.matrix.AxisAngle)8 RenderProps (maspack.render.RenderProps)8 HashMap (java.util.HashMap)7