use of maspack.geometry.PointMesh in project artisynth_core by artisynth.
the class PlyReader method readMesh.
public MeshBase readMesh(MeshBase mesh) throws IOException {
DataInputStream is = new DataInputStream(myIstream);
parseHeader(is);
ArrayList<Point3d> verts = new ArrayList<Point3d>();
ArrayList<Vector3d> nrmls = new ArrayList<Vector3d>();
ArrayList<int[]> faces = new ArrayList<int[]>();
if (myDataFormat == DataFormat.ASCII) {
ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new InputStreamReader(myIstream)));
readVertexInfo(rtok, verts, nrmls);
readFaceInfo(rtok, faces);
} else {
BinaryInputStream bis = new BinaryInputStream(new BufferedInputStream(myIstream));
if (myDataFormat == DataFormat.BINARY_LITTLE_ENDIAN) {
bis.setLittleEndian(true);
}
readVertexInfo(bis, verts, nrmls);
readFaceInfo(bis, faces);
}
if (mesh == null) {
if (myNumFaces == 0) {
mesh = new PointMesh();
} else {
mesh = new PolygonalMesh();
}
}
if (mesh instanceof PolygonalMesh) {
PolygonalMesh pmesh = (PolygonalMesh) mesh;
int icnt = 0;
for (Point3d pnt : verts) {
pmesh.addVertex(pnt);
}
for (int[] idxs : faces) {
pmesh.addFace(idxs);
icnt += idxs.length;
}
if (nrmls.size() > 0) {
// we have to assume here the there is one normal per vertex,
// and assign the normal indices accordingly]
int k = 0;
int[] normalIndices = new int[icnt];
for (int i = 0; i < faces.size(); i++) {
int[] idxs = pmesh.getFaces().get(i).getVertexIndices();
for (int j = 0; j < idxs.length; j++) {
normalIndices[k++] = idxs[j];
}
}
pmesh.setNormals(nrmls, normalIndices);
pmesh.setHardEdgesFromNormals();
}
} else if (mesh instanceof PointMesh) {
PointMesh pmesh = (PointMesh) mesh;
pmesh.set(verts.toArray(new Point3d[0]), nrmls.toArray(new Vector3d[0]));
} else {
throw new UnsupportedOperationException("Mesh type " + mesh.getClass() + " not supported by this reader");
}
return mesh;
}
use of maspack.geometry.PointMesh in project artisynth_core by artisynth.
the class XyzbReader method readMesh.
public PointMesh readMesh(PointMesh mesh, InputStream in) throws IOException {
BinaryInputStream bin = new BinaryInputStream(new BufferedInputStream(in));
bin.setLittleEndian(myLittleEndian);
if (mesh == null) {
mesh = new PointMesh();
}
mesh.clear();
ArrayList<Point3d> vtxs = new ArrayList<Point3d>();
ArrayList<Vector3d> nrms = new ArrayList<Vector3d>();
boolean done = false;
int cnt = 0;
while (!done) {
try {
double vx = bin.readFloat();
double vy = bin.readFloat();
double vz = bin.readFloat();
double nx = bin.readFloat();
double ny = bin.readFloat();
double nz = bin.readFloat();
if (cnt % mySkip == 0) {
vtxs.add(new Point3d(vx, vy, vz));
nrms.add(new Vector3d(nx, ny, nz));
}
} catch (EOFException e) {
done = true;
}
cnt++;
}
bin.close();
mesh.set(vtxs.toArray(new Point3d[0]), nrms.toArray(new Vector3d[0]));
return mesh;
}
Aggregations