Spaces:
Running
Running
File size: 2,305 Bytes
6cd9596 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
/**
* @author sunag / http://www.sunag.com.br/
*/
import { InputNode } from '../core/InputNode.js';
import { ReflectNode } from '../accessors/ReflectNode.js';
import { ColorSpaceNode } from '../utils/ColorSpaceNode.js';
function CubeTextureNode( value, uv, bias ) {
InputNode.call( this, 'v4', { shared: true } );
this.value = value;
this.uv = uv || new ReflectNode();
this.bias = bias;
}
CubeTextureNode.prototype = Object.create( InputNode.prototype );
CubeTextureNode.prototype.constructor = CubeTextureNode;
CubeTextureNode.prototype.nodeType = "CubeTexture";
CubeTextureNode.prototype.getTexture = function ( builder, output ) {
return InputNode.prototype.generate.call( this, builder, output, this.value.uuid, 'tc' );
};
CubeTextureNode.prototype.generate = function ( builder, output ) {
if ( output === 'samplerCube' ) {
return this.getTexture( builder, output );
}
var cubetex = this.getTexture( builder, output );
var uv = this.uv.build( builder, 'v3' );
var bias = this.bias ? this.bias.build( builder, 'f' ) : undefined;
if ( bias === undefined && builder.context.bias ) {
bias = new builder.context.bias( this ).build( builder, 'f' );
}
var code;
if ( bias ) code = 'texCubeBias( ' + cubetex + ', ' + uv + ', ' + bias + ' )';
else code = 'texCube( ' + cubetex + ', ' + uv + ' )';
// add this context to replace ColorSpaceNode.input to code
builder.addContext( { input: code, encoding: builder.getTextureEncodingFromMap( this.value ), include: builder.isShader( 'vertex' ) } );
this.colorSpace = this.colorSpace || new ColorSpaceNode( this );
code = this.colorSpace.build( builder, this.type );
builder.removeContext();
return builder.format( code, this.type, output );
};
CubeTextureNode.prototype.copy = function ( source ) {
InputNode.prototype.copy.call( this, source );
if ( source.value ) this.value = source.value;
this.uv = source.uv;
if ( source.bias ) this.bias = source.bias;
};
CubeTextureNode.prototype.toJSON = function ( meta ) {
var data = this.getJSONNode( meta );
if ( ! data ) {
data = this.createJSONNode( meta );
data.value = this.value.uuid;
data.uv = this.uv.toJSON( meta ).uuid;
if ( this.bias ) data.bias = this.bias.toJSON( meta ).uuid;
}
return data;
};
export { CubeTextureNode };
|