import React from 'react'
import { useGLTF, useTexture } from '@react-three/drei'
import * as THREE from 'three'
export default function Model(props) {
const { nodes } = useGLTF('/model.glb')
// Load the texture for the keyboard and mouse
const keyboardMouseTexture = useTexture('/Textures/test.jpg')
// Adjust texture properties based on UV map analysis
keyboardMouseTexture.wrapS = keyboardMouseTexture.wrapT = THREE.RepeatWrapping
keyboardMouseTexture.repeat.set(1.2, 1.2) // No scaling needed
keyboardMouseTexture.offset.set(2, 5) // Example values to adjust the position
keyboardMouseTexture.center.set(1, 1)
keyboardMouseTexture.rotation = Math.PI / 2
return (
<group {...props} dispose={null}>
<group rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
{/* Monitor */}
<mesh geometry={nodes.BackPowerButton.geometry} material={nodes.BackPowerButton.material}>
{/* Texture settings for the monitor can be added here similarly */}
</mesh>
<mesh geometry={nodes.Body001.geometry} material={nodes.Body001.material}>
{/* Texture settings for the monitor can be added here similarly */}
</mesh>
<mesh geometry={nodes.BrightnessKnob.geometry} material={nodes.BrightnessKnob.material}>
{/* Texture settings for the monitor can be added here similarly */}
</mesh>
<mesh geometry={nodes.Screen.geometry} material={nodes.Screen.material}>
{/* Texture settings for the monitor can be added here similarly */}
</mesh>
{/* Keyboard */}
<mesh geometry={nodes.Keyboard001.geometry} material={nodes.Keyboard001.material}>
<meshStandardMaterial map={keyboardMouseTexture} />
</mesh>
{[
'A', 'B', 'Backspace', 'BracketClose', 'BracketOpen', 'C', 'CapsLock', 'Colon',
'Command', 'D', 'E', 'Eight', 'Enter', 'F', 'Five', 'ForwardSlash', 'Four', 'G',
'GreaterThan', 'H', 'I', 'J', 'K', 'L', 'LessThan', 'M', 'Minus', 'N', 'Nine', 'O',
'One', 'Option_L', 'Option_R', 'P', 'Plus', 'Q', 'QuestionMark', 'Quotes', 'R',
'Return', 'S', 'Seven', 'Shift_L', 'Shift_R', 'Six', 'Spacebar', 'T', 'Tab', 'Three',
'Tilde', 'Two', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Zero'
].map(key => (
<mesh key={key} geometry={nodes[key].geometry} material={nodes[key].material}>
<meshStandardMaterial map={keyboardMouseTexture} />
</mesh>
))}
{/* Mouse */}
<mesh geometry={nodes.MouseBody.geometry} material={nodes.MouseBody.material}>
<meshStandardMaterial map={keyboardMouseTexture} />
</mesh>
<mesh geometry={nodes.MouseButton.geometry} material={nodes.MouseButton.material}>
<meshStandardMaterial map={keyboardMouseTexture} />
</mesh>
</group>
</group>
)
}
useGLTF.preload('/model.glb')
The texture applies perfectly in blender but even though I have tried editing and aligning it manually, it is not getting aligned properly. I’m very new to ThreeJs and have no idea what to do.