OpenVR+OSG_Successfully obtained VR controller model

IVRRenderModels::GetRenderModelName

Use this function to get the model provided by Steam, Steam also provides the handle model of the generic gamepad model oculus, etc...

However, there is no one-to-one correspondence between the IDs of the tracked devices and the model IDs. The models of the two controllers correspond to 3 and 4, while the IDs of the HTC VIVE controller models correspond to 3 and 4.

This ID value exceeds k_unMaxTrackedDeviceCount , so it has not been found before.

In the hellovr_opengl example, it is not taken like this. I don't see how it is taken.

Code:


	// 直接取VR手柄模型:
	if(!m_bController3Ready || !m_bController4Ready)
	{
		vr::RenderModel_t *pModel=nullptr;
		vr::EVRRenderModelError err= m_vrRenderModels->LoadRenderModel_Async("vr_controller_vive_1_5",&pModel);// 一但读取成功, err的结果为vr::VRRenderModelError_None
		if(pModel && err!=vr::VRRenderModelError_Loading)
		{
			m_vController3 = pModel;
			m_vController4 = pModel;
			m_bController3Ready=true;
			m_bController4Ready=true;
			cout<<"取模型完毕 vr_controller_vive_1_5"<<endl;
		}
	}

Here directly use the name of the model to get two handles sharing one model

 

About how to draw the obtained model. At present, it is temporarily replaced by polygon, and mesh objects cannot be used, so it is impossible to texture.

I have seen how the basic objects in OSG are drawn, which is more difficult than expected, so I haven't looked into it in depth.

 

Code for painting:

if(m_bController3Ready && !m_bController3DrawDone){
			osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
			//首先定义四个点:
			osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
			geom->setVertexArray(v.get());
			//v->push_back(osg::Vec3(0005.753f,0011.188f,0050.148f));
			//v->push_back(osg::Vec3(0005.27f,0012.092f,0050.272f));
			//v->push_back(osg::Vec3(0004.707f,0011.718f,0051.579f));

			for(uint32_t i=0;i<m_vController3->unVertexCount;++i){
				v->push_back(osg::Vec3(p1->vPosition.v[0] , p1->vPosition.v[1] , p1->vPosition.v[2] ));
				++p1;
			}

			// 定义颜色数组:
			osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
			geom->setColorArray(c.get());
			geom->setColorBinding(osg::Geometry::BIND_OVERALL);
			c->push_back(osg::Vec4(1.f,1.f,1.f,.5f));
			//c->push_back(osg::Vec4(0.f,1.f,0.f,1.f));
			//c->push_back(osg::Vec4(0.f,0.f,1.f,1.f));
			//c->push_back(osg::Vec4(1.f,1.f,1.f,1.f));

			//定义法线:
			osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;
			geom->setNormalArray(n.get());
			geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
			n->push_back(osg::Vec3(0.f,-1.f,0.f));

			cout<<"顶点数:"<<m_vController3->unVertexCount<<endl;
			//设置顶点关联方式
			geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,m_vController3->unVertexCount));

			//几何组节点
			osg::ref_ptr<osg::Geode> geode = new osg::Geode;
			geode->addDrawable(geom);

			// 放大一千倍			
			osg::Matrix cc = osg::Matrix::scale(99,99,99);
			osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform;
			trans->setMatrix(cc);		
			trans->addChild(geode);
			//gScene->addChild(trans);
			
			//cout<<"改变场景:"<<endl;
			//viewer->setSceneData(trans);

			osg::Group *gScene = new osg::Group;// 子场景

			cout <<"叁:把手柄放大"<<endl;
			gScene->addChild(trans);
			m_mtController3 = trans;
			viewer->addChild(gScene);
			m_bController3DrawDone=true;
		}/**/

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325426155&siteId=291194637
VR