Jme3-vr: Syncing audio Listener with HMD. Observer?

I’m struggling to understand how the VrAppState syncs the Listener (for audio positioning) with the HMD position.

A normal JME application uses AudioListenerState for this which syncs sound with camera position. This functionality seems to be missing for VR so we’ve been syncing the listener manually with VrAppState.getFinalObserverPosition().
This method crashes when no observer is set because it then tries to cast Camera into Spatial.

What is the purpose of the observer?
The javadoc says it will be linked to the HMD. But in which way? It seems to simply act as an offset to the VR camera position.

There is code that expects VREnvironment.getObserver() to return NULL but that’s never gonna happen, leading to potential crashes.


I’d suggest to abstract away the distinction between Camera and Spatial behind an Observer class so a caller doesn’t have to care about the observer type, simplifying code like this which exists at various places:

Object obs = environment.getObserver();
if( obs instanceof Camera ) {
    tempq.set(((Camera)obs).getRotation());
} else {
    tempq.set(((Spatial)obs).getWorldRotation());
}

I’d like to refactor this a bit and add a VR equivalent to AudioListenerState. Can I?

The observer node is something I added way way back for the original Oculus Rift plugin to get a physical representation of the user. This was before using the integrations to supply pose’s and you could only get a rotation from it. I’d say there are a lot of things still in there that could be up for refactoring.

The set/isSwapBuffers handling is also confusing and, I think, not relevant anymore.

In that case I wonder if we could ditch the Node-observer all together. Having the camera as observer integrates nicely with all camera Controls (FlyCam etc.) and I think it’s quite intuitive.
Would its removal severely break existing user projects?
Is there anything that can be done with a Node-observer that can’t be done with a Camera-observer?
Or are there usecases which need the camera for something else?