MeshPhongNodeMaterial.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js';
  2. import { shininess, specularColor } from '../core/PropertyNode.js';
  3. import { materialShininess, materialSpecularColor } from '../accessors/MaterialNode.js';
  4. import phongLightingModel from '../functions/PhongLightingModel.js';
  5. import { float } from '../shadernode/ShaderNode.js';
  6. import { MeshPhongMaterial } from 'three';
  7. const defaultValues = new MeshPhongMaterial();
  8. class MeshPhongNodeMaterial extends NodeMaterial {
  9. constructor( parameters ) {
  10. super();
  11. this.isMeshPhongNodeMaterial = true;
  12. this.lights = true;
  13. this.colorNode = null;
  14. this.opacityNode = null;
  15. this.shininessNode = null;
  16. this.specularNode = null;
  17. this.alphaTestNode = null;
  18. this.lightNode = null;
  19. this.positionNode = null;
  20. this.setDefaultValues( defaultValues );
  21. this.setValues( parameters );
  22. }
  23. constructLightingModel( /*builder*/ ) {
  24. return phongLightingModel;
  25. }
  26. constructVariants( { stack } ) {
  27. // SHININESS
  28. const shininessNode = ( this.shininessNode ? float( this.shininessNode ) : materialShininess ).max( 1e-4 ); // to prevent pow( 0.0, 0.0 )
  29. stack.assign( shininess, shininessNode );
  30. // SPECULAR COLOR
  31. const specularNode = this.specularNode || materialSpecularColor;
  32. stack.assign( specularColor, specularNode );
  33. }
  34. copy( source ) {
  35. this.colorNode = source.colorNode;
  36. this.opacityNode = source.opacityNode;
  37. this.alphaTestNode = source.alphaTestNode;
  38. this.shininessNode = source.shininessNode;
  39. this.specularNode = source.specularNode;
  40. this.lightNode = source.lightNode;
  41. this.positionNode = source.positionNode;
  42. return super.copy( source );
  43. }
  44. }
  45. export default MeshPhongNodeMaterial;
  46. addNodeMaterial( MeshPhongNodeMaterial );