OSVR / OSVR-Unity

Package for authoring OSVR experiences with Unity.
Apache License 2.0
99 stars 38 forks source link

Add camera components to VRSurfaces #101

Closed ImperialPenguin closed 8 years ago

ImperialPenguin commented 8 years ago

Better duplicates the main camera so that its image effects and other components are carried over by instantiating a copy of its GameObject and deleting unneeded components/children. This resolves #75

ImperialPenguin commented 8 years ago

Sorry, my Unity project didn't update correctly and this code won't work. The camera has moved since I started my project. I'll fix it and resubmit.

DuFF14 commented 8 years ago

I think this method will work, with some modification (other than what you've already noticed with the MainCamera moving to VRViewer). Not every component that's attached to VRViewer should be copied to VRSurface. For example, in the Unity VR Samples project, there are a bunch of scripts (VREyeRaycaster, VRInput, VRCameraFade, etc.) that would belong on VRViewer but not on each VRSurface.

I think a similar solution to what you've come up with here could work, but it would require adding another gameobject/component to the hierarchy (call it CopyToVRSurface, for example). One could attach any Image Effects and other components that should be on each VRSurface to this new gameobject, then duplicate it and add a VRSurface like you've done here. Delete the object afterwards, or delete it if there aren't any components to copy. You can still copy the camera component from VRViewer with the existing CopyCamera function. Hopefully this makes sense.

ImperialPenguin commented 8 years ago

Hmm. It seems like that brings up another problem then. The first VRViewer is created for them, but the code is setup to create additional VRViewers if needed. I'm not exactly sure why there would ever been a need for more viewers, more than two eyes, or more than one surface per eye, but the code supports it so any solution would need to as well. So if a VREyeRayaster, for example, is added to VRViewer0, and another VRViewer gets created by the code, it would lack that component. The VRViewers themselves could be created by instantiation.

A CopyToVRSurface game object would work, but it would make things convoluted. As would anything that requires setting up the camera components manually. Camera components are visual in nature, so they are usually applied to the camera and tweaked there. Most of them probably require a camera component, so I'm not sure they can be put in another GameObject without also giving it a camera, which would be necessary for the instantiation process anyway.