Skip to content

Instantly share code, notes, and snippets.

@nerestaren
Created March 21, 2018 10:40
Show Gist options
  • Save nerestaren/3150822fffa96a4a14aa01dd50d131a0 to your computer and use it in GitHub Desktop.
Save nerestaren/3150822fffa96a4a14aa01dd50d131a0 to your computer and use it in GitHub Desktop.
A-FRAME Alpha Map
// This component adds an alpha map to a mesh.
AFRAME.registerComponent('alpha-map', {
schema: {
src: {type: 'map'}
},
init: function() {
this.el.sceneEl.systems.material.loadTexture(this.data.src, {src: this.data.src}, this.callback.bind(this));
},
callback: function(texture) {
this.el.object3DMap.mesh.material.alphaMap = texture;
}
});
// Usage:
// <a-entity material="src: #texture" alpha-map="src: #alphaMap">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment