Is there a way to render to SteamVR in Panda3D?

I was working on a VR game in C++ and thought “Wow, this is extremely painful”. I remembered Panda3D and wondered if there was a way to render to SteamVR in Panda3D? Is this possible? Thanks in advance.

I made a wrapper for OpenVR some time ago : VR with Panda3D: panda3d-openvr

It’s for Python and uses pyopenvr, but I think it could easily be translated in C++ if needed, pyopenvr is almost a 1-to-1 mapping to OpenVR and my code is rather straightforward. The only important part is to use the draw callback to retrieve the texture id for the left and right eye buffers and submit them to the composer at the right time. The rest of the code is mainly how to retrieve the data and apply transforms to be usable in Panda3D.

Edit: To clarify: OpenVR is the API, SteamVR is an implementation of OpenVR.

1 Like

Thanks! Can I use this with existing code or will I have to redo it. If I don’t need to redo it, how do I change my code to support this?

If you stay in Python, the modification in your code are minimal, pand3d-openvr takes care of replacing and updating the camera according to the HMD position and orientation. The controllers need a bit more of work, depending if you use low level events or input/output manifest.

You can look at the changes needed in the Ralph sample, iti s based on the Panda3D Ralph demo so you can see what are the required changes.

If you want to integrate it in a C++ application, I’m afraid I think you have to recode everything in C/C++

Hello, is it possible to add locomotion in this library? It doesn’t seem to let me move the camera.

Actually you can not move the camera at all, it moves and rotates with the HMD. So if you need to move further than your room space (or you are using standing or sitting position), you have to move (or rotate) the whole tracking space instead.
So, imagine you have a control that allows you to move forward 1meter, you will apply an offset (0,1, 0) to the tracking_space node, and as the camera is a child of the tracking_space node it will move too.
You can check the Ralph demo, you can move in-world by moving physically and so move the camera, or by using the trackpad on the controller and so move the tracking_space node. The trackpad can also be used to fast rotate by rotating the tracking space.

1 Like

One more question, how can I make something headlocked?

If you want something that move with the head, you simply reparent it to the hmd_anchor node. Doing so it will follow any movements done by the headset. you may have to apply some offset as the hmd_anchor is a bit above the nose of the wearer.

1 Like

Hello, sorry to ask so many questions but is it possible to put text in the headset?

Yes it’s possible, but the text can not be parented to one of the 2d root node like aspect2d, pixel2d, … it must be in the 3D world (but you can attach it to the hmd_anchor so it moves the head)

It’s not possible to display the render2d and render2dp scenegraph, and I’m not sure if it’s useful : I think a flat UI will look at best unnatural and at worst could induce motion sickness.

Thanks, can you give me an example on how this would be done?

I don’t have an example ready to use, but you can use a TextNode and reparent it to hmd_anchor.

Note that, unless you have rescaled tracking_space, everything attached under it is using metric units, so if you attach your TextNode at (0, 1, 0) the text will be in front of you at 1 meter and centered between your eyes.

1 Like

Great, it seems as if when I build this, it doesn’t seem to build correctly, can you help?
EDIT: I mean build it into an exe with build_apps

I updated the Ralph example with a working setup.py and requirements.txt The most important part is to include the several libs of openvr.

However, I still have to make a wheel package and register it on pypi ! Until it is done, you have to build the p3dopenvr wheel yourself:

python3 setup.py bdist_wheel

and reference it in the requirements.txt of your project. Once the package is available in pypi this will be no longer needed.

Hmm, still doesn’t work. Can you help? Still getting the same problem.
EDIT: The problem being the game doesn’t launch.

Yes, but without any logs or more info I can’t really help you. Could you paste the output log of your program here ?

It doesn’t do anything. It just ends.
EDIT: Making a build now to get the build logs
EDIT2:
Build logs:

running build_apps
Building platforms: manylinux1_x86_64,macosx_10_6_x86_64,win_amd64
Gathering wheels for platform: manylinux1_x86_64
Looking in indexes: https://pypi.org/simple, https://archive.panda3d.org/simple/opt, https://archive.panda3d.org/thirdparty
Collecting https://github.com/el-dee/panda3d-openvr/archive/v0.1.0.zip (from -r C:\Users\zurgE\OneDrive\Documents\3D Python programs\FIREHAWK_VR\requirements.txt (line 3))
  Using cached https://github.com/el-dee/panda3d-openvr/archive/v0.1.0.zip
  Saved c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\v0.1.0.zip
Collecting keyboard
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\keyboard-0.13.5-py3-none-any.whl
Collecting panda3d
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\panda3d-1.10.6.post2+opt-cp37-cp37m-manylinux1_x86_64.whl
Collecting openvr
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\openvr-1.12.501-py3-none-any.whl
Successfully downloaded panda3d-openvr keyboard panda3d openvr
WARNING: You are using pip version 19.3.1; however, version 20.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Building runtime for platform: manylinux1_x86_64
There are some missing modules: ['AppKit', 'Quartz', '__builtin__', 'p3dopenvr.p3dopenvr']
Copying game files for platform: manylinux1_x86_64

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/manylinux1_x86_64/fhres/models/enem_placeholder.egg.bam

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/manylinux1_x86_64/fhres/models/player.egg.bam

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/manylinux1_x86_64/fhres/models/reddude.egg.bam

