Search in sources :

Example 76 with PolygonalMesh

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

the class MayaAsciiReader method getPolygonalMesh.

public PolygonalMesh getPolygonalMesh(Node<MayaNode> root, UnitInfo units) {
    if (units == null) {
        units = defaultUnits;
    }
    PolygonalMesh mesh = new PolygonalMesh();
    AffineTransform3d trans = new AffineTransform3d();
    recursiveBuildParentTransform(root, trans, units);
    recursiveAddPolygonalMeshes(root, mesh, trans, units);
    return mesh;
}
Also used : PolygonalMesh(maspack.geometry.PolygonalMesh) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 77 with PolygonalMesh

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

the class OffReader method buildMesh.

private static PolygonalMesh buildMesh(PolygonalMesh mesh, ArrayList<Point3d> nodes, ArrayList<ArrayList<Integer>> faces) {
    if (mesh == null) {
        mesh = new PolygonalMesh();
    } else {
        mesh.clear();
    }
    Point3d[] pnts = new Point3d[nodes.size()];
    int[][] faceIndices = new int[faces.size()][];
    for (int i = 0; i < nodes.size(); i++) {
        pnts[i] = nodes.get(i);
    }
    ArrayList<Integer> face;
    for (int i = 0; i < faces.size(); i++) {
        face = faces.get(i);
        faceIndices[i] = new int[face.size()];
        for (int j = 0; j < face.size(); j++) {
            faceIndices[i][j] = face.get(j);
        }
    }
    mesh.set(pnts, faceIndices);
    return mesh;
}
Also used : Point3d(maspack.matrix.Point3d) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 78 with PolygonalMesh

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

the class GtsReader method readMesh.

public PolygonalMesh readMesh(PolygonalMesh mesh) throws IOException {
    if (mesh == null) {
        mesh = new PolygonalMesh();
    } else {
        mesh.clear();
    }
    ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new InputStreamReader(myIstream)));
    rtok.commentChar('!');
    rtok.commentChar('#');
    rtok.eolIsSignificant(true);
    int numVerts = rtok.scanInteger();
    int numEdges = rtok.scanInteger();
    int numFaces = rtok.scanInteger();
    while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    ArrayList<Edge> edgeList = new ArrayList<Edge>();
    for (int i = 0; i < numVerts; i++) {
        double x = rtok.scanNumber();
        double y = rtok.scanNumber();
        double z = rtok.scanNumber();
        mesh.addVertex(new Point3d(x, y, z));
        while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    }
    ArrayList<Vertex3d> verts = mesh.getVertices();
    for (int i = 0; i < numEdges; i++) {
        int idx1 = rtok.scanInteger() - 1;
        int idx2 = rtok.scanInteger() - 1;
        if (idx1 < 0 || idx1 >= numVerts) {
            System.out.println("Error: vertex " + idx1 + " out of range, " + rtok);
            System.exit(1);
        }
        if (idx2 < 0 || idx2 >= numVerts) {
            System.out.println("Error: vertex " + idx2 + " out of range, " + rtok);
            System.exit(1);
        }
        edgeList.add(new Edge(verts.get(idx1), verts.get(idx2)));
        while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    }
    for (int i = 0; i < numFaces; i++) {
        ArrayList<Edge> edges = new ArrayList<Edge>();
        while (rtok.nextToken() == ReaderTokenizer.TT_NUMBER) {
            if (!rtok.tokenIsInteger()) {
                System.out.println("Error: edge index expected, " + rtok);
                System.exit(1);
            }
            int idx = (int) rtok.lval - 1;
            if (idx < 0 || idx >= edgeList.size()) {
                System.out.println("Error: edge index " + idx + " out of range, " + rtok);
                System.exit(1);
            }
            edges.add(edgeList.get(idx));
        }
        int[] idxs = getFaceIndices(edges);
        if (idxs == null) {
            System.out.println("Error: face edges are not adjacent, " + rtok);
        }
        mesh.addFace(idxs);
        rtok.pushBack();
        while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    }
    return mesh;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) PolygonalMesh(maspack.geometry.PolygonalMesh) Point3d(maspack.matrix.Point3d) ReaderTokenizer(maspack.util.ReaderTokenizer) BufferedReader(java.io.BufferedReader)

