Skip to content

Commit 7e6649c

Browse files
committed
Fix all face alignment
1 parent 9761489 commit 7e6649c

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

examples/jsm/geometries/RoundedBoxBufferGeometry.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from "../../../build/three.module.js";
55

66
const tempNormal = new Vector3();
7-
function applyUv( faceDirVector, normal, uvAxis, projectionAxis, radius, sideLength ) {
7+
function getUv( faceDirVector, normal, uvAxis, projectionAxis, radius, sideLength ) {
88

99
const totArcLength = 2 * Math.PI * radius / 4;
1010

@@ -85,31 +85,49 @@ class RoundedBoxBufferGeometry extends BoxBufferGeometry {
8585

8686
// generate UVs along Z then Y
8787
faceDirVector.set( 1, 0, 0 );
88-
uvs[ j + 0 ] = applyUv( faceDirVector, normal, 'z', 'y', radius, depth );
89-
uvs[ j + 1 ] = 1.0 - applyUv( faceDirVector, normal, 'y', 'z', radius, height );
88+
uvs[ j + 0 ] = getUv( faceDirVector, normal, 'z', 'y', radius, depth );
89+
uvs[ j + 1 ] = 1.0 - getUv( faceDirVector, normal, 'y', 'z', radius, height );
9090
break;
9191

92+
case 1: // left
9293

93-
// case 1: // left
94-
// uvs[ j + 0 ] = 0.5 + ( positions[ i + 2 ] / ( depth - radius ) );
95-
// uvs[ j + 1 ] = 0.5 + ( positions[ i + 1 ] / ( height - radius ) );
96-
// break;
97-
// case 2: // top
98-
// uvs[ j + 0 ] = 0.5 + ( positions[ i + 0 ] / ( width - radius ) );
99-
// uvs[ j + 1 ] = 0.5 - ( positions[ i + 2 ] / ( depth - radius ) );
100-
// break;
101-
// case 3: // bottom
102-
// uvs[ j + 0 ] = 0.5 + ( positions[ i + 0 ] / ( width - radius ) );
103-
// uvs[ j + 1 ] = 0.5 + ( positions[ i + 2 ] / ( depth - radius ) );
104-
// break;
105-
// case 4: // front
106-
// uvs[ j + 0 ] = 0.5 + ( positions[ i + 0 ] / ( width - radius ) );
107-
// uvs[ j + 1 ] = 0.5 + ( positions[ i + 1 ] / ( height - radius ) );
108-
// break;
109-
// case 5: // back
110-
// uvs[ j + 0 ] = 0.5 - ( positions[ i + 0 ] / ( width - radius ) );
111-
// uvs[ j + 1 ] = 0.5 + ( positions[ i + 1 ] / ( height - radius ) );
112-
// break;
94+
// generate UVs along Z then Y
95+
faceDirVector.set( - 1, 0, 0 );
96+
uvs[ j + 0 ] = 1.0 - getUv( faceDirVector, normal, 'z', 'y', radius, depth );
97+
uvs[ j + 1 ] = 1.0 - getUv( faceDirVector, normal, 'y', 'z', radius, height );
98+
break;
99+
100+
case 2: // top
101+
102+
// generate UVs along X then Z
103+
faceDirVector.set( 0, 1, 0 );
104+
uvs[ j + 0 ] = 1.0 - getUv( faceDirVector, normal, 'x', 'z', radius, width );
105+
uvs[ j + 1 ] = getUv( faceDirVector, normal, 'z', 'x', radius, depth );
106+
break;
107+
108+
case 3: // bottom
109+
110+
// generate UVs along X then Z
111+
faceDirVector.set( 0, -1, 0 );
112+
uvs[ j + 0 ] = 1.0 - getUv( faceDirVector, normal, 'x', 'z', radius, width );
113+
uvs[ j + 1 ] = 1.0 - getUv( faceDirVector, normal, 'z', 'x', radius, depth );
114+
break;
115+
116+
case 4: // front
117+
118+
// generate UVs along X then Y
119+
faceDirVector.set( 0, 0, 1 );
120+
uvs[ j + 0 ] = 1.0 - getUv( faceDirVector, normal, 'x', 'y', radius, width );
121+
uvs[ j + 1 ] = 1.0 - getUv( faceDirVector, normal, 'y', 'x', radius, height );
122+
break;
123+
124+
case 5: // back
125+
126+
// generate UVs along X then Y
127+
faceDirVector.set( 0, 0, - 1 );
128+
uvs[ j + 0 ] = getUv( faceDirVector, normal, 'x', 'y', radius, width );
129+
uvs[ j + 1 ] = 1.0 - getUv( faceDirVector, normal, 'y', 'x', radius, height );
130+
break;
113131

114132
}
115133

0 commit comments

Comments
 (0)