shortcuts and deletion

This commit is contained in:
wass08
2026-01-23 10:30:24 +09:00
parent cc9d9916b7
commit 4f20586ae9
4 changed files with 132 additions and 9 deletions
@@ -2,10 +2,33 @@ import { type AnyNodeId, type ItemNode, useRegistry, useScene } from '@pascal-ap
import { Clone } from '@react-three/drei/core/Clone'
import { useGLTF } from '@react-three/drei/core/Gltf'
import { Suspense, useEffect, useRef } from 'react'
import type { Group, Mesh } from 'three'
import type { Group, Material, Mesh } from 'three'
import { MeshStandardNodeMaterial } from 'three/webgpu'
import { useNodeEvents } from '../../../hooks/use-node-events'
// Shared materials to avoid creating new instances for every mesh
const defaultMaterial = new MeshStandardNodeMaterial({
color: 0xffffff,
roughness: 0.8,
metalness: 0,
})
const glassMaterial = new MeshStandardNodeMaterial({
name: 'glass',
color: 'skyblue',
roughness: 0.8,
metalness: 0,
transparent: true,
opacity: 0.25,
})
const getMaterialForOriginal = (original: Material): MeshStandardNodeMaterial => {
if (original.name.toLowerCase() === 'glass') {
return glassMaterial
}
return defaultMaterial
}
export const ItemRenderer = ({ node }: { node: ItemNode }) => {
const ref = useRef<Group>(null!)
@@ -37,14 +60,21 @@ const ModelRenderer = ({ node }: { node: ItemNode }) => {
useEffect(() => {
scene.traverse((child) => {
if ((child as Mesh).isMesh) {
child.castShadow = true
child.receiveShadow = true
// TODO: do it with a shared material
child.material = new MeshStandardNodeMaterial({
color: 0xffffff,
roughness: 0.8,
metalness: 0,
})
const mesh = child as Mesh
if (mesh.name === 'cutout') {
child.visible = false
return
}
mesh.castShadow = true
mesh.receiveShadow = true
// Handle both single material and material array cases
if (Array.isArray(mesh.material)) {
mesh.material = mesh.material.map((mat) => getMaterialForOriginal(mat))
} else {
mesh.material = getMaterialForOriginal(mesh.material)
}
}
})
}, [scene])