2
0
Эх сурвалжийг харах

BufferGeometryUtils: Rename and improve warnings for MikkTSpace tangents (#23815)

* BufferGeometryUtils: Rename and improve warnings for MikkTSpace tangents

- Renamed computeTangents → computeMikkTSpaceTangents
- Add warnings when position, normal, or uv attributes omitted

* Add missing computeTangents export

DeepScan is pretty nice. 🙏
Don McCurdy 3 жил өмнө
parent
commit
bd3fc5cbec

+ 1 - 1
docs/api/en/core/BufferGeometry.html

@@ -217,7 +217,7 @@
 		<p>
 		Calculates and adds a tangent attribute to this geometry.<br />
 		The computation is only supported for indexed geometries and if position, normal, and uv attributes are defined. When using a tangent space normal map, prefer the MikkTSpace algorithm provided by
-		[page:BufferGeometryUtils.computeTangents] instead.
+		[page:BufferGeometryUtils.computeMikkTSpaceTangents] instead.
 		</p>
 
 		<h3>[method:undefined computeVertexNormals]()</h3>

+ 1 - 1
docs/api/ko/core/BufferGeometry.html

@@ -209,7 +209,7 @@
 		기하학에 탄젠트 속성을 계산하고 추가합니다.<br />
 		이 계산은 인덱스가 있는 기하학에만 지원되며 위치, 법선, uv 속성이 정의되어야 합니다.
 		When using a tangent space normal map, prefer the MikkTSpace algorithm provided by
-		[page:BufferGeometryUtils.computeTangents] instead.
+		[page:BufferGeometryUtils.computeMikkTSpaceTangents] instead.
 		</p>
 
 		<h3>[method:undefined computeVertexNormals]()</h3>

+ 1 - 1
docs/api/zh/core/BufferGeometry.html

@@ -203,7 +203,7 @@
 		<p>
 		Calculates and adds a tangent attribute to this geometry.<br />
 		The computation is only supported for indexed geometries and if position, normal, and uv attributes are defined. When using a tangent space normal map, prefer the MikkTSpace algorithm provided by
-		[page:BufferGeometryUtils.computeTangents] instead.
+		[page:BufferGeometryUtils.computeMikkTSpaceTangents] instead.
 		</p>
 
 		<h3>[method:undefined computeVertexNormals]()</h3>

+ 1 - 1
docs/examples/en/utils/BufferGeometryUtils.html

@@ -96,7 +96,7 @@
 
 		</p>
 
-		<h3>[method:Object computeTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
+		<h3>[method:Object computeMikkTSpaceTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
 		<ul>
 			<li>geometry -- Instance of [page:BufferGeometry].</li>
 			<li>MikkTSpace -- Instance of <i>examples/jsm/libs/mikktspace.module.js</i>, or <i>mikktspace</i> npm package. Await <i>MikkTSpace.ready</i> before use.

+ 1 - 1
docs/examples/zh/utils/BufferGeometryUtils.html

@@ -91,7 +91,7 @@
 
 		</p>
 
-		<h3>[method:Object computeTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
+		<h3>[method:Object computeMikkTSpaceTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
 		<ul>
 			<li>geometry -- Instance of [page:BufferGeometry].</li>
 			<li>MikkTSpace -- Instance of <i>examples/jsm/libs/mikktspace.module.js</i>, or <i>mikktspace</i> npm package. Await <i>MikkTSpace.ready</i> before use.

+ 13 - 1
examples/jsm/utils/BufferGeometryUtils.js

@@ -11,8 +11,13 @@ import {
 	Vector3,
 } from 'three';
 
+function computeTangents() {
 
-function computeTangents( geometry, MikkTSpace, negateSign = true ) {
+	throw new Error( 'BufferGeometryUtils: computeTangents renamed to computeMikkTSpaceTangents.' );
+
+}
+
+function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
 
 	if ( ! MikkTSpace || ! MikkTSpace.isReady ) {
 
@@ -20,6 +25,12 @@ function computeTangents( geometry, MikkTSpace, negateSign = true ) {
 
 	}
 
+	if ( ! geometry.hasAttribute( 'position' ) || ! geometry.hasAttribute( 'normal' ) || ! geometry.hasAttribute( 'uv' ) ) {
+
+		throw new Error( 'BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.' );
+
+	}
+
 	function getAttributeArray( attribute ) {
 
 		if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) {
@@ -1110,6 +1121,7 @@ function mergeGroups( geometry ) {
 
 export {
 	computeTangents,
+	computeMikkTSpaceTangents,
 	mergeBufferGeometries,
 	mergeBufferAttributes,
 	interleaveAttributes,