2025-06-25 17:20:35 +05:30
|
|
|
import * as THREE from 'three';
|
|
|
|
|
import { Decal } from '@react-three/drei'
|
|
|
|
|
import { useLoader } from '@react-three/fiber';
|
|
|
|
|
import { useToggleView } from '../../../store/builder/store';
|
|
|
|
|
import { useBuilderStore } from '../../../store/builder/useBuilderStore';
|
|
|
|
|
|
|
|
|
|
import defaultMaterial from '../../../assets/textures/floor/wall-tex.png';
|
|
|
|
|
import useModuleStore from '../../../store/useModuleStore';
|
|
|
|
|
|
2025-06-30 16:21:54 +05:30
|
|
|
function DecalInstance({ visible = true, decal, zPosition = decal.decalPosition[2] }: { visible?: boolean, decal: Decal, zPosition?: number }) {
|
2025-06-27 11:56:54 +05:30
|
|
|
const { setSelectedWall, setSelectedFloor, selectedDecal, setSelectedDecal } = useBuilderStore();
|
2025-06-25 17:20:35 +05:30
|
|
|
const { togglView } = useToggleView();
|
|
|
|
|
const { activeModule } = useModuleStore();
|
|
|
|
|
const material = useLoader(THREE.TextureLoader, defaultMaterial);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Decal
|
|
|
|
|
// debug
|
|
|
|
|
visible={visible}
|
2025-06-30 16:21:54 +05:30
|
|
|
position={[decal.decalPosition[0], decal.decalPosition[1], zPosition]}
|
2025-06-25 17:20:35 +05:30
|
|
|
rotation={[0, 0, decal.decalRotation]}
|
|
|
|
|
scale={[decal.decalScale, decal.decalScale, 0.01]}
|
|
|
|
|
userData={decal}
|
2025-06-27 16:54:38 +05:30
|
|
|
onClick={(e) => {
|
2025-06-25 17:20:35 +05:30
|
|
|
if (visible && !togglView && activeModule === 'builder') {
|
|
|
|
|
if (e.object.userData.decalUuid) {
|
2025-06-27 15:58:34 +05:30
|
|
|
e.stopPropagation();
|
2025-06-25 17:20:35 +05:30
|
|
|
setSelectedDecal(e.object);
|
|
|
|
|
setSelectedWall(null);
|
2025-06-27 11:56:54 +05:30
|
|
|
setSelectedFloor(null);
|
2025-06-25 17:20:35 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onPointerMissed={() => {
|
|
|
|
|
if (selectedDecal && selectedDecal.userData.decalUuid === decal.decalUuid) {
|
|
|
|
|
setSelectedDecal(null);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<meshBasicMaterial
|
|
|
|
|
map={material}
|
|
|
|
|
side={THREE.DoubleSide}
|
|
|
|
|
polygonOffset
|
|
|
|
|
polygonOffsetFactor={-1}
|
|
|
|
|
/>
|
|
|
|
|
</Decal>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DecalInstance
|