浏览代码

Merge pull request #16606 from DanielSturk/fix-functionNodes

Fixed bug with nested FunctionNodes (or ExpressionNodes) looping infinitely
Mr.doob 6 年之前
父节点
当前提交
6abf9cc9ad
共有 2 个文件被更改,包括 14 次插入5 次删除
  1. 7 1
      examples/js/nodes/core/FunctionNode.js
  2. 7 4
      examples/webgl_materials_nodes.html

+ 7 - 1
examples/js/nodes/core/FunctionNode.js

@@ -85,7 +85,13 @@ FunctionNode.prototype.generate = function ( builder, output ) {
 
 	}
 
-	while ( match = propertiesRegexp.exec( this.src ) ) {
+	var matches = [];
+
+	while ( match = propertiesRegexp.exec( this.src ) ) matches.push( match );
+
+	for ( var i = 0; i < matches.length; i++ ) {
+
+		var match = matches[i];
 
 		var prop = match[ 0 ],
 			isGlobal = this.isMethod ? ! this.getInputByName( prop ) : true,

+ 7 - 4
examples/webgl_materials_nodes.html

@@ -2198,11 +2198,14 @@
 
 						var speed = new THREE.FloatNode( .5 );
 
-						mtl.color = new THREE.ExpressionNode( "myCustomUv + (sin(time*speed)*.5) + (position * .05)", "vec3" );
-						mtl.color.keywords[ "speed" ] = speed;
+						var myspeed = new THREE.ExpressionNode( "speed * time", "float" );
+						myspeed.keywords[ "speed" ] = speed;
 
-						mtl.position = new THREE.ExpressionNode( "mod(time*speed,1.0) < 0.5 ? position + (worldNormal*(1.0+sin(time*speed*1.0))*3.0) : position + sin( position.x * sin(time*speed*2.0))", "vec3" );
-						mtl.position.keywords[ "speed" ] = speed;
+						mtl.color = new THREE.ExpressionNode( "myCustomUv + (sin(myspeed)*.5) + (position * .05)", "vec3" );
+						mtl.color.keywords[ "myspeed" ] = myspeed;
+
+						mtl.position = new THREE.ExpressionNode( "mod(myspeed,1.0) < 0.5 ? position + (worldNormal*(1.0+sin(myspeed*1.0))*3.0) : position + sin( position.x * sin(myspeed*2.0))", "vec3" );
+						mtl.position.keywords[ "myspeed" ] = myspeed;
 
 						// add global keyword ( variable or const )
 						THREE.NodeLib.addKeyword( 'myCustomUv', function () {