Search in sources :

Example 56 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class DoubleArmDemo method addBody.

public void addBody(String name, RigidTransform3d pose, String meshName) {
    // add a simple rigid body to the simulation
    RigidBody rb = new RigidBody();
    rb.setName(name);
    rb.setPose(pose);
    model.addRigidBody(rb);
    PolygonalMesh mesh;
    try {
        String meshFilename = ArtisynthPath.getHomeRelativePath("src/artisynth/demos/mech/geometry/", ".") + meshName;
        mesh = new PolygonalMesh();
        mesh.read(new BufferedReader(new FileReader(new File(meshFilename))));
        rb.setMesh(mesh, meshFilename);
    } catch (IOException e) {
        System.out.println(e.getMessage());
        mesh = MeshFactory.createBox(size.x, size.y, size.z);
        rb.setMesh(mesh, null);
    }
    rb.setInertia(SpatialInertia.createBoxInertia(10.0, size.x, size.y, size.z));
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setFaceColor(Color.GRAY);
    rp.setShading(Renderer.Shading.FLAT);
    rb.setRenderProps(rp);
    rb.setFrameDamping(10);
    rb.setRotaryDamping(1000.0);
}
Also used : BufferedReader(java.io.BufferedReader) RenderProps(maspack.render.RenderProps) FileReader(java.io.FileReader) RigidBody(artisynth.core.mechmodels.RigidBody) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) File(java.io.File)

Example 57 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MuscleArm method addBody.

public void addBody(String name, RigidTransform3d pose, String meshName) {
    // add a simple rigid body to the simulation
    RigidBody rb = new RigidBody();
    rb.setName(name);
    rb.setPose(pose);
    model.addRigidBody(rb);
    PolygonalMesh mesh;
    try {
        String meshFilename = meshDir + meshName;
        mesh = new PolygonalMesh();
        mesh.read(new BufferedReader(new FileReader(new File(meshFilename))));
        rb.setMesh(mesh, meshFilename);
    } catch (IOException e) {
        System.out.println(e.getMessage());
        mesh = MeshFactory.createBox(size.x, size.y, size.z);
        rb.setMesh(mesh, null);
    }
    rb.setInertia(SpatialInertia.createBoxInertia(10.0, size.x, size.y, size.z));
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setFaceColor(Color.GRAY);
    rp.setShading(Renderer.Shading.FLAT);
    rb.setRenderProps(rp);
    rb.setFrameDamping(10);
    rb.setRotaryDamping(10000.0);
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) File(java.io.File)

Example 58 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MultiGL3Tester method addRenderObjects.

protected static void addRenderObjects(MultiViewer tester) {
    addCube(tester);
    addAxes(tester);
    addTransRotator(tester);
    addCylinder(tester);
    PolygonalMesh bunny = loadStanfordBunny();
    addStanfordBunnies(tester, bunny);
    addSolidBunny(tester, bunny);
    addHalfBunny(tester, bunny);
}
Also used : PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 59 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class TextureHeartTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    JFrame frame = new JFrame();
    JPanel controls = new JPanel();
    frame.add(controls);
    String heartObjFilename = PathFinder.findSourceDir(this) + "/data/heart/HumanHeart.obj";
    WavefrontReader reader = null;
    try {
        reader = new WavefrontReader(new File(heartObjFilename));
        PolygonalMesh mesh = reader.readMesh();
        RenderProps rprops = mesh.getRenderProps();
        if (rprops == null) {
            rprops = new RenderProps();
        }
        rprops.setShading(Shading.SMOOTH);
        rprops.setFaceColor(new Color(0.8f, 0.8f, 0.8f));
        rprops.getColorMap().setColorMixing(ColorMixing.MODULATE);
        rprops.setSpecular(new Color(0.4f, 0.4f, 0.4f));
        rprops.getBumpMap().setScaling(0.5f);
        rprops.setShininess(128);
        // mesh.setRenderProps(rprops);
        // FixedMeshBody fm = new FixedMeshBody (mesh);
        // fm.setRenderProps (mesh.getRenderProps ());
        // RenderProps rprops = mesh.getRenderProps();
        LabeledComponentBase base = PropertyWidget.create("Map", rprops.getColorMap(), "enabled");
        controls.add(base);
        base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
        controls.add(base);
        base = PropertyWidget.create("Lighting", rprops, "shading");
        controls.add(base);
        base = PropertyWidget.create("Specular", rprops.getColorMap(), "specularColoring");
        controls.add(base);
        base = PropertyWidget.create("Bump map scale", rprops.getBumpMap(), "scaling");
        controls.add(base);
        mv.addRenderable(mesh);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (reader != null) {
        reader.close();
    }
    mv.autoFitViewers();
    frame.pack();
    frame.setVisible(true);
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) JPanel(javax.swing.JPanel) JFrame(javax.swing.JFrame) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) LabeledComponentBase(maspack.widgets.LabeledComponentBase) IOException(java.io.IOException) File(java.io.File) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 60 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class GL2vsGL3Tester method addContent.

@Override
protected void addContent(MultiViewer mv) {
    addCube(mv);
    addAxes(mv);
    addTransRotator(mv);
    addCylinder(mv);
    PolygonalMesh bunny = loadStanfordBunny();
    addStanfordBunnies(mv, bunny);
    addSolidBunny(mv, bunny);
    addHalfBunny(mv, bunny);
    mv.autoFitViewers();
}
Also used : PolygonalMesh(maspack.geometry.PolygonalMesh)

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