Skip to content

Commit b386549

Browse files
committed
finishing
1 parent a1b4c42 commit b386549

9 files changed

Lines changed: 1169 additions & 424 deletions

File tree

‎package-lock.json‎

Lines changed: 1136 additions & 233 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"@react-spring/three": "^9.5.1",
77
"@react-three/drei": "9.14.3",
8+
"@react-three/fiber": "^8.2.1",
89
"@splinetool/react-spline": "^2.2.1",
910
"@testing-library/jest-dom": "^5.16.4",
1011
"@testing-library/react": "^13.3.0",
@@ -15,15 +16,13 @@
1516
"@types/react-dom": "^18.0.6",
1617
"@types/three": "0.141.0",
1718
"csstype": "^3.1.0",
19+
"leva": "^0.9.29",
1820
"postcss-cli": "^10.0.0",
1921
"react": "^18.2.0",
2022
"react-dom": "^18.2.0",
2123
"react-router": "^6.3.0",
2224
"react-router-dom": "^6.3.0",
23-
"react-spring": "8.0.27",
24-
"react-three-fiber": "4.0.12",
25-
"three": "0.112.1",
26-
"zustand": "^4.0.0-rc.1"
25+
"react-spring": "8.0.27"
2726
},
2827
"devDependencies": {
2928
"autoprefixer": "^9.8.8",

‎src/components/BoardCanvas/Board.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as React from 'react';
22
// import {useFrame /*useFrame*/} from '@react-three/fiber';
3-
import {Canvas} from 'react-three-fiber';
3+
import {Canvas} from '@react-three/fiber';
44
import Controls from './OrbitControls';
55
import {useImperativeHandle, useRef, forwardRef} from 'react';
6-
import {TrackballControls} from 'three/examples/jsm/controls/TrackballControls';
6+
import {TrackballControls} from '@react-three/fiber';
77
import OrbitControls from './OrbitControls';
8+
89
import Cells from './Cells';
910

1011

@@ -24,10 +25,10 @@ export const Board = ({board, layoutType, selectedPoint, onSelectPoint, mazeType
2425
return (
2526
<Canvas>
2627
<Controls ref = {controlsRef} selectedPoint = {selectedPoint}/>
27-
<mesh> {/* BorderBox */}
28-
<boxBufferGeometry attach = "geometry" args = {[80, 80, -10]}/>
29-
<meshBasicMaterial attach = "material" color = "black"/>
30-
</mesh>
28+
{/* <mesh> /!* BorderBox *!/ */}
29+
{/* <boxBufferGeometry attach = "geometry" args = {[80, 80, -10]}/> */}
30+
{/* <meshBasicMaterial attach = "material" color = "black"/> */}
31+
{/* </mesh> */}
3132

3233

3334
<ambientLight color = "white" intensity = {0.1}/>
@@ -38,6 +39,7 @@ export const Board = ({board, layoutType, selectedPoint, onSelectPoint, mazeType
3839
intensity = {1.0}
3940
/>
4041
<Cells
42+
4143
board = {board}
4244
layoutType = {layoutType}
4345
mazeType = {mazeType}

‎src/components/BoardCanvas/Cells.js‎

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import * as React from 'react';
22
import {useEffect, useRef, useMemo, useState, createContext} from 'react';
33
import {a} from '@react-spring/three';
4-
import {useAnimationHook, useGenerateMazeHook, useSolver} from './Layouts';
4+
import {useAnimationHook, useGenerateMazeHook, useSolver} from './LayoutsFunctions';
55
import {directions} from '../Algorithms/Maze/Directions';
66
import {_FindCell} from '../Algorithms/Maze/Tools';
7-
import board from './Board';
87
import {BinaryTreeCreation} from '../Algorithms/Maze/Generation/BinaryTreeCreation';
98
import {
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';
1613
import * 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+
6946
let tempCOLOR = new THREE.Color();
7047

7148
const usePointColorsHook = ({board, selectedPoint}) => {
@@ -86,6 +63,7 @@ const usePointColorsHook = ({board, selectedPoint}) => {
8663
return {colorAttrib, colorArray};
8764
};
8865

66+
8967
const _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

140118
const 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 */}

‎src/components/BoardCanvas/GridState.js‎

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/components/BoardCanvas/Layouts.js renamed to src/components/BoardCanvas/LayoutsFunctions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {PATH_TYPE, DEFAULT_TYPE, FLOOR_TYPE, WALL_TYPE, START_TYPE, GOAL_TYPE}
1818
* Board type selector hook.
1919
*
2020
*/
21-
export function useAnimationHook({board, layoutType = 'standard'}) {
21+
export function useAnimationHook({board, layoutType}) {
2222
console.log('useAnimationHook used.');
2323
// if (activeRef) {
2424
// return;
@@ -34,7 +34,7 @@ export function useAnimationHook({board, layoutType = 'standard'}) {
3434
break;
3535
}
3636
}
37-
}, [layoutType, board]);
37+
}, [layoutType]);
3838
console.log('useAnimationHook ended.');
3939
// return () => {board.reset()};
4040

@@ -64,8 +64,9 @@ export function useGenerateMazeHook({board, mazeType}) {
6464
}
6565
}
6666

67-
}, [mazeType, board]);
67+
}, [mazeType]);
6868
console.log('generatedMaze ended.');
69+
6970
// return board;
7071
}
7172

‎src/components/BoardCanvas/OrbitControls.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
// import {extend, useThree, useFrame} from '@react-three/fiber';
3-
import {extend, useThree, useFrame} from 'react-three-fiber';
4-
import {TrackballControls} from 'three/examples/jsm/controls/TrackballControls';
3+
import {extend, useThree, useFrame} from '@react-three/fiber';
4+
import { TrackballControls } from '@react-three/drei'
55
import * as Three from 'three';
66
import {forwardRef, useRef, useImperativeHandle, useEffect, useState} from 'react';
77

@@ -90,7 +90,7 @@ const OrbitControls = ({board, selectedPoint, onSelectedPoint}, ref) => {
9090

9191

9292
return (
93-
<trackballControls
93+
<TrackballControls
9494
ref = {controls}
9595
args = {[camera, gl.domElement]}
9696
dynamicDampingFactor = {0.1}

‎src/components/BoardCanvas/Point.js‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎src/components/BoardCanvas/board 2.css‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)