LineDashedNodeMaterial.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/MaterialNode.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.offsetNode = null;
  17. this.dashScaleNode = null;
  18. this.dashSizeNode = null;
  19. this.gapSizeNode = null;
  20. this.setValues( parameters );
  21. }
  22. setupVariants() {
  23. const offsetNode = this.offsetNode;
  24. const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale;
  25. const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialLineDashSize;
  26. const gapSizeNode = this.dashSizeNode ? float( this.dashGapNode ) : materialLineGapSize;
  27. dashSize.assign( dashSizeNode );
  28. gapSize.assign( gapSizeNode );
  29. const vLineDistance = varying( attribute( 'lineDistance' ).mul( dashScaleNode ) );
  30. const vLineDistanceOffset = offsetNode ? vLineDistance.add( offsetNode ) : vLineDistance;
  31. vLineDistanceOffset.mod( dashSize.add( gapSize ) ).greaterThan( dashSize ).discard();
  32. }
  33. }
  34. export default LineDashedNodeMaterial;
  35. addNodeMaterial( 'LineDashedNodeMaterial', LineDashedNodeMaterial );