Initial commit
This commit is contained in:
59
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/lights/LightContextNode.js
generated
vendored
Normal file
59
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/lights/LightContextNode.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import ContextNode from '../core/ContextNode.js';
|
||||
import VarNode from '../core/VarNode.js';
|
||||
import Vector3Node from '../inputs/Vector3Node.js';
|
||||
import OperatorNode from '../math/OperatorNode.js';
|
||||
import { PhysicalLightingModel } from '../functions/BSDFs.js';
|
||||
|
||||
class LightContextNode extends ContextNode {
|
||||
|
||||
constructor( node ) {
|
||||
|
||||
super( node );
|
||||
|
||||
}
|
||||
|
||||
getNodeType( /*builder*/ ) {
|
||||
|
||||
return 'vec3';
|
||||
|
||||
}
|
||||
|
||||
generate( builder ) {
|
||||
|
||||
const material = builder.material;
|
||||
|
||||
let lightingModel = null;
|
||||
|
||||
if ( material.isMeshStandardMaterial === true ) {
|
||||
|
||||
lightingModel = PhysicalLightingModel;
|
||||
|
||||
}
|
||||
|
||||
const directDiffuse = new VarNode( new Vector3Node(), 'DirectDiffuse', 'vec3' );
|
||||
const directSpecular = new VarNode( new Vector3Node(), 'DirectSpecular', 'vec3' );
|
||||
|
||||
this.context.directDiffuse = directDiffuse;
|
||||
this.context.directSpecular = directSpecular;
|
||||
|
||||
if ( lightingModel !== null ) {
|
||||
|
||||
this.context.lightingModel = lightingModel;
|
||||
|
||||
}
|
||||
|
||||
// add code
|
||||
|
||||
const type = this.getNodeType( builder );
|
||||
|
||||
super.generate( builder, type );
|
||||
|
||||
const totalLight = new OperatorNode( '+', directDiffuse, directSpecular );
|
||||
|
||||
return totalLight.build( builder, type );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default LightContextNode;
|
||||
79
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/lights/LightNode.js
generated
vendored
Normal file
79
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/lights/LightNode.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
import Node from '../core/Node.js';
|
||||
import Object3DNode from '../accessors/Object3DNode.js';
|
||||
import PositionNode from '../accessors/PositionNode.js';
|
||||
import ColorNode from '../inputs/ColorNode.js';
|
||||
import FloatNode from '../inputs/FloatNode.js';
|
||||
import OperatorNode from '../math/OperatorNode.js';
|
||||
import MathNode from '../math/MathNode.js';
|
||||
import { NodeUpdateType } from '../core/constants.js';
|
||||
import { getDistanceAttenuation } from '../functions/BSDFs.js';
|
||||
|
||||
import { Color } from 'three';
|
||||
|
||||
class LightNode extends Node {
|
||||
|
||||
constructor( light = null ) {
|
||||
|
||||
super( 'vec3' );
|
||||
|
||||
this.updateType = NodeUpdateType.Object;
|
||||
|
||||
this.light = light;
|
||||
|
||||
this.colorNode = new ColorNode( new Color() );
|
||||
|
||||
this.lightCutoffDistanceNode = new FloatNode( 0 );
|
||||
this.lightDecayExponentNode = new FloatNode( 0 );
|
||||
|
||||
}
|
||||
|
||||
update( /* frame */ ) {
|
||||
|
||||
this.colorNode.value.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
||||
this.lightCutoffDistanceNode.value = this.light.distance;
|
||||
this.lightDecayExponentNode.value = this.light.decay;
|
||||
|
||||
}
|
||||
|
||||
generate( builder ) {
|
||||
|
||||
const lightPositionView = new Object3DNode( Object3DNode.VIEW_POSITION );
|
||||
const positionView = new PositionNode( PositionNode.VIEW );
|
||||
|
||||
const lVector = new OperatorNode( '-', lightPositionView, positionView );
|
||||
|
||||
const lightDirection = new MathNode( MathNode.NORMALIZE, lVector );
|
||||
|
||||
const lightDistance = new MathNode( MathNode.LENGTH, lVector );
|
||||
|
||||
const lightAttenuation = getDistanceAttenuation( {
|
||||
lightDistance,
|
||||
cutoffDistance: this.lightCutoffDistanceNode,
|
||||
decayExponent: this.lightDecayExponentNode
|
||||
} );
|
||||
|
||||
const lightColor = new OperatorNode( '*', this.colorNode, lightAttenuation );
|
||||
|
||||
lightPositionView.object3d = this.light;
|
||||
|
||||
const lightingModelFunction = builder.context.lightingModel;
|
||||
|
||||
if ( lightingModelFunction !== undefined ) {
|
||||
|
||||
const directDiffuse = builder.context.directDiffuse;
|
||||
const directSpecular = builder.context.directSpecular;
|
||||
|
||||
lightingModelFunction( {
|
||||
lightDirection,
|
||||
lightColor,
|
||||
directDiffuse,
|
||||
directSpecular
|
||||
}, builder );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default LightNode;
|
||||
44
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/lights/LightsNode.js
generated
vendored
Normal file
44
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/lights/LightsNode.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import Node from '../core/Node.js';
|
||||
import LightNode from './LightNode.js';
|
||||
|
||||
class LightsNode extends Node {
|
||||
|
||||
constructor( lightNodes = [] ) {
|
||||
|
||||
super( 'vec3' );
|
||||
|
||||
this.lightNodes = lightNodes;
|
||||
|
||||
}
|
||||
|
||||
generate( builder ) {
|
||||
|
||||
const lightNodes = this.lightNodes;
|
||||
|
||||
for ( const lightNode of lightNodes ) {
|
||||
|
||||
lightNode.build( builder );
|
||||
|
||||
}
|
||||
|
||||
return 'vec3( 0.0 )';
|
||||
|
||||
}
|
||||
|
||||
static fromLights( lights ) {
|
||||
|
||||
const lightNodes = [];
|
||||
|
||||
for ( const light of lights ) {
|
||||
|
||||
lightNodes.push( new LightNode( light ) );
|
||||
|
||||
}
|
||||
|
||||
return new LightsNode( lightNodes );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default LightsNode;
|
||||
Reference in New Issue
Block a user