@@ -52,14 +52,15 @@ function updateInstancedMeshMatrices({mesh, board}) {
5252 return ;
5353
5454 }
55+
5556 // transform mesh to world space
5657 for ( let i = 0 ; i < board . length ; ++ i ) {
5758 const { x, y, z} = board [ i ] ;
5859 tempOBJ . position . set ( x , y , z ) ;
5960 tempOBJ . rotation . set ( 0.5 * Math . PI , 0 , 0 ) ; // Look at the origin
61+ tempCOLOR . set ( getColor ( board [ i ] . type ) ) ;
6062 tempOBJ . updateMatrix ( ) ;
61- mesh . setMatrixAt ( i , tempOBJ . matrix ) ;
62-
63+ mesh . setMatrixAt ( i , tempOBJ . matrix , tempCOLOR ) ;
6364 }
6465 mesh . instanceMatrix . needsUpdate = true ;
6566
@@ -68,7 +69,7 @@ function updateInstancedMeshMatrices({mesh, board}) {
6869
6970const tempCOLOR = new THREE . Color ( ) ;
7071
71- const usePointColorsHook = ( { board, selectedPoint } ) => {
72+ const usePointColorsHook = ( { board} ) => {
7273 const numPoints = board . length ;
7374 const colorAttrib = useRef ( ) ;
7475 const colorArray = useMemo ( ( ) => new Float32Array ( numPoints * 3 ) , [
@@ -100,7 +101,7 @@ const usePointColorsHook = ({board, selectedPoint}) => {
100101 tempCOLOR . toArray ( colorArray , i * 3 ) ;
101102 }
102103 colorAttrib . current . needsUpdate = true ;
103- } , [ board , selectedPoint , colorArray ] ) ;
104+ } , [ board , colorArray ] ) ;
104105
105106 return { colorAttrib, colorArray} ;
106107} ;
@@ -139,6 +140,7 @@ const _mouseClickHook = ({board, selectedPoint, onSelectPoint/* , useDrag */})
139140 }
140141
141142 const point = board [ instanceId ] ;
143+ console . log ( board [ instanceId ] ) ;
142144 console . log ( 'Point clicked: ' , point ) ;
143145 // toggle the point
144146 if ( point === selectedPoint ) {
@@ -164,40 +166,6 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
164166 board [ 1 ] . type = '_goal_' ;
165167
166168
167- /*
168- * Update the mesh matrixes based on the board state
169- * with the goal of constructing a solvable maze.
170- */
171- // useEffect(() => {
172- //
173- // })
174-
175-
176- /*
177- * Recursive backtracking algorithm to generate a solvable maze.
178- */
179- const backtrack = ( board , start , goal ) => {
180- let current = start ;
181- let path = [ ] ;
182- while ( current !== goal ) {
183- path . push ( current ) ;
184- current = board [ current . parent ] ;
185- }
186- path . push ( current ) ;
187- return path ;
188- } ;
189-
190-
191-
192-
193- const { generationInProgress} = useGeneratedMazeHook ( {
194- board,
195- mazeType,
196- onFrame : ( ) => {
197- updateInstancedMeshMatrices ( { mesh : meshRef . current , board} ) ;
198- } ,
199- } ) ;
200-
201169 const { animationInProgress} = useAnimationHook ( {
202170 board,
203171 layoutType,
@@ -209,7 +177,7 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
209177
210178 useEffect ( ( ) => {
211179 updateInstancedMeshMatrices ( { mesh : meshRef . current , board} ) ;
212- } , [ board , layoutType ] ) ;
180+ } , [ board , layoutType , mazeType ] ) ;
213181
214182 const { getClickTarget, setDownPointerCoord} = _mouseClickHook ( {
215183 board,
@@ -219,7 +187,7 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
219187 } ) ;
220188
221189
222- const { colorAttrib, colorArray} = usePointColorsHook ( { board, selectedPoint } ) ;
190+ const { colorAttrib, colorArray} = usePointColorsHook ( { board} ) ;
223191
224192
225193 return (
@@ -231,14 +199,14 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
231199 onClick = { getClickTarget }
232200 onPointerDown = { setDownPointerCoord }
233201 >
234- < boxBufferGeometry attach = "geometry" args = { [ 1 , 0.5 , 1 , 18 ] } >
202+ < boxBufferGeometry attach = "geometry" args = { [ 0.6 , 0.3 , 0.6 , 18 ] } >
235203 < instancedBufferAttribute
236204 ref = { colorAttrib }
237205 attachObject = { [ 'attributes' , 'color' ] }
238206 args = { [ colorArray , 3 ] }
239207 />
240208 </ boxBufferGeometry >
241- < boxBufferGeometry
209+ { /* <boxBufferGeometry
242210 attach = "geometry"
243211 args = {[.9, .4, 0.9, 18]}
244212 color = "black"
@@ -247,13 +215,15 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
247215 attachObject = {['attributes', 'color']}
248216 args = {[colorArray, 3]}
249217 />
250- </ boxBufferGeometry >
218+ </boxBufferGeometry> */ }
251219 < meshStandardMaterial
252220 attach = "material"
253221 vertexColors = { THREE . VertexColors }
254222 />
255223 </ instancedMesh >
256-
224+ { /* {generationInProgress && <a.group */ }
225+ { /* position = {generationInProgress.interpolate((x, y, z) => [x, y, z])} */ }
226+ { /* />} */ }
257227 { selectedPoint && (
258228 < a . group
259229 position = { animationInProgress . interpolate ( ( ) => [
0 commit comments