-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
…ty can now be grabbed and manipulated with hand tracking.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: hand-tracking-grab-controls | ||
type: components | ||
layout: docs | ||
parent_section: components | ||
source_code: src/components/hand-tracking-grab-controls.js | ||
examples: [] | ||
--- | ||
|
||
Grab any entity with hand tracking using the pinch gesture. | ||
|
||
## Example | ||
|
||
```html | ||
<a-entity id="leftHand" hand-tracking-grab-controls="hand: left;"></a-entity> | ||
<a-entity id="rightHand" hand-tracking-grab-controls="hand: right;"></a-entity> | ||
``` | ||
|
||
The `grabbable` component makes any entity hand grababble. | ||
|
||
```html | ||
<a-box grabbable></a-box> | ||
``` | ||
|
||
For debugging purposes you can make the colliders visible as below: | ||
|
||
```html | ||
<a-scene obb-collider="showColliders: false"></a-scene> | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Description | Default Value | | ||
|----------------|----------------------------------------------------------------------------------------|---------------| | ||
| hand | The hand that will be tracked (i.e., right, left). | left | | ||
| handColor | The color of the hand model. | white | | ||
| hoverColor | Hand color when hand intersects a grabbable entity bounding box. | #538df1 | | ||
| hoverEnabled | If the hand model changes color when intersecting a grabbable entity. | false | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
title: obb-collider | ||
type: components | ||
layout: docs | ||
parent_section: components | ||
source_code: src/components/obb-collider.js | ||
examples: [] | ||
--- | ||
|
||
[obb]: https://threejs.org/docs/#examples/en/math/OBB | ||
|
||
Collision system using Oriented Bounding Boxes based on [`THREE.OBB`][obb]. | ||
|
||
It checks collision accross all entities with the abb-collider component. It emits events when bounding boxes start and stop intersecting. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
## Example | ||
|
||
```html | ||
<a-entity obb-collider></a-entity> | ||
``` | ||
|
||
Set `showColliders` to `true` on the scene to render colliders for debugging purposes: | ||
|
||
```html | ||
<a-scene obb-collider="showColliders: true"></a-scene> | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Description | Default Value | | ||
|------------------|----------------------------------------------------------------------------------------|---------------| | ||
| size | Force collider to a specific size | 0 0 0 | | ||
| trackedObject3D | Variable path to the object3D used to calculate the collider. el.object3D by default | '' | | ||
|
||
## Events | ||
|
||
| Event Name | Description | | ||
| ---------- | ------------------------------------------------------------------------------------------- | | ||
| obbcollisionstarted | Emitted on the entities that start colliding. Event detail will contain `withEl` referencing the entity that has collided with. | | ||
| obbcollisionended | Emitted on the entities that stop colliding. Event detail will contain `withEl` referencing the entity that was colliding with | | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* global AFRAME */ | ||
AFRAME.registerComponent('hover', { | ||
init: function () { | ||
this.onCollisionStarted = this.onCollisionStarted.bind(this); | ||
this.onCollisionEnded = this.onCollisionEnded.bind(this); | ||
this.modalEl = this.el.querySelector('[spatial-modal]'); | ||
this.el.addEventListener('obbcollisionstarted', this.onCollisionStarted); | ||
this.el.addEventListener('obbcollisionended', this.onCollisionEnded); | ||
}, | ||
|
||
onCollisionStarted: function () { | ||
this.modalEl.setAttribute('spatial-modal', 'color', 'red'); | ||
}, | ||
|
||
onCollisionEnded: function () { | ||
this.modalEl.setAttribute('spatial-modal', 'color', 'white'); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Hand Tracking Grab Controls • A-Frame</title> | ||
<meta name="description" content="Hand Tracking Grab Controls • A-Frame"> | ||
<script src="../../dist/aframe-master.js"></script> | ||
<script src="../../js/spatial-ui/spatial-utils.js"></script> | ||
<script src="../../js/spatial-ui/spatial-modal.js"></script> | ||
<script src="../../js/spatial-ui/spatial-hero-image.js"></script> | ||
<script src="../../js/info-message.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/aframe-environment-component.min.js"></script> | ||
<script src="hover.js"></script> | ||
</head> | ||
<body> | ||
<a-scene | ||
environment | ||
obb-collider="showColliders: false" | ||
info-message="htmlSrc: #messageText"> | ||
<a-assets> | ||
<a-asset-item id="messageText" src="message.html"></a-asset-item> | ||
<img id="ubuntu" src="./images/ubuntu-desktop.png" /> | ||
</a-assets> | ||
<a-entity camera position="0 1.5 0" look-controls wasd-controls></a-entity> | ||
<a-entity position="0 1.6 -1" grabbable hover> | ||
<a-entity spatial-modal="width: 1.81; height: 1.035; roundCorners: false"> | ||
<a-entity spatial-hero-image="src: #ubuntu; width: 1.775; height: 1; roundCorners: false" position="0 0 0.001"></a-entity> | ||
</a-entity> | ||
</a-entity> | ||
<a-entity id="rightHand" hand-tracking-grab-controls="hand: right"></a-entity> | ||
<a-entity id="leftHand" hand-tracking-grab-controls="hand: left"></a-entity> | ||
</a-scene> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p> | ||
Image from <a href="https://ubuntu.com/download/desktop">Ubuntu Desktop</a><br> | ||
</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* global AFRAME */ | ||
AFRAME.registerComponent('grab', { | ||
// init: function () { | ||
// this.grabbed = null; | ||
|
||
// }, | ||
// events: { | ||
// gripdown: function (evt) { | ||
// if (evt.currentTarget.components['raycaster'].intersections.length>0) { | ||
// this.grabbed = evt.currentTarget.components['raycaster'].intersections[0].object.el; | ||
// evt.currentTarget.object3D.attach(this.grabbed.object3D); | ||
// } | ||
// }, gripup: function (evt) { | ||
// if (this.grabbed) { | ||
// this.el.sceneEl.object3D.attach(this.grabbed.object3D); | ||
// this.grabbed = null; | ||
// } | ||
// } | ||
// } | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,9 @@ module.exports.Component = registerComponent('gltf-model', { | |
self.loader.load(src, function gltfLoaded (gltfModel) { | ||
self.model = gltfModel.scene || gltfModel.scenes[0]; | ||
self.model.animations = gltfModel.animations; | ||
|
||
self.centerModel(); | ||
This comment has been minimized.
Sorry, something went wrong.
mrxz
Contributor
|
||
|
||
el.setObject3D('mesh', self.model); | ||
el.emit('model-loaded', {format: 'gltf', model: self.model}); | ||
}, undefined /* onProgress */, function gltfFailed (error) { | ||
|
@@ -54,6 +57,16 @@ module.exports.Component = registerComponent('gltf-model', { | |
}); | ||
}, | ||
|
||
centerModel: function () { | ||
var model = this.model; | ||
var box = new THREE.Box3().setFromObject(model); | ||
var center = box.getCenter(new THREE.Vector3()); | ||
|
||
model.position.x += (model.position.x - center.x); | ||
model.position.y += (model.position.y - center.y); | ||
model.position.z += (model.position.z - center.z); | ||
}, | ||
|
||
remove: function () { | ||
if (!this.model) { return; } | ||
this.el.removeObject3D('mesh'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var registerComponent = require('../core/component').registerComponent; | ||
|
||
registerComponent('grabbable', { | ||
init: function () { | ||
this.el.setAttribute('obb-collider', ''); | ||
} | ||
}); |
abb-collider -> obb-collider