# gaze-event

> Gaze event for WebVR project

Latest version **2.0.5** (published 2017-12-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install gaze-event
pnpm add gaze-event
yarn add gaze-event
bun add gaze-event
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2017-12-24 |
| First published | 2017-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Yone Chen |
| Maintainers | yorkchan |
| Keywords | webvr, gaze, three, event, listener |

## Links

- npm: https://www.npmjs.com/package/gaze-event
- Repository: https://github.com/yonechen/gaze-event
- Homepage: https://github.com/yonechen/gaze-event#readme
- Issues: https://github.com/yonechen/gaze-event/issues
- npm.io page: https://npm.io/package/gaze-event

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 2.0.5 (latest) — 2017-12-24
- 2.0.4 — 2017-12-24
- 2.0.3 — 2017-12-22
- 2.0.2 — 2017-12-22
- 2.0.1 — 2017-12-20
- 2.0.0 — 2017-12-20
- 1.0.0 — 2017-08-21

## README

# gaze-event

Gaze event listeners for webvr threejs project.

It observe basic gaze actions for mesh targets in your three.js project,such as `gazeEnter`, `gazeLeave`, `gazeTrigger` and `gazeWait`.

- gazeEnter: Emit in first animation frame when target is gazed;

- gazeLeave: Emit in last animation frame when target is gazed;

- gazeTrigger: Emit in each animation frame when target is gazed;

- gazeWait: Emit in a animation frame when target has gazed for a while;

[See the example.](https://yonechen.github.io/gaze-event/example)

## Installation

First,Make sure you have included the three.js for your project.

1. `yarn add gaze-event` or `npm install --save gaze-event`

1. `import GazeEvent from 'gaze-event'` or `const gazeEvent = require('gaze-event)` in project with module bundler.

Of course,You can also use `<script src="gaze-event/index.js"></script>` without module bundler.

## How to use

```javascript
// init scene, camera, renderer
...
// create crosshair here
// camera.add(createCrosshair());
// create cube
var cube = new THREE.Mesh( geometry, material );
scene.add(cube);

// Step1: init gazeEvent
var gazeEvent = new GazeEvent();

// Step2: add event listener for the cube
gazeEvent.on(cube, 'gazeEnter', function(target) {
    target.material.opacity = 0.5; // emit in first frame when the cube is gazed
});
gazeEvent.on(cube, 'gazeLeave', function(target) {
    target.material.opacity = 1; // emit in last frame when the cube isn't gazed
});
gazeEvent.on(cube, 'gazeTrigger', function(target) {
    target.rotation.y += 0.02; // emite in each frame when the cube is gazed
});

// Step3: update gazeEvent to observe the cube in each animation frame
function animateLoop() { // animate loop for requestAnimationFrame
    ...
    // update gazeEvent
    gazeEvent.update(camera);
    renderer.render(scene, camera);
}
```

## API

### constructor

create a GazeEvent instance.

```javascript
var gazeEvent = new GazeEvent();
```

### on(target,actionType,callback)

add a gaze action listener for a mesh target, `actionType` can be `'gazeEnter'||'gazeLeave'||'gazeTrigger'||'gazeWait'`

```javascript
gazeEvent.on(target,'gazeEnter')
```

### off(target,actionType)

remove a gaze action listener for a mesh target.

```javascript
gazeEvent.off(mesh,'gazeEnter');
```

### removeAll()

remove all gaze listeners.

```javascript
gazeEvent.removeAll();
```

## Need Help

Ask questions [here](https://github.com/yonechen/gaze-event/issues).

## Any Advise

PR welcome [here](https://github.com/yonechen/gaze-event/pulls).

## Contributors

YoneChen <yorkchan94@gmail.com>

## License

MIT

Please Star this Project if you like it! Following would also be appreciated!

---
_Source: https://npm.io/package/gaze-event · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
