-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebXR Input Sources #1873
WebXR Input Sources #1873
Conversation
Here is basic example, that provides simple entity picking by bounding box, that works with multi-controllers (Oculus Quest for example); gaze (mobile devices); screen (AR taps on screens). select.js (attach on entity with model): var Select = pc.createScript('select');
Select.prototype.initialize = function() {
// when select is triggered
this.app.xr.input.on('select', function(inputSource) {
// get mesh of this entity
var mesh = this.entity.model.meshInstances[0];
// check if input source ray intersects with mesh bounding box
if (mesh.aabb.intersectsRay(inputSource.ray)) {
// randomize its diffuse color
mesh.material.diffuse.set(Math.random(), Math.random(), Math.random());
mesh.material.update();
}
}, this);
}; |
Here is basic example for adding/removing input sources and positioning entity based on grip position and rotation of a physical controller. controllers.js: (somewhere on root) var Controllers = pc.createScript('controllers');
// entity for controller template
Controllers.attributes.add('template', {
type: 'entity'
});
Controllers.prototype.initialize = function() {
// when input source added
this.app.xr.input.on('add', function(inputSource) {
var entity = this.template.clone();
entity.script.controller.inputSource = inputSource;
entity.reparent(this.app.scene.root);
entity.enabled = true;
}, this);
}; controller.js: (on controller entity) var Controller = pc.createScript('controller');
Controller.attributes.add('inputSource', { type: 'string' });
Controller.prototype.initialize = function() {
this.inputSource.on('remove', function() {
// destroy self when input source is removed
this.entity.destroy();
}, this);
};
Controller.prototype.update = function(dt) {
if (this.inputSource.grip) {
// if can be gripped
this.entity.model.enabled = true;
this.entity.setLocalPosition(this.inputSource.position);
this.entity.setLocalRotation(this.inputSource.rotation);
} else {
// some controllers cannot be gripped
this.entity.model.enabled = false;
}
}; |
… webxr-inputsources
* master: (31 commits) WebXR Input Sources (playcanvas#1873) Simplified constants definition in Math classes (playcanvas#1876) Improve batching to handle 8-bit and 32-bit index buffers (playcanvas#1872) Add particle start frame example to browser [FIX] Update WebXR examples to use latest enums (playcanvas#1870) [FIX] Add XRWebGLLayer to externs for Closure compiler (playcanvas#1869) update paths in the particle system start frame example (playcanvas#1868) add a animation start frame variable to the particle system which def… (playcanvas#1864) point cloud example using engine directly, and custom shader changing size and color of points (playcanvas#1867) WebXR Support (playcanvas#1834) Hardware Instancing fixes / sample (playcanvas#1846) (playcanvas#1856) [VERSION] v1.25.0-dev [RELEASE] v1.24.7 Recompiled basis, now works on IE (playcanvas#1865) Small mesh cleanup (playcanvas#1866) [FIX] Revert memory-leak change (playcanvas#1862) [FIX] Flag model as immutable when it's added to a ModelComponent (playcanvas#1861) [FIX] Fix calculation of deprecated pc.MouseEvent#wheel (playcanvas#1859) [DOCS] Adjust Vec3.normalize docs to reflect behavior better (playcanvas#1849) pc.BatchManager.markGroupDirty is now public (playcanvas#1848) ...
This PR adds WebXR Input Sources, which provides interface to various input methods in VR and AR environments.
It is WIP PR, so comments and ideas are welcome.
New APIs:
I confirm I have signed the Contributor License Agreement.