Created
January 22, 2016 15:54
-
-
Save ryanbartley/cd89c4bedf0248c73212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just give it a path getAssetPath( "MyEnormous.obj" ) and it'll do the rest. | |
// the first time through will be very long. :) | |
geom::SourceRef getGeometry( const ci::fs::path &geomPath ) | |
{ | |
auto tri = TriMesh::create( TriMesh::Format().positions().normals().texCoords() ); | |
if( geomPath.extension() == ".obj" ) { | |
auto binPath = geomPath; | |
binPath.replace_extension( "bin" ); | |
if( !fs::exists( binPath ) ) { | |
CI_LOG_I( "Opening up Obj to reformat to bin..." ); | |
auto objLoader = ObjLoader( ci::loadFile( geomPath ) ); | |
CI_LOG_I( "Obj opened, creating Trimesh..." ); | |
auto tri = TriMesh::create( objLoader, ci::TriMesh::Format().positions().normals().texCoords() ); | |
auto target = writeFile( binPath ); | |
CI_LOG_I( "Writing Trimesh data to file..." ); | |
tri->write( target ); | |
} | |
else { | |
CI_LOG_I( "Bin file exists, loading..." ); | |
tri->read( loadFile( binPath ) ); | |
} | |
} | |
else if( geomPath.extension() == ".bin" ) { | |
CI_LOG_I( "Bin file exists, loading..." ); | |
tri->read( ci::loadFile( geomPath ) ); | |
} | |
return tri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment