123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /**
- * @author sunag / http://www.sunag.com.br/
- */
- THREE.NodeBuilder = function( material ) {
-
- this.material = material;
-
- this.require = {};
- this.isVerify = false;
- this.cache = '';
-
- };
- THREE.NodeBuilder.prototype = {
- constructor: THREE.NodeBuilder,
- include : function ( func ) {
-
- this.material.include( this.shader, func );
- },
-
- getFormatConstructor : function ( len ) {
-
- return THREE.NodeBuilder.constructors[len-1];
-
- },
-
- getFormat : function ( format ) {
-
- return format.replace('c','v3').replace(/fv1|iv1/, 'v1');
-
- },
-
- getFormatLength : function ( format ) {
-
- return parseInt( this.getFormat(format).substr(1) );
-
- },
-
- getFormatByLength : function ( len ) {
-
- if (len == 1) return 'fv1';
-
- return 'v' + len;
-
- },
-
- format : function ( code, from, to ) {
-
- var format = this.getFormat(from + '=' + to);
-
- switch ( format ) {
- case 'v1=v2': return 'vec2(' + code + ')';
- case 'v1=v3': return 'vec3(' + code + ')';
- case 'v1=v4': return 'vec4(' + code + ')';
-
- case 'v2=v1': return code + '.x';
- case 'v2=v3': return 'vec3(' + code + ',0.0)';
- case 'v2=v4': return 'vec4(' + code + ',0.0,0.0)';
-
- case 'v3=v1': return code + '.x';
- case 'v3=v2': return code + '.xy';
- case 'v3=v4': return 'vec4(' + code + ',0.0)';
-
- case 'v4=v1': return code + '.x';
- case 'v4=v2': return code + '.xy';
- case 'v4=v3': return code + '.xyz';
- }
-
- return code;
-
- },
-
- getType : function ( format ) {
-
- return THREE.NodeBuilder.type[ format ];
-
- },
-
- getUuid : function ( uuid, useCache ) {
-
- useCache = useCache !== undefined ? useCache : true;
-
- if (useCache && this.cache) uuid = this.cache + '-' + uuid;
-
- return uuid;
- },
-
- setCache : function ( name ) {
-
- this.cache = name || '';
-
- return this;
- },
-
- getElementByIndex : function ( index ) {
-
- return THREE.NodeBuilder.elements[ index ];
-
- },
-
- getElementIndex : function ( elm ) {
-
- return THREE.NodeBuilder.elements.indexOf( elm );
-
- },
-
- isShader : function ( shader ) {
-
- return this.shader == shader || this.isVerify;
- },
-
- setShader : function ( shader ) {
-
- this.shader = shader;
-
- return this;
- }
- };
- THREE.NodeBuilder.type = {
- float : 'fv1',
- vec2 : 'v2',
- vec3 : 'v3',
- vec4 : 'v4'
- };
- THREE.NodeBuilder.constructors = [
- '',
- 'vec2',
- 'vec3',
- 'vec4'
- ];
- THREE.NodeBuilder.elements = [
- 'x',
- 'y',
- 'z',
- 'w'
- ];
|