Search in sources :

Example 61 with PolygonalMesh

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

the class MultiGL2Tester 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 62 with PolygonalMesh

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

the class ColouredSphereTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    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);
    mv.addRenderable(mesh);
}
Also used : HueColorMap(maspack.render.color.HueColorMap) Vertex3d(maspack.geometry.Vertex3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 63 with PolygonalMesh

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

the class Main method setDragger.

private void setDragger() {
    translator3d.setVisible(false);
    transrotator3d.setVisible(false);
    scalar3d.setVisible(false);
    rotator3d.setVisible(false);
    constrainedTranslator3d.setVisible(false);
    constrainedTranslator3d.setMesh(null);
    currentDragger = null;
    myDraggableComponents.clear();
    if (mySelectionMode != SelectionMode.Select && mySelectionMode != SelectionMode.EllipticSelect && mySelectionMode != SelectionMode.Pull) {
        Point3d pmin = new Point3d(inf, inf, inf);
        Point3d pmax = new Point3d(-inf, -inf, -inf);
        int n = 0;
        for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
            if (sel instanceof Renderable && sel instanceof TransformableGeometry && !ComponentUtils.isAncestorSelected(sel)) {
                myDraggableComponents.add(sel);
                ((Renderable) sel).updateBounds(pmin, pmax);
                n++;
            }
        }
        if (n > 0) {
            RigidTransform3d TDW = new RigidTransform3d();
            double radius = computeDraggerToWorld(TDW, myDraggableComponents, null);
            // set a minimum radius to about 1/6 of the viewer window width
            radius = Math.max(radius, myViewer.distancePerPixel(myViewer.getCenter()) * myViewer.getScreenWidth() / 6);
            if (mySelectionMode == SelectionMode.Translate) {
                translator3d.setVisible(true);
                translator3d.setDraggerToWorld(TDW);
                translator3d.setSize(radius);
                currentDragger = translator3d;
            } else if (mySelectionMode == SelectionMode.Transrotate) {
                transrotator3d.setVisible(true);
                transrotator3d.setDraggerToWorld(TDW);
                transrotator3d.setSize(radius);
                currentDragger = transrotator3d;
            } else if (mySelectionMode == SelectionMode.Scale) {
                scalar3d.setVisible(true);
                scalar3d.setDraggerToWorld(TDW);
                scalar3d.setSize(radius);
                currentDragger = scalar3d;
            } else if (mySelectionMode == SelectionMode.Rotate) {
                rotator3d.setVisible(true);
                rotator3d.setDraggerToWorld(TDW);
                rotator3d.setSize(radius);
                currentDragger = rotator3d;
            } else if (mySelectionMode == SelectionMode.ConstrainedTranslate) {
                PolygonalMesh mesh = null;
                for (Object sel : mySelectionManager.getCurrentSelection()) {
                    if (sel instanceof FrameMarker) {
                        FrameMarker frameMarker = (FrameMarker) sel;
                        Point3d p = new Point3d(frameMarker.getPosition());
                        constrainedTranslator3d.setLocation(p);
                        Frame frame = frameMarker.getFrame();
                        if (frame instanceof RigidBody) {
                            mesh = ((RigidBody) frame).getMesh();
                        }
                        break;
                    }
                }
                if (mesh != null) {
                    constrainedTranslator3d.setSize(radius);
                    constrainedTranslator3d.setMesh(mesh);
                    constrainedTranslator3d.setVisible(true);
                    currentDragger = constrainedTranslator3d;
                }
            }
        }
    }
}
Also used : TransformableGeometry(artisynth.core.modelbase.TransformableGeometry) OrientedTransformableGeometry(artisynth.core.modelbase.OrientedTransformableGeometry) RigidTransform3d(maspack.matrix.RigidTransform3d) JFrame(javax.swing.JFrame) GLViewerFrame(maspack.render.GL.GLViewerFrame) Frame(artisynth.core.mechmodels.Frame) HasCoordinateFrame(artisynth.core.modelbase.HasCoordinateFrame) Renderable(maspack.render.Renderable) ModelComponent(artisynth.core.modelbase.ModelComponent) FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh) WayPoint(artisynth.core.probes.WayPoint)

Example 64 with PolygonalMesh

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

the class MeshComponent method getSurfaceMeshes.

public static PolygonalMesh[] getSurfaceMeshes(MeshComponentList<?> list) {
    PolygonalMesh[] meshes = new PolygonalMesh[numSurfaceMeshes(list)];
    int k = 0;
    for (MeshComponent mc : list) {
        MeshBase mesh = mc.getMesh();
        if (mesh != null && mesh instanceof PolygonalMesh) {
            meshes[k++] = (PolygonalMesh) mesh;
        }
    }
    return meshes;
}
Also used : MeshBase(maspack.geometry.MeshBase) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 65 with PolygonalMesh

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

the class MultiPointSpring method computeDefaultMaxWrapDisplacement.

private double computeDefaultMaxWrapDisplacement() {
    double mind = Double.POSITIVE_INFINITY;
    CompositeComponent comp = ComponentUtils.nearestEncapsulatingAncestor(this);
    if (comp instanceof Renderable) {
        mind = RenderableUtils.getRadius((Renderable) comp) / 10;
    }
    for (Wrappable w : myWrappables) {
        if (w instanceof HasSurfaceMesh) {
            PolygonalMesh mesh = ((HasSurfaceMesh) w).getSurfaceMesh();
            if (mesh != null) {
                OBB obb = new OBB(mesh);
                Vector3d widths = new Vector3d();
                obb.getWidths(widths);
                double hw = widths.minElement() / 2;
                if (hw < mind) {
                    mind = hw / 2;
                }
            }
        }
    }
    if (mind == Double.POSITIVE_INFINITY) {
        mind = 1.0;
    }
    return mind;
}
Also used : Renderable(maspack.render.Renderable) PolygonalMesh(maspack.geometry.PolygonalMesh) OBB(maspack.geometry.OBB)

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