Search in sources :

Example 1 with PolylineMesh

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

the class MeshViewer method loadMeshes.

public static void loadMeshes(ArrayList<MeshInfo> infoList, String fileName, AffineTransform3dBase X) {
    try {
        File meshFile = new File(fileName);
        if (!meshFile.exists()) {
            System.out.println("Error: mesh file " + meshFile.getName() + " not found");
            return;
        }
        if (meshFile.getName().endsWith(".obj") && !pointMesh.value) {
            Class meshClass = Class.forName(className.value);
            Class meshBaseClass = new PolygonalMesh().getClass();
            if (meshClass == null) {
                System.out.println("can't find class " + className.value);
                return;
            }
            if (!meshBaseClass.isAssignableFrom(meshClass)) {
                System.out.println(className.value + " is not an instance of " + meshBaseClass.getName());
                return;
            }
            WavefrontReader reader = new WavefrontReader(meshFile);
            reader.parse();
            String[] names = reader.getPolyhedralGroupNames();
            for (int i = 0; i < names.length; i++) {
                if (meshClass == PolygonalMesh.class) {
                    PolygonalMesh mesh = (PolygonalMesh) meshClass.newInstance();
                    reader.setMesh(mesh, names[i]);
                    if (printBounds.value) {
                        doPrintBounds(mesh);
                    }
                    if (mesh.numVertices() > 0) {
                        System.out.print("mesh " + names[i] + ": " + mesh.numVertices() + " vertices, " + mesh.numFaces() + " faces, ");
                        if (mesh.isTriangular()) {
                            System.out.println("triangular");
                        } else if (mesh.isQuad()) {
                            System.out.println("quad");
                        } else {
                            System.out.println("polygonal");
                        }
                        mesh.transform(X);
                        if (names[i].equals("default")) {
                            infoList.add(new MeshInfo(meshFile.getName(), mesh));
                        } else {
                            infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
                        }
                    }
                } else if (meshClass == PolylineMesh.class) {
                    PolylineMesh mesh = (PolylineMesh) meshClass.newInstance();
                    reader.setMesh(mesh, names[i]);
                    mesh.transform(X);
                    if (printBounds.value) {
                        doPrintBounds(mesh);
                    }
                    if (names[i].equals("default")) {
                        infoList.add(new MeshInfo(meshFile.getName(), mesh));
                    } else {
                        infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
                    }
                } else if (meshClass == PointMesh.class) {
                    PointMesh mesh = (PointMesh) meshClass.newInstance();
                    reader.setMesh(mesh, names[i]);
                    mesh.transform(X);
                    if (printBounds.value) {
                        doPrintBounds(mesh);
                    }
                    if (names[i].equals("default")) {
                        infoList.add(new MeshInfo(meshFile.getName(), mesh));
                    } else {
                        infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
                    }
                }
            }
        } else {
            MeshReader reader;
            if (meshFile.getName().endsWith(".xyzb")) {
                XyzbReader xyzbReader = new XyzbReader(meshFile);
                xyzbReader.setSkip(skipCount.value);
                reader = xyzbReader;
            } else {
                reader = new GenericMeshReader(meshFile);
            }
            MeshBase mesh = pointMesh.value ? new PointMesh() : null;
            mesh = reader.readMesh(mesh);
            if (printBounds.value) {
                doPrintBounds(mesh);
            }
            infoList.add(new MeshInfo(meshFile.getName(), mesh));
        }
    } catch (Exception e) {
        System.out.println("Error creating mesh");
        e.printStackTrace();
    }
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) MeshReader(maspack.geometry.io.MeshReader) GenericMeshReader(maspack.geometry.io.GenericMeshReader) PolygonalMesh(maspack.geometry.PolygonalMesh) Point(java.awt.Point) GenericMeshReader(maspack.geometry.io.GenericMeshReader) PointMesh(maspack.geometry.PointMesh) MeshBase(maspack.geometry.MeshBase) PolylineMesh(maspack.geometry.PolylineMesh) File(java.io.File) XyzbReader(maspack.geometry.io.XyzbReader)

Example 2 with PolylineMesh

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

the class MayaAsciiReader method getPolylineMesh.

public PolylineMesh getPolylineMesh(Node<MayaNode> root, UnitInfo units, String regex) {
    if (units == null) {
        units = defaultUnits;
    }
    PolylineMesh mesh = new PolylineMesh();
    AffineTransform3d trans = new AffineTransform3d();
    recursiveBuildParentTransform(root, trans, units);
    Pattern pregex = null;
    if (regex != null) {
        pregex = Pattern.compile(regex);
    }
    recursiveAddPolylines(root, mesh, trans, units, pregex);
    return mesh;
}
Also used : Pattern(java.util.regex.Pattern) PolylineMesh(maspack.geometry.PolylineMesh) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 3 with PolylineMesh

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

the class SkinDemo method addFiberMesh.

public void addFiberMesh() {
    PolylineMesh mesh = MeshFactory.createSphericalPolyline(8.0, 12, 12);
    mesh.scale(1, 1, 2.5);
    mesh.transform(new RigidTransform3d(-6, 0, 0, 0, Math.toRadians(22.5), 0));
    SkinMeshBody fiberMesh = new SkinMeshBody(mesh);
    fiberMesh.addFrame(model.rigidBodies().get(0));
    fiberMesh.addFrame(model.rigidBodies().get(1));
    fiberMesh.computeWeights();
    model.addMeshBody(fiberMesh);
    RenderProps.setLineColor(fiberMesh, Color.CYAN);
    myFiberMesh = fiberMesh;
}
Also used : SkinMeshBody(artisynth.core.femmodels.SkinMeshBody) RigidTransform3d(maspack.matrix.RigidTransform3d) PolylineMesh(maspack.geometry.PolylineMesh)

Example 4 with PolylineMesh

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

the class RigidCompositeBody method addMeshInertia.

protected void addMeshInertia(MeshBase base, double density) {
    if (base == null) {
        throw new IllegalStateException("Mesh has not been set");
    }
    if (base instanceof PolygonalMesh) {
        PolygonalMesh mesh = (PolygonalMesh) base;
        SpatialInertia M = mesh.createInertia(density);
        mySpatialInertia.add(M);
    } else if (base instanceof PointMesh) {
    // XXX to implement
    } else if (base instanceof PolylineMesh) {
    // XXX to implement
    }
}
Also used : PointMesh(maspack.geometry.PointMesh) PolylineMesh(maspack.geometry.PolylineMesh) PolygonalMesh(maspack.geometry.PolygonalMesh) SpatialInertia(maspack.spatialmotion.SpatialInertia)

Aggregations

PolylineMesh (maspack.geometry.PolylineMesh)4 PointMesh (maspack.geometry.PointMesh)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 SkinMeshBody (artisynth.core.femmodels.SkinMeshBody)1 Point (java.awt.Point)1 File (java.io.File)1 Pattern (java.util.regex.Pattern)1 MeshBase (maspack.geometry.MeshBase)1 GenericMeshReader (maspack.geometry.io.GenericMeshReader)1 MeshReader (maspack.geometry.io.MeshReader)1 WavefrontReader (maspack.geometry.io.WavefrontReader)1 XyzbReader (maspack.geometry.io.XyzbReader)1 AffineTransform3d (maspack.matrix.AffineTransform3d)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 SpatialInertia (maspack.spatialmotion.SpatialInertia)1