Merged
Conversation
Collaborator
Author
|
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);
}; |
Collaborator
Author
|
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
willeastcott
approved these changes
Feb 21, 2020
TheJonRobinson
added a commit
to Mojiworks/playcanvas-engine
that referenced
this pull request
Feb 23, 2020
* 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.