use of maspack.fileutil.FileCacher in project artisynth_core by artisynth.
the class MultiViewerTesterBase method loadStanfordBunny.
protected static PolygonalMesh loadStanfordBunny() {
// read Standford bunny directly
String bunnyURL = "http://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj";
// bunny
File bunnyFile = new File("tmp/data/stanford_bunny.obj");
PolygonalMesh bunny = null;
try {
if (!bunnyFile.exists()) {
bunnyFile.getParentFile().mkdirs();
// read file directly from remote
FileCacher cacher = new FileCacher();
cacher.initialize();
cacher.cache(new URIx(bunnyURL), bunnyFile);
cacher.release();
}
WavefrontReader reader = new WavefrontReader(bunnyFile);
bunny = new PolygonalMesh();
reader.readMesh(bunny);
// bunny.computeVertexNormals();
// normalize bunny
double r = bunny.computeRadius();
Vector3d c = new Vector3d();
bunny.computeCentroid(c);
c.negate();
bunny.scale(1.0 / r);
c.z -= 0.5;
bunny.transform(new RigidTransform3d(c, new AxisAngle(1, 0, 0, Math.PI / 2)));
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("Unable to load stanford bunny... requires internet connection");
bunny = null;
}
return bunny;
}
Aggregations