@@ -7,6 +7,7 @@ THREE.EdgeSplitModifier = function () {
77 var positions , normals ;
88 var indexes ;
99 var pointToIndexMap , splitIndexes ;
10+ let oldNormals ;
1011
1112
1213 function computeNormals ( ) {
@@ -150,7 +151,7 @@ THREE.EdgeSplitModifier = function () {
150151 }
151152
152153
153- this . modify = function ( geometry , cutOffAngle ) {
154+ this . modify = function ( geometry , cutOffAngle , tryKeepNormals = true ) {
154155
155156 const wasNotBufferGeometry = geometry . isBufferGeometry === undefined ;
156157 if ( ! geometry . isBufferGeometry ) {
@@ -161,13 +162,17 @@ THREE.EdgeSplitModifier = function () {
161162
162163
163164 let hadNormals = false ;
165+ oldNormals = null ;
164166 if ( geometry . attributes . normal ) {
165167
166168 hadNormals = true ;
167169
168170 if ( wasNotBufferGeometry === false )
169171 geometry = geometry . clone ( ) ;
170172
173+ if ( tryKeepNormals && geometry . index )
174+ oldNormals = geometry . attributes . normal . array ;
175+
171176 geometry . deleteAttribute ( 'normal' ) ;
172177
173178 }
@@ -249,6 +254,27 @@ THREE.EdgeSplitModifier = function () {
249254
250255 geometry . computeVertexNormals ( ) ;
251256
257+ if ( oldNormals !== null ) {
258+
259+ const changedNormals = new Array ( oldNormals . length / 3 ) . fill ( false ) ;
260+
261+ for ( const splitData of splitIndexes )
262+ changedNormals [ splitData . original ] = true ;
263+
264+ for ( let i = 0 ; i < changedNormals . length ; i ++ ) {
265+
266+ if ( changedNormals [ i ] === false ) {
267+
268+ for ( let j = 0 ; j < 3 ; j ++ )
269+ geometry . attributes . normal . array [ 3 * i + j ] = oldNormals [ 3 * i + j ] ;
270+
271+ }
272+
273+ }
274+
275+
276+ }
277+
252278 }
253279
254280 return geometry ;
0 commit comments