Skip to content

Commit 40a0f74

Browse files
committed
BufferGeometryUtils.toCreasedNormals(): call toNonIndexed() only on indexed geometries
1 parent a887bd5 commit 40a0f74

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

examples/jsm/utils/BufferGeometryUtils.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,21 @@ function mergeGroups( geometry ) {
12291229
}
12301230

12311231

1232-
// Creates a new, non-indexed geometry with smooth normals everywhere except faces that meet at
1233-
// an angle greater than the crease angle.
1232+
/**
1233+
* Modifies the supplied geometry if it is non-indexed, otherwise creates a new,
1234+
* non-indexed geometry. Returns the geometry with smooth normals everywhere except
1235+
* faces that meet at an angle greater than the crease angle.
1236+
*
1237+
* Backwards compatible with code such as @react-three/drei's `<RoundedBox>`
1238+
* which uses this method to operate on the original geometry.
1239+
*
1240+
* As of this writing, BufferGeometry.toNonIndexed() warns if the geometry is
1241+
* non-indexed and returns `this`, i.e. the same geometry on which it was called:
1242+
* `BufferGeometry is already non-indexed.`
1243+
*
1244+
* @param {number} geometry
1245+
* @param {number} [creaseAngle]
1246+
*/
12341247
function toCreasedNormals( geometry, creaseAngle = Math.PI / 3 /* 60 degrees */ ) {
12351248

12361249
const creaseDot = Math.cos( creaseAngle );
@@ -1253,7 +1266,7 @@ function toCreasedNormals( geometry, creaseAngle = Math.PI / 3 /* 60 degrees */
12531266

12541267
}
12551268

1256-
const resultGeometry = geometry.toNonIndexed();
1269+
const resultGeometry = geometry.index ? geometry.toNonIndexed() : geometry;
12571270
const posAttr = resultGeometry.attributes.position;
12581271
const vertexMap = {};
12591272

0 commit comments

Comments
 (0)