0.2.1 • Published 2 years ago

@metapins/aframe-element v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@metapins/aframe-element

aframe-element is a library inspired from the very nice library Polymer lit to map A-Frame AR / VR / 3D elements on typescript classes like Angular/React/Lit.
Used with @metapins/lit-observable, you can create simple, fast and reactive WebXR 3D /AR and VR scenes with all modern web development good practices.

Get started !

Installation

Use the package manager npm to install aframe-element.

npm install @metapins/aframe-element

Usage

By component

import { customElement, AFrameElement } from '@metapins/aframe-element';

@customElement('my-3d-element')
exports My3dElement extends AFrameElement {
  render() {
    return html`
      <a-entity text="value: Hello World;"></a-entity>
    `;
  }
}
<a-scene>
  <my-3d-element></my-3d-element>
</a-scene>

With parameters

import { customElement, AFrameElement } from '@metapins/aframe-element';

@customElement('my-text-element')
exports MyTextElement extends AFrameElement {
  static schema: {
    text: { type: 'string' },
  }

  render() {
    return html`
      <a-entity text="value: ${this.data.text};"></a-entity>
    `;
  }
}
<a-scene>
  <a-my-text-element _text="Hello World"></a-my-text-element>
</a-scene>

By attribute

import { customElement, AFrameElement } from '@metapins/aframe-element';

@customElement('my-text-element')
exports MyTextElement extends AFrameElement {
  static schema: {
    text: { type: 'string' },
  }

  render() {
    return html`
      <a-entity text="value: ${this.data.text};"></a-entity>
    `;
  }
}
<a-scene>
  <a-entity my-text-element="text: Hello World;"></a-entity>
</a-scene>

With an aframe event

import { customElement, AFrameElement } from '@metapins/aframe-element';

@customElement('my-3d-element')
exports My3dElement extends AFrameElement {
  init() {
    console.log('component initilized', this.el);
  }

  render() {
    return html`
      <a-entity text="value: Hello World;"></a-entity>
    `;
  }
}
<a-scene>
  <my-3d-element></my-3d-element>
</a-scene>

With @metapins/lit-observable and rxjs

import { customElement, AFrameElement } from '@metapins/aframe-element';

@customElement('pawn')
export class PawnElement extends AFrameElement {
  private background$ = new BehaviorSubject<string>('grey');

  render() {
    return html`
      <a-box
        scale="1 1 0.1"
        material="color: ${observe(this.background$)}"
        @mouseenter=${() => this.background$.next('white')}
        @mouseleave=${() => this.background$.next('grey')}
      ></a-box>
    `;
  }
}
<a-scene cursor="rayOrigin: mouse;  fuse: false;">
  <my-3d-element></my-3d-element>
</a-scene>

More information about @metapins/lit-observable here

Documentation

Example

Tictactoe with rxjs

aframe-element example tictactoe

Puissance4 with network playing & @vaadin/router & redux

The owner of the multiplayer game is the first to open the link (player yellow). Next users to open the demo are red.

Tips: You can open 2 tabs on the same browser to test multiplayer mode.

aframe-element example puissance4

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.2-alpha2

2 years ago

0.0.2-alpha1

2 years ago

0.0.1

2 years ago