1.2.0 • Published 5 years ago

aframe-door v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

aframe-sliding-door-component

A-Frame component for adding a sliding door.

Compatibility

VersionCompatibility with the core
1.20.9 and more
1.10.8
1.00.5

API

PropertyDescriptionDefault Value
widthWidth of the door1
heightHeight of the door2
depthDepth of the door0.25
colorColor of the door#AAA
textureTexture of the door''
typeDoor type ('simple' or 'double')simple
open_directionThe open direction ('right', 'left', 'up', 'down')right
open_durationThe duration of the opening animation in ms3000
close_durationThe duration of the closing animation in ms3000
open_eventThe event name which open the dooropen
close_eventThe event name which close the doorclose
open_soundThe sound ressource played at the opening''
close_soundThe sound ressource played at the closing''
auto_distanceThe distance to automatically open and close the door0

Usage

Just declare the entity in the HTML with the properties you want.

<a-entity id="door" door="width: 10; height: 5; color: #4D4437; depth: 0.25; type: double; open_direction: left;" position="0 2.5 -5"></a-entity>

And interact with it by emitting the 'open' or 'close' event.

document.querySelectorAll('#door').forEach(function(door) {door.emit('open');});

Sounds

In order to attach sounds to the opening and the closing events. Your just have to set the open_sound and close_sound attributes with your sound ressources previously declared in your assets.

<a-assets>
  <audio id="close_sound" src="close_sound.mp3" preload="auto"></audio>
</a-assets>
<a-entity door="close_sound: #close_sound;"></a-entity>

Speech Command

You can control the opening and the closing of the door by vocal command. This feature is based on the speech command component

The door component just exposes an open and close function in order to use this component. Use this syntax on your a-door element:

<a-entity speech-command__open="command: open; type: function; targetComponent: door; function: open;" speech-command__close="command: close; type: function; targetComponent: door; function: close;"></a-entity>

For more informations, report to the speech command component documentation.

Automatically open and close the door

You can automatically open and close the door when the user is close enough from the door by using the auto_distance attribute. You just set a number into this attribute and it represents the distance between the user and the center of the door. When the distance is lower than this limit, the door will open and when it's higher it will close.

This attribute is only compatible with the aframe teleport controls. You need to change your position with this component in order to have this feature otherwise it will just not work.

Notes

The component is pretty simple and create only sliding rectangular doors. It also doesn't support 3D models. If you have any idea to improve the component, do a pull request ;)

Browser

Install and use by directly including the browser files:

<head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
  <script src="https://raw.githubusercontent.com/pjoulot/a-door/master/dist/aframe-door.min.js"></script>
</head>

<body>
  <a-scene>
    <a-entity door="width: 10; height: 5; color: #4D4437; depth: 0.25; type: double; open_direction: left;" position="0 2.5 -5"></a-entity>
  </a-scene>
</body>