VarNode.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.VarNode = function ( type, value ) {
  5. THREE.GLNode.call( this, type );
  6. this.value = value;
  7. };
  8. THREE.VarNode.prototype = Object.create( THREE.GLNode.prototype );
  9. THREE.VarNode.prototype.constructor = THREE.VarNode;
  10. THREE.VarNode.prototype.nodeType = "Var";
  11. THREE.VarNode.prototype.getType = function ( builder ) {
  12. return builder.getTypeByFormat( this.type );
  13. };
  14. THREE.VarNode.prototype.generate = function ( builder, output ) {
  15. var varying = builder.material.getVar( this.uuid, this.type );
  16. if ( this.value && builder.isShader( 'vertex' ) ) {
  17. builder.material.addVertexNode( varying.name + ' = ' + this.value.build( builder, this.getType( builder ) ) + ';' );
  18. }
  19. return builder.format( varying.name, this.getType( builder ), output );
  20. };
  21. THREE.VarNode.prototype.copy = function ( source ) {
  22. THREE.GLNode.prototype.copy.call( this, source );
  23. this.type = source.type;
  24. this.value = source.value;
  25. };
  26. THREE.VarNode.prototype.toJSON = function ( meta ) {
  27. var data = this.getJSONNode( meta );
  28. if ( ! data ) {
  29. data = this.createJSONNode( meta );
  30. data.type = this.type;
  31. if ( this.value ) data.value = this.value.toJSON( meta ).uuid;
  32. }
  33. return data;
  34. };