فهرست منبع

TSL Transpiler: Add simplified `Fn()` layout (#31299)

* fix arithmetic operators check

* add simplified layout
sunag 6 ماه پیش
والد
کامیت
b1d24bdc37
2فایلهای تغییر یافته به همراه13 افزوده شده و 18 حذف شده
  1. 9 1
      examples/jsm/transpiler/GLSLDecoder.js
  2. 4 17
      examples/jsm/transpiler/TSLEncoder.js

+ 9 - 1
examples/jsm/transpiler/GLSLDecoder.js

@@ -4,6 +4,10 @@ const unaryOperators = [
 	'+', '-', '~', '!', '++', '--'
 ];
 
+const arithmeticOperators = [
+	'*', '/', '%', '+', '-', '<<', '>>'
+];
+
 const precedenceOperators = [
 	'*', '/', '%',
 	'-', '+',
@@ -328,7 +332,11 @@ class GLSLDecoder {
 				if ( ! token.isOperator || i === 0 || i === tokens.length - 1 ) return;
 
 				// important for negate operator after arithmetic operator: a * -1, a * -( b )
-				if ( ( inverse && tokens[ i - 1 ].isOperator ) || ( ! inverse && tokens[ i + 1 ].isOperator ) ) return;
+				if ( ( inverse && arithmeticOperators.includes( tokens[ i - 1 ].str ) ) || ( ! inverse && arithmeticOperators.includes( tokens[ i + 1 ].str ) ) ) {
+
+					return;
+
+				}
 
 				if ( groupIndex === 0 && token.str === operator ) {
 

+ 4 - 17
examples/jsm/transpiler/TSLEncoder.js

@@ -58,7 +58,6 @@ class TSLEncoder {
 		this.global = new Set();
 		this.overloadings = new Map();
 		this.iife = false;
-		this.uniqueNames = false;
 		this.reference = false;
 
 		this._currentVariable = null;
@@ -726,8 +725,6 @@ ${ this.tab }} )`;
 
 		for ( const param of node.params ) {
 
-			let str = `{ name: '${ param.name }', type: '${ param.type }'`;
-
 			let name = param.name;
 
 			if ( param.immutable === false && ( param.qualifier !== 'inout' && param.qualifier !== 'out' ) ) {
@@ -746,11 +743,9 @@ ${ this.tab }} )`;
 
 				}
 
-				str += ', qualifier: \'' + param.qualifier + '\'';
-
 			}
 
-			inputs.push( str + ' }' );
+			inputs.push( param.name + ': \'' + param.type + '\'' );
 			params.push( name );
 
 			this._currentProperties[ name ] = param;
@@ -795,23 +790,15 @@ ${ this.tab }} )`;
 
 ${ bodyStr }
 
-${ this.tab }} )`;
-
-		const layoutInput = inputs.length > 0 ? '\n\t\t' + this.tab + inputs.join( ',\n\t\t' + this.tab ) + '\n\t' + this.tab : '';
+${ this.tab }}`;
 
 		if ( node.layout !== false && hasPointer === false ) {
 
-			const uniqueName = this.uniqueNames ? fnName + '_' + Math.random().toString( 36 ).slice( 2 ) : fnName;
-
-			funcStr += `.setLayout( {
-${ this.tab }\tname: '${ uniqueName }',
-${ this.tab }\ttype: '${ type }',
-${ this.tab }\tinputs: [${ layoutInput }]
-${ this.tab }} )`;
+			funcStr += ', { ' + inputs.join( ', ' ) + ', return: \'' + type + '\' }';
 
 		}
 
-		funcStr += ';\n';
+		funcStr += ' );\n';
 
 		this.imports.add( 'Fn' );
 

粤ICP备19079148号