Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ def apply_masked_visuals(section):
|
|
9 |
mesh = trimesh.load('train.glb', force='mesh')
|
10 |
im = Image.open('rust_steel.png').convert('RGB')
|
11 |
|
12 |
-
# Calculate bounding box coordinates
|
13 |
bounds = mesh.bounds
|
14 |
min_bounds, max_bounds = bounds[0], bounds[1]
|
15 |
mid_x = (max_bounds[0] + min_bounds[0]) / 2
|
@@ -30,17 +30,15 @@ def apply_masked_visuals(section):
|
|
30 |
# Select the indices for the specified section
|
31 |
selected_indices = sections[section]
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
visual = mesh.visual.copy()
|
36 |
-
visual.update_vertices(mask=np.isin(range(len(mesh.vertices)), selected_indices))
|
37 |
-
else:
|
38 |
-
visual = trimesh.visual.ColorVisuals(vertex_colors=np.ones((len(mesh.vertices), 4)) * 255)
|
39 |
|
40 |
-
#
|
41 |
-
uv = np.
|
|
|
|
|
42 |
new_uv = np.copy(uv)
|
43 |
-
new_uv[
|
44 |
|
45 |
# Create a new material with the image texture
|
46 |
material = trimesh.visual.texture.SimpleMaterial(image=im)
|
|
|
9 |
mesh = trimesh.load('train.glb', force='mesh')
|
10 |
im = Image.open('rust_steel.png').convert('RGB')
|
11 |
|
12 |
+
# Calculate the bounding box coordinates
|
13 |
bounds = mesh.bounds
|
14 |
min_bounds, max_bounds = bounds[0], bounds[1]
|
15 |
mid_x = (max_bounds[0] + min_bounds[0]) / 2
|
|
|
30 |
# Select the indices for the specified section
|
31 |
selected_indices = sections[section]
|
32 |
|
33 |
+
# Ensure that all indices are valid
|
34 |
+
valid_indices = selected_indices[selected_indices < len(mesh.vertices)]
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
# Create or re-initialize the UV array
|
37 |
+
uv = np.random.rand(len(mesh.vertices), 2)
|
38 |
+
|
39 |
+
# Generate new UV coordinates only for the selected section
|
40 |
new_uv = np.copy(uv)
|
41 |
+
new_uv[valid_indices, :] = np.random.rand(len(valid_indices), 2)
|
42 |
|
43 |
# Create a new material with the image texture
|
44 |
material = trimesh.visual.texture.SimpleMaterial(image=im)
|