@@ -13,8 +13,24 @@ import {BinaryTreeCreation} from '../Algorithms/Maze/Generati
1313
1414
1515
16- export const TEST_COLOR = '#FF66CC' , BURN_COLOR = '#fad6ee' , PATH_COLOR = '#63caef' , WALL_COLOR = '#1c1b1b' , GOAL_COLOR = '#30fa04' , START_COLOR = '#ff0000' , SELECTED_COLOR = '#ffd300' , FLOOR_COLOR = '#ffffff' , DEFAULT_COLOR = '#8f8d8d' , FLOOR_TYPE = '_floor_' , DEFAULT_TYPE = '_default_' , WALL_TYPE = '_wall_' , PATH_TYPE = '_path_' , GOAL_TYPE = '_goal_' , START_TYPE = '_start_' , TEST_TYPE = '_test_' ;
17- const tempOBJ = new THREE . Object3D ( ) ;
16+ export const TEST_COLOR = '#FF66CC' ;
17+ export const BURN_COLOR = '#fad6ee' ;
18+ export const PATH_COLOR = '#63caef' ;
19+ export const WALL_COLOR = '#624646' ;
20+ export const GOAL_COLOR = '#30fa04' ;
21+ export const START_COLOR = '#ff0000' ;
22+ export const SELECTED_COLOR = '#ffd300' ;
23+ export const FLOOR_COLOR = '#ffffff' ;
24+ export const DEFAULT_COLOR = '#8f8d8d' ;
25+ export const FLOOR_TYPE = '_floor_' ;
26+ export const DEFAULT_TYPE = '_default_' ;
27+ export const WALL_TYPE = '_wall_' ;
28+ export const PATH_TYPE = '_path_' ;
29+ export const GOAL_TYPE = '_goal_' ;
30+ export const START_TYPE = '_start_' ;
31+ export const TEST_TYPE = '_test_' ;
32+
33+ export const tempOBJ = new THREE . Object3D ( ) ;
1834
1935
2036function getColor ( type ) {
@@ -40,32 +56,42 @@ function getColor(type) {
4056
4157
4258
43- function updateInstancedMeshMatrices ( { mesh, board} ) {
59+ function updateInstancedMeshMatrices ( { mesh, board, colorAttrib , colorArray } ) {
4460 if ( ! mesh ) {
4561 return ;
4662 }
63+ const numPoints = board . length ;
64+
4765 // transform mesh to world space
4866 for ( let i = 0 ; i < board . length ; ++ i ) {
4967 const { x, y, z} = board [ i ] ;
5068 tempOBJ . position . set ( x , y , z ) ;
5169 tempOBJ . rotation . set ( 0.5 * Math . PI , 0 , 0 ) ; // Look at the origin
5270 tempCOLOR . set ( getColor ( board [ i ] . type ) ) ;
71+ tempCOLOR . toArray ( colorArray , i * 3 ) ;
5372 tempOBJ . updateMatrix ( ) ;
54- mesh . setMatrixAt ( i , tempOBJ . matrix , tempCOLOR ) ;
73+ mesh . setMatrixAt ( i , tempOBJ . matrix ) ;
5574 }
75+ colorAttrib . current . needsUpdate = true ;
5676 mesh . instanceMatrix . needsUpdate = true ;
5777}
5878
5979
60- function updateInstancedMeshColors ( { mesh, board} ) {
61-
62- }
80+ // function updateInstancedMeshColors({mesh, board}) {
81+ // for (let i = 0; i < board.length; ++i) {
82+ // tempCOLOR.set(getColor(board[i].type));
83+ // mesh.setColorAt(i, tempCOLOR);
84+ // }
85+ //
86+ // return {colorAttrib, colorArray};
87+ //
88+ // }
6389
6490
6591
6692const tempCOLOR = new THREE . Color ( ) ;
6793
68- const usePointColorsHook = ( { board, mazeType } ) => {
94+ const usePointColorsHook = ( { board} ) => {
6995 console . log ( 'usePointColorsHook' ) ;
7096 const numPoints = board . length ;
7197 const colorAttrib = useRef ( ) ;
@@ -78,7 +104,7 @@ const usePointColorsHook = ({board, mazeType}) => {
78104 tempCOLOR . toArray ( colorArray , i * 3 ) ;
79105 }
80106 colorAttrib . current . needsUpdate = true ;
81- } , [ board , mazeType , colorArray ] ) ;
107+ } , [ board , colorArray ] ) ;
82108
83109 return { colorAttrib, colorArray} ;
84110} ;
@@ -162,10 +188,12 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
162188
163189 const { colorAttrib, colorArray} = usePointColorsHook ( { board} ) ;
164190
191+
165192 useEffect ( ( ) => {
166193 console . log ( 'Board updated' ) ;
167- updateInstancedMeshMatrices ( { mesh : meshRef . current , board} ) ;
168- } , [ layoutType , mazeType ] ) ;
194+ updateInstancedMeshMatrices ( { mesh : meshRef . current , board, colorAttrib, colorArray} ) ;
195+ } , [ board , layoutType , mazeType ] ) ;
196+
169197
170198
171199 return (
0 commit comments