|
4 | 4 | } from "../../../build/three.module.js"; |
5 | 5 |
|
6 | 6 | const tempNormal = new Vector3(); |
7 | | -function applyUv( faceDirVector, normal, uvAxis, projectionAxis, radius, sideLength ) { |
| 7 | +function getUv( faceDirVector, normal, uvAxis, projectionAxis, radius, sideLength ) { |
8 | 8 |
|
9 | 9 | const totArcLength = 2 * Math.PI * radius / 4; |
10 | 10 |
|
@@ -85,31 +85,49 @@ class RoundedBoxBufferGeometry extends BoxBufferGeometry { |
85 | 85 |
|
86 | 86 | // generate UVs along Z then Y |
87 | 87 | 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 ); |
90 | 90 | break; |
91 | 91 |
|
| 92 | + case 1: // left |
92 | 93 |
|
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; |
113 | 131 |
|
114 | 132 | } |
115 | 133 |
|
|
0 commit comments