You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
6 months ago
|
import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js';
|
||
|
import { attribute } from '../core/AttributeNode.js';
|
||
|
import { varying } from '../core/VaryingNode.js';
|
||
|
import { materialLineDashSize, materialLineGapSize, materialLineScale } from '../accessors/MaterialNode.js';
|
||
|
import { dashSize, gapSize } from '../core/PropertyNode.js';
|
||
|
import { float } from '../shadernode/ShaderNode.js';
|
||
|
import { LineDashedMaterial } from 'three';
|
||
|
|
||
|
const defaultValues = new LineDashedMaterial();
|
||
|
|
||
|
class LineDashedNodeMaterial extends NodeMaterial {
|
||
|
|
||
|
constructor( parameters ) {
|
||
|
|
||
|
super();
|
||
|
|
||
|
this.isLineDashedNodeMaterial = true;
|
||
|
|
||
|
this.lights = false;
|
||
|
this.normals = false;
|
||
|
|
||
|
this.setDefaultValues( defaultValues );
|
||
|
|
||
|
this.offsetNode = null;
|
||
|
this.dashScaleNode = null;
|
||
|
this.dashSizeNode = null;
|
||
|
this.gapSizeNode = null;
|
||
|
|
||
|
this.setValues( parameters );
|
||
|
|
||
|
}
|
||
|
|
||
|
setupVariants() {
|
||
|
|
||
|
const offsetNode = this.offsetNode;
|
||
|
const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale;
|
||
|
const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialLineDashSize;
|
||
|
const gapSizeNode = this.dashSizeNode ? float( this.dashGapNode ) : materialLineGapSize;
|
||
|
|
||
|
dashSize.assign( dashSizeNode );
|
||
|
gapSize.assign( gapSizeNode );
|
||
|
|
||
|
const vLineDistance = varying( attribute( 'lineDistance' ).mul( dashScaleNode ) );
|
||
|
const vLineDistanceOffset = offsetNode ? vLineDistance.add( offsetNode ) : vLineDistance;
|
||
|
|
||
|
vLineDistanceOffset.mod( dashSize.add( gapSize ) ).greaterThan( dashSize ).discard();
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export default LineDashedNodeMaterial;
|
||
|
|
||
|
addNodeMaterial( 'LineDashedNodeMaterial', LineDashedNodeMaterial );
|