Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Feature Request: Allow access to camera reference #43

Closed
morsdyce opened this issue Jan 22, 2017 · 11 comments
Closed

Feature Request: Allow access to camera reference #43

morsdyce opened this issue Jan 22, 2017 · 11 comments

Comments

@morsdyce
Copy link

Description

Currently React VR does not give you access or allow you to create your own camera.
I think this would be pretty helpful in case we want to manipulate the "player" location.

For example I implemented basic support for VR controllers using a native module, it makes sense that in the future i'd like to move around with either full locomotion (analog sticks) or teleportation (blink mechanic).

Solution

This can be fixed in 2 ways and should probably be implemented via both to allow maximum flexibility.

  1. Allow to pass a camera via VRInstance options object and pass it to the new Player invocation
  2. Implement a function on the VRInstance class that returns the current camera.
@amberroy amberroy self-assigned this Jan 24, 2017
@dukuo
Copy link

dukuo commented Jan 30, 2017

this is already implemented if i'm not mistaken, although we must modify:

initialize this.camera = options.camera || null; in the VRInstance constructor

then pass the camera to Player in
this.player = new Player({ elementOrId: parent, width: options.width, height: options.height, camera: this.camera, });

in OVRUI/lib/Player/Player.js add
this._camera = (options.hasOwnProperty('camera'))? options.camera : null;

And finally pass the camera while creating VRInstance in client.js. The only drawback of this "patch" is that we have to calculate manually width & height (I just copied this from Player.js' camera implementation):

// If container not specified, default to full window.
if (!this._el) {
this._el = document.body;
}
// If height and width are not provided, detect them from the container.
var fixedSize = true;
if (!width) {
if (this._el === document.body) {
fixedSize = false;
width = window.innerWidth;
} else {
width = this._el.clientWidth;
}
}
if (!height) {
if (this._el === document.body) {
fixedSize = false;
height = window.innerHeight;
} else {
height = this._el.clientHeight;
}
}

const camera = new THREE.PerspectiveCamera(60, width / height, 0.01, 10000.0);

I'm just starting out, so if this explanation wasn't clear i'll explain it further, although I think this patch might not be the ideal solution.

@morsdyce
Copy link
Author

I initially did it as you suggested, almost word for word but had some issues with passing my own camera, things didn't look right.

In the end I added a function that returns a reference to the Player instance camera

@dukuo
Copy link

dukuo commented Jan 30, 2017

i'll reproduce it on a clean installation, I guess I forgot a step. Any meaningful error ?

@dukuo
Copy link

dukuo commented Jan 30, 2017

@morsdyce forgot to add the line about adding the camera to the instance initialization in client.js:
const vr = new VRInstance(bundle, 'CentroArteVR', parent, { enableHotReload: true, scene: scene, // Custom scene camera: camera, // Custom camera ...options, });

@morsdyce
Copy link
Author

morsdyce commented Jan 30, 2017 via email

@dukuo
Copy link

dukuo commented Jan 30, 2017

the only time I had a black screen was because it need to get the width and height, so I just copied and pasted the width/height calculations done in Player.js when creating the camera. Btw do you have any idea how to use the sound module? looks like it's still broken (probably will open another thread but just in case..)

@morsdyce
Copy link
Author

morsdyce commented Jan 30, 2017 via email

@dukuo
Copy link

dukuo commented Jan 30, 2017

@morsdyce well I ran the code in my local repo at home and just by passing the camera in the VRInstance options (just as scene is passing) works just fine, without any patch. Would you test it please ?

@amberroy
Copy link
Contributor

amberroy commented Feb 3, 2017

yes you can pass a camera to the Player instance or use Player.camera to get the default one that is created, and I agree it would be convenient to have these options on the VRInstance as well.

@amberroy
Copy link
Contributor

Both 1 & 2 above are implemented. Added VRInstance.camera() to get current camera. Can also pass camera in the options to VRInstance constructor

@copypasteearth
Copy link

when I try to use VrInstance.camera() to get a camera it says that cannot read property camera from undefined, any help?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants