/* * Escribe en el string "files" una lista de archivos separados por salto de línea, * luego carga todos esos archivos con ObjLoader. */ void MeshViewer::initGeometry() { double start, end; sutilCurrentTime(&start); m_geometry_group = m_context->createGeometryGroup(); float min_y = FLT_MAX; std::string files = ""; size_t found; std::string m_filename = m_mesh_path + m_mesh_file; // En caso de no existir el archivo del modelo busca todos los modelos ".obj" del directorio if (ObjLoader::isMyFile(m_filename.c_str()) && MeshViewer::existsFile(m_filename.c_str())) { found = m_filename.find_last_of("/\\"); files = m_filename.substr(found+1) + "\n"; } else { std::string match = m_mesh_path + "*.obj"; files = MeshViewer::getFilesByExtension(match.c_str()); if (files.size() == 0) { std::cerr << "Unrecognized model file extension '" << m_filename << "'" << std::endl; exit( 0 ); } } // Carga todos los modelos del directorio while (files.size() > 0) { found = files.find_first_of('\n'); std::string filename = m_mesh_path + files.substr(0, found); ObjLoader* loader = new ObjLoader(filename.c_str(), m_context, m_geometry_group, m_accel_builder.c_str(), m_accel_traverser.c_str(), m_accel_refine.c_str(), false); loader->setPathProgram(m_program_path); loader->setIntersectProgram(m_intersect_file, m_intersect_name); loader->setBoundsProgram(m_bounds_file, m_bounds_name); loader->setAnyHitProgram(m_any_hit_file, m_any_hit_name); loader->setClosestHitProgram(m_closest_hit_file, m_closest_hit_name); files.erase(0, found+1); loader->load(); m_aabb = loader->getSceneBBox(); min_y = (m_aabb.m_min.y < min_y) ? m_aabb.m_min.y : min_y; delete loader; } m_context[ "top_object" ]->set( m_geometry_group ); m_context[ "top_shadower" ]->set( m_geometry_group ); m_context[ "floor_y" ]->setFloat( min_y ); sutilCurrentTime(&end); std::cerr << "Time to load " << (false ? "and cluster " : "") << "geometry: " << end-start << " s.\n"; }
void MeshViewer::preprocess() { // Settings which rely on previous initialization m_scene_epsilon = 1.e-4f * m_aabb.maxExtent(); m_context[ "scene_epsilon" ]->setFloat( m_scene_epsilon ); // Prepare to run m_context->validate(); double start, end_compile, end_AS_build; sutilCurrentTime(&start); m_context->compile(); sutilCurrentTime(&end_compile); std::cerr << "Time to compile kernel: " << end_compile-start << " s.\n"; m_context->launch(0,0); sutilCurrentTime(&end_AS_build); std::cerr << "Time to build AS : " << end_AS_build-end_compile << " s.\n"; }
RTresult sutilFrameBenchmark( const char *name, unsigned int warmup_frames, unsigned int timed_frames) { /* Handle benchmarking */ static double start_frame_time = 0, end_frame_time = 0; static unsigned int timed_frames_done = 0, warmup_frames_done = 0; if(warmup_frames_done < warmup_frames) { warmup_frames_done++; } else if(warmup_frames_done == warmup_frames) { sutilCurrentTime(&start_frame_time); warmup_frames_done++; }else { timed_frames_done++; if(timed_frames_done == timed_frames) { sutilCurrentTime(&end_frame_time); sutilPrintBenchmark( name, end_frame_time - start_frame_time, warmup_frames, timed_frames ); exit(0); } } return RT_SUCCESS; }