Materials.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import NodeMaterial from './NodeMaterial.js';
  2. import LineBasicNodeMaterial from './LineBasicNodeMaterial.js';
  3. import MeshBasicNodeMaterial from './MeshBasicNodeMaterial.js';
  4. import MeshStandardNodeMaterial from './MeshStandardNodeMaterial.js';
  5. import MeshPhysicalNodeMaterial from './MeshPhysicalNodeMaterial.js';
  6. import PointsNodeMaterial from './PointsNodeMaterial.js';
  7. import SpriteNodeMaterial from './SpriteNodeMaterial.js';
  8. export {
  9. NodeMaterial,
  10. LineBasicNodeMaterial,
  11. MeshBasicNodeMaterial,
  12. MeshStandardNodeMaterial,
  13. MeshPhysicalNodeMaterial,
  14. PointsNodeMaterial,
  15. SpriteNodeMaterial
  16. };
  17. NodeMaterial.fromMaterial = function ( material ) {
  18. const materialLib = {
  19. NodeMaterial,
  20. LineBasicNodeMaterial,
  21. MeshBasicNodeMaterial,
  22. MeshStandardNodeMaterial,
  23. MeshPhysicalNodeMaterial,
  24. PointsNodeMaterial,
  25. SpriteNodeMaterial
  26. };
  27. const type = material.type.replace( 'Material', 'NodeMaterial' );
  28. if ( materialLib[ type ] === undefined ) {
  29. return material; // is already a node material or cannot be converted
  30. }
  31. const nodeMaterial = new materialLib[ type ]( material );
  32. for ( const key in material ) {
  33. if ( nodeMaterial[ key ] === undefined ) {
  34. nodeMaterial[ key ] = material[ key ]; // currently this is needed only for material.alphaTest
  35. }
  36. }
  37. return nodeMaterial;
  38. };