2025-08-08
3D models have always fascinated me. Using Tencent's Hunyuan3D 2.1, I generated a 3D mesh from a single photo and created textures for it. Finally, I integrated the model into my homepage using Three.js.
I used ComfyUI's img2img model to process my photo and generate a Nintendo Mii-style figure. Then, I used the ComfyUI-Hunyuan3D-2.1 pipeline to create a 3D mesh that captured my facial features.
To generate realistic textures, I encountered a PyTorch device mismatch error. The fix was ensuring consistent device usage in this file:
Before:
img = torch.from_numpy(img).permute(2, 0, 1).unsqueeze(0).contiguous().half().to("cuda")
After:
img = torch.from_numpy(img).permute(2, 0, 1).unsqueeze(0).contiguous().to(device=unet_device, dtype=unet_dtype)
With the 3D model ready, I used Three.js to display it on my homepage. Here's a simple example of loading a 3D model:
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const loader = new THREE.GLTFLoader();
loader.load('static/model/me.glb', (gltf) => {
scene.add(gltf.scene);
renderer.render(scene, camera);
});
Here's the actual 3D model you can interact with! Move your mouse around to see it follow your cursor:
The 3D model is now live on my homepage 😊.