Search in sources :

Example 66 with PolygonalMesh

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

the class CollisionRenderer method buildFaceSegments.

protected void buildFaceSegments(RenderObject ro, CollisionHandler handler, ArrayList<TriTriIntersection> intersections) {
    BVFeatureQuery query = new BVFeatureQuery();
    PolygonalMesh mesh0 = handler.getCollidable(0).getCollisionMesh();
    PolygonalMesh mesh1 = handler.getCollidable(1).getCollisionMesh();
    ArrayList<Face> faces = new ArrayList<Face>();
    // mark faces as visited and add segments
    for (TriTriIntersection isect : intersections) {
        isect.face0.setVisited();
        isect.face1.setVisited();
    // add partials?
    }
    // mark interior faces and add segments
    for (TriTriIntersection isect : intersections) {
        if (isect.face0.getMesh() != mesh0) {
            findInsideFaces(isect.face0, query, mesh0, faces);
            findInsideFaces(isect.face1, query, mesh1, faces);
        } else {
            findInsideFaces(isect.face0, query, mesh1, faces);
            findInsideFaces(isect.face1, query, mesh0, faces);
        }
    }
    for (TriTriIntersection isect : intersections) {
        isect.face0.clearVisited();
        isect.face1.clearVisited();
    }
    // add faces to render object and clear visited flag
    Vector3d nrm = new Vector3d();
    Point3d p0 = new Point3d();
    Point3d p1 = new Point3d();
    Point3d p2 = new Point3d();
    for (Face face : faces) {
        face.clearVisited();
        face.getWorldNormal(nrm);
        ro.addNormal((float) nrm.x, (float) nrm.y, (float) nrm.z);
        HalfEdge he = face.firstHalfEdge();
        he.head.getWorldPoint(p0);
        he = he.getNext();
        he.head.getWorldPoint(p1);
        he = he.getNext();
        he.head.getWorldPoint(p2);
        int v0idx = ro.vertex((float) p0.x, (float) p0.y, (float) p0.z);
        int v1idx = ro.vertex((float) p1.x, (float) p1.y, (float) p1.z);
        int v2idx = ro.vertex((float) p2.x, (float) p2.y, (float) p2.z);
        ro.addTriangle(v0idx, v1idx, v2idx);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) TriTriIntersection(maspack.geometry.TriTriIntersection) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) BVFeatureQuery(maspack.geometry.BVFeatureQuery) PolygonalMesh(maspack.geometry.PolygonalMesh) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint)

Example 67 with PolygonalMesh

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

the class TorusWrapTest method build.

public void build(String[] args) {
    MechModel mechMod = new MechModel("mechMod");
    mechMod.setGravity(0, 0, -9.8);
    mechMod.setFrameDamping(10.0);
    mechMod.setRotaryDamping(0.1);
    RigidBody block = new RigidBody("block");
    PolygonalMesh mesh = MeshFactory.createBox(size, size, size);
    block.setMesh(mesh, null);
    block.setInertiaFromDensity(1);
    // mechMod.addRigidBody (block);
    Particle p0 = new Particle(0.1, size * 3, 0, size / 2);
    p0.setDynamic(false);
    mechMod.addParticle(p0);
    Particle p1 = new Particle(0.1, -size * 3, 0, size / 2);
    p1.setDynamic(false);
    mechMod.addParticle(p1);
    Particle p2 = new Particle(0.1, -size * 3, size, size / 2);
    p2.setDynamic(false);
    // mechMod.addParticle (p2);
    Particle p3 = new Particle(0.1, size * 3, size, size / 2);
    p3.setDynamic(false);
    // mechMod.addParticle (p3);
    RigidTorus torus1 = new RigidTorus("torus1", size, size / 3, myDensity, 50, 30);
    RigidTorus torus2 = new RigidTorus("torus2", size, size / 3, myDensity, 50, 30);
    RigidTorus torus3 = new RigidTorus("torus3", size, size / 3, myDensity, 50, 30);
    torus1.setPose(new RigidTransform3d(-2 * size, 0, 0, 0, Math.PI / 2, 0));
    torus2.setPose(new RigidTransform3d(2 * size, 0, 0, 0, Math.PI / 2, 0));
    torus3.setPose(new RigidTransform3d(0, 0, 0, 0, Math.PI / 2, 0));
    mechMod.addRigidBody(torus1);
    mechMod.addRigidBody(torus2);
    mechMod.addRigidBody(torus3);
    mechMod.setDefaultCollisionBehavior(true, 0);
    MultiPointSpring spring = new MultiPointSpring("spring", 100, 0.1, 0);
    spring.addPoint(p0);
    spring.setSegmentWrappable(50);
    spring.addWrappable(torus1);
    spring.addWrappable(torus2);
    spring.addWrappable(torus3);
    spring.addPoint(p1);
    // spring.addPoint (p2);
    // spring.setSegmentWrappable (50);
    // spring.addPoint (p3);
    // spring.setWrapDamping (1.0);
    // spring.setWrapStiffness (10);
    // spring.setWrapH (0.01);
    mechMod.addMultiPointSpring(spring);
    spring.setDrawKnots(false);
    spring.setDrawABPoints(true);
    spring.setWrapDamping(100);
    spring.setMaxWrapIterations(10);
    addModel(mechMod);
    RenderProps.setPointStyle(mechMod, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(mechMod, size / 10);
    RenderProps.setLineStyle(mechMod, Renderer.LineStyle.CYLINDER);
    RenderProps.setLineRadius(mechMod, size / 30);
    RenderProps.setLineColor(mechMod, Color.red);
    createControlPanel(mechMod);
}
Also used : Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh) RigidTorus(artisynth.core.mechmodels.RigidTorus) MultiPointSpring(artisynth.core.mechmodels.MultiPointSpring)

