Skip to content

Commit 7ce18f3

Browse files
bottlerfacebook-github-bot
authored andcommitted
TexturesAtlas in plotly
Summary: Lets a K=1 textures atlas be viewed in plotly. Fixes #916 . Test: Now get colored faces in ``` import torch from pytorch3d.utils import ico_sphere from pytorch3d.vis.plotly_vis import plot_batch_individually from pytorch3d.renderer import TexturesAtlas b = ico_sphere() face_colors = torch.rand(b.faces_padded().shape) tex = TexturesAtlas(face_colors[:,:,None,None]) b.textures=tex plot_batch_individually(b) ``` Reviewed By: gkioxari Differential Revision: D32190470 fbshipit-source-id: 258d30b7e9d79751a79db44684b5540657a2eff5
1 parent 5fbdb99 commit 7ce18f3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pytorch3d/vis/plotly_vis.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import plotly.graph_objects as go
1111
import torch
1212
from plotly.subplots import make_subplots
13-
from pytorch3d.renderer import RayBundle, TexturesVertex, ray_bundle_to_ray_points
13+
from pytorch3d.renderer import (
14+
RayBundle,
15+
TexturesAtlas,
16+
TexturesVertex,
17+
ray_bundle_to_ray_points,
18+
)
1419
from pytorch3d.renderer.camera_utils import camera_to_eye_at_up
1520
from pytorch3d.renderer.cameras import CamerasBase
1621
from pytorch3d.structures import Meshes, Pointclouds, join_meshes_as_scene
@@ -580,13 +585,19 @@ def _add_mesh_trace(
580585
mesh = mesh.detach().cpu()
581586
verts = mesh.verts_packed()
582587
faces = mesh.faces_packed()
583-
# If mesh has vertex colors defined as texture, use vertex colors
588+
# If mesh has vertex colors or face colors, use them
584589
# for figure, otherwise use plotly's default colors.
585590
verts_rgb = None
591+
faces_rgb = None
586592
if isinstance(mesh.textures, TexturesVertex):
587593
verts_rgb = mesh.textures.verts_features_packed()
588594
verts_rgb.clamp_(min=0.0, max=1.0)
589595
verts_rgb = torch.tensor(255.0) * verts_rgb
596+
if isinstance(mesh.textures, TexturesAtlas):
597+
atlas = mesh.textures.atlas_packed()
598+
# If K==1
599+
if atlas.shape[1] == 1 and atlas.shape[3] == 3:
600+
faces_rgb = atlas[:, 0, 0]
590601

591602
# Reposition the unused vertices to be "inside" the object
592603
# (i.e. they won't be visible in the plot).
@@ -602,6 +613,7 @@ def _add_mesh_trace(
602613
y=verts[:, 1],
603614
z=verts[:, 2],
604615
vertexcolor=verts_rgb,
616+
facecolor=faces_rgb,
605617
i=faces[:, 0],
606618
j=faces[:, 1],
607619
k=faces[:, 2],

0 commit comments

Comments
 (0)