:gobj(error): Texture::read() - couldn't read: ./tex/Color_A07 Base
Color.png
:gobj(error): Unable to find texture "./tex/Color_A07 Base Color.png" on
model-path /c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d_tools;/c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d/etc/..;/c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d/etc/../models
Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/manylinux1_x86_64/fhres/models/reddude2.egg.bam
Gathering wheels for platform: macosx_10_6_x86_64
Looking in indexes: https://pypi.org/simple, https://archive.panda3d.org/simple/opt, https://archive.panda3d.org/thirdparty
Collecting https://github.com/el-dee/panda3d-openvr/archive/v0.1.0.zip (from -r C:\Users\zurgE\OneDrive\Documents\3D Python programs\FIREHAWK_VR\requirements.txt (line 3))
  Using cached https://github.com/el-dee/panda3d-openvr/archive/v0.1.0.zip
  Saved c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\v0.1.0.zip
Collecting keyboard
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\keyboard-0.13.5-py3-none-any.whl
Collecting panda3d
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\panda3d-1.10.6+opt-cp37-cp37m-macosx_10_6_x86_64.whl
Collecting openvr
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\openvr-1.12.501-py3-none-any.whl
Successfully downloaded panda3d-openvr keyboard panda3d openvr
WARNING: You are using pip version 19.3.1; however, version 20.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Building runtime for platform: macosx_10_6_x86_64
Copying game files for platform: macosx_10_6_x86_64

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/macosx_10_6_x86_64/fhres/models/enem_placeholder.egg.bam

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/macosx_10_6_x86_64/fhres/models/player.egg.bam

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/macosx_10_6_x86_64/fhres/models/reddude.egg.bam

:gobj(error): Texture::read() - couldn't read: ./tex/Color_A07 Base
Color.png
:gobj(error): Unable to find texture "./tex/Color_A07 Base Color.png" on
model-path /c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d_tools;/c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d/etc/..;/c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d/etc/../models
Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/macosx_10_6_x86_64/fhres/models/reddude2.egg.bam
Bundling macOS app into C:\Users\zurgE\OneDrive\Documents\3D Python programs\FIREHAWK_VR\build\macosx_10_6_x86_64\FIREHAWKVR.app
Gathering wheels for platform: win_amd64
Looking in indexes: https://pypi.org/simple, https://archive.panda3d.org/simple/opt, https://archive.panda3d.org/thirdparty
Collecting https://github.com/el-dee/panda3d-openvr/archive/v0.1.0.zip (from -r C:\Users\zurgE\OneDrive\Documents\3D Python programs\FIREHAWK_VR\requirements.txt (line 3))
  Using cached https://github.com/el-dee/panda3d-openvr/archive/v0.1.0.zip
  Saved c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\v0.1.0.zip
Collecting keyboard
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\keyboard-0.13.5-py3-none-any.whl
Collecting panda3d
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\panda3d-1.10.6+opt-cp37-cp37m-win_amd64.whl
Collecting openvr
  File was already downloaded c:\users\zurge\onedrive\documents\3d python programs\firehawk_vr\build\__whl_cache__\openvr-1.12.501-py3-none-any.whl
Successfully downloaded panda3d-openvr keyboard panda3d openvr
WARNING: You are using pip version 19.3.1; however, version 20.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Building runtime for platform: win_amd64
There are some missing modules: ['_posixsubprocess', 'grp']
warning: build_apps: could not find dependency VERSION.dll (referenced by python37.dll)

warning: build_apps: could not find dependency VCRUNTIME140.dll (referenced by python37.dll)

warning: build_apps: could not find dependency VCRUNTIME140.dll (referenced by deploy-stubw.exe)

warning: build_apps: could not find dependency SETUPAPI.dll (referenced by libpanda.dll)

warning: build_apps: could not find dependency bcrypt.dll (referenced by libcrypto-1_1.dll)

Copying game files for platform: win_amd64

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/win_amd64/fhres/models/enem_placeholder.egg.bam

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/win_amd64/fhres/models/player.egg.bam

Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/win_amd64/fhres/models/reddude.egg.bam

:gobj(error): Texture::read() - couldn't read: ./tex/Color_A07 Base
Color.png
:gobj(error): Unable to find texture "./tex/Color_A07 Base Color.png" on
model-path /c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d_tools;/c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d/etc/..;/c/Users/zurgE/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/panda3d/etc/../models
Writing /c/Users/zurgE/OneDrive/Documents/3D Python
programs/FIREHAWK_VR/build/win_amd64/fhres/models/reddude2.egg.bam

Wait, could it be because I’m using Intel, and the exe is built for win_amd64? Or does this not matter.
EDIT: It looks like the problem is here:
:gobj(error): Texture::read() - couldn't read: ./tex/Color_A07 Base Color.png

amd64 is the name of the instruction set that is used in both 64-bit AMD and Intel CPUs.

Have you made sure that the png file is being covered by your include patterns?

My include patterns are here.


            'include_patterns': [
                '**/*.json',
                '**/*.png',
                '**/*.jpg',
                '**/*.egg',
                '**/*.pz',
            ],