src/ofxOpenVR.cpp
//-----------------------------------------------------------------------------
// Purpose: Finds a render model we've already loaded or loads a new one
//-----------------------------------------------------------------------------
Finds a render model we've already loaded or loads a new one
Finds a render model we ' ve already loaded or loads a new one
CGLRenderModel *ofxOpenVR::findOrLoadRenderModel(const char *pchRenderModelName)
{
	CGLRenderModel *pRenderModel = NULL;
	for (std::vector< CGLRenderModel * >::iterator i = _vecRenderModels.begin(); i != _vecRenderModels.end(); i++) {
		if (!stricmp((*i)->GetName().c_str(), pchRenderModelName)) {
			pRenderModel = *i;
			break;
		}
	}
	if (!pRenderModel) {
		vr::RenderModel_t *pModel;
		vr::EVRRenderModelError error;
		while (1) {
			error = vr::VRRenderModels()->LoadRenderModel_Async(pchRenderModelName, &pModel);
			if (error != vr::VRRenderModelError_Loading)
				break;
			Sleep(1);
		}
		if (error != vr::VRRenderModelError_None) {
			printf("Unable to load render model %s - %s\n", pchRenderModelName, vr::VRRenderModels()->GetRenderModelErrorNameFromEnum(error));
			return NULL; 
		}
		vr::RenderModel_TextureMap_t *pTexture;
		while (1) {
			error = vr::VRRenderModels()->LoadTexture_Async(pModel->diffuseTextureId, &pTexture);
			if (error != vr::VRRenderModelError_Loading)
				break;
			Sleep(1);
		}
		if (error != vr::VRRenderModelError_None) {
			printf("Unable to load render texture id:%d for render model %s\n", pModel->diffuseTextureId, pchRenderModelName);
			vr::VRRenderModels()->FreeRenderModel(pModel);
			return NULL; 
		}
		pRenderModel = new CGLRenderModel(pchRenderModelName);
		if (!pRenderModel->BInit(*pModel, *pTexture)) {
			printf("Unable to create GL model from render model %s\n", pchRenderModelName);
			delete pRenderModel;
			pRenderModel = NULL;
		}
		else {
			_vecRenderModels.push_back(pRenderModel);
		}
		vr::VRRenderModels()->FreeRenderModel(pModel);
		vr::VRRenderModels()->FreeTexture(pTexture);
	}
	return pRenderModel;
}
CGLRenderModel * ofxOpenVR :: findOrLoadRenderModel ( const char * pchRenderModelName ) { CGLRenderModel * pRenderModel = NULL ; for ( std :: vector < CGLRenderModel * > :: iterator i = _vecRenderModels . begin ( ) ; i != _vecRenderModels . end ( ) ; i ++ ) { if ( ! stricmp ( ( * i ) -> GetName ( ) . c_str ( ) , pchRenderModelName ) ) { pRenderModel = * i ; break ; } } if ( ! pRenderModel ) { vr :: RenderModel_t * pModel ; vr :: EVRRenderModelError error ; while ( 1 ) { error = vr :: VRRenderModels ( ) -> LoadRenderModel_Async ( pchRenderModelName , & pModel ) ; if ( error != vr :: VRRenderModelError_Loading ) break ; Sleep ( 1 ) ; } if ( error != vr :: VRRenderModelError_None ) { printf ( " \n " , pchRenderModelName , vr :: VRRenderModels ( ) -> GetRenderModelErrorNameFromEnum ( error ) ) ; return NULL ; } vr :: RenderModel_TextureMap_t * pTexture ; while ( 1 ) { error = vr :: VRRenderModels ( ) -> LoadTexture_Async ( pModel -> diffuseTextureId , & pTexture ) ; if ( error != vr :: VRRenderModelError_Loading ) break ; Sleep ( 1 ) ; } if ( error != vr :: VRRenderModelError_None ) { printf ( " \n " , pModel -> diffuseTextureId , pchRenderModelName ) ; vr :: VRRenderModels ( ) -> FreeRenderModel ( pModel ) ; return NULL ; } pRenderModel = new CGLRenderModel ( pchRenderModelName ) ; if ( ! pRenderModel -> BInit ( * pModel , * pTexture ) ) { printf ( " \n " , pchRenderModelName ) ; delete pRenderModel ; pRenderModel = NULL ; } else { _vecRenderModels . push_back ( pRenderModel ) ; } vr :: VRRenderModels ( ) -> FreeRenderModel ( pModel ) ; vr :: VRRenderModels ( ) -> FreeTexture ( pTexture ) ; } return pRenderModel ; }
Purpose: Finds a render model we've already loaded or loads a new one
Purpose : Finds a render model we ' ve already loaded or loads a new one
// load the model if we didn't find one // move on to the next tracked device // move on to the next tracked device