Spaces:
Runtime error
Runtime error
File size: 1,248 Bytes
c79165d c2bccfe 08602a0 c79165d c2bccfe c79165d 4d4ba0c c2bccfe 08602a0 c2bccfe 4d4ba0c 1538180 4d4ba0c 1538180 c2bccfe 1538180 c2bccfe f536866 c2bccfe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import gradio as gr
import trimesh
import numpy as np
from PIL import Image
import io
def visualize_texture():
# Load the GLB file
mesh = trimesh.load('train.glb', force='mesh')
# Load the texture image
im = Image.open('defect.jpg')
im = im.convert('RGB') # Ensure the image is in RGB format
# Create random UV coordinates for the mesh
uv = np.random.rand(len(mesh.vertices), 2)
# Create material and apply texture
material = trimesh.visual.texture.SimpleMaterial(image=im)
color_visuals = trimesh.visual.TextureVisuals(uv=uv, image=im, material=material)
# Apply the texture to the original mesh
textured_mesh = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, visual=color_visuals, validate=True, process=False)
# Export the modified model to a file
textured_mesh.export('trainm.glb')
# Return the file path
return 'trainm.glb'
with gr.Blocks() as app:
gr.Markdown("### 3D Model Texture Application")
original_model = gr.Model3D('train.glb', label="Original Model")
modified_model = gr.Model3D(label="Textured Model")
button = gr.Button("Visualize Texture")
button.click(visualize_texture, outputs=[modified_model])
app.launch()
|