11import * as React from 'react' ;
22import { useEffect , useRef , useMemo , useState , createContext } from 'react' ;
33import { a } from '@react-spring/three' ;
4- import { useAnimationHook , useGenerateMazeHook , useSolver } from './Layouts ' ;
4+ import { useAnimationHook , useGenerateMazeHook , useSolver } from './LayoutsFunctions ' ;
55import { directions } from '../Algorithms/Maze/Directions' ;
66import { _FindCell } from '../Algorithms/Maze/Tools' ;
7- import board from './Board' ;
87import { BinaryTreeCreation } from '../Algorithms/Maze/Generation/BinaryTreeCreation' ;
98import {
109 FLOOR_TYPE , FLOOR_COLOR , WALL_TYPE , WALL_COLOR ,
1110 getColor , GOAL_TYPE , START_TYPE , SELECTED_COLOR ,
1211 BURN_COLOR , PATH_TYPE , PATH_COLOR ,
1312} from '../../Utility/Colors' ;
14- // import {BufferPoints} from './Point';
15- import { Object3D , Color } from 'three' ;
1613import * as THREE from 'three' ;
17- // import {PointEvent} from './Point';
14+ import { PointMaterial , Points , Point } from '@react-three/drei' ;
15+
1816
1917
2018
@@ -23,12 +21,12 @@ const tempOBJ = new THREE.Object3D();
2321
2422
2523
26- function updateInstancedMeshMatrices ( { mesh, board, colorAttrib , colorArray } ) {
24+ function updateInstancedMeshMatrices ( { mesh, board, colorArray , colorAttrib } ) {
2725 if ( ! mesh ) {
2826 return ;
2927 }
3028 const numPoints = board . length ;
31-
29+ const tempCOLOR = new THREE . Color ( ) ;
3230 // transform mesh to world space
3331 for ( let i = 0 ; i < board . length ; ++ i ) {
3432 const { x, y, z} = board [ i ] ;
@@ -44,28 +42,7 @@ function updateInstancedMeshMatrices({mesh, board, colorAttrib, colorArray}) {
4442}
4543
4644
47- // function updateInstancedMeshColors({mesh, board}) {
48- // for (let i = 0; i < board.length; ++i) {
49- // tempCOLOR.set(getColor(board[i].type));
50- // mesh.setColorAt(i, tempCOLOR);
51- // }
52- //
53- // return {colorAttrib, colorArray};
54- //
55- // }
56-
57-
58- //
59- // tempCOLOR.update = (color) => {
60- // tempCOLOR.current = color;
61- // }
62- //
63- // tempCOLOR.toArray = (color, i) => {
64- // let rbg = THREE.Get.toArray(tempCOLOR);
65- // color[i] = rbg.r;
66- // color[i + 1] = rbg.g;
67- // color[i + 2] = rbg.b;
68- // }
45+
6946let tempCOLOR = new THREE . Color ( ) ;
7047
7148const usePointColorsHook = ( { board, selectedPoint} ) => {
@@ -86,6 +63,7 @@ const usePointColorsHook = ({board, selectedPoint}) => {
8663 return { colorAttrib, colorArray} ;
8764} ;
8865
66+
8967const _mouseClickHook = ( { board, selectedPoint, onSelectPoint/* , useDrag */ } ) => {
9068 const onMouseDownHandler = useRef ( [ 0 , 0 ] ) ; // Record and maintain the handler for the mouse down event
9169 const onMouseUpHandler = useRef ( [ 0 , 0 ] ) ; // Record and maintain the handler for the mouse up event
@@ -139,7 +117,7 @@ const _mouseClickHook = ({board, selectedPoint, onSelectPoint/* , useDrag */})
139117
140118const Cells = ( { board, layoutType, mazeType, solverType, selectedPoint, onSelectPoint /*, useDrag */ } ) => {
141119 const meshRef = useRef ( ) ;
142- const boardRef = useRef ( board ) ;
120+ // const boardRef = useRef(board);
143121 const [ activeRef , setActive ] = useState ( false ) ;
144122 const numPoints = board . length ;
145123
@@ -151,21 +129,9 @@ const Cells = ({board, layoutType, mazeType, solverType, selectedPoint, onSelect
151129
152130 useAnimationHook ( { board, layoutType} ) ;
153131
154- // useEffect(() => {
155- // console.log('useEffect');
156- // boardRef.current = board;
157- // layoutRef.current = layoutType;
158- // mazeRef.current = mazeType;
159- // solverRef.current = solverType;
160- // pathRef.current = Array.from(board).filter(point => point.type === PATH_TYPE);
161- // }, [board, layoutType, mazeType, solverType]);
132+
162133 useGenerateMazeHook ( { board, mazeType} ) ;
163- /*
164- const [_Animation] = useSolver({board, solverType,
165- onFrame: () => {
166- updateInstancedMeshMatrices({mesh: meshRef.current, board});
167- },
168- }); */
134+
169135
170136 const { getClickTarget, setDownPointerCoord} = _mouseClickHook ( {
171137 board,
@@ -174,13 +140,13 @@ const Cells = ({board, layoutType, mazeType, solverType, selectedPoint, onSelect
174140 /* useDrag */
175141 } ) ;
176142
177- const { colorAttrib, colorArray} = usePointColorsHook ( { board, selectedPoint } ) ;
143+ const { colorAttrib, colorArray} = usePointColorsHook ( { board} ) ;
178144
179145
180146 useEffect ( ( ) => {
181147 console . log ( 'Board updated' ) ;
182- updateInstancedMeshMatrices ( { mesh : meshRef . current , board, colorAttrib , colorArray } ) ;
183- } , [ board ] ) ;
148+ updateInstancedMeshMatrices ( { mesh : meshRef . current , board, colorArray , colorAttrib } ) ;
149+ } , [ board , mazeType , colorAttrib , layoutType ] ) ;
184150
185151
186152
@@ -203,7 +169,8 @@ const Cells = ({board, layoutType, mazeType, solverType, selectedPoint, onSelect
203169 </ boxBufferGeometry >
204170 < meshStandardMaterial
205171 attach = "material"
206- vertexColors = { THREE . VertexColors }
172+ vertexColors = { true }
173+
207174 />
208175 </ instancedMesh >
209176 { /* {generationInProgress && <a.group */ }
0 commit comments