use of org.sunflow.util.FloatArray in project joons-renderer by joonhyublee.
the class ShaveRibParser method parseFloatArray.
private float[] parseFloatArray(Parser p) throws IOException {
FloatArray array = new FloatArray();
boolean done = false;
do {
String s = p.getNextToken();
if (s.startsWith("[")) {
s = s.substring(1);
}
if (s.endsWith("]")) {
s = s.substring(0, s.length() - 1);
done = true;
}
array.add(Float.parseFloat(s));
} while (!done);
return array.trim();
}
use of org.sunflow.util.FloatArray in project joons-renderer by joonhyublee.
the class Gumbo method parseFloatArray.
private static float[] parseFloatArray(Parser p) throws IOException {
FloatArray array = new FloatArray();
boolean done = false;
do {
String s = p.getNextToken();
if (s.startsWith("[")) {
s = s.substring(1);
}
if (s.endsWith("]")) {
s = s.substring(0, s.length() - 1);
done = true;
}
array.add(Float.parseFloat(s));
} while (!done);
return array.trim();
}
use of org.sunflow.util.FloatArray in project joons-renderer by joonhyublee.
the class FileMesh method tesselate.
public PrimitiveList tesselate() {
if (filename.endsWith(".ra3")) {
try {
UI.printInfo(Module.GEOM, "RA3 - Reading geometry: \"%s\" ...", filename);
File file = new File(filename);
FileInputStream stream = new FileInputStream(filename);
MappedByteBuffer map = stream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
map.order(ByteOrder.LITTLE_ENDIAN);
IntBuffer ints = map.asIntBuffer();
FloatBuffer buffer = map.asFloatBuffer();
int numVerts = ints.get(0);
int numTris = ints.get(1);
UI.printInfo(Module.GEOM, "RA3 - * Reading %d vertices ...", numVerts);
float[] verts = new float[3 * numVerts];
for (int i = 0; i < verts.length; i++) {
verts[i] = buffer.get(2 + i);
}
UI.printInfo(Module.GEOM, "RA3 - * Reading %d triangles ...", numTris);
int[] tris = new int[3 * numTris];
for (int i = 0; i < tris.length; i++) {
tris[i] = ints.get(2 + verts.length + i);
}
stream.close();
UI.printInfo(Module.GEOM, "RA3 - * Creating mesh ...");
return generate(tris, verts, smoothNormals);
} catch (FileNotFoundException e) {
Logger.getLogger(FileMesh.class.getName()).log(Level.SEVERE, null, e);
UI.printError(Module.GEOM, "Unable to read mesh file \"%s\" - file not found", filename);
} catch (IOException e) {
Logger.getLogger(FileMesh.class.getName()).log(Level.SEVERE, null, e);
UI.printError(Module.GEOM, "Unable to read mesh file \"%s\" - I/O error occured", filename);
}
} else if (filename.endsWith(".obj")) {
int lineNumber = 1;
try {
UI.printInfo(Module.GEOM, "OBJ - Reading geometry: \"%s\" ...", filename);
FloatArray verts = new FloatArray();
IntArray tris = new IntArray();
FileReader file = new FileReader(filename);
BufferedReader bf = new BufferedReader(file);
String line;
while ((line = bf.readLine()) != null) {
if (line.startsWith("v")) {
String[] v = line.split("\\s+");
verts.add(Float.parseFloat(v[1]));
verts.add(Float.parseFloat(v[2]));
verts.add(Float.parseFloat(v[3]));
} else if (line.startsWith("f")) {
String[] f = line.split("\\s+");
if (f.length == 5) {
tris.add(Integer.parseInt(f[1]) - 1);
tris.add(Integer.parseInt(f[2]) - 1);
tris.add(Integer.parseInt(f[3]) - 1);
tris.add(Integer.parseInt(f[1]) - 1);
tris.add(Integer.parseInt(f[3]) - 1);
tris.add(Integer.parseInt(f[4]) - 1);
} else if (f.length == 4) {
tris.add(Integer.parseInt(f[1]) - 1);
tris.add(Integer.parseInt(f[2]) - 1);
tris.add(Integer.parseInt(f[3]) - 1);
}
}
if (lineNumber % 100000 == 0) {
UI.printInfo(Module.GEOM, "OBJ - * Parsed %7d lines ...", lineNumber);
}
lineNumber++;
}
file.close();
UI.printInfo(Module.GEOM, "OBJ - * Creating mesh ...");
return generate(tris.trim(), verts.trim(), smoothNormals);
} catch (FileNotFoundException e) {
Logger.getLogger(FileMesh.class.getName()).log(Level.SEVERE, null, e);
UI.printError(Module.GEOM, "Unable to read mesh file \"%s\" - file not found", filename);
} catch (NumberFormatException e) {
Logger.getLogger(FileMesh.class.getName()).log(Level.SEVERE, null, e);
UI.printError(Module.GEOM, "Unable to read mesh file \"%s\" - syntax error at line %d", lineNumber);
} catch (IOException e) {
Logger.getLogger(FileMesh.class.getName()).log(Level.SEVERE, null, e);
UI.printError(Module.GEOM, "Unable to read mesh file \"%s\" - I/O error occured", filename);
}
} else if (filename.endsWith(".stl")) {
try {
UI.printInfo(Module.GEOM, "STL - Reading geometry: \"%s\" ...", filename);
FileInputStream file = new FileInputStream(filename);
DataInputStream stream = new DataInputStream(new BufferedInputStream(file));
file.skip(80);
int numTris = getLittleEndianInt(stream.readInt());
UI.printInfo(Module.GEOM, "STL - * Reading %d triangles ...", numTris);
long filesize = new File(filename).length();
if (filesize != (84 + 50 * numTris)) {
UI.printWarning(Module.GEOM, "STL - Size of file mismatch (expecting %s, found %s)", Memory.bytesToString(84 + 14 * numTris), Memory.bytesToString(filesize));
return null;
}
int[] tris = new int[3 * numTris];
float[] verts = new float[9 * numTris];
for (int i = 0, i3 = 0, index = 0; i < numTris; i++, i3 += 3) {
// skip normal
stream.readInt();
stream.readInt();
stream.readInt();
for (int j = 0; j < 3; j++, index += 3) {
tris[i3 + j] = i3 + j;
// get xyz
verts[index + 0] = getLittleEndianFloat(stream.readInt());
verts[index + 1] = getLittleEndianFloat(stream.readInt());
verts[index + 2] = getLittleEndianFloat(stream.readInt());
}
stream.readShort();
if ((i + 1) % 100000 == 0) {
UI.printInfo(Module.GEOM, "STL - * Parsed %7d triangles ...", i + 1);
}
}
file.close();
// create geometry
UI.printInfo(Module.GEOM, "STL - * Creating mesh ...");
if (smoothNormals) {
UI.printWarning(Module.GEOM, "STL - format does not support shared vertices - normal smoothing disabled");
}
return generate(tris, verts, false);
} catch (FileNotFoundException e) {
Logger.getLogger(FileMesh.class.getName()).log(Level.SEVERE, null, e);
UI.printError(Module.GEOM, "Unable to read mesh file \"%s\" - file not found", filename);
} catch (IOException e) {
Logger.getLogger(FileMesh.class.getName()).log(Level.SEVERE, null, e);
UI.printError(Module.GEOM, "Unable to read mesh file \"%s\" - I/O error occured", filename);
}
} else {
UI.printWarning(Module.GEOM, "Unable to read mesh file \"%s\" - unrecognized format", filename);
}
return null;
}
Aggregations