From ccbb6f33911d2f9bfe6626843f04053b0ddf62d3 Mon Sep 17 00:00:00 2001
From: kpvhn <129968478+kpvhn@users.noreply.github.com>
Date: Wed, 5 Jul 2023 10:38:09 +0200
Subject: [PATCH 1/6] BufferGeometryUtils.toCreasedNormals(): call
`toNonIndexed()` only on indexed geometries
---
examples/jsm/utils/BufferGeometryUtils.js | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/examples/jsm/utils/BufferGeometryUtils.js b/examples/jsm/utils/BufferGeometryUtils.js
index ff86be0b7a8de9..7c82aeb37a6982 100644
--- a/examples/jsm/utils/BufferGeometryUtils.js
+++ b/examples/jsm/utils/BufferGeometryUtils.js
@@ -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 ``
+ * 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 );
@@ -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 = {};
From b799d3dd05a8d350e81aa734f38ce4e093043914 Mon Sep 17 00:00:00 2001
From: kpvhn <129968478+kpvhn@users.noreply.github.com>
Date: Wed, 5 Jul 2023 13:35:53 +0200
Subject: [PATCH 2/6] update BufferGeometry.toCreasedNormals() documentation
---
docs/examples/en/utils/BufferGeometryUtils.html | 12 +++++++++++-
docs/examples/zh/utils/BufferGeometryUtils.html | 12 +++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/docs/examples/en/utils/BufferGeometryUtils.html b/docs/examples/en/utils/BufferGeometryUtils.html
index 1b4fe1f4f83fa5..ad61fbb0d898f7 100644
--- a/docs/examples/en/utils/BufferGeometryUtils.html
+++ b/docs/examples/en/utils/BufferGeometryUtils.html
@@ -126,7 +126,17 @@ [method:BufferGeometry toCreasedNormals]( [param:BufferGeometry geometry], [
geometry -- The input geometry.
creaseAngle -- The crease angle.
- 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 that uses this method to operate on the original geometry.
+
+ [page: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.
[method:BufferGeometry toTrianglesDrawMode]( [param:BufferGeometry geometry], [param:TrianglesDrawMode drawMode] )
diff --git a/docs/examples/zh/utils/BufferGeometryUtils.html b/docs/examples/zh/utils/BufferGeometryUtils.html
index 4e8c9bbc3ad9bc..e838bf0f0d02d5 100644
--- a/docs/examples/zh/utils/BufferGeometryUtils.html
+++ b/docs/examples/zh/utils/BufferGeometryUtils.html
@@ -125,7 +125,17 @@ [method:BufferGeometry toCreasedNormals]( [param:BufferGeometry geometry], [
creaseAngle -- The crease angle.
- 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 that uses this method to operate on the original geometry.
+
+ [page: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.
[method:BufferGeometry toTrianglesDrawMode]( [param:BufferGeometry geometry], [param:TrianglesDrawMode drawMode] )
From 1ea61988f1e95fab1ec0690382834f75ab739a92 Mon Sep 17 00:00:00 2001
From: kpvhn <129968478+kpvhn@users.noreply.github.com>
Date: Wed, 5 Jul 2023 14:06:12 +0200
Subject: [PATCH 3/6] BufferGeometry.toCreasedNormals() documentation: use more
common HTML formatting & remove redundant info
---
.../en/utils/BufferGeometryUtils.html | 22 ++++++++++--------
.../zh/utils/BufferGeometryUtils.html | 23 ++++++++++---------
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/docs/examples/en/utils/BufferGeometryUtils.html b/docs/examples/en/utils/BufferGeometryUtils.html
index ad61fbb0d898f7..01c2844ea645d8 100644
--- a/docs/examples/en/utils/BufferGeometryUtils.html
+++ b/docs/examples/en/utils/BufferGeometryUtils.html
@@ -122,21 +122,23 @@ [method:BufferGeometry mergeVertices]( [param:BufferGeometry geometry], [par
[method:BufferGeometry toCreasedNormals]( [param:BufferGeometry geometry], [param:Number creaseAngle] )
-
- geometry -- The input geometry.
- creaseAngle -- The crease angle.
+
+ - geometry -- The input geometry.
+ - creaseAngle -- The crease angle.
+
+
Modifies the supplied geometry if it is non-indexed, otherwise creates a new,
- non-indexed geometry.
+ 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 that uses this method to operate on the original geometry.
+ that meet at an angle greater than the crease angle.
+
- [page: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.
+
+ Backwards compatible with code that uses this method to operate on the original geometry.
[method:BufferGeometry toTrianglesDrawMode]( [param:BufferGeometry geometry], [param:TrianglesDrawMode drawMode] )
diff --git a/docs/examples/zh/utils/BufferGeometryUtils.html b/docs/examples/zh/utils/BufferGeometryUtils.html
index e838bf0f0d02d5..0caad11c20f75b 100644
--- a/docs/examples/zh/utils/BufferGeometryUtils.html
+++ b/docs/examples/zh/utils/BufferGeometryUtils.html
@@ -120,22 +120,23 @@ [method:BufferGeometry mergeVertices]( [param:BufferGeometry geometry], [par
[method:BufferGeometry toCreasedNormals]( [param:BufferGeometry geometry], [param:Number creaseAngle] )
-
- geometry -- The input geometry.
- creaseAngle -- The crease angle.
-
+
+ - geometry -- The input geometry.
+ - creaseAngle -- The crease angle.
+
+
Modifies the supplied geometry if it is non-indexed, otherwise creates a new,
- non-indexed geometry.
+ 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 that uses this method to operate on the original geometry.
+ that meet at an angle greater than the crease angle.
+
- [page: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.
+
+ Backwards compatible with code that uses this method to operate on the original geometry.
[method:BufferGeometry toTrianglesDrawMode]( [param:BufferGeometry geometry], [param:TrianglesDrawMode drawMode] )
From 83993a7ea4efb7cd363509cd358a6c6d3ce44381 Mon Sep 17 00:00:00 2001
From: kpvhn <129968478+kpvhn@users.noreply.github.com>
Date: Thu, 6 Jul 2023 09:49:32 +0200
Subject: [PATCH 4/6] BufferGeometry.toCreasedNormals() documentation: remove
redundant compatibility note
---
docs/examples/en/utils/BufferGeometryUtils.html | 4 ----
docs/examples/zh/utils/BufferGeometryUtils.html | 4 ----
2 files changed, 8 deletions(-)
diff --git a/docs/examples/en/utils/BufferGeometryUtils.html b/docs/examples/en/utils/BufferGeometryUtils.html
index 01c2844ea645d8..479d62d233e210 100644
--- a/docs/examples/en/utils/BufferGeometryUtils.html
+++ b/docs/examples/en/utils/BufferGeometryUtils.html
@@ -137,10 +137,6 @@ [method:BufferGeometry toCreasedNormals]( [param:BufferGeometry geometry], [
that meet at an angle greater than the crease angle.
-
- Backwards compatible with code that uses this method to operate on the original geometry.
-
-
[method:BufferGeometry toTrianglesDrawMode]( [param:BufferGeometry geometry], [param:TrianglesDrawMode drawMode] )
geometry -- Instance of [page:BufferGeometry BufferGeometry].
diff --git a/docs/examples/zh/utils/BufferGeometryUtils.html b/docs/examples/zh/utils/BufferGeometryUtils.html
index 0caad11c20f75b..fcf71105d46443 100644
--- a/docs/examples/zh/utils/BufferGeometryUtils.html
+++ b/docs/examples/zh/utils/BufferGeometryUtils.html
@@ -135,10 +135,6 @@
[method:BufferGeometry toCreasedNormals]( [param:BufferGeometry geometry], [
that meet at an angle greater than the crease angle.
-
- Backwards compatible with code that uses this method to operate on the original geometry.
-
-
[method:BufferGeometry toTrianglesDrawMode]( [param:BufferGeometry geometry], [param:TrianglesDrawMode drawMode] )
geometry -- Instance of [page:BufferGeometry BufferGeometry].
From fa546c753d30c8e33fdbf8897d8dd9e34ed6b2f5 Mon Sep 17 00:00:00 2001
From: kpvhn <129968478+kpvhn@users.noreply.github.com>
Date: Mon, 17 Jul 2023 09:55:38 +0200
Subject: [PATCH 5/6] BufferGeometryUtils.toCreasedNormals(): explain the
indexed geometry check in code, not JSDoc
---
examples/jsm/utils/BufferGeometryUtils.js | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/examples/jsm/utils/BufferGeometryUtils.js b/examples/jsm/utils/BufferGeometryUtils.js
index 7c82aeb37a6982..9bfd2bb7c782ee 100644
--- a/examples/jsm/utils/BufferGeometryUtils.js
+++ b/examples/jsm/utils/BufferGeometryUtils.js
@@ -1234,13 +1234,6 @@ function mergeGroups( geometry ) {
* 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 ``
- * 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}
@@ -1267,6 +1260,8 @@ function toCreasedNormals( geometry, creaseAngle = Math.PI / 3 /* 60 degrees */
}
+ // BufferGeometry.toNonIndexed() warns if the geometry is non-indexed
+ // and returns the original geometry
const resultGeometry = geometry.index ? geometry.toNonIndexed() : geometry;
const posAttr = resultGeometry.attributes.position;
const vertexMap = {};
From 71170e107a9420dec2a5e465d3b8b4ce65d3bafe Mon Sep 17 00:00:00 2001
From: kpvhn <129968478+kpvhn@users.noreply.github.com>
Date: Mon, 17 Jul 2023 10:04:15 +0200
Subject: [PATCH 6/6] BufferGeometryUtils.toCreasedNormals(): fix typo: vertors
=> vectors
---
examples/jsm/utils/BufferGeometryUtils.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/jsm/utils/BufferGeometryUtils.js b/examples/jsm/utils/BufferGeometryUtils.js
index 9bfd2bb7c782ee..56179a04d9e82c 100644
--- a/examples/jsm/utils/BufferGeometryUtils.js
+++ b/examples/jsm/utils/BufferGeometryUtils.js
@@ -1243,7 +1243,7 @@ function toCreasedNormals( geometry, creaseAngle = Math.PI / 3 /* 60 degrees */
const creaseDot = Math.cos( creaseAngle );
const hashMultiplier = ( 1 + 1e-10 ) * 1e2;
- // reusable vertors
+ // reusable vectors
const verts = [ new Vector3(), new Vector3(), new Vector3() ];
const tempVec1 = new Vector3();
const tempVec2 = new Vector3();