Python的一面
virtualrealit的Python项目详细描述
虚拟现实
hobo_vr的python端
主要用来写假发
在位置跟踪、串行/套接字/蓝牙通信等方面有许多有用的实用程序
具有异步套接字服务器
安装
要安装模块,请运行以下命令:
python -m pip install virtualreality
如果您想要基于相机的跟踪,请使用camera
额外的
要安装开发版本,请执行以下操作:
git clone https://github.com/okawo80085/hobo_vr
cd ./hobo_vr
python -m pip install -e .
简单的例子
importasyncioimporttimeimportnumpyasnpfromvirtualrealityimporttemplatesclassMyPoser(templates.PoserTemplate):def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)@templates.PoserTemplate.register_member_thread(1/100)asyncdefexample_thread1(self):'''moves the headset in a circle'''h=0whileself.coro_keep_alive["example_thread1"].is_alive:try:self.pose.x=np.sin(h)self.pose.y=np.cos(h)h+=0.01awaitasyncio.sleep(self.coro_keep_alive["example_thread1"].sleep_delay)exceptExceptionase:print(f"example_thread1 failed: {e}")breakself.coro_keep_alive["example_thread1"].is_alive=False@templates.PoserTemplate.register_member_thread(1/100,runInDefaultExecutor=True)defexample_thread2(self):'''moves the left controller up and down'''h=0whileself.coro_keep_alive["example_thread2"].is_alive:try:self.pose_controller_l.y=1+np.cos(h*3)/5h+=0.01time.sleep(self.coro_keep_alive["example_thread2"].sleep_delay)exceptExceptionase:print(f"example_thread2 failed: {e}")breakself.coro_keep_alive["example_thread2"].is_alive=Falseposer=MyPoser()asyncio.run(poser.main())
poser客户端示例
importasyncioimporttimeimportnumpyasnpfromvirtualrealityimporttemplatesposer=templates.PoserClient()@poser.thread_register(1/60)asyncdefexample_thread():'''moves the headset in a circle'''h=0whileposer.coro_keep_alive["example_thread"].is_alive:poser.pose.y=round(np.sin(h),4)poser.pose.x=round(np.cos(h),4)h+=0.01awaitasyncio.sleep(poser.coro_keep_alive["example_thread"].sleep_delay)@poser.thread_register(1/60,runInDefaultExecutor=True)defexample_thread2():'''moves the controller up and down'''whileposer.coro_keep_alive["example_thread2"].is_alive:poser.pose_controller_l.x=1+np.cos(h*3)/5time.sleep(poser.coro_keep_alive["example_thread2"].sleep_delay)asyncio.run(poser.main())
udu poser客户端示例
u - unlimited
d - devices
u - upgrade
但它更像是一种模式
这里有一个例子
"""udu poser client examplemore info: help(templates.UduPoserTemplate)"""importasyncioimporttimeimportnumpyasnpimportpyrrfromvirtualrealityimporttemplatesfromvirtualreality.serverimportserverposer=templates.UduPoserClient("h c t")# ^^^^^# this dictates devices used# for this example its:# hmd controller tracker# poser = templates.UduPoserClient("h c c") btw normal posers use this device configuration@poser.thread_register(1/60)asyncdefexample_thread():# spins all devices in an orbith=0whileposer.coro_keep_alive["example_thread"].is_alive:x,y,z,w=pyrr.Quaternion.from_y_rotation(h)foriinrange(len(poser.poses)):poser.poses[i].x=np.sin(h/(i+1))poser.poses[i].z=np.cos(h/(i+1))poser.poses[i].r_x=xposer.poses[i].r_y=yposer.poses[i].r_z=zposer.poses[i].r_w=wh+=0.01awaitasyncio.sleep(poser.coro_keep_alive["example_thread"].sleep_delay)# any poser can do this actually@poser.thread_register(1/60)asyncdefexample_receive_haptics_thread():whileposer.coro_keep_alive["example_receive_haptics_thread"].is_alive:# check for new readsifposer.last_read:print(poser.last_read)# print receivedposer.last_read=b""# resetawaitasyncio.sleep(poser.coro_keep_alive["example_receive_haptics_thread"].sleep_delay)asyncio.run(poser.main())
不同于普通的poser,udu poser在开始时生成pose结构
然后需要在驱动程序配置中使用这些pose结构作为DeviceManifestList
的值
更多示例
还有一个^{
- 项目
标签: