Skip to content

Commit bd3fc5c

Browse files
authored
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. 🙏
1 parent b1321b1 commit bd3fc5c

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

docs/api/en/core/BufferGeometry.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ <h3>[method:undefined computeTangents]()</h3>
217217
<p>
218218
Calculates and adds a tangent attribute to this geometry.<br />
219219
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
220-
[page:BufferGeometryUtils.computeTangents] instead.
220+
[page:BufferGeometryUtils.computeMikkTSpaceTangents] instead.
221221
</p>
222222

223223
<h3>[method:undefined computeVertexNormals]()</h3>

docs/api/ko/core/BufferGeometry.html

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

215215
<h3>[method:undefined computeVertexNormals]()</h3>

docs/api/zh/core/BufferGeometry.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ <h3>[method:undefined computeTangents]()</h3>
203203
<p>
204204
Calculates and adds a tangent attribute to this geometry.<br />
205205
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
206-
[page:BufferGeometryUtils.computeTangents] instead.
206+
[page:BufferGeometryUtils.computeMikkTSpaceTangents] instead.
207207
</p>
208208

209209
<h3>[method:undefined computeVertexNormals]()</h3>

docs/examples/en/utils/BufferGeometryUtils.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ <h3>[method:Object computeMorphedAttributes]( [param:Mesh | Line | Points object
9696

9797
</p>
9898

99-
<h3>[method:Object computeTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
99+
<h3>[method:Object computeMikkTSpaceTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
100100
<ul>
101101
<li>geometry -- Instance of [page:BufferGeometry].</li>
102102
<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.

docs/examples/zh/utils/BufferGeometryUtils.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ <h3>[method:Object computeMorphedAttributes]( [param:Mesh | Line | Points object
9191

9292
</p>
9393

94-
<h3>[method:Object computeTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
94+
<h3>[method:Object computeMikkTSpaceTangents]( [param:BufferGeometry geometry], [param:Object MikkTSpace], [param:Boolean negateSign] = true )</h3>
9595
<ul>
9696
<li>geometry -- Instance of [page:BufferGeometry].</li>
9797
<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.

examples/jsm/utils/BufferGeometryUtils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@ import {
1111
Vector3,
1212
} from 'three';
1313

14+
function computeTangents() {
1415

15-
function computeTangents( geometry, MikkTSpace, negateSign = true ) {
16+
throw new Error( 'BufferGeometryUtils: computeTangents renamed to computeMikkTSpaceTangents.' );
17+
18+
}
19+
20+
function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
1621

1722
if ( ! MikkTSpace || ! MikkTSpace.isReady ) {
1823

1924
throw new Error( 'BufferGeometryUtils: Initialized MikkTSpace library required.' );
2025

2126
}
2227

28+
if ( ! geometry.hasAttribute( 'position' ) || ! geometry.hasAttribute( 'normal' ) || ! geometry.hasAttribute( 'uv' ) ) {
29+
30+
throw new Error( 'BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.' );
31+
32+
}
33+
2334
function getAttributeArray( attribute ) {
2435

2536
if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) {
@@ -1110,6 +1121,7 @@ function mergeGroups( geometry ) {
11101121

11111122
export {
11121123
computeTangents,
1124+
computeMikkTSpaceTangents,
11131125
mergeBufferGeometries,
11141126
mergeBufferAttributes,
11151127
interleaveAttributes,

0 commit comments

Comments
 (0)