|
@@ -39,14 +39,14 @@ function getUv( faceDirVector, normal, uvAxis, projectionAxis, radius, sideLengt
|
|
|
|
|
|
class RoundedBoxBufferGeometry extends BoxBufferGeometry {
|
|
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
|
|
// ensure segments is odd so we have a plane connecting the rounded corners
|
|
segments = segments % 2 === 0 ? segments + 1 : segments;
|
|
segments = segments % 2 === 0 ? segments + 1 : segments;
|
|
|
|
|
|
super( 1, 1, 1, segments, segments, 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 ) {
|
|
if ( segments === 1 ) {
|
|
|
|
|
|
return;
|
|
return;
|
|
@@ -78,18 +78,16 @@ class RoundedBoxBufferGeometry extends BoxBufferGeometry {
|
|
for ( let i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
|
|
for ( let i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
|
|
|
|
|
|
position.fromArray( positions, i );
|
|
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.copy( position );
|
|
normal.x -= Math.sign( normal.x ) * halfSegmentSize;
|
|
normal.x -= Math.sign( normal.x ) * halfSegmentSize;
|
|
normal.y -= Math.sign( normal.y ) * halfSegmentSize;
|
|
normal.y -= Math.sign( normal.y ) * halfSegmentSize;
|
|
normal.z -= Math.sign( normal.z ) * halfSegmentSize;
|
|
normal.z -= Math.sign( normal.z ) * halfSegmentSize;
|
|
normal.normalize();
|
|
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 + 0 ] = normal.x;
|
|
normals[ i + 1 ] = normal.y;
|
|
normals[ i + 1 ] = normal.y;
|
|
normals[ i + 2 ] = normal.z;
|
|
normals[ i + 2 ] = normal.z;
|