bring back ground occluder
This commit is contained in:
@@ -239,6 +239,7 @@ export const ZoneRenderer = ({ node }: { node: ZoneNode }) => {
|
|||||||
rotation={[-Math.PI / 2, 0, 0]}
|
rotation={[-Math.PI / 2, 0, 0]}
|
||||||
material={floorMaterial}
|
material={floorMaterial}
|
||||||
name="floor"
|
name="floor"
|
||||||
|
layers={2}
|
||||||
>
|
>
|
||||||
<shapeGeometry args={[floorShape]} />
|
<shapeGeometry args={[floorShape]} />
|
||||||
</mesh>
|
</mesh>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { useScene } from '@pascal-app/core'
|
import { useScene } from '@pascal-app/core'
|
||||||
|
import polygonClipping from 'polygon-clipping'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import useViewer from '../../store/use-viewer'
|
import useViewer from '../../store/use-viewer'
|
||||||
import polygonClipping from 'polygon-clipping'
|
|
||||||
|
|
||||||
export const GroundOccluder = () => {
|
export const GroundOccluder = () => {
|
||||||
const theme = useViewer((state) => state.theme)
|
const theme = useViewer((state) => state.theme)
|
||||||
const bgColor = theme === 'dark' ? '#1f2433' : '#fafafa'
|
const bgColor = theme === 'dark' ? '#1f2433' : '#fafafa'
|
||||||
|
|
||||||
const nodes = useScene((state) => state.nodes)
|
const nodes = useScene((state) => state.nodes)
|
||||||
|
|
||||||
const shape = useMemo(() => {
|
const shape = useMemo(() => {
|
||||||
@@ -22,17 +22,17 @@ export const GroundOccluder = () => {
|
|||||||
|
|
||||||
// Collect all polygons for slabs and zones
|
// Collect all polygons for slabs and zones
|
||||||
const polygons: [number, number][][] = []
|
const polygons: [number, number][][] = []
|
||||||
|
|
||||||
Object.values(nodes).forEach((node) => {
|
Object.values(nodes).forEach((node) => {
|
||||||
if ((node.type === 'slab' || node.type === 'zone') && node.polygon && node.polygon.length >= 3) {
|
if (node.type === 'slab' && node.polygon && node.polygon.length >= 3) {
|
||||||
polygons.push(node.polygon as [number, number][])
|
polygons.push(node.polygon as [number, number][])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (polygons.length > 0) {
|
if (polygons.length > 0) {
|
||||||
// Format for polygon-clipping: [[[x, y], [x, y], ...]]
|
// Format for polygon-clipping: [[[x, y], [x, y], ...]]
|
||||||
const multiPolygons = polygons.map(pts => {
|
const multiPolygons = polygons.map((pts) => {
|
||||||
const ring = pts.map(p => [p[0], -p[1]] as [number, number]) // Negate Y (which was Z)
|
const ring = pts.map((p) => [p[0], -p[1]] as [number, number]) // Negate Y (which was Z)
|
||||||
return [ring]
|
return [ring]
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export const GroundOccluder = () => {
|
|||||||
if (geom.length > 0) {
|
if (geom.length > 0) {
|
||||||
const ring = geom[0]!
|
const ring = geom[0]!
|
||||||
const hole = new THREE.Path()
|
const hole = new THREE.Path()
|
||||||
|
|
||||||
if (ring.length > 0) {
|
if (ring.length > 0) {
|
||||||
hole.moveTo(ring[0]![0], ring[0]![1])
|
hole.moveTo(ring[0]![0], ring[0]![1])
|
||||||
for (let i = 1; i < ring.length; i++) {
|
for (let i = 1; i < ring.length; i++) {
|
||||||
@@ -64,8 +64,8 @@ export const GroundOccluder = () => {
|
|||||||
return (
|
return (
|
||||||
<mesh rotation-x={-Math.PI / 2} position-y={-0.05}>
|
<mesh rotation-x={-Math.PI / 2} position-y={-0.05}>
|
||||||
<shapeGeometry args={[shape]} />
|
<shapeGeometry args={[shape]} />
|
||||||
<meshBasicMaterial
|
<meshBasicMaterial
|
||||||
color={bgColor}
|
color={bgColor}
|
||||||
depthWrite={true}
|
depthWrite={true}
|
||||||
polygonOffset={true}
|
polygonOffset={true}
|
||||||
polygonOffsetFactor={1}
|
polygonOffsetFactor={1}
|
||||||
|
|||||||
Reference in New Issue
Block a user