3D Models for VR motion controllers

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
Post Reply
User avatar
biospud
Posts: 206
Joined: Mon Oct 14, 2013 2:19 pm
Location: California, USA
Contact:

3D Models for VR motion controllers

Post by biospud »

I'm just starting to investigate how to display 3D models of the hand-held motion controllers in VR in gzdoom, so I'd appreciate advice on how to proceed.

I notice that certain 3D models can be loaded from pk3 resource files. But in my case, I would be loading the controller model data dynamically at runtime, using the OpenVR API. This API provides vertex positions, normals, texture coordinates, triangle indices, and a surface texture image, for the particular controller model. I would also need to dynamically update the controller model "model matrix" transform at each rendered frame. Is there anything in gzdoom that already does something like this?

One wrinkle is that these controller models might come and go during game play.

Should I define a new derived class from the class FModel, found in src/gl/models/gl_models.h?
User avatar
biospud
Posts: 206
Joined: Mon Oct 14, 2013 2:19 pm
Location: California, USA
Contact:

Re: 3D Models for VR motion controllers

Post by biospud »

I started to sketch a derived class of FModel, based on the FVoxelModel implementation, which seems closest to what I am trying to accomplish.
https://github.com/cmbruns/gz3doom/blob ... r.cpp#L793

How do I actually get this model displayed? One approach is to insert something in GLSceneDrawer::CreateScene() to get the model added to the drawlists, near here
https://github.com/cmbruns/gz3doom/blob ... e.cpp#L256

I might need to create a GLSprite for this, to take advantage of the exisiting drawlist population code here
https://github.com/cmbruns/gz3doom/blob ... e.cpp#L498

Another approach would be to add something into the GLSceneDrawer::RenderScene() method, near where the current models are drawn here
https://github.com/cmbruns/gz3doom/blob ... e.cpp#L384
dpJudas
 
 
Posts: 3040
Joined: Sat May 28, 2016 1:01 pm

Re: 3D Models for VR motion controllers

Post by dpJudas »

The main function drawing a model is called gl_RenderModel (gl_models.cpp). It is called by GLSprite::Draw (gl_sprite.cpp) whenever a sprite has a model attached to it.

Most of the code you're referring to is the OpenGL 2 compatibility path, which is not relevant as it will never be used in the VR case (as it requires renderbuffers for the eye buffers). If I'm reading the code correctly, gl_RenderModel will draw the model right there on the spot, which means you roughly have two options:

1) Set up your own fake GLSprite structure and call gl_RenderModel. Do that at the end of ProcessScene (gl_scene.cpp), maybe just before it calls FDrawInfo::EndDrawInfo.

2) Make your model somehow a real player sprite so that GLSprite will render it for you.

I'm not sure which of those two options is better, but I hope this helps you a little bit.
User avatar
biospud
Posts: 206
Joined: Mon Oct 14, 2013 2:19 pm
Location: California, USA
Contact:

Re: 3D Models for VR motion controllers

Post by biospud »

dpJudas wrote:The main function drawing a model is called gl_RenderModel (gl_models.cpp). It is called by GLSprite::Draw (gl_sprite.cpp) whenever a sprite has a model attached to it.

Most of the code you're referring to is the OpenGL 2 compatibility path, which is not relevant as it will never be used in the VR case (as it requires renderbuffers for the eye buffers). If I'm reading the code correctly, gl_RenderModel will draw the model right there on the spot, which means you roughly have two options:

1) Set up your own fake GLSprite structure and call gl_RenderModel. Do that at the end of ProcessScene (gl_scene.cpp), maybe just before it calls FDrawInfo::EndDrawInfo.

2) Make your model somehow a real player sprite so that GLSprite will render it for you.

I'm not sure which of those two options is better, but I hope this helps you a little bit.
Thank you for this advice. Just now I'm pursuing option 1), which involves faking up a GLSprite. In the process, I believe I need to fake up an AActor too, which looks rather complicated.
Post Reply

Return to “General”