NodeMaterialLoader.js 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { MaterialLoader } from 'three';
  2. import { createNodeMaterialFromType } from '../materials/Materials.js';
  3. const superFromTypeFunction = MaterialLoader.createMaterialFromType;
  4. MaterialLoader.createMaterialFromType = function ( type ) {
  5. const material = createNodeMaterialFromType( type );
  6. if ( material !== undefined ) {
  7. return material;
  8. }
  9. return superFromTypeFunction.call( this, type );
  10. };
  11. class NodeMaterialLoader extends MaterialLoader {
  12. constructor( manager ) {
  13. super( manager );
  14. this.nodes = {};
  15. }
  16. parse( json ) {
  17. const material = super.parse( json );
  18. const nodes = this.nodes;
  19. const inputNodes = json.inputNodes;
  20. for ( const property in inputNodes ) {
  21. const uuid = inputNodes[ property ];
  22. material[ property ] = nodes[ uuid ];
  23. }
  24. return material;
  25. }
  26. setNodes( value ) {
  27. this.nodes = value;
  28. return this;
  29. }
  30. }
  31. export default NodeMaterialLoader;