LineDashedNodeMaterial.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js';
  2. import { attribute } from '../core/AttributeNode.js';
  3. import { varying } from '../core/VaryingNode.js';
  4. import { materialLineDashSize, materialLineGapSize, materialLineScale } from '../accessors/LineMaterialNode.js';
  5. import { dashSize, gapSize } from '../core/PropertyNode.js';
  6. import { float } from '../shadernode/ShaderNode.js';
  7. import { LineDashedMaterial } from 'three';
  8. const defaultValues = new LineDashedMaterial();
  9. class LineDashedNodeMaterial extends NodeMaterial {
  10. constructor( parameters ) {
  11. super();
  12. this.isLineDashedNodeMaterial = true;
  13. this.lights = false;
  14. this.normals = false;
  15. this.setDefaultValues( defaultValues );
  16. this.dashScaleNode = null;
  17. this.dashSizeNode = null;
  18. this.gapSizeNode = null;
  19. this.setValues( parameters );
  20. }
  21. constructVariants( { stack } ) {
  22. const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale;
  23. const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialLineDashSize;
  24. const gapSizeNode = this.dashSizeNode ? float( this.dashGapNode ) : materialLineGapSize;
  25. stack.assign( dashSize, dashSizeNode );
  26. stack.assign( gapSize, gapSizeNode );
  27. const vLineDistance = varying( attribute( 'lineDistance' ).mul( dashScaleNode ) );
  28. stack.add( vLineDistance.mod( dashSize.add( gapSize ) ).greaterThan( dashSize ).discard() );
  29. }
  30. }
  31. export default LineDashedNodeMaterial;
  32. addNodeMaterial( LineDashedNodeMaterial );