Jelajahi Sumber

TSL: Move `MatcapUVNode` to `matcapUV` Fn constant (#31284)

* Move MatcapUVNode to matcapUV Fn constant

* rename
sunag 6 bulan lalu
induk
melakukan
c1c72c7084

+ 1 - 1
src/materials/nodes/MeshMatcapNodeMaterial.js

@@ -3,7 +3,7 @@ import { materialReference } from '../../nodes/accessors/MaterialReferenceNode.j
 import { diffuseColor } from '../../nodes/core/PropertyNode.js';
 import { vec3 } from '../../nodes/tsl/TSLBase.js';
 import { mix } from '../../nodes/math/MathNode.js';
-import { matcapUV } from '../../nodes/utils/MatcapUVNode.js';
+import { matcapUV } from '../../nodes/utils/MatcapUV.js';
 
 import { MeshMatcapMaterial } from '../MeshMatcapMaterial.js';
 

+ 0 - 1
src/nodes/Nodes.js

@@ -45,7 +45,6 @@ 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';
-export { default as MatcapUVNode } from './utils/MatcapUVNode.js';
 export { default as MaxMipLevelNode } from './utils/MaxMipLevelNode.js';
 export { default as RemapNode } from './utils/RemapNode.js';
 export { default as RotateNode } from './utils/RotateNode.js';

+ 1 - 1
src/nodes/TSL.js

@@ -27,7 +27,7 @@ export * from './math/TriNoise3D.js';
 export * from './utils/EquirectUVNode.js';
 export * from './utils/FunctionOverloadingNode.js';
 export * from './utils/LoopNode.js';
-export * from './utils/MatcapUVNode.js';
+export * from './utils/MatcapUV.js';
 export * from './utils/MaxMipLevelNode.js';
 export * from './utils/Oscillators.js';
 export * from './utils/Packing.js';

+ 22 - 0
src/nodes/utils/MatcapUV.js

@@ -0,0 +1,22 @@
+import { normalView } from '../accessors/Normal.js';
+import { positionViewDirection } from '../accessors/Position.js';
+import { Fn, vec2, vec3 } from '../tsl/TSLBase.js';
+
+/**
+ * TSL function for creating a matcap uv node.
+ *
+ * Can be used to compute texture coordinates for projecting a
+ * matcap onto a mesh. Used by {@link MeshMatcapNodeMaterial}.
+ *
+ * @tsl
+ * @function
+ * @returns {Node<vec2>} The matcap UV coordinates.
+ */
+export const matcapUV = /*@__PURE__*/ Fn( () => {
+
+	const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
+	const y = positionViewDirection.cross( x );
+
+	return vec2( x.dot( normalView ), y.dot( normalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks
+
+} ).once( [ 'NORMAL', 'VERTEX' ] )().toVar( 'matcapUV' );

+ 0 - 49
src/nodes/utils/MatcapUVNode.js

@@ -1,49 +0,0 @@
-import TempNode from '../core/TempNode.js';
-import { normalView } from '../accessors/Normal.js';
-import { positionViewDirection } from '../accessors/Position.js';
-import { nodeImmutable, vec2, vec3 } from '../tsl/TSLBase.js';
-
-/**
- * Can be used to compute texture coordinates for projecting a
- * matcap onto a mesh. Used by {@link MeshMatcapNodeMaterial}.
- *
- * @augments TempNode
- */
-class MatcapUVNode extends TempNode {
-
-	static get type() {
-
-		return 'MatcapUVNode';
-
-	}
-
-	/**
-	 * Constructs a new matcap uv node.
-	 */
-	constructor() {
-
-		super( 'vec2' );
-
-	}
-
-	setup() {
-
-		const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
-		const y = positionViewDirection.cross( x );
-
-		return vec2( x.dot( normalView ), y.dot( normalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks
-
-	}
-
-}
-
-export default MatcapUVNode;
-
-/**
- * TSL function for creating a matcap uv node.
- *
- * @tsl
- * @function
- * @returns {MatcapUVNode}
- */
-export const matcapUV = /*@__PURE__*/ nodeImmutable( MatcapUVNode );

粤ICP备19079148号