41 lines
		
	
	
		
			760 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			41 lines
		
	
	
		
			760 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|  | import Node, { addNodeClass } from '../core/Node.js'; | ||
|  | import { nodeImmutable, float } from '../shadernode/ShaderNode.js'; | ||
|  | import { BackSide, WebGLCoordinateSystem } from 'three'; | ||
|  | 
 | ||
|  | class FrontFacingNode extends Node { | ||
|  | 
 | ||
|  | 	constructor() { | ||
|  | 
 | ||
|  | 		super( 'bool' ); | ||
|  | 
 | ||
|  | 		this.isFrontFacingNode = true; | ||
|  | 
 | ||
|  | 	} | ||
|  | 
 | ||
|  | 	generate( builder ) { | ||
|  | 
 | ||
|  | 		const { renderer, material } = builder; | ||
|  | 
 | ||
|  | 		if ( renderer.coordinateSystem === WebGLCoordinateSystem ) { | ||
|  | 
 | ||
|  | 			if ( material.side === BackSide ) { | ||
|  | 
 | ||
|  | 				return 'false'; | ||
|  | 
 | ||
|  | 			} | ||
|  | 
 | ||
|  | 		} | ||
|  | 
 | ||
|  | 		return builder.getFrontFacing(); | ||
|  | 
 | ||
|  | 	} | ||
|  | 
 | ||
|  | } | ||
|  | 
 | ||
|  | export default FrontFacingNode; | ||
|  | 
 | ||
|  | export const frontFacing = nodeImmutable( FrontFacingNode ); | ||
|  | export const faceDirection = float( frontFacing ).mul( 2.0 ).sub( 1.0 ); | ||
|  | 
 | ||
|  | addNodeClass( 'FrontFacingNode', FrontFacingNode ); |