Materials.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import NodeMaterial from './NodeMaterial.js';
  2. import LineBasicNodeMaterial from './LineBasicNodeMaterial.js';
  3. import MeshBasicNodeMaterial from './MeshBasicNodeMaterial.js';
  4. import MeshPhongNodeMaterial from './MeshPhongNodeMaterial.js';
  5. import MeshStandardNodeMaterial from './MeshStandardNodeMaterial.js';
  6. import MeshPhysicalNodeMaterial from './MeshPhysicalNodeMaterial.js';
  7. import PointsNodeMaterial from './PointsNodeMaterial.js';
  8. import SpriteNodeMaterial from './SpriteNodeMaterial.js';
  9. export {
  10. NodeMaterial,
  11. LineBasicNodeMaterial,
  12. MeshBasicNodeMaterial,
  13. MeshPhongNodeMaterial,
  14. MeshStandardNodeMaterial,
  15. MeshPhysicalNodeMaterial,
  16. PointsNodeMaterial,
  17. SpriteNodeMaterial
  18. };
  19. NodeMaterial.fromMaterial = function ( material ) {
  20. const materialLib = {
  21. NodeMaterial,
  22. LineBasicNodeMaterial,
  23. MeshBasicNodeMaterial,
  24. MeshPhongNodeMaterial,
  25. MeshStandardNodeMaterial,
  26. MeshPhysicalNodeMaterial,
  27. PointsNodeMaterial,
  28. SpriteNodeMaterial
  29. };
  30. const type = material.type.replace( 'Material', 'NodeMaterial' );
  31. if ( materialLib[ type ] === undefined ) {
  32. if ( material.isNodeMaterial !== true ) {
  33. throw new Error( `NodeMaterial: Material "${ material.type }" is not compatible.` );
  34. }
  35. return material; // is already a node material
  36. }
  37. const nodeMaterial = new materialLib[ type ]();
  38. for ( const key in material ) {
  39. nodeMaterial[ key ] = material[ key ];
  40. }
  41. return nodeMaterial;
  42. };