UNPKG

@edsilv/ami.js

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/214063/46479857-4cd66e80-c7f0-11e8-9585-5748409c9490.png" width="60%"> </p>

67 lines (57 loc) 1.8 kB
/** * Helpers material mixin. * * @module helpers/material/mixin */ const helpersMaterialMixin = (three = window.THREE) => { if (three === undefined || three.Object3D === undefined) { return null; } const Constructor = three.Object3D; return class extends Constructor { _createMaterial(extraOptions) { // generate shaders on-demand! let fs = new this._shadersFragment(this._uniforms); let vs = new this._shadersVertex(); // material let globalOptions = { uniforms: this._uniforms, vertexShader: vs.compute(), fragmentShader: fs.compute(), }; let options = Object.assign(extraOptions, globalOptions); this._material = new three.ShaderMaterial(options); this._material.needsUpdate = true; } _updateMaterial() { // generate shaders on-demand! let fs = new this._shadersFragment(this._uniforms); let vs = new this._shadersVertex(); this._material.vertexShader = vs.compute(); this._material.fragmentShader = fs.compute(); this._material.needsUpdate = true; } _prepareTexture() { this._textures = []; for (let m = 0; m < this._stack._rawData.length; m++) { let tex = new three.DataTexture( this._stack.rawData[m], this._stack.textureSize, this._stack.textureSize, this._stack.textureType, three.UnsignedByteType, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.NearestFilter, three.NearestFilter ); tex.needsUpdate = true; tex.flipY = true; this._textures.push(tex); } } }; }; export { helpersMaterialMixin }; export default helpersMaterialMixin();