Просмотр исходного кода

TSL: Move `EquirectUVNode` to `equirectUV()` TSL function (#31283)

sunag 6 месяцев назад
Родитель
Сommit
91de2913aa

+ 0 - 1
src/nodes/Nodes.js

@@ -41,7 +41,6 @@ export { NodeUtils };
 // utils
 export { default as ArrayElementNode } from './utils/ArrayElementNode.js';
 export { default as ConvertNode } from './utils/ConvertNode.js';
-export { default as EquirectUVNode } from './utils/EquirectUVNode.js';
 export { default as FunctionOverloadingNode } from './utils/FunctionOverloadingNode.js';
 export { default as JoinNode } from './utils/JoinNode.js';
 export { default as LoopNode } from './utils/LoopNode.js';

+ 1 - 1
src/nodes/TSL.js

@@ -24,7 +24,7 @@ export * from './math/MathUtils.js';
 export * from './math/TriNoise3D.js';
 
 // utils
-export * from './utils/EquirectUVNode.js';
+export * from './utils/EquirectUV.js';
 export * from './utils/FunctionOverloadingNode.js';
 export * from './utils/LoopNode.js';
 export * from './utils/MatcapUV.js';

+ 27 - 0
src/nodes/utils/EquirectUV.js

@@ -0,0 +1,27 @@
+import { positionWorldDirection } from '../accessors/Position.js';
+import { Fn, vec2 } from '../tsl/TSLBase.js';
+
+/**
+ * TSL function for creating an equirect uv node.
+ *
+ * Can be used to compute texture coordinates for projecting an
+ * equirectangular texture onto a mesh for using it as the scene's
+ * background.
+ *
+ * ```js
+ * scene.backgroundNode = texture( equirectTexture, equirectUV() );
+ * ```
+ *
+ * @tsl
+ * @function
+ * @param {?Node<vec3>} [dirNode=positionWorldDirection] - A direction vector for sampling which is by default `positionWorldDirection`.
+ * @returns {Node<vec2>}
+ */
+export const equirectUV = /*@__PURE__*/ Fn( ( [ dir = positionWorldDirection ] ) => {
+
+	const u = dir.z.atan( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
+	const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 );
+
+	return vec2( u, v );
+
+} );

+ 0 - 65
src/nodes/utils/EquirectUVNode.js

@@ -1,65 +0,0 @@
-import TempNode from '../core/TempNode.js';
-import { positionWorldDirection } from '../accessors/Position.js';
-import { nodeProxy, vec2 } from '../tsl/TSLBase.js';
-
-/**
- * Can be used to compute texture coordinates for projecting an
- * equirectangular texture onto a mesh for using it as the scene's
- * background.
- *
- * ```js
- * scene.backgroundNode = texture( equirectTexture, equirectUV() );
- * ```
- *
- * @augments TempNode
- */
-class EquirectUVNode extends TempNode {
-
-	static get type() {
-
-		return 'EquirectUVNode';
-
-	}
-
-	/**
-	 * Constructs a new equirect uv node.
-	 *
-	 * @param {Node<vec3>} [dirNode=positionWorldDirection] - A direction vector for sampling which is by default `positionWorldDirection`.
-	 */
-	constructor( dirNode = positionWorldDirection ) {
-
-		super( 'vec2' );
-
-		/**
-		 * A direction vector for sampling why is by default `positionWorldDirection`.
-		 *
-		 * @type {Node<vec3>}
-		 */
-		this.dirNode = dirNode;
-
-	}
-
-	setup() {
-
-		const dir = this.dirNode;
-
-		const u = dir.z.atan( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
-		const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 );
-
-		return vec2( u, v );
-
-	}
-
-}
-
-export default EquirectUVNode;
-
-/**
- * TSL function for creating an equirect uv node.
- *
- * @tsl
- * @function
- * @param {?Node<vec3>} [dirNode=positionWorldDirection] - A direction vector for sampling which is by default `positionWorldDirection`.
- * @returns {EquirectUVNode}
- */
-export const equirectUV = /*@__PURE__*/ nodeProxy( EquirectUVNode ).setParameterLength( 0, 1 );

+ 1 - 1
src/renderers/common/CubeRenderTarget.js

@@ -1,4 +1,4 @@
-import { equirectUV } from '../../nodes/utils/EquirectUVNode.js';
+import { equirectUV } from '../../nodes/utils/EquirectUV.js';
 import { texture as TSL_Texture } from '../../nodes/accessors/TextureNode.js';
 import { positionWorldDirection } from '../../nodes/accessors/Position.js';
 import NodeMaterial from '../../materials/nodes/NodeMaterial.js';

+ 1 - 1
src/renderers/common/extras/PMREMGenerator.js

@@ -1,6 +1,6 @@
 import NodeMaterial from '../../../materials/nodes/NodeMaterial.js';
 import { getDirection, blur } from '../../../nodes/pmrem/PMREMUtils.js';
-import { equirectUV } from '../../../nodes/utils/EquirectUVNode.js';
+import { equirectUV } from '../../../nodes/utils/EquirectUV.js';
 import { uniform } from '../../../nodes/core/UniformNode.js';
 import { uniformArray } from '../../../nodes/accessors/UniformArrayNode.js';
 import { texture } from '../../../nodes/accessors/TextureNode.js';

粤ICP备19079148号