Пример #1
0
/*
* 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";
}
Пример #2
0
void MeshViewer::initGeometry()
{
  m_geometry_group = m_context->createGeometryGroup();

  if( ObjLoader::isMyFile( m_filename.c_str() ) ) {
    // Load OBJ model 
    ObjLoader* loader = 0;
    if( m_shade_mode == SM_NORMAL || m_shade_mode == SM_AO ) {
      loader = new ObjLoader( m_filename.c_str(), m_context, m_geometry_group, m_material );
    } else if ( m_shade_mode == SM_ONE_BOUNCE_DIFFUSE ) {
      loader = new ObjLoader( m_filename.c_str(), m_context, m_geometry_group, m_material, true );
    } else {
      loader = new ObjLoader( m_filename.c_str(), m_context, m_geometry_group );
    }

    const std::string geom_ptx = ptxpath( "displacement", "geometry_programs.cu" );
    loader->setIntersectProgram(m_context->createProgramFromPTXFile( geom_ptx, "mesh_intersect" ) );
    loader->setBboxProgram(m_context->createProgramFromPTXFile( geom_ptx, "mesh_bounds" ) );

    loader->load();
    m_aabb = loader->getSceneBBox();
    delete loader;

  } else if( PlyLoader::isMyFile( m_filename ) ) {
    // Load PLY model 
    PlyLoader loader( m_filename, m_context, m_geometry_group, m_material );
    loader.load();

    m_aabb = loader.getSceneBBox();

  } else {
    std::cerr << "Unrecognized model file extension '" << m_filename << "'" << std::endl;
    exit( 0 );
  }

  // Override acceleration structure builder. The default used by the ObjLoader is Sbvh.
  if( !m_accel_builder.empty() ) {
    Acceleration accel = m_geometry_group->getAcceleration();
    accel->setBuilder( m_accel_builder );
  }

  Acceleration accel = m_geometry_group->getAcceleration();
  accel->setBuilder("Bvh");

  // Override traverer if one is given.
  if( !m_accel_traverser.empty() ) {
    Acceleration accel = m_geometry_group->getAcceleration();
    accel->setTraverser( m_accel_traverser );
  }

  if( m_accel_builder == "TriangleKdTree" || m_accel_traverser == "KdTree") {
    Acceleration accel = m_geometry_group->getAcceleration();
    accel->setProperty( "vertex_buffer_name", "vertex_buffer" );
    accel->setProperty( "index_buffer_name", "vindex_buffer" );
  }
  
  // Load acceleration structure from a file if that was enabled on the
  // command line, and if we can find a cache file. Note that the type of
  // acceleration used will be overridden by what is found in the file.
  loadAccelCache();

  
  m_context[ "top_object" ]->set( m_geometry_group );
  m_context[ "top_shadower" ]->set( m_geometry_group );

}