Răsfoiți Sursa

TSL: Move `SceneNode` to TSL functions (#32838)

sunag 1 lună în urmă
părinte
comite
8fa6498afe

+ 0 - 1
src/nodes/Nodes.js

@@ -58,7 +58,6 @@ export { default as PointUVNode } from './accessors/PointUVNode.js';
 export { default as ReferenceBaseNode } from './accessors/ReferenceBaseNode.js';
 export { default as ReferenceNode } from './accessors/ReferenceNode.js';
 export { default as RendererReferenceNode } from './accessors/RendererReferenceNode.js';
-export { default as SceneNode } from './accessors/SceneNode.js';
 export { default as SkinningNode } from './accessors/SkinningNode.js';
 export { default as StorageBufferNode } from './accessors/StorageBufferNode.js';
 export { default as StorageTextureNode } from './accessors/StorageTextureNode.js';

+ 1 - 1
src/nodes/TSL.js

@@ -81,7 +81,7 @@ export * from './accessors/Position.js';
 export * from './accessors/ReferenceNode.js';
 export * from './accessors/ReflectVector.js';
 export * from './accessors/SkinningNode.js';
-export * from './accessors/SceneNode.js';
+export * from './accessors/SceneProperties.js';
 export * from './accessors/StorageBufferNode.js';
 export * from './accessors/Tangent.js';
 export * from './accessors/TextureNode.js';

+ 0 - 145
src/nodes/accessors/SceneNode.js

@@ -1,145 +0,0 @@
-import { UVMapping } from '../../constants.js';
-import { Euler } from '../../math/Euler.js';
-import { Matrix4 } from '../../math/Matrix4.js';
-import Node from '../core/Node.js';
-import { renderGroup } from '../core/UniformGroupNode.js';
-import { nodeImmutable, uniform } from '../tsl/TSLBase.js';
-import { reference } from './ReferenceNode.js';
-import { error } from '../../utils.js';
-
-const _e1 = /*@__PURE__*/ new Euler();
-const _m1 = /*@__PURE__*/ new Matrix4();
-
-/**
- * This module allows access to a collection of scene properties. The following predefined TSL objects
- * are available for easier use:
- *
- * - `backgroundBlurriness`: A node that represents the scene's background blurriness.
- * - `backgroundIntensity`: A node that represents the scene's background intensity.
- * - `backgroundRotation`: A node that represents the scene's background rotation.
- *
- * @augments Node
- */
-class SceneNode extends Node {
-
-	static get type() {
-
-		return 'SceneNode';
-
-	}
-
-	/**
-	 * Constructs a new scene node.
-	 *
-	 * @param {('backgroundBlurriness'|'backgroundIntensity'|'backgroundRotation')} scope - The scope defines the type of scene property that is accessed.
-	 * @param {?Scene} [scene=null] - A reference to the scene.
-	 */
-	constructor( scope = SceneNode.BACKGROUND_BLURRINESS, scene = null ) {
-
-		super();
-
-		/**
-		 * The scope defines the type of scene property that is accessed.
-		 *
-		 * @type {('backgroundBlurriness'|'backgroundIntensity'|'backgroundRotation')}
-		 */
-		this.scope = scope;
-
-		/**
-		 * A reference to the scene that is going to be accessed.
-		 *
-		 * @type {?Scene}
-		 * @default null
-		 */
-		this.scene = scene;
-
-	}
-
-	/**
-	 * Depending on the scope, the method returns a different type of node that represents
-	 * the respective scene property.
-	 *
-	 * @param {NodeBuilder} builder - The current node builder.
-	 * @return {Node} The output node.
-	 */
-	setup( builder ) {
-
-		const scope = this.scope;
-		const scene = this.scene !== null ? this.scene : builder.scene;
-
-		let output;
-
-		if ( scope === SceneNode.BACKGROUND_BLURRINESS ) {
-
-			output = reference( 'backgroundBlurriness', 'float', scene );
-
-		} else if ( scope === SceneNode.BACKGROUND_INTENSITY ) {
-
-			output = reference( 'backgroundIntensity', 'float', scene );
-
-		} else if ( scope === SceneNode.BACKGROUND_ROTATION ) {
-
-			output = uniform( 'mat4' ).setName( 'backgroundRotation' ).setGroup( renderGroup ).onRenderUpdate( () => {
-
-				const background = scene.background;
-
-				if ( background !== null && background.isTexture && background.mapping !== UVMapping ) {
-
-					_e1.copy( scene.backgroundRotation );
-
-					// accommodate left-handed frame
-					_e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1;
-
-					_m1.makeRotationFromEuler( _e1 );
-
-				} else {
-
-					_m1.identity();
-
-				}
-
-				return _m1;
-
-			} );
-
-		} else {
-
-			error( 'SceneNode: Unknown scope:', scope );
-
-		}
-
-		return output;
-
-	}
-
-}
-
-SceneNode.BACKGROUND_BLURRINESS = 'backgroundBlurriness';
-SceneNode.BACKGROUND_INTENSITY = 'backgroundIntensity';
-SceneNode.BACKGROUND_ROTATION = 'backgroundRotation';
-
-export default SceneNode;
-
-/**
- * TSL object that represents the scene's background blurriness.
- *
- * @tsl
- * @type {SceneNode}
- */
-export const backgroundBlurriness = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_BLURRINESS );
-
-/**
- * TSL object that represents the scene's background intensity.
- *
- * @tsl
- * @type {SceneNode}
- */
-export const backgroundIntensity = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_INTENSITY );
-
-/**
- * TSL object that represents the scene's background rotation.
- *
- * @tsl
- * @type {SceneNode}
- */
-export const backgroundRotation = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_ROTATION );

+ 53 - 0
src/nodes/accessors/SceneProperties.js

@@ -0,0 +1,53 @@
+import { UVMapping } from '../../constants.js';
+import { Euler } from '../../math/Euler.js';
+import { Matrix4 } from '../../math/Matrix4.js';
+import { renderGroup } from '../core/UniformGroupNode.js';
+import { uniform } from '../tsl/TSLBase.js';
+
+const _e1 = /*@__PURE__*/ new Euler();
+const _m1 = /*@__PURE__*/ new Matrix4();
+
+/**
+ * TSL object that represents the scene's background blurriness.
+ *
+ * @tsl
+ * @type {Node<float>}
+ */
+export const backgroundBlurriness = /*@__PURE__*/ uniform( 0 ).setGroup( renderGroup ).onRenderUpdate( ( { scene } ) => scene.backgroundBlurriness );
+
+/**
+ * TSL object that represents the scene's background intensity.
+ *
+ * @tsl
+ * @type {Node<float>}
+ */
+export const backgroundIntensity = /*@__PURE__*/ uniform( 1 ).setGroup( renderGroup ).onRenderUpdate( ( { scene } ) => scene.backgroundIntensity );
+
+/**
+ * TSL object that represents the scene's background rotation.
+ *
+ * @tsl
+ * @type {Node<mat4>}
+ */
+export const backgroundRotation = /*@__PURE__*/ uniform( new Matrix4() ).setGroup( renderGroup ).onRenderUpdate( ( { scene } ) => {
+
+	const background = scene.background;
+
+	if ( background !== null && background.isTexture && background.mapping !== UVMapping ) {
+
+		_e1.copy( scene.backgroundRotation );
+
+		// accommodate left-handed frame
+		_e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1;
+
+		_m1.makeRotationFromEuler( _e1 );
+
+	} else {
+
+		_m1.identity();
+
+	}
+
+	return _m1;
+
+} );

粤ICP备19079148号