diff --git a/examples/jsm/nodes/Nodes.js b/examples/jsm/nodes/Nodes.js index bac1a3e9c4aea8..3407cd071e3295 100644 --- a/examples/jsm/nodes/Nodes.js +++ b/examples/jsm/nodes/Nodes.js @@ -95,9 +95,9 @@ export { default as ModelViewProjectionNode, modelViewProjection } from './acces export * from './accessors/NormalNode.js'; export { default as Object3DNode, objectDirection, objectViewMatrix, objectNormalMatrix, objectWorldMatrix, objectPosition, objectScale, objectViewPosition } from './accessors/Object3DNode.js'; export { default as PointUVNode, pointUV } from './accessors/PointUVNode.js'; -export { default as PositionNode, positionGeometry, positionLocal, positionWorld, positionWorldDirection, positionView, positionViewDirection } from './accessors/PositionNode.js'; +export * from './accessors/PositionNode.js'; export { default as ReferenceNode, reference, referenceBuffer } from './accessors/ReferenceNode.js'; -export { default as ReflectVectorNode, reflectVector } from './accessors/ReflectVectorNode.js'; +export * from './accessors/ReflectVectorNode.js'; export { default as SkinningNode, skinning } from './accessors/SkinningNode.js'; export { default as SceneNode, backgroundBlurriness, backgroundIntensity } from './accessors/SceneNode.js'; export { default as StorageBufferNode, storage, storageObject } from './accessors/StorageBufferNode.js'; diff --git a/examples/jsm/nodes/accessors/PositionNode.js b/examples/jsm/nodes/accessors/PositionNode.js index 89dc162e2fd4ad..f77d84563b01af 100644 --- a/examples/jsm/nodes/accessors/PositionNode.js +++ b/examples/jsm/nodes/accessors/PositionNode.js @@ -1,104 +1,10 @@ -import Node, { addNodeClass } from '../core/Node.js'; import { attribute } from '../core/AttributeNode.js'; import { varying } from '../core/VaryingNode.js'; -import { normalize } from '../math/MathNode.js'; import { modelWorldMatrix, modelViewMatrix } from './ModelNode.js'; -import { nodeImmutable } from '../shadernode/ShaderNode.js'; -class PositionNode extends Node { - - constructor( scope = PositionNode.LOCAL ) { - - super( 'vec3' ); - - this.scope = scope; - - } - - isGlobal() { - - return true; - - } - - getHash( /*builder*/ ) { - - return `position-${this.scope}`; - - } - - generate( builder ) { - - const scope = this.scope; - - let outputNode = null; - - if ( scope === PositionNode.GEOMETRY ) { - - outputNode = attribute( 'position', 'vec3' ); - - } else if ( scope === PositionNode.LOCAL ) { - - outputNode = varying( positionGeometry ); - - } else if ( scope === PositionNode.WORLD ) { - - const vertexPositionNode = modelWorldMatrix.mul( positionLocal ); - outputNode = varying( vertexPositionNode ); - - } else if ( scope === PositionNode.VIEW ) { - - const vertexPositionNode = modelViewMatrix.mul( positionLocal ); - outputNode = varying( vertexPositionNode ); - - } else if ( scope === PositionNode.VIEW_DIRECTION ) { - - const vertexPositionNode = positionView.negate(); - outputNode = normalize( varying( vertexPositionNode ) ); - - } else if ( scope === PositionNode.WORLD_DIRECTION ) { - - const vertexPositionNode = positionLocal.transformDirection( modelWorldMatrix ); - outputNode = normalize( varying( vertexPositionNode ) ); - - } - - return outputNode.build( builder, this.getNodeType( builder ) ); - - } - - serialize( data ) { - - super.serialize( data ); - - data.scope = this.scope; - - } - - deserialize( data ) { - - super.deserialize( data ); - - this.scope = data.scope; - - } - -} - -PositionNode.GEOMETRY = 'geometry'; -PositionNode.LOCAL = 'local'; -PositionNode.WORLD = 'world'; -PositionNode.WORLD_DIRECTION = 'worldDirection'; -PositionNode.VIEW = 'view'; -PositionNode.VIEW_DIRECTION = 'viewDirection'; - -export default PositionNode; - -export const positionGeometry = nodeImmutable( PositionNode, PositionNode.GEOMETRY ); -export const positionLocal = nodeImmutable( PositionNode, PositionNode.LOCAL ).temp( 'Position' ); -export const positionWorld = nodeImmutable( PositionNode, PositionNode.WORLD ); -export const positionWorldDirection = nodeImmutable( PositionNode, PositionNode.WORLD_DIRECTION ); -export const positionView = nodeImmutable( PositionNode, PositionNode.VIEW ); -export const positionViewDirection = nodeImmutable( PositionNode, PositionNode.VIEW_DIRECTION ); - -addNodeClass( 'PositionNode', PositionNode ); +export const positionGeometry = /*#__PURE__*/ attribute( 'position', 'vec3' ); +export const positionLocal = /*#__PURE__*/ positionGeometry.toVar( 'positionLocal' ); +export const positionWorld = /*#__PURE__*/ varying( modelWorldMatrix.mul( positionLocal ).xyz, 'v_positionWorld' ); +export const positionWorldDirection = /*#__PURE__*/ varying( positionLocal.transformDirection( modelWorldMatrix ), 'v_positionWorldDirection' ).normalize().toVar( 'positionWorldDirection' ); +export const positionView = /*#__PURE__*/ varying( modelViewMatrix.mul( positionLocal ).xyz, 'v_positionView' ); +export const positionViewDirection = /*#__PURE__*/ varying( positionView.negate(), 'v_positionViewDirection' ).normalize().toVar( 'positionViewDirection' ); diff --git a/examples/jsm/nodes/accessors/ReflectVectorNode.js b/examples/jsm/nodes/accessors/ReflectVectorNode.js index b552b268e91704..ced16b3993b5c1 100644 --- a/examples/jsm/nodes/accessors/ReflectVectorNode.js +++ b/examples/jsm/nodes/accessors/ReflectVectorNode.js @@ -1,35 +1,6 @@ -import Node, { addNodeClass } from '../core/Node.js'; import { cameraViewMatrix } from './CameraNode.js'; import { transformedNormalView } from './NormalNode.js'; import { positionViewDirection } from './PositionNode.js'; -import { nodeImmutable } from '../shadernode/ShaderNode.js'; -class ReflectVectorNode extends Node { - - constructor() { - - super( 'vec3' ); - - } - - getHash( /*builder*/ ) { - - return 'reflectVector'; - - } - - setup() { - - const reflectView = positionViewDirection.negate().reflect( transformedNormalView ); - - return reflectView.transformDirection( cameraViewMatrix ); - - } - -} - -export default ReflectVectorNode; - -export const reflectVector = nodeImmutable( ReflectVectorNode ); - -addNodeClass( 'ReflectVectorNode', ReflectVectorNode ); +export const reflectView = /*#__PURE__*/ positionViewDirection.negate().reflect( transformedNormalView ); +export const reflectVector = /*#__PURE__*/ reflectView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' );