From 07236bb765fd2d2231196ca89125b335144241e1 Mon Sep 17 00:00:00 2001 From: sunag Date: Wed, 30 Jan 2019 22:26:21 -0200 Subject: [PATCH] fix needsUpdate --- examples/js/nodes/materials/NodeMaterial.js | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/examples/js/nodes/materials/NodeMaterial.js b/examples/js/nodes/materials/NodeMaterial.js index 43d14deaa728e3..3220408b4811eb 100644 --- a/examples/js/nodes/materials/NodeMaterial.js +++ b/examples/js/nodes/materials/NodeMaterial.js @@ -11,11 +11,21 @@ function NodeMaterial( vertex, fragment ) { THREE.ShaderMaterial.call( this ); + var self = this; + this.vertex = vertex || new RawNode( new PositionNode( PositionNode.PROJECTION ) ); this.fragment = fragment || new RawNode( new ColorNode( 0xFF0000 ) ); this.updaters = []; + // it fix the programCache and share the code with others materials + + this.onBeforeCompile.toString = function() { + + return self.needsCompile; + + }; + } NodeMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype ); @@ -34,6 +44,22 @@ Object.defineProperties( NodeMaterial.prototype, { } + }, + + needsUpdate: { + + set: function ( value ) { + + this.needsCompile = value; + + }, + + get: function () { + + return this.needsCompile; + + } + } } );