ソースを参照

Fixed NodeMaterial not compiling when a material of same class is created afterwards with needsUpdate=false

Daniel Sturk 6 年 前
コミット
1b8c82f95f
1 ファイル変更16 行追加14 行削除
  1. 16 14
      examples/js/nodes/materials/NodeMaterial.js

+ 16 - 14
examples/js/nodes/materials/NodeMaterial.js

@@ -18,6 +18,22 @@ function NodeMaterial( vertex, fragment ) {
 
 	this.updaters = [];
 
+	// onBeforeCompile can't be in the prototype because onBeforeCompile.toString varies per material
+
+	this.onBeforeCompile = function ( shader, renderer ) {
+
+		if ( this.needsUpdate ) {
+
+			this.build( { renderer: renderer } );
+
+			shader.uniforms = this.uniforms;
+			shader.vertexShader = this.vertexShader;
+			shader.fragmentShader = this.fragmentShader;
+
+		}
+
+	};
+
 	// it fix the programCache and share the code with others materials
 
 	this.onBeforeCompile.toString = function() {
@@ -74,20 +90,6 @@ NodeMaterial.prototype.updateFrame = function ( frame ) {
 
 };
 
-NodeMaterial.prototype.onBeforeCompile = function ( shader, renderer ) {
-
-	if ( this.needsUpdate ) {
-
-		this.build( { renderer: renderer } );
-
-		shader.uniforms = this.uniforms;
-		shader.vertexShader = this.vertexShader;
-		shader.fragmentShader = this.fragmentShader;
-
-	}
-
-};
-
 NodeMaterial.prototype.build = function ( params ) {
 
 	params = params || {};