three 基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
978 B

import { TempNode } from '../core/TempNode.js';
import { NodeLib } from '../core/NodeLib.js';
class UVNode extends TempNode {
constructor( index ) {
super( 'v2', { shared: false } );
this.index = index || 0;
}
generate( builder, output ) {
builder.requires.uv[ this.index ] = true;
const uvIndex = this.index > 0 ? this.index + 1 : '';
const result = builder.isShader( 'vertex' ) ? 'uv' + uvIndex : 'vUv' + uvIndex;
return builder.format( result, this.getType( builder ), output );
}
copy( source ) {
super.copy( source );
this.index = source.index;
return this;
}
toJSON( meta ) {
let data = this.getJSONNode( meta );
if ( ! data ) {
data = this.createJSONNode( meta );
data.index = this.index;
}
return data;
}
}
UVNode.prototype.nodeType = 'UV';
NodeLib.addKeyword( 'uv', function () {
return new UVNode();
} );
NodeLib.addKeyword( 'uv2', function () {
return new UVNode( 1 );
} );
export { UVNode };