Skip to content

Commit

Permalink
BufferGeometryUtils.toCreasedNormals(): call toNonIndexed() only on…
Browse files Browse the repository at this point in the history
… indexed geometries
  • Loading branch information
kpvhn committed Jul 5, 2023
1 parent a887bd5 commit ccbb6f3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions examples/jsm/utils/BufferGeometryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,22 @@ function mergeGroups( geometry ) {
}


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

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

}

const resultGeometry = geometry.toNonIndexed();
const resultGeometry = geometry.index ? geometry.toNonIndexed() : geometry;
const posAttr = resultGeometry.attributes.position;
const vertexMap = {};

Expand Down

0 comments on commit ccbb6f3

Please sign in to comment.