Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import trimesh
|
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
import tempfile
|
6 |
-
import os
|
7 |
|
8 |
def visualize_texture(section):
|
9 |
# Load the original mesh
|
@@ -31,23 +30,16 @@ def visualize_texture(section):
|
|
31 |
# Get indices for the selected section
|
32 |
selected_indices = sections[section]
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
original_colors = mesh.visual.vertex_colors
|
37 |
|
38 |
-
#
|
39 |
-
new_uv = np.
|
40 |
-
new_uv[selected_indices, :] =
|
41 |
-
updated_vertex_colors = np.copy(original_colors)
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
for index in selected_indices:
|
47 |
-
updated_vertex_colors[index] = blend_factor * new_texture.image[index % new_texture.image.shape[0], index % new_texture.image.shape[1]] + (1 - blend_factor) * original_colors[index]
|
48 |
-
|
49 |
-
# Create a texture visual with blended colors and updated UVs
|
50 |
-
color_visuals = trimesh.visual.TextureVisuals(uv=new_uv, vertex_colors=updated_vertex_colors, material=new_texture)
|
51 |
|
52 |
# Create a new mesh with the visual
|
53 |
textured_mesh = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, visual=color_visuals, validate=True, process=False)
|
|
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
import tempfile
|
|
|
6 |
|
7 |
def visualize_texture(section):
|
8 |
# Load the original mesh
|
|
|
30 |
# Get indices for the selected section
|
31 |
selected_indices = sections[section]
|
32 |
|
33 |
+
# Initialize the UV map with the original values
|
34 |
+
original_uv = mesh.visual.uv if mesh.visual.uv is not None else np.random.rand(len(mesh.vertices), 2)
|
|
|
35 |
|
36 |
+
# Initialize a new UV map and keep the original values for non-selected vertices
|
37 |
+
new_uv = np.copy(original_uv)
|
38 |
+
new_uv[selected_indices, :] = np.random.rand(len(selected_indices), 2) # Randomized UV for the selected section
|
|
|
39 |
|
40 |
+
# Create material and apply texture only to the selected section
|
41 |
+
material = trimesh.visual.texture.SimpleMaterial(image=im)
|
42 |
+
color_visuals = trimesh.visual.TextureVisuals(uv=new_uv, material=material)
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# Create a new mesh with the visual
|
45 |
textured_mesh = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, visual=color_visuals, validate=True, process=False)
|