Example 79 with PolygonalMesh

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

the class EditorUtils method saveMesh.

public static void saveMesh(MeshBase mesh, AffineTransform3dBase X) {
    Main main = Main.getMain();
    JFrame frame = main.getMainFrame();
    if (mesh == null) {
        showError(frame, "Component does not have a mesh");
        return;
    }
    if (X != null) {
        mesh = mesh.copy();
        mesh.transform(X);
    }
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(main.getModelDirectory());
    int retVal = chooser.showSaveDialog(frame);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
            if (mesh instanceof PolygonalMesh) {
                GenericMeshWriter writer = new GenericMeshWriter(file);
                writer.writeMesh(mesh);
                writer.close();
            } else {
                PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file)));
                mesh.write(pw, "%.8g");
                pw.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            showError(frame, "Error saving file: " + ex.getMessage());
        }
        main.setModelDirectory(chooser.getCurrentDirectory());
    }
}
Also used : GenericMeshWriter(maspack.geometry.io.GenericMeshWriter) Main(artisynth.core.driver.Main) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 80 with PolygonalMesh

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

the class FemModel3dAgent method actionPerformed.

public void actionPerformed(ActionEvent evt) {
    String cmd = evt.getActionCommand();
    if (cmd.equals("Add")) {
        ViewerManager viewerMan = myMain.getWorkspace().getViewerManager();
        viewerMan.removeRenderable(fem.getSurfaceMesh());
        viewerMan.removeDragger(rotator);
        rotator = null;
        setProperties(fem, getPrototypeComponent(myComponentType));
        // basicPropTree.setTreeValuesInHost (
        // fem, getPrototypeComponent (myComponentType));
        // myPropTree.setTreeValuesInHost (
        // fem, getPrototypeComponent (myComponentType));
        setProperties(myPrototype, myPrototype);
        PolygonalMesh mesh = fem.getSurfaceMesh();
        mesh.setRenderProps(mesh.createRenderProps());
        mesh.setMeshToWorld(RigidTransform3d.IDENTITY);
        mesh.setFixed(false);
        mesh.setColorsFixed(false);
        RigidTransform3d rigidX = new RigidTransform3d();
        rigidX.p.set(positionField.getVectorValue());
        rigidX.R.setAxisAngle(orientationField.getAxisAngleValue());
        AffineTransform3d X = new AffineTransform3d();
        X.set(rigidX);
        Object scale = scaleField.getValue();
        resetScaling();
        double sx = 1, sy = 1, sz = 1;
        if (scale instanceof Double) {
            sx = sy = sz = (Double) scale;
        } else if (scale instanceof Vector3d) {
            sx = ((Vector3d) scale).x;
            sy = ((Vector3d) scale).y;
            sz = ((Vector3d) scale).z;
        }
        X.applyScaling(sx, sy, sz);
        fem.transformGeometry(X);
        addComponent(new AddComponentsCommand("add FemModel3d", fem, myContainer));
        myDisplay.setVisible(false);
        dispose();
    } else if (cmd.equals("Clear")) {
        maskAllValueChangeListeners(true);
        restoreDefaultValues();
        myHostList.restoreBackupValues();
        myPropertyPanel.updateWidgetValues();
        // basicHostList.restoreBackupValues();
        // moreHostList.restoreBackupValues();
        // basicPropsPanel.updateWidgetValues();
        // morePropsPanel.updateWidgetValues();
        disposePreviewModel();
        resetState();
        maskAllValueChangeListeners(false);
        updateMeshPanel();
        updateState();
    } else if (cmd.equals("Cancel")) {
        disposePreviewModel();
        myDisplay.setVisible(false);
        dispose();
    } else if (evt.getSource() == autoScaleBtn) {
        if (fem != null) {
            updateScale();
        }
    } else {
        super.actionPerformed(evt);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) ViewerManager(artisynth.core.driver.ViewerManager) PolygonalMesh(maspack.geometry.PolygonalMesh) AffineTransform3d(maspack.matrix.AffineTransform3d)

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