Search in sources :

Example 1 with FixedMeshBody

use of artisynth.core.mechmodels.FixedMeshBody in project artisynth_core by artisynth.

the class SDGridTest method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    PolygonalMesh mesh = new PolygonalMesh();
    Vertex3d[] v = new Vertex3d[9 * 2 + 8];
    Face[] f = new Face[8 * 6];
    int idx = 0;
    int fidx = 0;
    double c = 64;
    v[idx++] = mesh.addVertex(-c, -c, -c);
    v[idx++] = mesh.addVertex(-c, -c, 0);
    v[idx++] = mesh.addVertex(-c, -c, c);
    v[idx++] = mesh.addVertex(-c, 0, -c);
    v[idx++] = mesh.addVertex(-c, 0, 0);
    v[idx++] = mesh.addVertex(-c, 0, c);
    v[idx++] = mesh.addVertex(-c, c, -c);
    v[idx++] = mesh.addVertex(-c, c, 0);
    v[idx++] = mesh.addVertex(-c, c, c);
    // left
    f[fidx++] = mesh.addFace(v[0], v[1], v[4]);
    f[fidx++] = mesh.addFace(v[1], v[2], v[4]);
    f[fidx++] = mesh.addFace(v[2], v[5], v[4]);
    f[fidx++] = mesh.addFace(v[5], v[8], v[4]);
    f[fidx++] = mesh.addFace(v[8], v[7], v[4]);
    f[fidx++] = mesh.addFace(v[7], v[6], v[4]);
    f[fidx++] = mesh.addFace(v[6], v[3], v[4]);
    f[fidx++] = mesh.addFace(v[3], v[0], v[4]);
    v[idx++] = mesh.addVertex(0, -c, -c);
    v[idx++] = mesh.addVertex(0, -c, 0);
    v[idx++] = mesh.addVertex(0, -c, c);
    v[idx++] = mesh.addVertex(0, 0, -c);
    // test.addVertex( 0, 0, 0);
    v[idx++] = mesh.addVertex(0, 0, c);
    v[idx++] = mesh.addVertex(0, c, -c);
    v[idx++] = mesh.addVertex(0, c, 0);
    v[idx++] = mesh.addVertex(0, c, c);
    // back
    f[fidx++] = mesh.addFace(v[0], v[9], v[10]);
    f[fidx++] = mesh.addFace(v[1], v[0], v[10]);
    f[fidx++] = mesh.addFace(v[2], v[1], v[10]);
    f[fidx++] = mesh.addFace(v[11], v[2], v[10]);
    // top
    f[fidx++] = mesh.addFace(v[2], v[11], v[13]);
    f[fidx++] = mesh.addFace(v[5], v[2], v[13]);
    f[fidx++] = mesh.addFace(v[8], v[5], v[13]);
    f[fidx++] = mesh.addFace(v[16], v[8], v[13]);
    // front
    f[fidx++] = mesh.addFace(v[8], v[16], v[15]);
    f[fidx++] = mesh.addFace(v[7], v[8], v[15]);
    f[fidx++] = mesh.addFace(v[6], v[7], v[15]);
    f[fidx++] = mesh.addFace(v[14], v[6], v[15]);
    // bottom
    f[fidx++] = mesh.addFace(v[3], v[6], v[12]);
    f[fidx++] = mesh.addFace(v[6], v[14], v[12]);
    f[fidx++] = mesh.addFace(v[0], v[3], v[12]);
    f[fidx++] = mesh.addFace(v[9], v[0], v[12]);
    v[idx++] = mesh.addVertex(c, -c, -c);
    v[idx++] = mesh.addVertex(c, -c, 0);
    v[idx++] = mesh.addVertex(c, -c, c);
    v[idx++] = mesh.addVertex(c, 0, -c);
    v[idx++] = mesh.addVertex(c, 0, 0);
    v[idx++] = mesh.addVertex(c, 0, c);
    v[idx++] = mesh.addVertex(c, c, -c);
    v[idx++] = mesh.addVertex(c, c, 0);
    v[idx++] = mesh.addVertex(c, c, c);
    // bottom
    f[fidx++] = mesh.addFace(v[17], v[9], v[12]);
    f[fidx++] = mesh.addFace(v[20], v[17], v[12]);
    f[fidx++] = mesh.addFace(v[23], v[20], v[12]);
    f[fidx++] = mesh.addFace(v[14], v[23], v[12]);
    f[fidx++] = mesh.addFace(v[9], v[17], v[10]);
    f[fidx++] = mesh.addFace(v[17], v[18], v[10]);
    f[fidx++] = mesh.addFace(v[18], v[19], v[10]);
    f[fidx++] = mesh.addFace(v[19], v[11], v[10]);
    f[fidx++] = mesh.addFace(v[11], v[19], v[13]);
    f[fidx++] = mesh.addFace(v[19], v[22], v[13]);
    f[fidx++] = mesh.addFace(v[22], v[25], v[13]);
    f[fidx++] = mesh.addFace(v[25], v[16], v[13]);
    f[fidx++] = mesh.addFace(v[16], v[25], v[15]);
    f[fidx++] = mesh.addFace(v[25], v[24], v[15]);
    f[fidx++] = mesh.addFace(v[24], v[23], v[15]);
    f[fidx++] = mesh.addFace(v[23], v[14], v[15]);
    f[fidx++] = mesh.addFace(v[25], v[22], v[21]);
    f[fidx++] = mesh.addFace(v[22], v[19], v[21]);
    f[fidx++] = mesh.addFace(v[19], v[18], v[21]);
    f[fidx++] = mesh.addFace(v[18], v[17], v[21]);
    f[fidx++] = mesh.addFace(v[17], v[20], v[21]);
    f[fidx++] = mesh.addFace(v[20], v[23], v[21]);
    f[fidx++] = mesh.addFace(v[23], v[24], v[21]);
    f[fidx++] = mesh.addFace(v[24], v[25], v[21]);
    // Move in some corner(s)
    v[0].setPosition(new Point3d(0, 0, 0));
    // v[25].setPosition(new Point3d(0,0,0));
    int divisions = 3;
    mesh = MeshFactory.subdivide(mesh, divisions);
    // randomize vertex order and re-number (to test different chiralities)
    ArrayList<Vertex3d> vertices = mesh.getVertices();
    Collections.shuffle(vertices);
    for (int i = 0; i < vertices.size(); ++i) {
        vertices.get(i).setIndex(i);
    }
    FixedMeshBody fm = new FixedMeshBody("cube", mesh);
    RenderProps.setFaceStyle(fm, FaceStyle.FRONT_AND_BACK);
    addRenderable(fm);
    int cells = 1 << (divisions + 2);
    double margin = 1.0 / cells;
    cells += 2;
    sdgrid = new DistanceGrid(mesh.getFaces(), margin, cells, /*signed=*/
    true);
    // test a bunch of inside points
    Vector3d norm = new Vector3d();
    double dx = 2 * c / ((1 << (divisions + 1)));
    for (double x = -c + dx; x < c; x += dx) {
        for (double y = -c + dx; y < c; y += dx) {
            for (double z = -c + dx; z < c; z += dx) {
                double d = sdgrid.getLocalDistanceAndNormal(norm, x, y, z);
                // check bottom corner
                if ((x < 0 && y < 0 && z < 0)) {
                    // ||(x > 0 && y > 0 && z > 0)) {
                    if (d < 0) {
                        System.err.println("Point (" + x + "," + y + "," + z + ") incorrectly labelled as inside");
                    }
                } else {
                    if (d > 0) {
                        System.err.println("Point (" + x + "," + y + "," + z + ") incorrectly labelled as outside");
                    }
                }
            }
        }
    }
    RenderProps.setDrawEdges(fm, true);
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) DistanceGrid(maspack.geometry.DistanceGrid) Face(maspack.geometry.Face) FixedMeshBody(artisynth.core.mechmodels.FixedMeshBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 2 with FixedMeshBody

use of artisynth.core.mechmodels.FixedMeshBody 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 3 with FixedMeshBody

use of artisynth.core.mechmodels.FixedMeshBody in project artisynth_core by artisynth.

the class SpecularTest method build.

public void build(String[] args) {
    MechModel mech = new MechModel("mech");
    addModel(mech);
    RenderProps.setShininess(mech, 128);
    RenderProps.setFaceStyle(mech, FaceStyle.FRONT_AND_BACK);
    RenderProps.setFaceColor(mech, Color.GRAY.darker().darker());
    RenderProps.setSpecular(mech, Color.WHITE);
    // mech.getRenderProps().setColorMap (createTextureProps());
    // mech.getRenderProps().setNormalMap (createNormalProps());
    // mech.getRenderProps().setBumpMap (createBumpProps());
    FixedMeshBody body0 = createMesh(mech, 0);
// FixedMeshBody body1 = createMesh (mech, 2);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) FixedMeshBody(artisynth.core.mechmodels.FixedMeshBody)

Example 4 with FixedMeshBody

use of artisynth.core.mechmodels.FixedMeshBody in project artisynth_core by artisynth.

the class CSGCubeTest method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    PolygonalMesh cube1 = MeshFactory.createBox(1, 1, 1);
    PolygonalMesh cube2 = MeshFactory.createBox(0.5, 0.5, 0.5);
    cube2.transform(new RigidTransform3d(new Vector3d(0.25, 0.25, 0.25), AxisAngle.IDENTITY));
    cube1.setHardEdgesFromFaceNormals(0.707);
    cube2.setHardEdgesFromFaceNormals(0.707);
    PolygonalMesh isect = MeshFactory.getIntersection(cube1, cube2);
    isect.setHardEdgesFromFaceNormals(0.707);
    PolygonalMesh sub = MeshFactory.getSubtraction(cube1, cube2);
    sub.setHardEdgesFromFaceNormals(0.707);
    PolygonalMesh union = MeshFactory.getUnion(cube1, cube2);
    union.setHardEdgesFromFaceNormals(0.707);
    addRenderable(new FixedMeshBody("cube1", cube1));
    addRenderable(new FixedMeshBody("cube2", cube2));
    addRenderable(new FixedMeshBody("intersection", isect));
    addRenderable(new FixedMeshBody("subtraction", sub));
    addRenderable(new FixedMeshBody("union", union));
    for (Renderable r : renderables()) {
        if (r instanceof FixedMeshBody) {
            FixedMeshBody fmesh = (FixedMeshBody) r;
            PolygonalMesh mesh = (PolygonalMesh) (fmesh.getMesh());
            System.out.println("Mesh: " + fmesh.getName());
            System.out.println("  # verts: " + mesh.numVertices());
            System.out.println("  # faces: " + mesh.numFaces());
            System.out.println("  closed:  " + mesh.isClosed());
            System.out.println("  manifo:  " + mesh.isManifold());
            System.out.println("  area:    " + mesh.computeArea());
            System.out.println("  volume:  " + mesh.computeVolume());
        }
    }
    // PolygonalMesh cube3 = new PolygonalMesh(cube1);
    // cube3 = MeshFactory.subdivide(cube3);
    // cube3.mergeCoplanarFaces(0.99);
    // for (Face f : cube3.getFaces()) {
    // System.out.println(f.getIndex() + ", " + f.numEdges());
    // }
    // 
    // int[] nrmIdxs = cube3.getNormalIndices();
    // int[] offsets = cube3.getFeatureIndexOffsets();
    // for (int i=0; i<offsets.length-1; ++i) {
    // System.out.println("Face " + i + ": ");
    // for (int j = offsets[i]; j<offsets[i+1]; ++j) {
    // Vector3d nrm = cube3.getNormal(nrmIdxs[j]);
    // System.out.println(nrm.toString());
    // }
    // }
    // FixedMeshBody fm = new FixedMeshBody("cube3", cube3);
    // addRenderable(fm);
    // RenderProps.setFaceStyle(fm, FaceStyle.FRONT_AND_BACK);
    // RenderProps.setFaceColor(fm, Color.BLUE);
    // RenderProps.setBackColor(fm, Color.YELLOW);
    RenderProps.setDrawEdges(this, true);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Renderable(maspack.render.Renderable) Vector3d(maspack.matrix.Vector3d) FixedMeshBody(artisynth.core.mechmodels.FixedMeshBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 5 with FixedMeshBody

use of artisynth.core.mechmodels.FixedMeshBody in project artisynth_core by artisynth.

the class ColoredSphereTest method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    PolygonalMesh mesh = MeshFactory.createOctahedralSphere(1, 4);
    HueColorMap map = new HueColorMap();
    mesh.setVertexColoringEnabled();
    for (int i = 0; i < mesh.numVertices(); ++i) {
        // hsv interpolation of colors based on height (-1 to 1)
        Vertex3d vtx = mesh.getVertex(i);
        double pos = vtx.getPosition().z;
        Color c = map.getColor((pos + 1) / 2);
        mesh.setColor(i, c);
    }
    RenderProps rprops = new RenderProps();
    rprops.setShading(Shading.SMOOTH);
    rprops.setShininess(128);
    rprops.setSpecular(Color.WHITE);
    mesh.setRenderProps(rprops);
    FixedMeshBody fm = new FixedMeshBody(mesh);
    addRenderable(fm);
}
Also used : HueColorMap(maspack.render.color.HueColorMap) Vertex3d(maspack.geometry.Vertex3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) FixedMeshBody(artisynth.core.mechmodels.FixedMeshBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

FixedMeshBody (artisynth.core.mechmodels.FixedMeshBody)6 PolygonalMesh (maspack.geometry.PolygonalMesh)5 Vertex3d (maspack.geometry.Vertex3d)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2 Vector3d (maspack.matrix.Vector3d)2 MechModel (artisynth.core.mechmodels.MechModel)1 HudPrintStream (artisynth.core.renderables.HudPrintStream)1 Color (java.awt.Color)1 DistanceGrid (maspack.geometry.DistanceGrid)1 Face (maspack.geometry.Face)1 Point3d (maspack.matrix.Point3d)1 RenderProps (maspack.render.RenderProps)1 Renderable (maspack.render.Renderable)1 HueColorMap (maspack.render.color.HueColorMap)1