InputNode.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.InputNode = function ( type, params ) {
  5. params = params || {};
  6. params.shared = params.shared !== undefined ? params.shared : false;
  7. THREE.TempNode.call( this, type, params );
  8. this.readonly = false;
  9. };
  10. THREE.InputNode.prototype = Object.create( THREE.TempNode.prototype );
  11. THREE.InputNode.prototype.constructor = THREE.InputNode;
  12. THREE.InputNode.prototype.isReadonly = function ( builder ) {
  13. return this.readonly;
  14. };
  15. THREE.InputNode.prototype.copy = function ( source ) {
  16. THREE.GLNode.prototype.copy.call( this, source );
  17. if ( source.readonly !== undefined ) this.readonly = source.readonly;
  18. };
  19. THREE.InputNode.prototype.createJSONNode = function ( meta ) {
  20. var data = THREE.GLNode.prototype.createJSONNode.call( this, meta );
  21. if ( this.readonly === true ) data.readonly = this.readonly;
  22. return data;
  23. };
  24. THREE.InputNode.prototype.generate = function ( builder, output, uuid, type, ns, needsUpdate ) {
  25. var material = builder.material;
  26. uuid = builder.getUuid( uuid || this.getUuid() );
  27. type = type || this.getType( builder );
  28. var data = material.getDataNode( uuid ),
  29. readonly = this.isReadonly( builder ) && this.generateReadonly !== undefined;
  30. if ( readonly ) {
  31. return this.generateReadonly( builder, output, uuid, type, ns, needsUpdate );
  32. } else {
  33. if ( builder.isShader( 'vertex' ) ) {
  34. if ( ! data.vertex ) {
  35. data.vertex = material.createVertexUniform( type, this, ns, needsUpdate );
  36. }
  37. return builder.format( data.vertex.name, type, output );
  38. } else {
  39. if ( ! data.fragment ) {
  40. data.fragment = material.createFragmentUniform( type, this, ns, needsUpdate );
  41. }
  42. return builder.format( data.fragment.name, type, output );
  43. }
  44. }
  45. };