Added a switch button for Albedo/PBR
This commit is contained in:
parent
f1b69f64a1
commit
bffb4febbd
4 changed files with 159 additions and 21 deletions
|
|
@ -43,8 +43,14 @@
|
|||
},
|
||||
"4": {
|
||||
"inputs": {
|
||||
"width": 1024,
|
||||
"height": 1024,
|
||||
"width": [
|
||||
"9",
|
||||
0
|
||||
],
|
||||
"height": [
|
||||
"9",
|
||||
0
|
||||
],
|
||||
"batch_size": 1,
|
||||
"color": 16777215
|
||||
},
|
||||
|
|
@ -58,7 +64,7 @@
|
|||
"filename_prefix": "MeshWithUV",
|
||||
"file_format": "glb",
|
||||
"trimesh": [
|
||||
"3",
|
||||
"8",
|
||||
0
|
||||
]
|
||||
},
|
||||
|
|
@ -79,5 +85,49 @@
|
|||
"_meta": {
|
||||
"title": "Preview 3D & Animation"
|
||||
}
|
||||
},
|
||||
"7": {
|
||||
"inputs": {
|
||||
"width": [
|
||||
"9",
|
||||
0
|
||||
],
|
||||
"height": [
|
||||
"9",
|
||||
0
|
||||
],
|
||||
"batch_size": 1,
|
||||
"color": 16777215
|
||||
},
|
||||
"class_type": "EmptyImage",
|
||||
"_meta": {
|
||||
"title": "EmptyImage"
|
||||
}
|
||||
},
|
||||
"8": {
|
||||
"inputs": {
|
||||
"texture": "metallic_roughness",
|
||||
"trimesh": [
|
||||
"3",
|
||||
0
|
||||
],
|
||||
"image": [
|
||||
"7",
|
||||
0
|
||||
]
|
||||
},
|
||||
"class_type": "Hy3DSetMeshPBRTextures",
|
||||
"_meta": {
|
||||
"title": "Hy3D Set Mesh PBR Textures"
|
||||
}
|
||||
},
|
||||
"9": {
|
||||
"inputs": {
|
||||
"value": 2048
|
||||
},
|
||||
"class_type": "PrimitiveInt",
|
||||
"_meta": {
|
||||
"title": "Texture Resolution"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ export default function MeshPreviewDialog({ asset, titleId = 'mesh-preview-dialo
|
|||
const [showNormals, setShowNormals] = useState(false)
|
||||
const [showGrid, setShowGrid] = useState(true)
|
||||
const [showShadows, setShowShadows] = useState(false)
|
||||
const [showAlbedo, setShowAlbedo] = useState(false)
|
||||
const [showLightSlider, setShowLightSlider] = useState(false)
|
||||
const [lightIntensity, setLightIntensity] = useState(2.2)
|
||||
|
||||
|
|
@ -34,6 +35,15 @@ export default function MeshPreviewDialog({ asset, titleId = 'mesh-preview-dialo
|
|||
>
|
||||
N
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`mesh-preview-dialog__tool ${showAlbedo ? 'mesh-preview-dialog__tool--active' : ''}`}
|
||||
onClick={() => setShowAlbedo(current => !current)}
|
||||
aria-pressed={showAlbedo}
|
||||
title="Toggle albedo (unlit) / PBR"
|
||||
>
|
||||
A
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`mesh-preview-dialog__tool ${showGrid ? 'mesh-preview-dialog__tool--active' : ''}`}
|
||||
|
|
@ -80,6 +90,7 @@ export default function MeshPreviewDialog({ asset, titleId = 'mesh-preview-dialo
|
|||
showNormals={showNormals}
|
||||
showGrid={showGrid}
|
||||
showShadows={showShadows}
|
||||
showAlbedo={showAlbedo}
|
||||
lightIntensity={lightIntensity}
|
||||
fitMode="center"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -120,7 +120,29 @@ function loadWithLoader(loader, url) {
|
|||
})
|
||||
}
|
||||
|
||||
function applyDisplayMaterial(object, showNormals, showShadows) {
|
||||
function buildAlbedoMaterial(sourceMaterial) {
|
||||
const params = {}
|
||||
if (sourceMaterial?.color?.isColor) {
|
||||
params.color = sourceMaterial.color.clone()
|
||||
} else if (sourceMaterial?.color) {
|
||||
params.color = new THREE.Color(sourceMaterial.color)
|
||||
} else {
|
||||
params.color = new THREE.Color('#ffffff')
|
||||
}
|
||||
if (sourceMaterial?.map) {
|
||||
params.map = sourceMaterial.map
|
||||
}
|
||||
if (sourceMaterial?.transparent) {
|
||||
params.transparent = true
|
||||
params.opacity = sourceMaterial.opacity ?? 1
|
||||
}
|
||||
if (typeof sourceMaterial?.side === 'number') {
|
||||
params.side = sourceMaterial.side
|
||||
}
|
||||
return new THREE.MeshBasicMaterial(params)
|
||||
}
|
||||
|
||||
function applyDisplayMaterial(object, showNormals, showShadows, showAlbedo) {
|
||||
object?.traverse(child => {
|
||||
if (!child.isMesh) {
|
||||
return
|
||||
|
|
@ -142,6 +164,20 @@ function applyDisplayMaterial(object, showNormals, showShadows) {
|
|||
return
|
||||
}
|
||||
|
||||
if (showAlbedo) {
|
||||
if (!child.userData.albedoMat) {
|
||||
const source = child.userData.originalMat
|
||||
if (Array.isArray(source)) {
|
||||
child.userData.albedoMat = source.map(buildAlbedoMaterial)
|
||||
} else {
|
||||
child.userData.albedoMat = buildAlbedoMaterial(source)
|
||||
}
|
||||
}
|
||||
|
||||
child.material = child.userData.albedoMat
|
||||
return
|
||||
}
|
||||
|
||||
if (child.userData.originalMat) {
|
||||
child.material = child.userData.originalMat
|
||||
}
|
||||
|
|
@ -212,6 +248,7 @@ export default function Viewer({
|
|||
showNormals = false,
|
||||
showGrid = true,
|
||||
showShadows = true,
|
||||
showAlbedo = false,
|
||||
lightIntensity = 2.2,
|
||||
fitMode = 'ground'
|
||||
}) {
|
||||
|
|
@ -256,9 +293,9 @@ export default function Viewer({
|
|||
}
|
||||
|
||||
const modelClone = modelState.object.clone(true)
|
||||
applyDisplayMaterial(modelClone, showNormals, showShadows)
|
||||
applyDisplayMaterial(modelClone, showNormals, showShadows, showAlbedo)
|
||||
return modelClone
|
||||
}, [modelState, modelUrl, showNormals, showShadows])
|
||||
}, [modelState, modelUrl, showNormals, showShadows, showAlbedo])
|
||||
|
||||
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)
|
||||
|
|
@ -300,7 +337,7 @@ export default function Viewer({
|
|||
/>
|
||||
)}
|
||||
</Suspense>
|
||||
<Environment preset="night" />
|
||||
<Environment preset="studio" />
|
||||
<CameraController autoRotate={!modelUrl} target={cameraTarget} cameraPosition={cameraPosition} />
|
||||
</Canvas>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1929,7 +1929,7 @@ function CameraRig({ geometry, frameKey, onCameraReady, controlsEnabled = true,
|
|||
)
|
||||
}
|
||||
|
||||
function EditorMesh({ geometry, selectedFaceIndices, selectedVertexIndices, showShadows = false }) {
|
||||
function EditorMesh({ geometry, selectedFaceIndices, selectedVertexIndices, showShadows = false, showAlbedo = false }) {
|
||||
const faceSelectionGeometry = useMemo(() => getFaceSelectionGeometry(geometry, selectedFaceIndices), [geometry, selectedFaceIndices])
|
||||
const selectedVertexPositions = useMemo(() => getVertexSelectionPositions(geometry, selectedVertexIndices), [geometry, selectedVertexIndices])
|
||||
const selectedVertexVectors = useMemo(() => {
|
||||
|
|
@ -1951,7 +1951,9 @@ function EditorMesh({ geometry, selectedFaceIndices, selectedVertexIndices, show
|
|||
return (
|
||||
<group>
|
||||
<mesh geometry={geometry} castShadow={showShadows} receiveShadow={showShadows}>
|
||||
<meshStandardMaterial color="#a9b6ff" metalness={0.08} roughness={0.62} />
|
||||
{showAlbedo
|
||||
? <meshBasicMaterial color="#a9b6ff" />
|
||||
: <meshStandardMaterial color="#a9b6ff" metalness={0.08} roughness={0.62} />}
|
||||
</mesh>
|
||||
<mesh geometry={geometry}>
|
||||
<meshBasicMaterial color="#ffffff" wireframe transparent opacity={0.36} />
|
||||
|
|
@ -2108,7 +2110,7 @@ function BooleanPreviewMesh({
|
|||
)
|
||||
}
|
||||
|
||||
function TexturedMesh({ root, textureKey, displayTexture, showShadows = false }) {
|
||||
function TexturedMesh({ root, textureKey, displayTexture, showShadows = false, showAlbedo = false }) {
|
||||
const baseObject = useMemo(() => {
|
||||
if (!root || !displayTexture) {
|
||||
return null
|
||||
|
|
@ -2117,6 +2119,40 @@ function TexturedMesh({ root, textureKey, displayTexture, showShadows = false })
|
|||
const object = root.clone(true)
|
||||
const materials = []
|
||||
|
||||
const buildMaterial = sourceMaterial => {
|
||||
const isTargetTexture = sourceMaterial && getTextureKeyFromMaterial(sourceMaterial) === textureKey
|
||||
|
||||
if (showAlbedo) {
|
||||
const params = {}
|
||||
if (sourceMaterial?.color?.isColor) {
|
||||
params.color = sourceMaterial.color.clone()
|
||||
} else if (sourceMaterial?.color) {
|
||||
params.color = new THREE.Color(sourceMaterial.color)
|
||||
} else {
|
||||
params.color = new THREE.Color('#ffffff')
|
||||
}
|
||||
const albedoMap = isTargetTexture ? displayTexture : (sourceMaterial?.map || null)
|
||||
if (albedoMap) {
|
||||
params.map = albedoMap
|
||||
}
|
||||
if (sourceMaterial?.transparent) {
|
||||
params.transparent = true
|
||||
params.opacity = sourceMaterial.opacity ?? 1
|
||||
}
|
||||
if (typeof sourceMaterial?.side === 'number') {
|
||||
params.side = sourceMaterial.side
|
||||
}
|
||||
return new THREE.MeshBasicMaterial(params)
|
||||
}
|
||||
|
||||
const nextMaterial = sourceMaterial?.clone?.() || sourceMaterial
|
||||
if (nextMaterial && isTargetTexture) {
|
||||
nextMaterial.map = displayTexture
|
||||
nextMaterial.needsUpdate = true
|
||||
}
|
||||
return nextMaterial
|
||||
}
|
||||
|
||||
object.traverse(child => {
|
||||
if (!child.isMesh) {
|
||||
return
|
||||
|
|
@ -2127,11 +2163,7 @@ function TexturedMesh({ root, textureKey, displayTexture, showShadows = false })
|
|||
|
||||
if (Array.isArray(child.material)) {
|
||||
child.material = child.material.map(material => {
|
||||
const nextMaterial = material?.clone?.() || material
|
||||
if (nextMaterial && getTextureKeyFromMaterial(material) === textureKey) {
|
||||
nextMaterial.map = displayTexture
|
||||
nextMaterial.needsUpdate = true
|
||||
}
|
||||
const nextMaterial = buildMaterial(material)
|
||||
if (nextMaterial) {
|
||||
materials.push(nextMaterial)
|
||||
}
|
||||
|
|
@ -2140,11 +2172,7 @@ function TexturedMesh({ root, textureKey, displayTexture, showShadows = false })
|
|||
return
|
||||
}
|
||||
|
||||
const nextMaterial = child.material?.clone?.() || child.material
|
||||
if (nextMaterial && getTextureKeyFromMaterial(child.material) === textureKey) {
|
||||
nextMaterial.map = displayTexture
|
||||
nextMaterial.needsUpdate = true
|
||||
}
|
||||
const nextMaterial = buildMaterial(child.material)
|
||||
child.material = nextMaterial
|
||||
if (nextMaterial) {
|
||||
materials.push(nextMaterial)
|
||||
|
|
@ -2153,7 +2181,7 @@ function TexturedMesh({ root, textureKey, displayTexture, showShadows = false })
|
|||
|
||||
object.userData.meshEditorMaterials = materials
|
||||
return object
|
||||
}, [displayTexture, root, showShadows, textureKey])
|
||||
}, [displayTexture, root, showAlbedo, showShadows, textureKey])
|
||||
|
||||
useEffect(() => () => {
|
||||
baseObject?.userData?.meshEditorMaterials?.forEach(material => material?.dispose?.())
|
||||
|
|
@ -2641,6 +2669,7 @@ export default function MeshEditorPage() {
|
|||
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
const [showShadows, setShowShadows] = useState(false)
|
||||
const [showAlbedo, setShowAlbedo] = useState(false)
|
||||
const [activeMenu, setActiveMenu] = useState('modeling')
|
||||
const [geometry, setGeometry] = useState(null)
|
||||
const [texturableMesh, setTexturableMesh] = useState(null)
|
||||
|
|
@ -6912,6 +6941,15 @@ export default function MeshEditorPage() {
|
|||
>
|
||||
{showShadows ? 'Shadows on' : 'Shadows off'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`mesh-editor-btn ${showAlbedo ? 'mesh-editor-btn--secondary' : 'mesh-editor-btn--ghost'}`}
|
||||
onClick={() => setShowAlbedo(current => !current)}
|
||||
aria-pressed={showAlbedo}
|
||||
title="Toggle albedo (unlit) / PBR shading"
|
||||
>
|
||||
{showAlbedo ? 'Albedo' : 'PBR'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mesh-editor-toolbar__stats">
|
||||
|
|
@ -7993,6 +8031,7 @@ export default function MeshEditorPage() {
|
|||
textureKey={texturableMesh.textureKey}
|
||||
displayTexture={displayTextureRef.current}
|
||||
showShadows={showShadows}
|
||||
showAlbedo={showAlbedo}
|
||||
/>
|
||||
) : activeMenu === 'boolean' && booleanHasPreview && booleanMaskTexture ? (
|
||||
<BooleanPreviewMesh
|
||||
|
|
@ -8015,6 +8054,7 @@ export default function MeshEditorPage() {
|
|||
selectedFaceIndices={activeMenu === 'modeling' ? selectedFaceIndices : []}
|
||||
selectedVertexIndices={activeMenu === 'modeling' ? selectedVertexIndices : []}
|
||||
showShadows={showShadows}
|
||||
showAlbedo={showAlbedo}
|
||||
/>
|
||||
)}
|
||||
{activeMenu === 'boolean' && booleanHasPreview && (!booleanMaskTexture || booleanPlaceMode) && (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue