Ejemplo n.º 1
0
void NormalMapScene::initialise()
{
    // Create a material that performs multi-texturing
#if !defined(Q_OS_MAC)
    MaterialPtr material = createTextureMaterial(
                               "../../../opengl/assets/meshes/ogrehead/ogrehead_diffuse.png",
                               "../../../opengl/assets/meshes/ogrehead/ogre_normalmap.png" );
#else
    MaterialPtr material = createTextureMaterial(
                               "../../../../../../opengl/assets/meshes/ogrehead/ogrehead_diffuse.png",
                               "../../../../../../opengl/assets/meshes/ogrehead/ogre_normalmap.png" );
#endif

    // Load the model mesh
    ObjLoader loader;
    loader.setLoadTextureCoordinatesEnabled( true );
    loader.setTangentGenerationEnabled( true );
#if !defined(Q_OS_MAC)
    loader.load( "../../../opengl/assets/meshes/ogrehead/ogrehead.obj" );
#else
    loader.load( "../../../../../../opengl/assets/meshes/ogrehead/ogrehead.obj" );
#endif

    m_mesh = new Mesh( this );
    m_mesh->setMaterial( material );
    m_mesh->setMeshData( loader );

    // Enable depth testing
    glEnable( GL_DEPTH_TEST );

    // Set the clear color to white
    glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
}
void AmbientOcclusionScene::initialise()
{
    // Load the model mesh
    ObjLoader loader;
    loader.setTangentGenerationEnabled( false );
#if !defined(Q_OS_MAC)
    loader.load( "../../../opengl/assets/meshes/ogrehead/ogrehead.obj" );
#else
    loader.load( "../../../../../../opengl/assets/meshes/ogrehead/ogrehead.obj" );
#endif

    // Create an ambient occlusion material that uses a diffuse texture
    // and an ambient occlusion (accessibility factors) texture
#if !defined(Q_OS_MAC)
    MaterialPtr material =
        createAmbientOcclusionMaterial(
                "../../../opengl/assets/meshes/ogrehead/ogrehead_diffuse.png",
                "../../../opengl/assets/meshes/ogrehead/ogrehead_ambientocclusion.png" );
#else
    MaterialPtr material =
        createAmbientOcclusionMaterial(
                "../../../../../../opengl/assets/meshes/ogrehead/ogrehead_diffuse.png",
                "../../../../../../opengl/assets/meshes/ogrehead/ogrehead_ambientocclusion.png" );
#endif

    // Create a renderable object
    m_mesh = new Mesh;
    m_mesh->setMaterial( material );
    m_mesh->setMeshData( loader );

    // Enable depth testing
    glEnable( GL_DEPTH_TEST );

    glClearColor( 0.9f, 0.9f, 0.9f, 1.0f );
}
Ejemplo n.º 3
0
void NormalMapScene::initialise()
{
    //dumpTextureUnitConfiguration();

#if !defined(Q_OS_MAC)
    m_funcs = m_context->versionFunctions<QOpenGLFunctions_3_3_Compatibility>();
#else
    m_funcs = m_context->versionFunctions<QOpenGLFunctions_2_1>();
#endif
    if ( !m_funcs )
        qFatal( "Could not obtain functions object" );
    m_funcs->initializeOpenGLFunctions();

    // Create a material that performs multi-texturing
#if !defined(Q_OS_MAC)
    MaterialPtr material = createTextureMaterial( "../../assets/meshes/ogrehead/ogrehead_diffuse.png",
                                                  "../../assets/meshes/ogrehead/ogre_normalmap.png" );
#else
    MaterialPtr material = createTextureMaterial(
                               "../../../opengl/assets/meshes/ogrehead/ogrehead_diffuse.png",
                               "../../../opengl/assets/meshes/ogrehead/ogre_normalmap.png" );
#endif

    // Load the model mesh
    ObjLoader loader;
    loader.setLoadTextureCoordinatesEnabled( true );
    loader.setTangentGenerationEnabled( true );
#if !defined(Q_OS_MAC)
    loader.load( "../../assets/meshes/ogrehead/ogrehead.obj" );
#else
    loader.load( "../../../opengl/assets/meshes/ogrehead/ogrehead.obj" );
#endif

    m_mesh = new Mesh;
    m_mesh->setMaterial( material );
    m_mesh->setMeshData( loader );

    // Enable depth testing
    glEnable( GL_DEPTH_TEST );

    // Set the clear color to (almost) white
    glClearColor( 0.9f, 0.9f, 0.9f, 1.0f );

    m_funcs->glActiveTexture( GL_TEXTURE1 );
    m_funcs->glBindTexture( GL_TEXTURE_2D, 0 );
    m_funcs->glActiveTexture( GL_TEXTURE0 );
    m_funcs->glBindTexture( GL_TEXTURE_2D, 0 );

    //dumpTextureUnitConfiguration();
}
Ejemplo n.º 4
0
void initVariables()
{
    interoculardistance = str2num<double>(parameters.find("IOD"));
    stimulusEmiCycles= atoi(parameters.find("StimulusEmiCycles").c_str());
    trial.init(parameters);
    factors = trial.getNext(); // Initialize the factors in order to start from trial 1

    if ( atoi(parameters.find("DrawOccluder").c_str()) ==1 )
    {
        redDotsPlane.setNpoints(500);  //XXX controllare densita di distribuzione dei punti
        redDotsPlane.setDimensions(200,200,0.1);
    }
    else
    {
        redDotsPlane.setNpoints(75);  //XXX controllare densita di distribuzione dei punti
        redDotsPlane.setDimensions(50,50,0.1);
    }
    //redDotsPlane.setSlantTilt( factors["Slant"], (int) factors["Tilt"] );
    redDotsPlane.compute();
    stimDrawer.setStimulus(&redDotsPlane);
    stimDrawer.initList(&redDotsPlane);

    /** Bound check things **/
    signsX.push_back(false);
    signsX.push_back(false);

    signsY.push_back(false);
    signsY.push_back(false);

    headEyeCoords.init(Vector3d(-32.5,0,0),Vector3d(32.5,0,0), Vector3d(0,0,0),Vector3d(0,10,0),Vector3d(0,0,10),interoculardistance );
    eyeCalibration=headEyeCoords.getRightEye();
    model.load("../data/objmodels/occluder.obj");
}
Ejemplo n.º 5
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";
}
void drawBuddha()
{
   model.load("../../cncsvision/data/objmodels/happyBuddha.obj");
   glPushMatrix();
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   //TRANSLUCENT
   glTranslatef(0,0,factors["AbsDepth"]);
   glScalef(800,800,800);
   model.draw();
   glPopMatrix();
}
void CubeMapRefractionScene::initialise()
{
    // Set the clear color to black
    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

    // Create a material to be shared by the skybox and reflective object
    MaterialPtr material( new Material );
    material->setShaders( ":/shaders/skyboxrefraction.vert",
                          ":/shaders/skyboxrefraction.frag" );

    // Create the skybox
    m_skyBox->setMaterial( material );
    m_skyBox->create();
#if !defined(Q_OS_MAC)
    m_skyBox->setCubeMapBaseName( "../../../opengl/assets/textures/cubemap_miramar/miramar" );
#else
    m_skyBox->setCubeMapBaseName( "../../../../../../opengl/assets/textures/cubemap_miramar/miramar" );
#endif

    // Create a renderable object
    // Load the model mesh
    ObjLoader loader;
    loader.setTangentGenerationEnabled( false );
#if !defined(Q_OS_MAC)
    loader.load( "../../../opengl/assets/meshes/toyplane.obj" );
#else
    loader.load( "../../../../../../opengl/assets/meshes/toyplane.obj" );
#endif

    m_mesh = new Mesh;
    m_mesh->setMaterial( m_skyBox->material() );
    m_mesh->setMeshData( loader );

    // Enable depth testing
    glEnable( GL_DEPTH_TEST );
}
Ejemplo n.º 8
0
int main(int argc, char*argv[])
{

    optotrak.setTranslation(calibration);
    if ( optotrak.init(LastAlignedFile) != 0)
    {   cleanup();
        exit(0);
    }

    screen.setWidthHeight(SCREEN_WIDE_SIZE, SCREEN_WIDE_SIZE*SCREEN_HEIGHT/SCREEN_WIDTH);
    screen.setOffset(alignmentX,alignmentY);
    screen.setFocalDistance(focalDistance);
    cam.init(screen);

    recordHeadEyeRelativePositions();

    glutInit(&argc, argv);
    if (stereo)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STEREO);
    else
        glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

    if ( gameMode )
    {
        glutGameModeString(ROVERETO_GAME_MODE_STRING);
        glutEnterGameMode();
    }
    else
    {
        glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
        glutCreateWindow("CNCSVISION Example 2 HappyBuddha");
        glutFullScreen();
    }
    initRendering();

    model.load("../../data/objmodels/happyBuddha.obj");
    glutDisplayFunc(drawGLScene);
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);
    glutTimerFunc(TIMER_MS, update, 0);
    glutSetCursor(GLUT_CURSOR_NONE);
    /* Application main loop */
    glutMainLoop();

    cleanup();
    return 0;
}
Ejemplo n.º 9
0
Model* ModelFactory::createObjModel(const char* filename)
{
    if(filename == NULL)
    {
        LOG_ERROR("filename is NULL\n");
        return nullptr;
    }
    
    Model *pModel = new Model;
    
    bool success = false;
    string strFileName(filename);
    ObjLoader objLoader;
    success = objLoader.load(pModel, strFileName);
    if(success) return pModel;
    
    delete pModel;
    return nullptr;
}
/**
 * @brief main
 * @param argc
 * @param argv
 * @return
 */
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
    glutInitWindowSize(width, height);

    glutCreateWindow("OBJ Loader");
    initRendering();

    obj.load("/home/carlo/workspace/cncsvisioncmake/data/objmodels/skull.obj");
    //obj.centerToUnitBoundingBox();
    glutDisplayFunc(drawScene);
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);
    glutMouseFunc(mouseFunc);
    glutMotionFunc(mouseDrag);
    glutTimerFunc(15, update, 0);
    glutMainLoop();
    return 0;
}
Ejemplo n.º 11
0
//Thread1 for Getting Every Frames Body
DWORD WINAPI GetBodyData(LPVOID pParam)
{
	for (int i = StartNum + 1; i <= StopNum; i++)
	{
		string file_name;
		char num[4];
		_itoa_s(i, num, 10);
		string s = num;
		file_name = clothfile + s + ".obj";

		ObjLoader loader;

		Mesh new_body;
		loader.load(new_body, file_name);
		new_body.scale(0.30f);
		new_body.translate(0.0f, 1.0f, 0.0f);
		BodyQueue.push(new_body);
	}

	return 0;
}
Ejemplo n.º 12
0
int main(int argc, char*argv[])
{
    initOptotrak();
    model.load("../data/objmodels/face.obj");
    initObjectReferencePoints();

    glutInit(&argc, argv);
    if (stereo)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STEREO);
    else
        glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

    if (gameMode==false)
    {   glutInitWindowSize( SCREEN_WIDTH , SCREEN_HEIGHT );
        glutCreateWindow("EXP WEXLER");
        glutFullScreen();
    }
    else
    {   glutGameModeString("1024x768:32@60");
        glutEnterGameMode();
        glutFullScreen();
    }

    initRendering();
    initProjectionScreen(focalDistance,Affine3d::Identity());

    glutDisplayFunc(drawGLScene);
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);
    glutTimerFunc(TIMER_MS, update, 0);
    glutSetCursor(GLUT_CURSOR_NONE);
    /* Application main loop */
    glutMainLoop();

    cleanup();

    return 0;
}
Ejemplo n.º 13
0
    const Model* ModelManager::loadModel(const std::string &filename)
    {
        ///Check if the model is already loaded
        if (m_models.count(filename))
            return nullptr;

        ObjLoader loader;
        ObjResource obj = loader.load(filename);

        if (!obj.model)
            return nullptr;

        ///Try to load first all textures and GLSLPrograms
        std::vector<int> textureIDs;
        std::vector<int> programIDs;
        textureIDs.reserve(obj.resources.size());

        for (const ObjMaterialResource &res : obj.resources)
        {
            int texID = m_textureMgr->loadTexture(res.mapDiffuseFile);

            std::string err;
            int programID = m_programMgr->loadProgram(res.vertexShaderFile,res.fragmentShaderFile,err);

            if (-1 == texID || -1 == programID)
            {
                ///Unload all previous allocated textures
                for (size_t i = 0; i < textureIDs.size(); ++i)
                    m_textureMgr->unloadTexture(textureIDs[i]);

                return nullptr;
            }

            textureIDs.push_back(texID);
            programIDs.push_back(programID);
        }

        ///Create corresponding materials
        std::vector<size_t> associatedPos;
        associatedPos.reserve(obj.resources.size());

        for (size_t i = 0; i < obj.resources.size(); ++i)
        {
            Material material;
            material.ID = m_materials.size();
            material.textureIDs[Material::TEXMAP_DIFFUSE] = textureIDs[i];
            material.programID = programIDs[i];

            ///If theres an empty position available use that one instead.
            if (!m_matEmptyPositions.empty())
            {
                material.ID = m_matEmptyPositions.front();
                m_matEmptyPositions.pop();

                m_materials[material.ID] = material;
            }
            else
            {
                m_materials.push_back(material);
            }

            associatedPos.push_back(material.ID);
        }

        ///Update model meshes material IDs with
        ///the new assigned ones.
        int meshCount = obj.model->getMeshCount();
        for (int i = 0; i < meshCount; ++i)
        {
            int matID = obj.model->getMeshMaterial(i);
            obj.model->setMeshMaterial(i,associatedPos[matID]);
        }

        const Model *ptr = obj.model.get();
        m_models.emplace(filename,std::move(obj.model));

        return ptr;
    }
