Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/modules/workshop/components/Brick/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,7 @@ export const Brick = ({
<Decal
position={[0, 0, dimensions.x == 2 ? base + 0.005 : 13 + 0.005]}
rotation={[0, 0, 0]}
scale={[
base * 3,
heightBase,
5,
]}
scale={[base * 3, heightBase, 5]}
>
{/*<meshPhysicalMaterial*/}
{/* map={texturez}*/}
Expand All @@ -256,8 +252,17 @@ export const Brick = ({
{/* polygonOffset*/}
{/* polygonOffsetFactor={-1}*/}
{/*/>*/}
<meshStandardMaterial map={texturez} polygonOffset roughness={1} metalness={0.35} color={'#fff'}
emissive={'#000'} alphaHash={true} transparent alphaTest={0} />
<meshStandardMaterial
map={texturez}
polygonOffset
roughness={1}
metalness={0.35}
color={'#fff'}
emissive={'#000'}
alphaHash={true}
transparent
alphaTest={0}
/>
</Decal>
)}
</mesh>
Expand Down
22 changes: 10 additions & 12 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down