最新代码
This commit is contained in:
61
public/sdk/three/jsm/nodes/utils/JoinNode.js
Normal file
61
public/sdk/three/jsm/nodes/utils/JoinNode.js
Normal file
@ -0,0 +1,61 @@
|
||||
import { addNodeClass } from '../core/Node.js';
|
||||
import TempNode from '../core/TempNode.js';
|
||||
|
||||
class JoinNode extends TempNode {
|
||||
|
||||
constructor( nodes = [], nodeType = null ) {
|
||||
|
||||
super( nodeType );
|
||||
|
||||
this.nodes = nodes;
|
||||
|
||||
}
|
||||
|
||||
getNodeType( builder ) {
|
||||
|
||||
if ( this.nodeType !== null ) {
|
||||
|
||||
return builder.getVectorType( this.nodeType );
|
||||
|
||||
}
|
||||
|
||||
return builder.getTypeFromLength( this.nodes.reduce( ( count, cur ) => count + builder.getTypeLength( cur.getNodeType( builder ) ), 0 ) );
|
||||
|
||||
}
|
||||
|
||||
generate( builder, output ) {
|
||||
|
||||
const type = this.getNodeType( builder );
|
||||
const nodes = this.nodes;
|
||||
|
||||
const primitiveType = builder.getComponentType( type );
|
||||
|
||||
const snippetValues = [];
|
||||
|
||||
for ( const input of nodes ) {
|
||||
|
||||
let inputSnippet = input.build( builder );
|
||||
|
||||
const inputPrimitiveType = builder.getComponentType( input.getNodeType( builder ) );
|
||||
|
||||
if ( inputPrimitiveType !== primitiveType ) {
|
||||
|
||||
inputSnippet = builder.format( inputSnippet, inputPrimitiveType, primitiveType );
|
||||
|
||||
}
|
||||
|
||||
snippetValues.push( inputSnippet );
|
||||
|
||||
}
|
||||
|
||||
const snippet = `${ builder.getType( type ) }( ${ snippetValues.join( ', ' ) } )`;
|
||||
|
||||
return builder.format( snippet, type, output );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default JoinNode;
|
||||
|
||||
addNodeClass( 'JoinNode', JoinNode );
|
Reference in New Issue
Block a user