use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class MayaJointToMatlab method doJointExport.
public void doJointExport(String inputFile, String outputFile) {
PrintStream out;
ReaderTokenizer rtok;
// output stream
if (outputFile == null) {
out = System.out;
} else {
try {
out = new PrintStream(outputFile);
} catch (IOException e) {
e.printStackTrace();
return;
}
}
// input stream
try {
rtok = new ReaderTokenizer(new FileReader(inputFile));
rtok.eolIsSignificant(true);
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");
out.println("% Exported matlab file from '" + inputFile + "', " + dateFormat.format(date));
int iJoint = 0;
try {
String line = readLine(rtok);
while (rtok.ttype != ReaderTokenizer.TT_EOF) {
// find joint
if (line.contains("createNode joint")) {
String jointName = getMayaName(line);
String jointParent = getMayaParent(line);
out.println();
out.println(jointName + ".parent = " + jointParent + ";");
line = readLine(rtok);
while (!line.contains("createNode") && rtok.ttype != ReaderTokenizer.TT_EOF) {
if (line.contains("setAttr")) {
MayaAttribute attr = new MayaAttribute();
getAttribute(line, attr);
if (!attr.dashed) {
out.println(jointName + "." + attr.name + "= " + attr.attr + ";");
}
}
line = readLine(rtok);
}
iJoint++;
out.println("JointArray(" + iJoint + ").joint=" + jointName + ";");
out.println("JointArray(" + iJoint + ").name=\'" + jointName + "\';");
} else {
line = readLine(rtok);
}
}
} catch (IOException e) {
e.printStackTrace();
out.close();
return;
}
if (out != System.out) {
out.close();
}
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class StlReader method readASCII.
public static PolygonalMesh readASCII(PolygonalMesh mesh, Reader reader, double tol) throws IOException {
ReaderTokenizer rtok = new ReaderTokenizer(reader);
ArrayList<Point3d> nodeList = new ArrayList<Point3d>();
ArrayList<ArrayList<Integer>> faceList = new ArrayList<ArrayList<Integer>>();
rtok.eolIsSignificant(true);
String solidName = "";
// read until we find "solid"
while (rtok.nextToken() != ReaderTokenizer.TT_EOF) {
if (rtok.ttype == ReaderTokenizer.TT_WORD) {
String word = rtok.sval.toLowerCase();
if (word.equals("solid")) {
rtok.nextToken();
if (rtok.ttype == ReaderTokenizer.TT_WORD) {
solidName = rtok.sval;
}
toEOL(rtok);
} else if (word.equals("facet")) {
ArrayList<Integer> face = readFace(rtok, nodeList, tol);
if (face != null) {
faceList.add(face);
}
} else if (word.equals("endsolid") || word.equals("end")) {
boolean setMeshName = true;
if (mesh != null) {
setMeshName = false;
}
mesh = buildMesh(mesh, nodeList, faceList);
if (setMeshName) {
mesh.setName(solidName);
}
return mesh;
}
}
}
return null;
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class WavefrontReader method parseMaterialFile.
private void parseMaterialFile(String matFileName) throws IOException {
File parentFile = new File(currPath);
File matFile = new File(parentFile, matFileName);
if (!matFile.canRead() && verbose) {
System.out.println("WavefrontReader warning: can't read material file '" + matFile + "'; ignoring");
}
ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new FileReader(matFile)));
myCurrentProps = null;
rtok.commentChar('#');
rtok.eolIsSignificant(true);
// fast-forward to first definition
nextToken(rtok);
RenderProps newProps = null;
String matName = null;
while (rtok.ttype != ReaderTokenizer.TT_EOF) {
if (rtok.ttype == ReaderTokenizer.TT_WORD) {
if (rtok.sval.equals("newmtl")) {
break;
}
}
toNextLine(rtok);
}
while (rtok.ttype != ReaderTokenizer.TT_EOF) {
if (rtok.ttype == ReaderTokenizer.TT_WORD) {
if (rtok.sval.equals("newmtl")) {
// save old
if (newProps != null) {
// this doesn't work
myMaterialMap.put(matName, newProps);
}
matName = scanName(rtok);
newProps = new RenderProps();
// System.out.println ("found new material '"+matName+"'");
} else {
processMaterialLine(rtok, newProps);
}
toNextLine(rtok);
} else {
if (rtok.ttype != ReaderTokenizer.TT_EOL) {
throw new IOException("unexpected token " + rtok.ttype + " in material file " + matFile + ", line " + rtok.lineno());
} else {
// move to next token
nextToken(rtok);
}
}
}
if (newProps != null) {
// add final render props
myMaterialMap.put(matName, newProps);
}
rtok.close();
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class WavefrontReader method parse.
public void parse() throws IOException {
ReaderTokenizer rtok = myRtok;
boolean savedEol = rtok.getEolIsSignificant();
int savePound = rtok.getCharSetting('#');
int saveSlash = rtok.getCharSetting('/');
rtok.commentChar('#');
rtok.ordinaryChar('/');
rtok.eolIsSignificant(true);
while (nextToken(rtok) != ReaderTokenizer.TT_EOF) {
if (rtok.ttype == ReaderTokenizer.TT_WORD) {
if (rtok.sval.equals("EOF")) {
break;
}
if (!processLine(rtok)) {
// flush to EOL
toEOL(rtok);
}
} else if (rtok.ttype != ReaderTokenizer.TT_EOL) {
throw new IOException("unexpected token " + rtok.ttype + " , line " + rtok.lineno());
}
}
rtok.eolIsSignificant(savedEol);
rtok.setCharSetting('#', savePound);
rtok.setCharSetting('/', saveSlash);
myInputHasBeenParsed = true;
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class XyzReader method read.
public PointMesh read(PointMesh mesh, InputStream in) throws IOException {
ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new InputStreamReader(in)));
if (mesh == null) {
mesh = new PointMesh();
}
mesh.clear();
ArrayList<Point3d> vtxs = new ArrayList<Point3d>();
ArrayList<Vector3d> nrms = new ArrayList<Vector3d>();
boolean done = false;
while (!done) {
try {
double vx = rtok.scanNumber();
double vy = rtok.scanNumber();
double vz = rtok.scanNumber();
double nx = rtok.scanNumber();
double ny = rtok.scanNumber();
double nz = rtok.scanNumber();
vtxs.add(new Point3d(vx, vy, vz));
nrms.add(new Vector3d(nx, ny, nz));
} catch (EOFException e) {
done = true;
}
}
mesh.set(vtxs.toArray(new Point3d[0]), nrms.toArray(new Vector3d[0]));
return mesh;
}
Aggregations