|
@@ -7,6 +7,7 @@ THREE.EdgeSplitModifier = function () {
|
|
var positions, normals;
|
|
var positions, normals;
|
|
var indexes;
|
|
var indexes;
|
|
var pointToIndexMap, splitIndexes;
|
|
var pointToIndexMap, splitIndexes;
|
|
|
|
+ let oldNormals;
|
|
|
|
|
|
|
|
|
|
function computeNormals() {
|
|
function computeNormals() {
|
|
@@ -150,7 +151,7 @@ THREE.EdgeSplitModifier = function () {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- this.modify = function ( geometry, cutOffAngle ) {
|
|
|
|
|
|
+ this.modify = function ( geometry, cutOffAngle, tryKeepNormals = true ) {
|
|
|
|
|
|
const wasNotBufferGeometry = geometry.isBufferGeometry === undefined;
|
|
const wasNotBufferGeometry = geometry.isBufferGeometry === undefined;
|
|
if ( ! geometry.isBufferGeometry ) {
|
|
if ( ! geometry.isBufferGeometry ) {
|
|
@@ -161,6 +162,7 @@ THREE.EdgeSplitModifier = function () {
|
|
|
|
|
|
|
|
|
|
let hadNormals = false;
|
|
let hadNormals = false;
|
|
|
|
+ oldNormals = null;
|
|
if ( geometry.attributes.normal ) {
|
|
if ( geometry.attributes.normal ) {
|
|
|
|
|
|
hadNormals = true;
|
|
hadNormals = true;
|
|
@@ -168,6 +170,9 @@ THREE.EdgeSplitModifier = function () {
|
|
if ( wasNotBufferGeometry === false )
|
|
if ( wasNotBufferGeometry === false )
|
|
geometry = geometry.clone();
|
|
geometry = geometry.clone();
|
|
|
|
|
|
|
|
+ if ( tryKeepNormals && geometry.index )
|
|
|
|
+ oldNormals = geometry.attributes.normal.array;
|
|
|
|
+
|
|
geometry.deleteAttribute( 'normal' );
|
|
geometry.deleteAttribute( 'normal' );
|
|
|
|
|
|
}
|
|
}
|
|
@@ -249,6 +254,27 @@ THREE.EdgeSplitModifier = function () {
|
|
|
|
|
|
geometry.computeVertexNormals();
|
|
geometry.computeVertexNormals();
|
|
|
|
|
|
|
|
+ if ( oldNormals !== null ) {
|
|
|
|
+
|
|
|
|
+ const changedNormals = new Array( oldNormals.length / 3 ).fill( false );
|
|
|
|
+
|
|
|
|
+ for ( const splitData of splitIndexes )
|
|
|
|
+ changedNormals[ splitData.original ] = true;
|
|
|
|
+
|
|
|
|
+ for ( let i = 0; i < changedNormals.length; i ++ ) {
|
|
|
|
+
|
|
|
|
+ if ( changedNormals[ i ] === false ) {
|
|
|
|
+
|
|
|
|
+ for ( let j = 0; j < 3; j ++ )
|
|
|
|
+ geometry.attributes.normal.array[ 3 * i + j ] = oldNormals[ 3 * i + j ];
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
return geometry;
|
|
return geometry;
|