Skip to content

Instantly share code, notes, and snippets.

@DhruvDange
Forked from nerestaren/alphamap.js
Created January 23, 2023 15:21
Show Gist options
  • Save DhruvDange/2d1601539381843f0b2724f8be0b2a46 to your computer and use it in GitHub Desktop.
Save DhruvDange/2d1601539381843f0b2724f8be0b2a46 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