Browse Source

fix needsUpdate

sunag 6 years ago
parent
commit
07236bb765
1 changed files with 26 additions and 0 deletions
  1. 26 0
      examples/js/nodes/materials/NodeMaterial.js

+ 26 - 0
examples/js/nodes/materials/NodeMaterial.js

@@ -11,11 +11,21 @@ function NodeMaterial( vertex, fragment ) {
 
 
 	THREE.ShaderMaterial.call( this );
 	THREE.ShaderMaterial.call( this );
 
 
+	var self = this;
+
 	this.vertex = vertex || new RawNode( new PositionNode( PositionNode.PROJECTION ) );
 	this.vertex = vertex || new RawNode( new PositionNode( PositionNode.PROJECTION ) );
 	this.fragment = fragment || new RawNode( new ColorNode( 0xFF0000 ) );
 	this.fragment = fragment || new RawNode( new ColorNode( 0xFF0000 ) );
 
 
 	this.updaters = [];
 	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 );
 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;
+
+		}
+
 	}
 	}
 
 
 } );
 } );