Added Wireframe mode in Mesh Previewer
This commit is contained in:
parent
4558969b6c
commit
e66c0c3fcd
2 changed files with 44 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ export default function MeshPreviewDialog({ asset, titleId = 'mesh-preview-dialo
|
|||
const [showGrid, setShowGrid] = useState(true)
|
||||
const [showShadows, setShowShadows] = useState(false)
|
||||
const [showAlbedo, setShowAlbedo] = useState(false)
|
||||
const [showWireframe, setShowWireframe] = useState(false)
|
||||
const [showLightSlider, setShowLightSlider] = useState(false)
|
||||
const [lightIntensity, setLightIntensity] = useState(2.2)
|
||||
const [showExport, setShowExport] = useState(false)
|
||||
|
|
@ -46,6 +47,15 @@ export default function MeshPreviewDialog({ asset, titleId = 'mesh-preview-dialo
|
|||
>
|
||||
A
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`mesh-preview-dialog__tool ${showWireframe ? 'mesh-preview-dialog__tool--active' : ''}`}
|
||||
onClick={() => setShowWireframe(current => !current)}
|
||||
aria-pressed={showWireframe}
|
||||
title="Toggle wireframe"
|
||||
>
|
||||
W
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`mesh-preview-dialog__tool ${showGrid ? 'mesh-preview-dialog__tool--active' : ''}`}
|
||||
|
|
@ -93,6 +103,7 @@ export default function MeshPreviewDialog({ asset, titleId = 'mesh-preview-dialo
|
|||
showGrid={showGrid}
|
||||
showShadows={showShadows}
|
||||
showAlbedo={showAlbedo}
|
||||
showWireframe={showWireframe}
|
||||
lightIntensity={lightIntensity}
|
||||
fitMode="center"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -184,6 +184,36 @@ function applyDisplayMaterial(object, showNormals, showShadows, showAlbedo) {
|
|||
})
|
||||
}
|
||||
|
||||
function applyWireframeOverlay(object, showWireframe) {
|
||||
if (!showWireframe || !object) {
|
||||
return
|
||||
}
|
||||
|
||||
const meshes = []
|
||||
object.traverse(child => {
|
||||
if (child.isMesh && child.geometry) {
|
||||
meshes.push(child)
|
||||
}
|
||||
})
|
||||
|
||||
meshes.forEach(mesh => {
|
||||
const overlay = new THREE.Mesh(
|
||||
mesh.geometry,
|
||||
new THREE.MeshBasicMaterial({
|
||||
color: '#ffffff',
|
||||
wireframe: true,
|
||||
transparent: true,
|
||||
opacity: 0.36,
|
||||
depthWrite: false
|
||||
})
|
||||
)
|
||||
overlay.castShadow = false
|
||||
overlay.receiveShadow = false
|
||||
overlay.userData.isWireframeOverlay = true
|
||||
mesh.add(overlay)
|
||||
})
|
||||
}
|
||||
|
||||
async function loadModelFromUrl(url, fitMode = 'ground') {
|
||||
const extension = getExtensionFromUrl(url)
|
||||
|
||||
|
|
@ -249,6 +279,7 @@ export default function Viewer({
|
|||
showGrid = true,
|
||||
showShadows = true,
|
||||
showAlbedo = false,
|
||||
showWireframe = false,
|
||||
lightIntensity = 2.2,
|
||||
fitMode = 'ground'
|
||||
}) {
|
||||
|
|
@ -294,8 +325,9 @@ export default function Viewer({
|
|||
|
||||
const modelClone = modelState.object.clone(true)
|
||||
applyDisplayMaterial(modelClone, showNormals, showShadows, showAlbedo)
|
||||
applyWireframeOverlay(modelClone, showWireframe)
|
||||
return modelClone
|
||||
}, [modelState, modelUrl, showNormals, showShadows, showAlbedo])
|
||||
}, [modelState, modelUrl, showNormals, showShadows, showAlbedo, showWireframe])
|
||||
|
||||
const cameraTarget = modelState?.modelUrl === modelUrl ? modelState.target : new THREE.Vector3(0, 0.75, 0)
|
||||
const cameraPosition = modelState?.modelUrl === modelUrl ? modelState.cameraPosition : new THREE.Vector3(3, 3, 5)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue