Search in sources :

Example 1 with FileCacher

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;
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) FileCacher(maspack.fileutil.FileCacher) URIx(maspack.fileutil.uri.URIx) IOException(java.io.IOException) File(java.io.File) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 FileCacher (maspack.fileutil.FileCacher)1 URIx (maspack.fileutil.uri.URIx)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 WavefrontReader (maspack.geometry.io.WavefrontReader)1 AxisAngle (maspack.matrix.AxisAngle)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 Vector3d (maspack.matrix.Vector3d)1