Example 68 with PolygonalMesh

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

the class RigidBodyCollision method build.

public void build(String[] args) throws IOException {
    try {
        mechmod = new MechModel();
        mechmod.setMaxStepSize(0.005);
        boxes = new ArrayList<RigidBody>();
        table = new RigidBody("table");
        table.setDynamic(false);
        table.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
        AffineTransform3d trans = new AffineTransform3d();
        trans.setIdentity();
        trans.applyScaling(4, 2, 0.5);
        table.transformGeometry(trans);
        table.setPose(new RigidTransform3d(new Vector3d(0, 0, 0.8077474533228615), new AxisAngle()));
        table.setInertia(SpatialInertia.createBoxInertia(1, 1, 1, 1));
        mechmod.addRigidBody(table);
        boxes.add(table);
        if (wireFrame) {
            setWireFrame(table);
        }
        // middle box in pile
        box0 = new RigidBody("box0");
        box0.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
        trans.setIdentity();
        trans.applyScaling(0.5, 0.5, 0.5);
        box0.transformGeometry(trans);
        box0.setInertia(SpatialInertia.createBoxInertia(4, 1, 1, 1));
        addBox(box0, Color.GREEN);
        if (wireFrame) {
            setWireFrame(box0);
        }
        // long thin box, bottom of pile
        box1 = new RigidBody("box1");
        box1.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
        trans.setIdentity();
        trans.applyScaling(0.6, 0.1, 1.9);
        box1.transformGeometry(trans);
        box1.setInertia(SpatialInertia.createBoxInertia(1, 1, 0.1, 4));
        addBox(box1, Color.YELLOW);
        if (wireFrame) {
            setWireFrame(box1);
        }
        // left hand box falling on unsupported end of
        box2 = new RigidBody("box2");
        // box1
        box2.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
        trans.setIdentity();
        trans.applyScaling(0.5, 0.5, 0.5);
        box2.transformGeometry(trans);
        box2.setInertia(SpatialInertia.createBoxInertia(20, 1, 1, 1));
        addBox(box2, Color.BLUE);
        if (wireFrame) {
            setWireFrame(box2);
        }
        // top box in pile
        box3 = new RigidBody("box3");
        box3.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
        trans.setIdentity();
        trans.applyScaling(0.4, 0.4, 0.4);
        box3.transformGeometry(trans);
        box3.setInertia(SpatialInertia.createBoxInertia(0.5, 0.5, 0.5, 4));
        addBox(box3, Color.CYAN);
        // box3.getMesh().name = "box3";
        if (wireFrame) {
            setWireFrame(box3);
        }
        // solo box off to the right.
        box4 = new RigidBody("box4");
        box4.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
        trans.setIdentity();
        trans.applyScaling(0.6, 0.6, 0.3);
        box4.transformGeometry(trans);
        box4.setInertia(SpatialInertia.createBoxInertia(0.5, 0.5, 0.5, 4));
        box4.setPose(new RigidTransform3d(new Vector3d(1, 0.0, 5), new AxisAngle(0, 0, 0, 0)));
        addBox(box4, Color.RED);
        // box4.getMesh().name = "box4";
        if (wireFrame) {
            setWireFrame(box4);
        }
        mechmod.setDefaultCollisionBehavior(true, 0.05);
        reset();
        addModel(mechmod);
        ControlPanel panel = new ControlPanel();
        panel.addWidget(mechmod, "integrator");
        panel.addWidget(mechmod, "maxStepSize");
        addControlPanel(panel);
        Main.getMain().arrangeControlPanels(this);
        CollisionManager cm = mechmod.getCollisionManager();
        RenderProps.setVisible(cm, true);
        RenderProps.setLineWidth(cm, 3);
        RenderProps.setLineColor(cm, Color.RED);
        cm.setDrawContactNormals(true);
        // addBreakPoint (0.74);
        for (int i = 1; i <= 10; i++) {
            addWayPoint(0.1 * i);
        }
    // setWaypointChecking (true);
    } catch (IOException e) {
        throw e;
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) MechModel(artisynth.core.mechmodels.MechModel) AxisAngle(maspack.matrix.AxisAngle) CollisionManager(artisynth.core.mechmodels.CollisionManager) Vector3d(maspack.matrix.Vector3d) ControlPanel(artisynth.core.gui.ControlPanel) RigidBody(artisynth.core.mechmodels.RigidBody) File(java.io.File) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 69 with PolygonalMesh

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

the class SkinDemo method addBody.

public RigidBody 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);
    return rb;
}
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 70 with PolygonalMesh

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

the class SkinDemo method addSkinMesh.

public void addSkinMesh() {
    PolygonalMesh mesh;
    mesh = MeshFactory.createSphere(10.0, 12, 12);
    mesh.scale(1, 1, 2.5);
    mesh.transform(new RigidTransform3d(-6, 0, 0, 0, Math.toRadians(22.5), 0));
    SkinMeshBody skinMesh = new SkinMeshBody(mesh);
    skinMesh.addFrame(model.rigidBodies().get(0));
    skinMesh.addFrame(model.rigidBodies().get(1));
    skinMesh.computeWeights();
    model.addMeshBody(skinMesh);
    RenderProps.setFaceStyle(skinMesh, Renderer.FaceStyle.NONE);
    RenderProps.setDrawEdges(skinMesh, true);
    RenderProps.setLineColor(skinMesh, Color.GRAY);
    mySkinMesh = skinMesh;
}
Also used : SkinMeshBody(artisynth.core.femmodels.SkinMeshBody) RigidTransform3d(maspack.matrix.RigidTransform3d) 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