adds : adaptive grid size

This commit is contained in:
bhushan6
2023-08-12 12:21:42 +05:30
parent 015bfa07a7
commit 14852144f1
+23 -1
View File
@@ -25,6 +25,8 @@ import { ChangeColor } from "./ChangeColor";
export const Scene = () => {
const [bricks, setBricks] = useState([]);
const minWorkSpaceSizeRef = useRef(minWorkSpaceSize);
const [workspaceSize, setWorkspaceSize] = useState(minWorkSpaceSize);
const bricksBoundBox = useRef([]);
@@ -97,6 +99,26 @@ export const Scene = () => {
brickCursorRef.current
);
const maxMax = Math.max(
Math.abs(boundingBoxOfBrickToBeAdded.max.x * 2),
Math.abs(boundingBoxOfBrickToBeAdded.max.z * 2)
);
const maxMin = Math.max(
Math.abs(boundingBoxOfBrickToBeAdded.min.x * 2),
Math.abs(boundingBoxOfBrickToBeAdded.min.z * 2)
);
const max = Math.max(maxMax, maxMin);
minWorkSpaceSizeRef.current = Math.max(max, minWorkSpaceSizeRef.current);
setWorkspaceSize((currentSize) => {
if (currentSize <= max) {
return max;
}
return currentSize;
});
let canCreate = true;
for (let index = 0; index < bricksBoundBox.current.length; index++) {
@@ -181,7 +203,7 @@ export const Scene = () => {
Math.abs(brickXEnd + anchorX) * base * 2 - currentSize,
Math.abs(brickZEnd + anchorZ) * base * 2 - currentSize
);
if (sizeDiff > 0 || currentSize > minWorkSpaceSize) {
if (sizeDiff > 0 || currentSize > minWorkSpaceSizeRef.current) {
return currentSize + sizeDiff;
}
return currentSize;