Skip to content

Commit

Permalink
Fix: dragndrop interference between objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
extraymond committed Jul 5, 2019
1 parent f32cc1b commit 2121663
Show file tree
Hide file tree
Showing 8 changed files with 72,991 additions and 34 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
[![npm version](https://badgen.net/npm/v/aframe-mouse-dragndrop-component)](https://www.npmjs.com/package/aframe-mouse-dragndrop-component)
[![jsdelivr version](https://badgen.net/jsdelivr/v/npm/aframe-mouse-dragndrop-component)](https://cdn.jsdelivr.net/npm/aframe-mouse-dragndrop-component@1.0.4/dist/index.js)


# aframe-mouse-dragndrop

Drag-n-drop entites using mouse cursor.

## implementation

There's a new parameter in cursor component that we can use to monitor mouse interaction.

```html
<a-scene cursor="rayOrigin: mouse"></a-scene>
```

Based on this feature, we can intercept the event data emitting by the cursor component. [read more about cursor component](https://aframe.io/docs/0.9.0/components/cursor.html#intersection-data)

I've sperated this module into two sepearte component, **track-cursor** and **dragndrop**. And use dependencies to chain component startup. [read more about component dependencies](https://aframe.io/docs/0.9.0/core/component.html#dependencies)
Expand All @@ -23,26 +25,29 @@ if (this.el.is("tracking")) {
...
}
```

If a draggable component is being pressed, it will enter the dragging state. Likewise you can check it with:

```js
if (this.el.is("dragging")) {
...
}
```

If you want to do some startup/cleanup before entering/exiting these two states, be sure to listener to "stateadded"/"stateremoved" events.

## usage

```html
<a-entity dragndrop></a-entity>
```

After adding the component, you can drag and drop it with mouse click.

## additional features

1. When dragging the entity, look-controls on the camera will be temporary disabled.
2. You can use mousewheel to send it further/closer when dragging.
1. When dragging the entity, look-controls on the camera will be temporary disabled.
2. You can use mousewheel to send it further/closer when dragging.

Check out the live demo: [link](https://sassy-piper.glitch.me)

Expand Down
13 changes: 13 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<head>
<script type="text/javascript" src="/src.7ed060e2.js">
</script>
</head>
<body>
<a-scene>
<a-box dragndrop="" position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
<a-sphere dragndrop="" position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
<a-cylinder dragndrop="" position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
</body>
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 2121663

Please sign in to comment.