Browse Source

Merge pull request #20672 from gkjohnson/rounded-box-size

RoundedBoxBufferGeometry: Fix the total size to match box geometry
Mr.doob 4 years ago
parent
commit
60cbc05dfa
1 changed files with 6 additions and 8 deletions
  1. 6 8
      examples/jsm/geometries/RoundedBoxBufferGeometry.js

+ 6 - 8
examples/jsm/geometries/RoundedBoxBufferGeometry.js

@@ -39,14 +39,14 @@ function getUv( faceDirVector, normal, uvAxis, projectionAxis, radius, sideLengt
 
 class RoundedBoxBufferGeometry extends BoxBufferGeometry {
 
-	constructor( width = 1, height = 1, depth = 1, segments = 1, radius = 1 ) {
+	constructor( width = 1, height = 1, depth = 1, segments = 4, radius = 0.1 ) {
 
 		// ensure segments is odd so we have a plane connecting the rounded corners
 		segments = segments % 2 === 0 ? segments + 1 : segments;
 
 		super( 1, 1, 1, segments, segments, segments );
 
-		// if we just have one segment we'r the same as a regular box
+		// if we just have one segment we're the same as a regular box
 		if ( segments === 1 ) {
 
 			return;
@@ -78,18 +78,16 @@ class RoundedBoxBufferGeometry extends BoxBufferGeometry {
 		for ( let i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
 
 			position.fromArray( positions, i );
-			normal.copy( position ).normalize();
-
-			positions[ i + 0 ] = box.x * Math.sign( position.x ) + normal.x * radius;
-			positions[ i + 1 ] = box.y * Math.sign( position.y ) + normal.y * radius;
-			positions[ i + 2 ] = box.z * Math.sign( position.z ) + normal.z * radius;
-
 			normal.copy( position );
 			normal.x -= Math.sign( normal.x ) * halfSegmentSize;
 			normal.y -= Math.sign( normal.y ) * halfSegmentSize;
 			normal.z -= Math.sign( normal.z ) * halfSegmentSize;
 			normal.normalize();
 
+			positions[ i + 0 ] = box.x * Math.sign( position.x ) + normal.x * radius;
+			positions[ i + 1 ] = box.y * Math.sign( position.y ) + normal.y * radius;
+			positions[ i + 2 ] = box.z * Math.sign( position.z ) + normal.z * radius;
+
 			normals[ i + 0 ] = normal.x;
 			normals[ i + 1 ] = normal.y;
 			normals[ i + 2 ] = normal.z;