Search in sources :

Example 11 with RigidTransform3d

use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.

the class SpecularTest method createMesh.

FixedMeshBody createMesh(MechModel mech, double z) {
    PolygonalMesh mesh = MeshFactory.createRectangle(3, 1, 20, 20, /*texture=*/
    true);
    FixedMeshBody body = new FixedMeshBody(mesh);
    mech.addMeshBody(body);
    body.setPose(new RigidTransform3d(0, 0, z, 0, 0, Math.PI / 2));
    return body;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FixedMeshBody(artisynth.core.mechmodels.FixedMeshBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 12 with RigidTransform3d

use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.

the class PointFemAttachment method addFem.

// create an FEM beam model, translate it to (x,y,z), fix the leftmost
// nodes, and add it to a mech model
private FemModel3d addFem(MechModel mech, double x, double y, double z) {
    FemModel3d fem = FemFactory.createHexGrid(null, 1.0, 0.2, 0.2, 10, 3, 3);
    fem.setMaterial(new NeoHookeanMaterial());
    // RenderProps.setSphericalPoints (fem, 0.005, Color.GREEN);
    RenderProps.setLineColor(fem, Color.BLUE);
    RenderProps.setLineWidth(fem, 2);
    mech.addModel(fem);
    fem.transformGeometry(new RigidTransform3d(x, y, z));
    // find and fix the leftmost elements:
    PointList<FemNode3d> nodes = fem.getNodes();
    for (int i = 0; i < nodes.size(); i++) {
        FemNode3d n = nodes.get(i);
        if (Math.abs(n.getPosition().x - (-0.5 + x)) < 1e-8) {
            n.setDynamic(false);
        }
    }
    return fem;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) NeoHookeanMaterial(artisynth.core.materials.NeoHookeanMaterial)

Example 13 with RigidTransform3d

use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.

the class MeshFactory method createOpenQuadCylinder.

/**
 * Creates an open quad cylindrical mesh centered on the origin with the
 * main axis aligned with the z axis. All faces are quads.
 *
 * @param r outer radius of the cylinder
 * @param h height of the cylinder
 * @param nslices number of segments about the z axis
 * @param nh number of height segments along the z axis
 */
public static PolygonalMesh createOpenQuadCylinder(double r, double h, int nslices, int nh) {
    if (nslices < 3) {
        throw new IllegalArgumentException("argument nslices must be at least 3");
    }
    // set map tolerance to be 0.01 times smallest spacing between vertices
    double tol = Math.min(0.01 * h / nh, 0.01 * r * Math.sin(2 * Math.PI / nslices));
    VertexMap vtxMap = new VertexMap(tol);
    PolygonalMesh mesh = new PolygonalMesh();
    RigidTransform3d XLM = new RigidTransform3d();
    addQuadCylindricalSection(mesh, r, h, 2 * Math.PI, nh, nslices, /*outward=*/
    true, XLM, vtxMap);
    return mesh;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d)

Example 14 with RigidTransform3d

use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.

the class MeshFactory method createBox.

/**
 * Creates a box mesh, with a specified mesh resolution in each direction,
 * and centered at a defined center point. The faces type is specified
 * by <code>faceType</code>
 *
 * @param wx width in the x direction
 * @param wy width in the y direction
 * @param wz width in the z direction
 * @param center center of the box
 * @param nx number of subdivisions along x
 * @param ny number of subdivisions along y
 * @param nz number of subdivisions along z
 * @param addNormals if <code>true</code>, generates normals perpendicular
 * to each side
 * @param faceType specifies the face type to be either quads, triangles,
 * or triangles with alternating diagonals
 */
public static PolygonalMesh createBox(double wx, double wy, double wz, Point3d center, int nx, int ny, int nz, boolean addNormals, FaceType faceType) {
    PolygonalMesh mesh = new PolygonalMesh();
    Vertex3d[][][] vtxs = new Vertex3d[nx + 1][ny + 1][nz + 1];
    Vertex3d[] faceVtxs = new Vertex3d[4];
    ArrayList<Vector3d> nrmls = null;
    int[] nrmlIdxs = null;
    if (addNormals) {
        nrmls = new ArrayList<Vector3d>();
        nrmls.add(new Vector3d(1, 0, 0));
        nrmls.add(new Vector3d(0, 1, 0));
        nrmls.add(new Vector3d(0, 0, 1));
        nrmls.add(new Vector3d(-1, 0, 0));
        nrmls.add(new Vector3d(0, -1, 0));
        nrmls.add(new Vector3d(0, 0, -1));
        int nindices;
        if (faceType == FaceType.QUAD) {
            nindices = 8 * (nx * ny + nx * nz + ny * nz);
        } else {
            // trianglar
            nindices = 12 * (nx * ny + nx * nz + ny * nz);
        }
        nrmlIdxs = new int[nindices];
    }
    Vector3d dx = new Vector3d(wx / (nx), wy / (ny), wz / (nz));
    Point3d offset = new Point3d(-wx / 2, -wy / 2, -wz / 2);
    boolean[] hardEdges;
    // bottom/top (sides in x/y plane)
    for (int i = 0; i < nx; i++) {
        for (int j = 0; j < ny; j++) {
            faceVtxs[0] = getOrCreateVertex(i, j, 0, vtxs, offset, dx, mesh);
            faceVtxs[1] = getOrCreateVertex(i, j + 1, 0, vtxs, offset, dx, mesh);
            faceVtxs[2] = getOrCreateVertex(i + 1, j + 1, 0, vtxs, offset, dx, mesh);
            faceVtxs[3] = getOrCreateVertex(i + 1, j, 0, vtxs, offset, dx, mesh);
            // notes: edge(i) appears *before* vertex(i).
            hardEdges = new boolean[] { j == 0, i == 0, j == ny - 1, i == nx - 1 };
            addFaces(mesh, faceVtxs, hardEdges, 5, nrmlIdxs, i + j, faceType);
            faceVtxs[0] = getOrCreateVertex(i, j, nz, vtxs, offset, dx, mesh);
            faceVtxs[3] = getOrCreateVertex(i, j + 1, nz, vtxs, offset, dx, mesh);
            faceVtxs[2] = getOrCreateVertex(i + 1, j + 1, nz, vtxs, offset, dx, mesh);
            faceVtxs[1] = getOrCreateVertex(i + 1, j, nz, vtxs, offset, dx, mesh);
            hardEdges = new boolean[] { i == 0, j == 0, i == nx - 1, j == ny - 1 };
            addFaces(mesh, faceVtxs, hardEdges, 2, nrmlIdxs, i + j, faceType);
        }
    }
    // back/front (sides in z/x plane)
    for (int i = 0; i < nx; i++) {
        for (int k = 0; k < nz; k++) {
            faceVtxs[0] = getOrCreateVertex(i, 0, k, vtxs, offset, dx, mesh);
            faceVtxs[3] = getOrCreateVertex(i, 0, k + 1, vtxs, offset, dx, mesh);
            faceVtxs[2] = getOrCreateVertex(i + 1, 0, k + 1, vtxs, offset, dx, mesh);
            faceVtxs[1] = getOrCreateVertex(i + 1, 0, k, vtxs, offset, dx, mesh);
            hardEdges = new boolean[] { i == 0, k == 0, i == nx - 1, k == nz - 1 };
            addFaces(mesh, faceVtxs, hardEdges, 4, nrmlIdxs, i + k, faceType);
            faceVtxs[0] = getOrCreateVertex(i, ny, k, vtxs, offset, dx, mesh);
            faceVtxs[1] = getOrCreateVertex(i, ny, k + 1, vtxs, offset, dx, mesh);
            faceVtxs[2] = getOrCreateVertex(i + 1, ny, k + 1, vtxs, offset, dx, mesh);
            faceVtxs[3] = getOrCreateVertex(i + 1, ny, k, vtxs, offset, dx, mesh);
            hardEdges = new boolean[] { k == 0, i == 0, k == nz - 1, i == nx - 1 };
            addFaces(mesh, faceVtxs, hardEdges, 1, nrmlIdxs, i + k, faceType);
        }
    }
    // left/right (sides in y/z plane)
    for (int j = 0; j < ny; j++) {
        for (int k = 0; k < nz; k++) {
            faceVtxs[0] = getOrCreateVertex(0, j, k, vtxs, offset, dx, mesh);
            faceVtxs[3] = getOrCreateVertex(0, j + 1, k, vtxs, offset, dx, mesh);
            faceVtxs[2] = getOrCreateVertex(0, j + 1, k + 1, vtxs, offset, dx, mesh);
            faceVtxs[1] = getOrCreateVertex(0, j, k + 1, vtxs, offset, dx, mesh);
            hardEdges = new boolean[] { k == 0, j == 0, k == nz - 1, j == ny - 1 };
            addFaces(mesh, faceVtxs, hardEdges, 3, nrmlIdxs, j + k, faceType);
            faceVtxs[0] = getOrCreateVertex(nx, j, k, vtxs, offset, dx, mesh);
            faceVtxs[1] = getOrCreateVertex(nx, j + 1, k, vtxs, offset, dx, mesh);
            faceVtxs[2] = getOrCreateVertex(nx, j + 1, k + 1, vtxs, offset, dx, mesh);
            faceVtxs[3] = getOrCreateVertex(nx, j, k + 1, vtxs, offset, dx, mesh);
            hardEdges = new boolean[] { j == 0, k == 0, j == ny - 1, k == nz - 1 };
            addFaces(mesh, faceVtxs, hardEdges, 0, nrmlIdxs, j + k, faceType);
        }
    }
    if (addNormals) {
        mesh.setNormals(nrmls, nrmlIdxs);
    }
    if (center != null) {
        mesh.transform(new RigidTransform3d(center.x, center.y, center.z));
    }
    return mesh;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 15 with RigidTransform3d

use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.

the class MeshFactory method createOctahedralSphere.

public static PolygonalMesh createOctahedralSphere(double r, Point3d c, int divisions) {
    PolygonalMesh mesh = createOctahedralSphere(r, divisions);
    mesh.transform(new RigidTransform3d(c.x, c.y, c.z));
    return mesh;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d)

Aggregations

RigidTransform3d (maspack.matrix.RigidTransform3d)206 Vector3d (maspack.matrix.Vector3d)56 Point3d (maspack.matrix.Point3d)48 PolygonalMesh (maspack.geometry.PolygonalMesh)21 MechModel (artisynth.core.mechmodels.MechModel)19 RigidBody (artisynth.core.mechmodels.RigidBody)18 AxisAngle (maspack.matrix.AxisAngle)18 RotationMatrix3d (maspack.matrix.RotationMatrix3d)17 AffineTransform3d (maspack.matrix.AffineTransform3d)13 FemModel3d (artisynth.core.femmodels.FemModel3d)11 RenderProps (maspack.render.RenderProps)11 FemNode3d (artisynth.core.femmodels.FemNode3d)9 Color (java.awt.Color)7 Point (java.awt.Point)7 Matrix3d (maspack.matrix.Matrix3d)7 Shading (maspack.render.Renderer.Shading)7 LinearMaterial (artisynth.core.materials.LinearMaterial)6 Renderable (maspack.render.Renderable)6 ArrayList (java.util.ArrayList)5 Vector2d (maspack.matrix.Vector2d)5