File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,19 +87,27 @@ const tiles: THREE.Mesh[] = [];
8787const evenColor = new THREE . Color ( 0.082 , 0.509 , 0.690 ) . convertSRGBToLinear ( ) ;
8888const oddColor = new THREE . Color ( 0.286 , 0.851 , 0.882 ) . convertSRGBToLinear ( ) ; ;
8989
90+ const evenMat = new THREE . MeshStandardMaterial ( {
91+ metalness : 0.1 ,
92+ roughness : 0.35 ,
93+ color : evenColor
94+ } ) ;
95+
96+ const oddMat = new THREE . MeshStandardMaterial ( {
97+ metalness : 0.1 ,
98+ roughness : 0.35 ,
99+ color : oddColor
100+ } ) ;
101+
90102// === Scene setup ===
91103async function init ( ) {
92- const tile_mesh = ( await loadGLB ( "/models/box.glb" ) ) . children [ 0 ] ! ;
104+ const tileSrc = ( await loadGLB ( "/models/box.glb" ) ) . children [ 0 ] as THREE . Mesh ;
105+ const tileGeometry = ( tileSrc . geometry as THREE . BufferGeometry ) . clone ( ) ;
106+ tileGeometry . computeBoundingBox ( ) ;
93107
94108 for ( let x = 0 ; x < boardSize ; x ++ ) {
95109 for ( let z = 0 ; z < boardSize ; z ++ ) {
96- const mat = new THREE . MeshStandardMaterial (
97- {
98- metalness : 0.1 ,
99- roughness : 0.35
100- }
101- ) ;
102- const tile = tile_mesh . clone ( ) as THREE . Mesh ;
110+ const tile = new THREE . Mesh ( tileGeometry , ( x + z ) % 2 === 0 ? evenMat : oddMat ) ;
103111 tile . scale . multiplyScalar ( 0.98 ) ;
104112 tile . castShadow = false ;
105113 tile . receiveShadow = true ;
@@ -109,8 +117,6 @@ async function init() {
109117 ( z - boardSize / 2 + 0.5 ) * tileSize
110118 ) ;
111119
112- mat . color . copy ( ( x + z ) % 2 === 0 ? evenColor : oddColor ) ;
113- tile . material = mat ;
114120 tile . name = `tile_${ x } _${ z } ` ;
115121 scene . add ( tile ) ;
116122 tiles . push ( tile ) ;
You can’t perform that action at this time.
0 commit comments