diff --git a/src/modules/workshop/components/Brick/index.tsx b/src/modules/workshop/components/Brick/index.tsx index ccd4ba8..9b17f08 100644 --- a/src/modules/workshop/components/Brick/index.tsx +++ b/src/modules/workshop/components/Brick/index.tsx @@ -238,11 +238,7 @@ export const Brick = ({ {/**/} - + )} diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index c3faa99..56bac9e 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,6 +1,7 @@ import { mergeBufferGeometries } from 'three-stdlib' import { base, heightBase, knobSize } from '../constant/datablocks' import { BoxGeometry, CylinderGeometry } from 'three' +import { diffProps } from '@react-three/fiber/dist/declarations/src/core/utils' import { DOMAIN_URL } from '@/constant/constant' import toast from 'react-hot-toast' @@ -68,6 +69,7 @@ export function radToDeg(angle) { export const checkCollision = (boundingBoxToCheck, otherBoundingBoxes) => { let isCollied = false let isSomethingBelow = false + let isSomethingTop = false let isFirstLayer = boundingBoxToCheck.brickBoundingBox.min.y === 0 if (otherBoundingBoxes.length < 1) return true @@ -80,14 +82,10 @@ export const checkCollision = (boundingBoxToCheck, otherBoundingBoxes) => { const diffX = boundingBoxToCheck.brickBoundingBox.min.x - brickBoundingBox.min.x const diffZ = boundingBoxToCheck.brickBoundingBox.min.z - brickBoundingBox.min.z const diffY = boundingBoxToCheck.brickBoundingBox.min.y - brickBoundingBox.min.y - const widthToCheck = Math.round( - boundingBoxToCheck.brickBoundingBox.max.x - boundingBoxToCheck.brickBoundingBox.min.x, - ) - const depthToCheck = Math.round( - boundingBoxToCheck.brickBoundingBox.max.z - boundingBoxToCheck.brickBoundingBox.min.z, - ) - - if (diffY <= 0) { + const widthToCheck = boundingBoxToCheck.brickBoundingBox.max.x - boundingBoxToCheck.brickBoundingBox.min.x + const depthToCheck = boundingBoxToCheck.brickBoundingBox.max.z - boundingBoxToCheck.brickBoundingBox.min.z + + if (diffY === 0) { // TOP LEFT CORNER if (Math.abs(diffX) === base && Math.abs(diffZ) === base) { isCollied = true @@ -106,13 +104,13 @@ export const checkCollision = (boundingBoxToCheck, otherBoundingBoxes) => { } } - // Filter out the top layer if (isFirstLayer || Math.abs(diffY) > heightBase) continue - if (diffY === heightBase && Math.abs(diffX) <= base && Math.abs(diffZ) <= base) isSomethingBelow = true - } + if (diffY > 0 && Math.abs(diffX) <= base && Math.abs(diffZ) <= base) isSomethingBelow = true - return !isCollied && ((isSomethingBelow && !isFirstLayer) || isFirstLayer) // true if it is not colliding + if (diffY < 0 && diffY === -heightBase && Math.abs(diffX) <= base && Math.abs(diffZ) <= base) isSomethingTop = true + } + return !isCollied && (((isSomethingBelow || isSomethingTop) && !isFirstLayer) || isFirstLayer) // true if it is not colliding } export function uID(length = 8) {