Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
from PIL import Image
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
-
def
|
| 8 |
# Load the original mesh
|
| 9 |
mesh = trimesh.load('train.glb', force='mesh')
|
| 10 |
im = Image.open('rust_steel.png').convert('RGB')
|
|
@@ -30,17 +30,17 @@ def apply_texture_with_uv(section):
|
|
| 30 |
# Select the indices for the specified section
|
| 31 |
selected_indices = sections[section]
|
| 32 |
|
| 33 |
-
#
|
| 34 |
if mesh.visual.kind == 'texture':
|
| 35 |
-
original_uv = mesh.visual.uv
|
| 36 |
else:
|
| 37 |
-
original_uv = np.random.rand(len(mesh.vertices), 2)
|
| 38 |
|
| 39 |
-
#
|
| 40 |
new_uv = np.copy(original_uv)
|
| 41 |
-
new_uv[selected_indices, :] = np.random.rand(len(selected_indices), 2)
|
| 42 |
|
| 43 |
-
# Create a new material
|
| 44 |
material = trimesh.visual.texture.SimpleMaterial(image=im)
|
| 45 |
new_visuals = trimesh.visual.TextureVisuals(uv=new_uv, material=material)
|
| 46 |
|
|
@@ -60,6 +60,6 @@ with gr.Blocks() as app:
|
|
| 60 |
|
| 61 |
section_dropdown = gr.Dropdown(choices=['upper', 'lower', 'middle', 'top', 'right'], label="Select Section")
|
| 62 |
button = gr.Button("Apply Texture to Section")
|
| 63 |
-
button.click(
|
| 64 |
|
| 65 |
app.launch()
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
+
def apply_texture_to_selected(section):
|
| 8 |
# Load the original mesh
|
| 9 |
mesh = trimesh.load('train.glb', force='mesh')
|
| 10 |
im = Image.open('rust_steel.png').convert('RGB')
|
|
|
|
| 30 |
# Select the indices for the specified section
|
| 31 |
selected_indices = sections[section]
|
| 32 |
|
| 33 |
+
# Initialize the UV mapping with default or existing values
|
| 34 |
if mesh.visual.kind == 'texture':
|
| 35 |
+
original_uv = mesh.visual.uv
|
| 36 |
else:
|
| 37 |
+
original_uv = np.random.rand(len(mesh.vertices), 2)
|
| 38 |
|
| 39 |
+
# Generate new UV coordinates for the selected region only
|
| 40 |
new_uv = np.copy(original_uv)
|
| 41 |
+
new_uv[selected_indices, :] = np.random.rand(len(selected_indices), 2)
|
| 42 |
|
| 43 |
+
# Create a new material using the texture image
|
| 44 |
material = trimesh.visual.texture.SimpleMaterial(image=im)
|
| 45 |
new_visuals = trimesh.visual.TextureVisuals(uv=new_uv, material=material)
|
| 46 |
|
|
|
|
| 60 |
|
| 61 |
section_dropdown = gr.Dropdown(choices=['upper', 'lower', 'middle', 'top', 'right'], label="Select Section")
|
| 62 |
button = gr.Button("Apply Texture to Section")
|
| 63 |
+
button.click(apply_texture_to_selected, inputs=section_dropdown, outputs=modified_model)
|
| 64 |
|
| 65 |
app.launch()
|