Skip to content

Commit

Permalink
stool uv fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisVassilev1 committed Aug 15, 2024
1 parent aa7ef59 commit c3fcd4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/assets-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ class SmoothExtrudeGeometry extends BufferGeometry {
const extrudePath = properties.extrudePath;
const caps = properties.caps ?? [ 1, 1 ];
const uvMatrix = properties.uvMatrix ?? new Matrix3();
const topUVMatrix = properties.topUVMatrix ?? new Matrix3();
const bottomUVMatrix = properties.bottomUVMatrix ?? new Matrix3();

const shapePoints = shape.getPoints();
const shapeNormals = new Float32Array( shapePoints.length * 2 );
Expand Down Expand Up @@ -506,8 +508,11 @@ class SmoothExtrudeGeometry extends BufferGeometry {

const capPos = cap.getAttribute( "position" ).array;
const capIndex = cap.getIndex().array;
cap.computeBoundingBox();
const capSize = new Vector3();
cap.boundingBox.getSize( capSize );

const addCap = ( mat, normal_dir = 1, flip = false ) => {
const addCap = ( mat, uvMatrix, normal_dir = 1, flip = false ) => {

n.set( 0, 0, normal_dir ).transformDirection( mat );
const capOffset = vOffset;
Expand All @@ -521,6 +526,10 @@ class SmoothExtrudeGeometry extends BufferGeometry {
normals[ 3 * vOffset + 0 ] = n.x;
normals[ 3 * vOffset + 1 ] = n.y;
normals[ 3 * vOffset + 2 ] = n.z;

uv.set( capPos[ i ] / capSize.x + 0.5, capPos[ i+1 ] / capSize.y + 0.5 ).applyMatrix3( uvMatrix );
uvs[ 2 * vOffset + 0 ] = uv.x;
uvs[ 2 * vOffset + 1 ] = uv.y;
++vOffset;

}
Expand All @@ -546,7 +555,7 @@ class SmoothExtrudeGeometry extends BufferGeometry {
frames.tangents[ 0 ].multiplyScalar( 1 ),
)
.setPosition( pos[ 0 ]);
addCap( matrix, -1, true );
addCap( matrix, topUVMatrix, -1, true );

}

Expand All @@ -555,7 +564,7 @@ class SmoothExtrudeGeometry extends BufferGeometry {
matrix
.makeBasis( frames.normals[ steps ], frames.binormals[ steps ], frames.tangents[ steps ])
.setPosition( pos[ steps ]);
addCap( matrix );
addCap( matrix, bottomUVMatrix );

}

Expand Down
10 changes: 6 additions & 4 deletions src/stool.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class Stool extends THREE.Group {
bevelEnabled: false,
extrudePath: curve,
caps: [ 1, 1 ],
uvMatrix: new THREE.Matrix3().makeScale( 0.48, 0.48 ).translate( Math.floor( i / 2 ) * 0.5 + 0.01, ( i % 2 ) * 0.5 + 0.01 )
uvMatrix: new THREE.Matrix3().makeScale( 0.79, 0.79 ).translate( 0.01, 0.01 ),
topUVMatrix: new THREE.Matrix3().makeScale( 0.18, 0.18 ).translate( 0.81, 0.01 ),
bottomUVMatrix: new THREE.Matrix3().makeScale( 0.18, 0.18 ).translate( 0.81, 0.2 ),
} );
geom.uvIndex = 0;

Expand All @@ -113,9 +115,9 @@ class Stool extends THREE.Group {
}

const seatGeom = new ASSETS.UVCylinderGeometry( size, size, thickness, params.seatDetail, 1, false, {
bodyUVMatrix: new THREE.Matrix3().makeScale( 0.98, 0.48 ).translate( .01, .01 ),
topUVMatrix: new THREE.Matrix3().makeScale( 0.48, 0.48 ).translate( 0.01, 0.51 ),
bottomUVMatrix: new THREE.Matrix3().makeScale( 0.48, 0.48 ).translate( 0.51, 0.51 ),
bodyUVMatrix: new THREE.Matrix3().makeScale( 0.98, 0.28 ).translate( .01, .01 ),
topUVMatrix: new THREE.Matrix3().makeScale( 0.48, 0.48 ).translate( 0.01, 0.31 ),
bottomUVMatrix: new THREE.Matrix3().makeScale( 0.48, 0.48 ).translate( 0.51, 0.31 ),
} );
seatGeom.uvIndex = 1;

Expand Down

0 comments on commit c3fcd4f

Please # to comment.