AttributeNode.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.toJSON = function ( meta ) {
  24. var data = this.getJSONNode( meta );
  25. if ( ! data ) {
  26. data = this.createJSONNode( meta );
  27. data.out = this.type;
  28. }
  29. return data;
  30. };