From b73315791ccbea45ebd5ec667e6564b4cf2db698 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Thu, 3 Sep 2026 15:19:50 +0530 Subject: [PATCH] fix: Use native GLTF material when mappingType is 'uv' to preserve exact original UV mappings and texture orientations --- src/components/ModelViewer.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/ModelViewer.tsx b/src/components/ModelViewer.tsx index 0289cd8..73dc635 100644 --- a/src/components/ModelViewer.tsx +++ b/src/components/ModelViewer.tsx @@ -58,7 +58,7 @@ const MeshMaterialManager = ({ mesh, sceneObj, textureCache }: MeshMaterialManag activeMat.triplanarUniforms.uTriplanarScale.value = uvScale; activeMat.triplanarUniforms.uBlendSharpness.value = 5.0; // Default or from props - } else { + } else if (mappingType !== 'uv') { activeMat = MaterialFactory.getInstance().getStandardUVMaterial( baseParams, mesh.uuid @@ -71,6 +71,9 @@ const MeshMaterialManager = ({ mesh, sceneObj, textureCache }: MeshMaterialManag activeMat.uvUniforms.uMappingMode.value = modeIndex; activeMat.updateUVTransform(uvOffset, [uvTiling[0] * uvScale, uvTiling[1] * uvScale], uvRotation * (Math.PI / 180)); + } else { + // Use the native material to preserve exact GLTF UV behavior + activeMat = origMat; } // Apply basic props @@ -117,6 +120,14 @@ const MeshMaterialManager = ({ mesh, sceneObj, textureCache }: MeshMaterialManag if (mappingType === 'triplanar') activeMat.triplanarUniforms['t' + type.charAt(0).toUpperCase() + type.slice(1).replace('Map', '')].value = null; activeMat.needsUpdate = true; } + + // Native UV mapping transforms + if (mappingType === 'uv' && activeMat[type]) { + activeMat[type].repeat.set(uvTiling[0] * uvScale, uvTiling[1] * uvScale); + activeMat[type].offset.set(uvOffset[0], uvOffset[1]); + activeMat[type].rotation = uvRotation * (Math.PI / 180); + activeMat[type].needsUpdate = true; + } }); mesh.visible = sceneObj.visible;