Ejemplo n.º 14
0
int main(int argc, char* *argv)
{
	Scene::instance().initialize(argc, argv); //initialize opengl 

	ObjLoader loader;
	Cloth cloth(SINGLE_LAYER_NOB);

	////²âÊÔÒ·þ
	//Obj cloth("../cloth/cloth.obj");    //pose0
	//cloth.scale_translate(0.31, 0, 1.95, 0.02);
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/dress2/dress2-iso.obj",SINGLE_LAYER_NOB);  
	//cloth.rotation(90, X);   //
	//cloth.scale_translate(0.24, 0, 1.2, 0.02); 
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/dress3/dress3.obj",SINGLE_LAYER_NOB);  
	//cloth.rotation(90, X);   
	//cloth.scale_translate(0.24, 0, 0.45, 0.02); 
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/dress-asymmetric/dress-asymmetric.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   //
	//cloth.scale_translate(0.25, 0, 1.10, 0.02);
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/dress-victor/dress-victor.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   
	//cloth.scale_translate(0.25, 0, 1.60, 0.02);
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/robe/robe.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   //
	//cloth.scale_translate(0.3, 0, 0.5, 0.0);
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/tshirt/tshirt.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   
	//cloth.rotation(-5, Z);
	//cloth.scale_translate(0.26, 0, 1.18, -0.1);
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/shirt/shirt.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   
	//cloth.rotation(-4, Z);
	//cloth.scale_translate(0.27, 0, 2.1, 0.15);
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/skirt/skirt.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   
	//cloth.scale_translate(0.29, 0, 0.5, 0);
	//cloth.unified();

	loader.load(cloth, "../cloth_no_boundary/tshirt2/tshirt2.obj");
	cloth.rotation(90, 0, 0);
	cloth.rotation(0, 0, -4);
	cloth.scale(0.28f);
	cloth.translate(0, 0.9f, -2.2f);


	//Obj cloth("../cloth_no_boundary/shorts/shorts.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   //
	//cloth.scale_translate(0.29, 0, 0.5, 0);
	//cloth.unified();

	//Obj cloth("../cloth_no_boundary/vest/vest.obj", SINGLE_LAYER_NOB);
	//cloth.rotation(90, X);   
	//cloth.scale_translate(0.28, 0, 1.4, 0.02); 
	//cloth.unified();


	//string file;
	//char num_s[4];
	//_itoa_s(StartNum, num_s, 10);
	//string ss = num_s;
	//file = clothfile + ss + ".obj";
	//Obj body(file);

	VAOMesh body, head;

	loader.load(body, "../Template/MALE.obj");
	body.scale(0.3f);
	body.translate(0.0f, 0.6f, 0.0f);

	loader.load(head, "../DoudouHead/HeadColored.obj");
	DoudouHead_Solver.Init(head);


	Scene::instance().add(cloth);
	Scene::instance().add(body);
	Scene::instance().add(head);

	Scene::instance().initiate_body_template(body);
	Scene::instance().update_simulating_cloth(cloth);
	Scene::instance().update_simulating_body(body);

	HANDLE hThread1 = CreateThread(NULL, 0, DtoG, NULL, 0, NULL);
	CloseHandle(hThread1);
	hMutex = CreateMutex(NULL, FALSE, NULL);

	Scene::instance().render();

	return 0;
}
Ejemplo n.º 15
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 );

}