AttributeNode.js 1.3 KB

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