Search in sources :

Example 11 with WavefrontReader

use of maspack.geometry.io.WavefrontReader in project artisynth_core by artisynth.

the class WavefrontToMaya method doFiberExport.

public static void doFiberExport(String inputFile, String outputFile, NumberFormat fmt) {
    PrintStream out;
    WavefrontReader wfr;
    String outputFileName = "unknown";
    // output stream
    if (outputFile == null) {
        out = System.out;
    } else {
        try {
            out = new PrintStream(outputFile);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        outputFileName = outputFile.substring(outputFile.lastIndexOf(File.separator) + 1);
    }
    try {
        wfr = new WavefrontReader(inputFile);
        wfr.parse();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    Date date = new Date();
    DateFormat dateFormat = new SimpleDateFormat("EEE, MMM dd, yyyy HH:mm:ss z");
    // maya header
    out.println("//Maya ASCII 2012 scene");
    out.println("//Name: " + outputFileName);
    out.println("//Last modified: " + dateFormat.format(date));
    out.println("//Codeset: 1252");
    out.println("requires maya \"" + requiresMayaVersion + "\";");
    int lineNum = 0;
    for (String groupName : wfr.getPolylineGroupNames()) {
        wfr.setGroup(groupName);
        ArrayList<Point3d> vtxList = new ArrayList<Point3d>();
        int[][] indices;
        try {
            indices = wfr.getLocalLineIndicesAndVertices(vtxList);
        } catch (IOException e) {
            e.printStackTrace();
            continue;
        }
        for (int i = 0; i < indices.length; i++) {
            lineNum++;
            String lineStr = stringifyPolyline(indices[i], vtxList, "curve" + lineNum, fmt);
            out.print(lineStr);
        }
    }
    // maya footer
    out.println("// End of " + outputFileName);
    if (out != System.out) {
        out.flush();
        out.close();
    }
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) PrintStream(java.io.PrintStream) Point3d(maspack.matrix.Point3d) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

WavefrontReader (maspack.geometry.io.WavefrontReader)11 IOException (java.io.IOException)6 File (java.io.File)4 PolygonalMesh (maspack.geometry.PolygonalMesh)4 Color (java.awt.Color)2 Point3d (maspack.matrix.Point3d)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2 Vector3d (maspack.matrix.Vector3d)2 RenderProps (maspack.render.RenderProps)2 FemElement3d (artisynth.core.femmodels.FemElement3d)1 FemMeshComp (artisynth.core.femmodels.FemMeshComp)1 FemMuscleModel (artisynth.core.femmodels.FemMuscleModel)1 MuscleBundle (artisynth.core.femmodels.MuscleBundle)1 FemMaterial (artisynth.core.materials.FemMaterial)1 LinearMaterial (artisynth.core.materials.LinearMaterial)1 MuscleMaterial (artisynth.core.materials.MuscleMaterial)1 SimpleForceMuscle (artisynth.core.materials.SimpleForceMuscle)1 MechModel (artisynth.core.mechmodels.MechModel)1 RigidBody (artisynth.core.mechmodels.RigidBody)1 Point (java.awt.Point)1