Note
Go to the end to download the full example as a Python script or as a Jupyter notebook.
Surface with multiple textures#
This example demonstrates one possible method for displaying a 3D surface with multiple textures.
Thanks to Emmanuel Reynaud and Luis Gutierrez for providing the gorgeous coral model for this demo. You can find the data on FigShare: https://zenodo.org/records/13380203
More information on the methods used to generate this model can be found in L. Gutierrez-Heredia, C. Keogh, E. G. Reynaud, Assessing the Capabilities of Additive Manufacturing Technologies for Coral Studies, Education, and Monitoring. Front. Mar. Sci. 5 (2018), doi:10.3389/fmars.2018.00278.
A bit about 3D models#
A standard way to define a 3D model (mesh, or Surface in napari) is by listing vertices (3D point coordinates) and faces (triplets of vertex indices - each face is a triangle in 3D space). Meshes are often stored in “Wavefront” (.obj) files, which may have companion material (.mtl) files that describe some shading properties (base color, shinyness, etc.) for different parts of the model.
In some cases, the color of a vertex is given by a single point value that is then colormapped on the fly (vertex_values). In other cases, each vertex or face may be assigned a specific color (vertex_colors). These methods are demonstrated in Surface with texture and vertex_colors.
In the case of “photorealistic” models, the color of each vertex is instead determined by mapping a vertex to a point in an image called a texture using 2D texture coordinates in the range [0, 1]. The color of each individual pixel is smoothly interpolated (sampled) on the fly from the texture (the GPU makes this interpolation very fast).
Napari does not (yet) support models with multiple textures or materials. If the textures don’t overlap, you can display them on separate meshes as shown in this demo. If the textures do overlap, you may instead be able to combine the textures as images. This relies on textures having the same texture coordinates, and may require resizing the textures to match each other.
Download the model#
download = pooch.DOIDownloader(progressbar=True)
doi = '10.5281/zenodo.13380203'
tmp_dir = pooch.os_cache('napari-surface-texture-example')
os.makedirs(tmp_dir, exist_ok=True)
data_files = {
'mesh': 'PocilloporaDamicornisSkin.obj',
# "materials": "PocilloporaVerrugosaSkinCrop.mtl", # not yet supported
'Texture_0': 'PocilloporaDamicornisSkin_Texture_0.jpg',
'GeneratedMat2': 'PocilloporaDamicornisSkin_GeneratedMat2.png',
}
print(f'downloading data into {tmp_dir}')
for file_name in data_files.values():
if not (tmp_dir / file_name).exists():
print(f'downloading {file_name}')
download(
f'doi:{doi}/{file_name}',
output_file=tmp_dir / file_name,
pooch=None,
)
else:
print(f'using cached {tmp_dir / file_name}')
downloading data into /home/runner/.cache/napari-surface-texture-example
downloading PocilloporaDamicornisSkin.obj
0%| | 0.00/93.8M [00:00<?, ?B/s]
0%| | 32.8k/93.8M [00:00<06:36, 236kB/s]
0%| | 104k/93.8M [00:00<04:05, 382kB/s]
0%| | 268k/93.8M [00:00<02:29, 626kB/s]
0%|▏ | 447k/93.8M [00:00<02:03, 758kB/s]
1%|▎ | 660k/93.8M [00:00<01:44, 890kB/s]
1%|▎ | 841k/93.8M [00:01<01:42, 907kB/s]
1%|▍ | 1.04M/93.8M [00:01<01:38, 944kB/s]
1%|▌ | 1.25M/93.8M [00:01<01:32, 995kB/s]
2%|▌ | 1.44M/93.8M [00:01<01:32, 1.00MB/s]
2%|▋ | 1.67M/93.8M [00:01<01:26, 1.06MB/s]
2%|▋ | 1.85M/93.8M [00:02<01:30, 1.02MB/s]
2%|▊ | 2.10M/93.8M [00:02<01:23, 1.10MB/s]
2%|▉ | 2.33M/93.8M [00:02<01:21, 1.12MB/s]
3%|█ | 2.54M/93.8M [00:02<01:21, 1.11MB/s]
3%|█ | 2.75M/93.8M [00:02<01:21, 1.11MB/s]
3%|█▏ | 2.93M/93.8M [00:02<01:25, 1.06MB/s]
3%|█▏ | 3.11M/93.8M [00:03<01:28, 1.02MB/s]
4%|█▎ | 3.29M/93.8M [00:03<01:30, 995kB/s]
4%|█▍ | 3.51M/93.8M [00:03<01:27, 1.03MB/s]
4%|█▍ | 3.72M/93.8M [00:03<01:25, 1.05MB/s]
4%|█▌ | 3.96M/93.8M [00:03<01:20, 1.12MB/s]
4%|█▋ | 4.18M/93.8M [00:04<01:20, 1.11MB/s]
5%|█▋ | 4.39M/93.8M [00:04<01:20, 1.11MB/s]
5%|█▊ | 4.63M/93.8M [00:04<01:16, 1.16MB/s]
5%|█▉ | 4.90M/93.8M [00:04<01:12, 1.22MB/s]
6%|██ | 5.17M/93.8M [00:04<00:59, 1.50MB/s]
6%|██ | 5.34M/93.8M [00:05<01:08, 1.30MB/s]
6%|██▏ | 5.49M/93.8M [00:05<01:18, 1.12MB/s]
6%|██▏ | 5.68M/93.8M [00:05<01:21, 1.09MB/s]
6%|██▎ | 5.94M/93.8M [00:05<01:03, 1.38MB/s]
7%|██▍ | 6.10M/93.8M [00:05<01:13, 1.20MB/s]
7%|██▍ | 6.27M/93.8M [00:05<01:20, 1.09MB/s]
7%|██▌ | 6.53M/93.8M [00:06<01:14, 1.17MB/s]
7%|██▋ | 6.76M/93.8M [00:06<01:13, 1.18MB/s]
7%|██▊ | 6.97M/93.8M [00:06<01:15, 1.15MB/s]
8%|██▊ | 7.15M/93.8M [00:06<01:19, 1.09MB/s]
8%|██▉ | 7.33M/93.8M [00:06<01:23, 1.04MB/s]
8%|██▉ | 7.58M/93.8M [00:07<01:17, 1.11MB/s]
8%|███ | 7.79M/93.8M [00:07<01:17, 1.11MB/s]
9%|███▏ | 8.02M/93.8M [00:07<01:15, 1.13MB/s]
9%|███▏ | 8.23M/93.8M [00:07<01:16, 1.13MB/s]
9%|███▎ | 8.41M/93.8M [00:07<01:20, 1.07MB/s]
9%|███▍ | 8.57M/93.8M [00:08<01:25, 1.00MB/s]
9%|███▌ | 8.74M/93.8M [00:08<01:28, 957kB/s]
10%|███▌ | 8.95M/93.8M [00:08<01:24, 1.00MB/s]
10%|███▌ | 9.15M/93.8M [00:08<01:24, 1.01MB/s]
10%|███▋ | 9.34M/93.8M [00:08<01:23, 1.01MB/s]
10%|███▊ | 9.57M/93.8M [00:08<01:19, 1.06MB/s]
10%|███▊ | 9.79M/93.8M [00:09<01:18, 1.07MB/s]
11%|███▉ | 9.96M/93.8M [00:09<01:21, 1.03MB/s]
11%|████ | 10.2M/93.8M [00:09<01:12, 1.16MB/s]
11%|████▏ | 10.5M/93.8M [00:09<01:13, 1.14MB/s]
11%|████▏ | 10.6M/93.8M [00:09<01:17, 1.07MB/s]
12%|████▎ | 10.8M/93.8M [00:10<01:18, 1.05MB/s]
12%|████▎ | 11.0M/93.8M [00:10<01:19, 1.04MB/s]
12%|████▍ | 11.3M/93.8M [00:10<01:12, 1.14MB/s]
12%|████▌ | 11.5M/93.8M [00:10<01:09, 1.18MB/s]
13%|████▋ | 11.8M/93.8M [00:10<01:09, 1.18MB/s]
13%|████▋ | 12.0M/93.8M [00:11<01:10, 1.16MB/s]
13%|████▊ | 12.2M/93.8M [00:11<01:08, 1.19MB/s]
13%|████▉ | 12.4M/93.8M [00:11<01:11, 1.14MB/s]
13%|████▉ | 12.6M/93.8M [00:11<01:11, 1.13MB/s]
14%|█████ | 12.8M/93.8M [00:11<01:12, 1.12MB/s]
14%|█████▏ | 13.0M/93.8M [00:12<01:15, 1.06MB/s]
14%|█████▏ | 13.3M/93.8M [00:12<01:13, 1.10MB/s]
14%|█████▎ | 13.4M/93.8M [00:12<01:16, 1.05MB/s]
15%|█████▍ | 13.6M/93.8M [00:12<01:15, 1.06MB/s]
15%|█████▍ | 13.9M/93.8M [00:12<01:06, 1.20MB/s]
15%|█████▌ | 14.1M/93.8M [00:13<01:10, 1.12MB/s]
15%|█████▋ | 14.3M/93.8M [00:13<01:16, 1.04MB/s]
15%|█████▋ | 14.5M/93.8M [00:13<01:16, 1.03MB/s]
16%|█████▊ | 14.7M/93.8M [00:13<01:13, 1.08MB/s]
16%|█████▉ | 14.9M/93.8M [00:13<01:14, 1.06MB/s]
16%|█████▉ | 15.1M/93.8M [00:13<01:14, 1.05MB/s]
16%|██████ | 15.4M/93.8M [00:14<01:08, 1.14MB/s]
17%|██████▏ | 15.6M/93.8M [00:14<01:07, 1.16MB/s]
17%|██████▏ | 15.8M/93.8M [00:14<01:05, 1.19MB/s]
17%|██████▎ | 16.1M/93.8M [00:14<01:05, 1.19MB/s]
17%|██████▍ | 16.3M/93.8M [00:14<01:02, 1.24MB/s]
18%|██████▌ | 16.5M/93.8M [00:15<01:06, 1.17MB/s]
18%|██████▌ | 16.7M/93.8M [00:15<01:08, 1.13MB/s]
18%|██████▋ | 16.9M/93.8M [00:15<01:08, 1.12MB/s]
18%|██████▊ | 17.2M/93.8M [00:15<01:03, 1.21MB/s]
19%|██████▉ | 17.5M/93.8M [00:15<01:02, 1.23MB/s]
19%|██████▉ | 17.7M/93.8M [00:16<00:58, 1.29MB/s]
19%|███████ | 17.9M/93.8M [00:16<01:02, 1.21MB/s]
19%|███████▏ | 18.1M/93.8M [00:16<01:07, 1.13MB/s]
20%|███████▏ | 18.3M/93.8M [00:16<01:10, 1.07MB/s]
20%|███████▎ | 18.5M/93.8M [00:16<01:11, 1.05MB/s]
20%|███████▎ | 18.7M/93.8M [00:17<01:13, 1.02MB/s]
20%|███████▍ | 18.9M/93.8M [00:17<01:11, 1.04MB/s]
20%|███████▌ | 19.2M/93.8M [00:17<01:02, 1.19MB/s]
21%|███████▋ | 19.3M/93.8M [00:17<01:08, 1.09MB/s]
21%|███████▋ | 19.5M/93.8M [00:17<01:08, 1.09MB/s]
21%|███████▊ | 19.8M/93.8M [00:18<01:00, 1.22MB/s]
21%|███████▉ | 20.0M/93.8M [00:18<00:55, 1.34MB/s]
22%|███████▉ | 20.2M/93.8M [00:18<01:04, 1.13MB/s]
22%|████████ | 20.4M/93.8M [00:18<01:06, 1.10MB/s]
22%|████████▏ | 20.7M/93.8M [00:18<00:55, 1.31MB/s]
22%|████████▎ | 20.9M/93.8M [00:18<00:58, 1.25MB/s]
23%|████████▎ | 21.2M/93.8M [00:19<00:57, 1.26MB/s]
23%|████████▍ | 21.4M/93.8M [00:19<00:55, 1.31MB/s]
23%|████████▌ | 21.6M/93.8M [00:19<00:58, 1.22MB/s]
23%|████████▌ | 21.9M/93.8M [00:19<00:51, 1.39MB/s]
24%|████████▋ | 22.1M/93.8M [00:19<00:54, 1.32MB/s]
24%|████████▊ | 22.4M/93.8M [00:19<00:49, 1.44MB/s]
24%|████████▉ | 22.8M/93.8M [00:20<00:45, 1.55MB/s]
25%|█████████ | 23.0M/93.8M [00:20<00:47, 1.49MB/s]
25%|█████████▏ | 23.2M/93.8M [00:20<00:51, 1.37MB/s]
25%|█████████▎ | 23.5M/93.8M [00:20<00:52, 1.34MB/s]
25%|█████████▎ | 23.7M/93.8M [00:20<00:53, 1.32MB/s]
26%|█████████▍ | 24.0M/93.8M [00:21<00:49, 1.40MB/s]
26%|█████████▌ | 24.3M/93.8M [00:21<00:51, 1.34MB/s]
26%|█████████▋ | 24.6M/93.8M [00:21<00:47, 1.45MB/s]
26%|█████████▊ | 24.8M/93.8M [00:21<00:48, 1.42MB/s]
27%|█████████▉ | 25.1M/93.8M [00:21<00:50, 1.35MB/s]
27%|██████████ | 25.4M/93.8M [00:22<00:47, 1.45MB/s]
27%|██████████ | 25.6M/93.8M [00:22<00:51, 1.32MB/s]
28%|██████████▏ | 25.9M/93.8M [00:22<00:49, 1.36MB/s]
28%|██████████▎ | 26.1M/93.8M [00:22<00:53, 1.26MB/s]
28%|██████████▍ | 26.3M/93.8M [00:22<00:52, 1.29MB/s]
28%|██████████▌ | 26.7M/93.8M [00:22<00:40, 1.67MB/s]
29%|██████████▌ | 26.9M/93.8M [00:23<00:38, 1.72MB/s]
29%|██████████▋ | 27.1M/93.8M [00:23<00:44, 1.49MB/s]
29%|██████████▊ | 27.4M/93.8M [00:23<00:42, 1.56MB/s]
30%|██████████▉ | 27.7M/93.8M [00:23<00:43, 1.52MB/s]
30%|███████████ | 28.0M/93.8M [00:23<00:44, 1.49MB/s]
30%|███████████▏ | 28.3M/93.8M [00:23<00:33, 1.94MB/s]
30%|███████████▎ | 28.6M/93.8M [00:24<00:38, 1.68MB/s]
31%|███████████▎ | 28.8M/93.8M [00:24<00:43, 1.49MB/s]
31%|███████████▍ | 29.1M/93.8M [00:24<00:43, 1.50MB/s]
31%|███████████▌ | 29.3M/93.8M [00:24<00:44, 1.46MB/s]
32%|███████████▋ | 29.7M/93.8M [00:24<00:40, 1.58MB/s]
32%|███████████▉ | 30.2M/93.8M [00:25<00:32, 1.96MB/s]
33%|████████████ | 30.6M/93.8M [00:25<00:27, 2.28MB/s]
33%|████████████▏ | 30.8M/93.8M [00:25<00:32, 1.96MB/s]
33%|████████████▎ | 31.1M/93.8M [00:25<00:37, 1.68MB/s]
33%|████████████▍ | 31.4M/93.8M [00:25<00:36, 1.69MB/s]
34%|████████████▍ | 31.6M/93.8M [00:25<00:40, 1.53MB/s]
34%|████████████▌ | 32.0M/93.8M [00:26<00:32, 1.91MB/s]
34%|████████████▋ | 32.2M/93.8M [00:26<00:37, 1.65MB/s]
35%|████████████▊ | 32.4M/93.8M [00:26<00:42, 1.43MB/s]
35%|████████████▉ | 32.6M/93.8M [00:26<00:42, 1.42MB/s]
35%|█████████████ | 33.0M/93.8M [00:26<00:32, 1.89MB/s]
35%|█████████████ | 33.3M/93.8M [00:26<00:36, 1.65MB/s]
36%|█████████████▏ | 33.6M/93.8M [00:27<00:36, 1.66MB/s]
36%|█████████████▎ | 33.8M/93.8M [00:27<00:38, 1.56MB/s]
36%|█████████████▍ | 34.2M/93.8M [00:27<00:35, 1.66MB/s]
37%|█████████████▌ | 34.5M/93.8M [00:27<00:35, 1.67MB/s]
37%|█████████████▊ | 34.9M/93.8M [00:27<00:33, 1.76MB/s]
38%|█████████████▉ | 35.2M/93.8M [00:28<00:33, 1.76MB/s]
38%|██████████████ | 35.5M/93.8M [00:28<00:35, 1.64MB/s]
38%|██████████████▏ | 35.9M/93.8M [00:28<00:27, 2.13MB/s]
39%|██████████████▎ | 36.2M/93.8M [00:28<00:32, 1.78MB/s]
39%|██████████████▍ | 36.5M/93.8M [00:28<00:34, 1.66MB/s]
39%|██████████████▍ | 36.7M/93.8M [00:28<00:37, 1.52MB/s]
39%|██████████████▌ | 37.0M/93.8M [00:29<00:36, 1.57MB/s]
40%|██████████████▋ | 37.3M/93.8M [00:29<00:37, 1.50MB/s]
40%|██████████████▊ | 37.6M/93.8M [00:29<00:34, 1.61MB/s]
40%|██████████████▉ | 38.0M/93.8M [00:29<00:33, 1.66MB/s]
41%|███████████████ | 38.2M/93.8M [00:29<00:36, 1.52MB/s]
41%|███████████████▏ | 38.5M/93.8M [00:30<00:38, 1.44MB/s]
41%|███████████████▎ | 38.7M/93.8M [00:30<00:40, 1.37MB/s]
41%|███████████████▎ | 38.8M/93.8M [00:30<00:45, 1.21MB/s]
42%|███████████████▍ | 39.2M/93.8M [00:30<00:39, 1.38MB/s]
42%|███████████████▌ | 39.5M/93.8M [00:30<00:35, 1.52MB/s]
43%|███████████████▋ | 39.9M/93.8M [00:31<00:34, 1.55MB/s]
43%|███████████████▉ | 40.3M/93.8M [00:31<00:30, 1.77MB/s]
43%|███████████████▉ | 40.5M/93.8M [00:31<00:32, 1.62MB/s]
44%|████████████████▏ | 40.9M/93.8M [00:31<00:30, 1.75MB/s]
44%|████████████████▏ | 41.1M/93.8M [00:31<00:34, 1.53MB/s]
44%|████████████████▎ | 41.5M/93.8M [00:31<00:27, 1.89MB/s]
44%|████████████████▍ | 41.7M/93.8M [00:32<00:31, 1.63MB/s]
45%|████████████████▌ | 41.9M/93.8M [00:32<00:34, 1.48MB/s]
45%|████████████████▋ | 42.2M/93.8M [00:32<00:35, 1.44MB/s]
45%|████████████████▋ | 42.4M/93.8M [00:32<00:37, 1.36MB/s]
46%|████████████████▊ | 42.7M/93.8M [00:32<00:30, 1.68MB/s]
46%|████████████████▉ | 43.1M/93.8M [00:33<00:29, 1.73MB/s]
46%|█████████████████ | 43.3M/93.8M [00:33<00:33, 1.52MB/s]
46%|█████████████████▏ | 43.6M/93.8M [00:33<00:31, 1.58MB/s]
47%|█████████████████▎ | 43.9M/93.8M [00:33<00:31, 1.59MB/s]
47%|█████████████████▍ | 44.2M/93.8M [00:33<00:32, 1.52MB/s]
47%|█████████████████▌ | 44.5M/93.8M [00:33<00:32, 1.52MB/s]
48%|█████████████████▋ | 44.8M/93.8M [00:34<00:30, 1.60MB/s]
48%|█████████████████▊ | 45.2M/93.8M [00:34<00:29, 1.65MB/s]
48%|█████████████████▉ | 45.5M/93.8M [00:34<00:29, 1.64MB/s]
49%|██████████████████ | 45.7M/93.8M [00:34<00:32, 1.48MB/s]
49%|██████████████████▏ | 46.0M/93.8M [00:34<00:30, 1.57MB/s]
49%|██████████████████▎ | 46.3M/93.8M [00:35<00:30, 1.56MB/s]
50%|██████████████████▎ | 46.5M/93.8M [00:35<00:33, 1.42MB/s]
50%|██████████████████▍ | 46.9M/93.8M [00:35<00:30, 1.53MB/s]
50%|██████████████████▌ | 47.1M/93.8M [00:35<00:32, 1.43MB/s]
51%|██████████████████▋ | 47.4M/93.8M [00:35<00:31, 1.48MB/s]
51%|██████████████████▊ | 47.8M/93.8M [00:36<00:23, 1.97MB/s]
51%|██████████████████▉ | 48.1M/93.8M [00:36<00:25, 1.76MB/s]
51%|███████████████████ | 48.3M/93.8M [00:36<00:29, 1.52MB/s]
52%|███████████████████▏ | 48.7M/93.8M [00:36<00:27, 1.65MB/s]
52%|███████████████████▎ | 48.9M/93.8M [00:36<00:26, 1.71MB/s]
52%|███████████████████▎ | 49.0M/93.8M [00:36<00:30, 1.45MB/s]
53%|███████████████████▍ | 49.3M/93.8M [00:37<00:32, 1.39MB/s]
53%|███████████████████▌ | 49.5M/93.8M [00:37<00:34, 1.27MB/s]
53%|███████████████████▋ | 49.8M/93.8M [00:37<00:25, 1.72MB/s]
54%|███████████████████▊ | 50.2M/93.8M [00:37<00:25, 1.74MB/s]
54%|███████████████████▉ | 50.5M/93.8M [00:37<00:25, 1.70MB/s]
54%|████████████████████ | 50.9M/93.8M [00:37<00:23, 1.83MB/s]
55%|████████████████████▎ | 51.3M/93.8M [00:38<00:18, 2.35MB/s]
55%|████████████████████▍ | 51.7M/93.8M [00:38<00:19, 2.21MB/s]
56%|████████████████████▌ | 52.1M/93.8M [00:38<00:19, 2.10MB/s]
56%|████████████████████▋ | 52.5M/93.8M [00:38<00:15, 2.62MB/s]
56%|████████████████████▊ | 52.9M/93.8M [00:38<00:18, 2.26MB/s]
57%|████████████████████▉ | 53.1M/93.8M [00:38<00:20, 1.96MB/s]
57%|█████████████████████ | 53.3M/93.8M [00:39<00:23, 1.70MB/s]
57%|█████████████████████▏ | 53.6M/93.8M [00:39<00:25, 1.59MB/s]
57%|█████████████████████▎ | 53.9M/93.8M [00:39<00:25, 1.54MB/s]
58%|█████████████████████▎ | 54.1M/93.8M [00:39<00:27, 1.46MB/s]
58%|█████████████████████▍ | 54.4M/93.8M [00:39<00:25, 1.53MB/s]
58%|█████████████████████▌ | 54.8M/93.8M [00:40<00:25, 1.55MB/s]
59%|█████████████████████▊ | 55.2M/93.8M [00:40<00:21, 1.77MB/s]
59%|█████████████████████▉ | 55.5M/93.8M [00:40<00:22, 1.73MB/s]
60%|██████████████████████ | 56.0M/93.8M [00:40<00:19, 1.97MB/s]
60%|██████████████████████▏ | 56.2M/93.8M [00:40<00:22, 1.69MB/s]
60%|██████████████████████▎ | 56.5M/93.8M [00:41<00:23, 1.61MB/s]
60%|██████████████████████▎ | 56.7M/93.8M [00:41<00:25, 1.43MB/s]
61%|██████████████████████▍ | 57.0M/93.8M [00:41<00:24, 1.48MB/s]
61%|██████████████████████▋ | 57.5M/93.8M [00:41<00:16, 2.18MB/s]
62%|██████████████████████▊ | 57.8M/93.8M [00:41<00:18, 1.92MB/s]
62%|██████████████████████▉ | 58.0M/93.8M [00:41<00:21, 1.68MB/s]
62%|██████████████████████▉ | 58.2M/93.8M [00:42<00:23, 1.51MB/s]
62%|███████████████████████ | 58.5M/93.8M [00:42<00:24, 1.47MB/s]
63%|███████████████████████▏ | 58.8M/93.8M [00:42<00:22, 1.54MB/s]
63%|███████████████████████▎ | 59.2M/93.8M [00:42<00:20, 1.66MB/s]
63%|███████████████████████▍ | 59.5M/93.8M [00:42<00:20, 1.70MB/s]
64%|███████████████████████▌ | 59.8M/93.8M [00:43<00:21, 1.57MB/s]
64%|███████████████████████▋ | 60.0M/93.8M [00:43<00:23, 1.45MB/s]
64%|███████████████████████▊ | 60.3M/93.8M [00:43<00:22, 1.48MB/s]
65%|███████████████████████▉ | 60.6M/93.8M [00:43<00:22, 1.49MB/s]
65%|████████████████████████ | 60.8M/93.8M [00:43<00:23, 1.43MB/s]
65%|████████████████████████ | 61.0M/93.8M [00:44<00:25, 1.30MB/s]
65%|████████████████████████▏ | 61.3M/93.8M [00:44<00:23, 1.37MB/s]
66%|████████████████████████▎ | 61.7M/93.8M [00:44<00:20, 1.57MB/s]
66%|████████████████████████▍ | 62.0M/93.8M [00:44<00:20, 1.55MB/s]
66%|████████████████████████▌ | 62.3M/93.8M [00:44<00:20, 1.55MB/s]
67%|████████████████████████▋ | 62.6M/93.8M [00:44<00:20, 1.54MB/s]
67%|████████████████████████▊ | 62.8M/93.8M [00:45<00:21, 1.46MB/s]
67%|████████████████████████▊ | 63.0M/93.8M [00:45<00:24, 1.28MB/s]
68%|█████████████████████████ | 63.4M/93.8M [00:45<00:20, 1.48MB/s]
68%|█████████████████████████ | 63.6M/93.8M [00:45<00:20, 1.44MB/s]
68%|█████████████████████████▎ | 64.0M/93.8M [00:45<00:18, 1.57MB/s]
69%|█████████████████████████▍ | 64.4M/93.8M [00:46<00:17, 1.68MB/s]
69%|█████████████████████████▍ | 64.6M/93.8M [00:46<00:16, 1.75MB/s]
69%|█████████████████████████▌ | 64.8M/93.8M [00:46<00:19, 1.47MB/s]
69%|█████████████████████████▋ | 65.0M/93.8M [00:46<00:20, 1.40MB/s]
70%|█████████████████████████▊ | 65.3M/93.8M [00:46<00:19, 1.44MB/s]
70%|█████████████████████████▉ | 65.6M/93.8M [00:47<00:19, 1.47MB/s]
70%|█████████████████████████▉ | 65.8M/93.8M [00:47<00:19, 1.41MB/s]
70%|██████████████████████████ | 66.0M/93.8M [00:47<00:21, 1.28MB/s]
71%|██████████████████████████▏ | 66.3M/93.8M [00:47<00:21, 1.28MB/s]
72%|██████████████████████████▍ | 67.1M/93.8M [00:47<00:10, 2.56MB/s]
72%|██████████████████████████▌ | 67.4M/93.8M [00:47<00:11, 2.30MB/s]
72%|██████████████████████████▋ | 67.7M/93.8M [00:48<00:12, 2.05MB/s]
73%|██████████████████████████▊ | 68.1M/93.8M [00:48<00:13, 1.96MB/s]
73%|███████████████████████████ | 68.5M/93.8M [00:48<00:12, 1.95MB/s]
73%|███████████████████████████▏ | 68.9M/93.8M [00:48<00:12, 2.00MB/s]
74%|███████████████████████████▎ | 69.2M/93.8M [00:48<00:12, 1.91MB/s]
74%|███████████████████████████▍ | 69.4M/93.8M [00:49<00:14, 1.72MB/s]
74%|███████████████████████████▌ | 69.7M/93.8M [00:49<00:14, 1.68MB/s]
75%|███████████████████████████▌ | 70.0M/93.8M [00:49<00:15, 1.51MB/s]
75%|███████████████████████████▋ | 70.3M/93.8M [00:49<00:14, 1.62MB/s]
75%|███████████████████████████▉ | 70.7M/93.8M [00:49<00:13, 1.72MB/s]
76%|████████████████████████████ | 71.0M/93.8M [00:50<00:13, 1.71MB/s]
76%|████████████████████████████▏ | 71.4M/93.8M [00:50<00:12, 1.73MB/s]
76%|████████████████████████████▏ | 71.6M/93.8M [00:50<00:14, 1.54MB/s]
77%|████████████████████████████▎ | 71.9M/93.8M [00:50<00:13, 1.56MB/s]
77%|████████████████████████████▌ | 72.3M/93.8M [00:50<00:12, 1.78MB/s]
77%|████████████████████████████▋ | 72.6M/93.8M [00:50<00:13, 1.60MB/s]
78%|████████████████████████████▋ | 72.8M/93.8M [00:51<00:13, 1.50MB/s]
78%|████████████████████████████▊ | 73.1M/93.8M [00:51<00:13, 1.56MB/s]
78%|████████████████████████████▉ | 73.4M/93.8M [00:51<00:14, 1.45MB/s]
79%|█████████████████████████████ | 73.7M/93.8M [00:51<00:13, 1.47MB/s]
79%|█████████████████████████████▏ | 73.9M/93.8M [00:51<00:14, 1.41MB/s]
79%|█████████████████████████████▎ | 74.3M/93.8M [00:52<00:12, 1.57MB/s]
80%|█████████████████████████████▍ | 74.7M/93.8M [00:52<00:11, 1.69MB/s]
80%|█████████████████████████████▌ | 74.9M/93.8M [00:52<00:12, 1.56MB/s]
80%|█████████████████████████████▋ | 75.2M/93.8M [00:52<00:12, 1.50MB/s]
80%|█████████████████████████████▊ | 75.4M/93.8M [00:52<00:12, 1.43MB/s]
81%|█████████████████████████████▊ | 75.7M/93.8M [00:53<00:12, 1.44MB/s]
81%|██████████████████████████████ | 76.1M/93.8M [00:53<00:10, 1.64MB/s]
82%|██████████████████████████████▏ | 76.4M/93.8M [00:53<00:08, 1.98MB/s]
82%|██████████████████████████████▎ | 76.7M/93.8M [00:53<00:10, 1.70MB/s]
82%|██████████████████████████████▎ | 76.9M/93.8M [00:53<00:10, 1.60MB/s]
82%|██████████████████████████████▍ | 77.2M/93.8M [00:53<00:11, 1.50MB/s]
83%|██████████████████████████████▌ | 77.5M/93.8M [00:54<00:08, 1.81MB/s]
83%|██████████████████████████████▋ | 77.8M/93.8M [00:54<00:08, 1.83MB/s]
83%|██████████████████████████████▊ | 78.1M/93.8M [00:54<00:09, 1.64MB/s]
84%|██████████████████████████████▉ | 78.5M/93.8M [00:54<00:08, 1.76MB/s]
84%|███████████████████████████████▏ | 79.0M/93.8M [00:54<00:06, 2.39MB/s]
85%|███████████████████████████████▎ | 79.3M/93.8M [00:54<00:06, 2.17MB/s]
85%|███████████████████████████████▍ | 79.6M/93.8M [00:55<00:07, 1.90MB/s]
85%|███████████████████████████████▌ | 79.9M/93.8M [00:55<00:07, 1.81MB/s]
85%|███████████████████████████████▌ | 80.1M/93.8M [00:55<00:08, 1.56MB/s]
86%|███████████████████████████████▋ | 80.3M/93.8M [00:55<00:09, 1.39MB/s]
86%|███████████████████████████████▊ | 80.7M/93.8M [00:55<00:06, 1.93MB/s]
86%|███████████████████████████████▉ | 80.9M/93.8M [00:55<00:07, 1.69MB/s]
87%|████████████████████████████████▏ | 81.4M/93.8M [00:56<00:06, 1.96MB/s]
87%|████████████████████████████████▏ | 81.7M/93.8M [00:56<00:06, 1.77MB/s]
88%|████████████████████████████████▍ | 82.1M/93.8M [00:56<00:06, 1.85MB/s]
88%|████████████████████████████████▌ | 82.4M/93.8M [00:56<00:06, 1.80MB/s]
88%|████████████████████████████████▋ | 82.9M/93.8M [00:56<00:05, 1.98MB/s]
89%|████████████████████████████████▊ | 83.2M/93.8M [00:57<00:05, 1.97MB/s]
89%|████████████████████████████████▉ | 83.5M/93.8M [00:57<00:05, 1.78MB/s]
89%|█████████████████████████████████ | 83.9M/93.8M [00:57<00:04, 2.20MB/s]
90%|█████████████████████████████████▏ | 84.2M/93.8M [00:57<00:05, 1.90MB/s]
90%|█████████████████████████████████▎ | 84.4M/93.8M [00:57<00:05, 1.65MB/s]
90%|█████████████████████████████████▍ | 84.7M/93.8M [00:58<00:05, 1.61MB/s]
91%|█████████████████████████████████▌ | 85.1M/93.8M [00:58<00:04, 1.77MB/s]
91%|█████████████████████████████████▋ | 85.4M/93.8M [00:58<00:04, 1.82MB/s]
91%|█████████████████████████████████▊ | 85.8M/93.8M [00:58<00:04, 1.76MB/s]
92%|██████████████████████████████████ | 86.3M/93.8M [00:58<00:03, 2.07MB/s]
92%|██████████████████████████████████▏ | 86.7M/93.8M [00:58<00:03, 2.01MB/s]
93%|██████████████████████████████████▍ | 87.1M/93.8M [00:59<00:03, 2.16MB/s]
93%|██████████████████████████████████▍ | 87.4M/93.8M [00:59<00:03, 1.87MB/s]
93%|██████████████████████████████████▌ | 87.6M/93.8M [00:59<00:03, 1.69MB/s]
94%|██████████████████████████████████▋ | 88.0M/93.8M [00:59<00:02, 2.00MB/s]
94%|██████████████████████████████████▊ | 88.3M/93.8M [00:59<00:02, 2.00MB/s]
95%|███████████████████████████████████ | 88.8M/93.8M [01:00<00:02, 2.04MB/s]
95%|███████████████████████████████████ | 89.0M/93.8M [01:00<00:02, 1.79MB/s]
95%|███████████████████████████████████▎ | 89.4M/93.8M [01:00<00:02, 1.84MB/s]
96%|███████████████████████████████████▍ | 89.8M/93.8M [01:00<00:02, 1.95MB/s]
96%|███████████████████████████████████▌ | 90.0M/93.8M [01:00<00:02, 1.67MB/s]
96%|███████████████████████████████████▋ | 90.3M/93.8M [01:01<00:02, 1.67MB/s]
97%|███████████████████████████████████▊ | 90.7M/93.8M [01:01<00:01, 1.83MB/s]
97%|███████████████████████████████████▉ | 91.1M/93.8M [01:01<00:01, 1.79MB/s]
97%|████████████████████████████████████ | 91.3M/93.8M [01:01<00:01, 1.63MB/s]
98%|████████████████████████████████████▏| 91.7M/93.8M [01:01<00:01, 1.73MB/s]
98%|████████████████████████████████████▎| 92.0M/93.8M [01:01<00:01, 1.62MB/s]
98%|████████████████████████████████████▍| 92.4M/93.8M [01:02<00:00, 1.77MB/s]
99%|████████████████████████████████████▌| 92.6M/93.8M [01:02<00:00, 1.62MB/s]
99%|████████████████████████████████████▋| 93.0M/93.8M [01:02<00:00, 1.67MB/s]
99%|████████████████████████████████████▊| 93.2M/93.8M [01:02<00:00, 1.58MB/s]
100%|████████████████████████████████████▉| 93.5M/93.8M [01:02<00:00, 1.51MB/s]
0%| | 0.00/93.8M [00:00<?, ?B/s]
100%|██████████████████████████████████████| 93.8M/93.8M [00:00<00:00, 330GB/s]
downloading PocilloporaDamicornisSkin_Texture_0.jpg
0%| | 0.00/17.3M [00:00<?, ?B/s]
0%| | 4.10k/17.3M [00:00<07:45, 37.1kB/s]
0%|▏ | 69.6k/17.3M [00:00<00:49, 348kB/s]
1%|▎ | 159k/17.3M [00:00<00:36, 474kB/s]
2%|▋ | 332k/17.3M [00:00<00:24, 682kB/s]
3%|█ | 485k/17.3M [00:00<00:23, 730kB/s]
4%|█▌ | 682k/17.3M [00:00<00:19, 837kB/s]
5%|█▉ | 862k/17.3M [00:01<00:18, 872kB/s]
6%|██▎ | 1.06M/17.3M [00:01<00:17, 918kB/s]
7%|██▋ | 1.24M/17.3M [00:01<00:17, 923kB/s]
8%|███ | 1.40M/17.3M [00:01<00:17, 900kB/s]
9%|███▍ | 1.58M/17.3M [00:01<00:17, 910kB/s]
10%|███▉ | 1.81M/17.3M [00:02<00:15, 995kB/s]
12%|████▎ | 2.04M/17.3M [00:02<00:14, 1.05MB/s]
13%|████▉ | 2.28M/17.3M [00:02<00:13, 1.12MB/s]
14%|█████▎ | 2.46M/17.3M [00:02<00:13, 1.06MB/s]
16%|█████▊ | 2.71M/17.3M [00:02<00:12, 1.12MB/s]
17%|██████▎ | 2.94M/17.3M [00:03<00:12, 1.14MB/s]
18%|██████▋ | 3.13M/17.3M [00:03<00:12, 1.10MB/s]
19%|███████ | 3.30M/17.3M [00:03<00:11, 1.20MB/s]
20%|███████▎ | 3.45M/17.3M [00:03<00:13, 1.06MB/s]
21%|███████▊ | 3.67M/17.3M [00:03<00:12, 1.09MB/s]
22%|████████▎ | 3.87M/17.3M [00:03<00:12, 1.07MB/s]
23%|████████▋ | 4.05M/17.3M [00:04<00:12, 1.03MB/s]
25%|█████████ | 4.26M/17.3M [00:04<00:12, 1.05MB/s]
26%|█████████▋ | 4.54M/17.3M [00:04<00:10, 1.17MB/s]
27%|██████████▏ | 4.75M/17.3M [00:04<00:10, 1.15MB/s]
29%|██████████▌ | 4.97M/17.3M [00:04<00:10, 1.13MB/s]
30%|███████████▏ | 5.21M/17.3M [00:05<00:10, 1.18MB/s]
31%|███████████▌ | 5.41M/17.3M [00:05<00:10, 1.13MB/s]
33%|████████████▏ | 5.70M/17.3M [00:05<00:09, 1.25MB/s]
34%|████████████▋ | 5.91M/17.3M [00:05<00:09, 1.21MB/s]
35%|█████████████ | 6.11M/17.3M [00:05<00:09, 1.15MB/s]
37%|█████████████▌ | 6.36M/17.3M [00:06<00:09, 1.18MB/s]
38%|██████████████ | 6.60M/17.3M [00:06<00:08, 1.21MB/s]
40%|██████████████▋ | 6.85M/17.3M [00:06<00:08, 1.23MB/s]
41%|███████████████ | 7.03M/17.3M [00:06<00:09, 1.14MB/s]
42%|███████████████▌ | 7.27M/17.3M [00:06<00:08, 1.18MB/s]
44%|████████████████▏ | 7.57M/17.3M [00:07<00:07, 1.28MB/s]
45%|████████████████▋ | 7.78M/17.3M [00:07<00:07, 1.23MB/s]
46%|█████████████████▏ | 8.04M/17.3M [00:07<00:07, 1.27MB/s]
48%|█████████████████▋ | 8.29M/17.3M [00:07<00:07, 1.27MB/s]
49%|██████████████████▏ | 8.48M/17.3M [00:07<00:07, 1.19MB/s]
50%|██████████████████▌ | 8.69M/17.3M [00:08<00:07, 1.17MB/s]
51%|███████████████████ | 8.91M/17.3M [00:08<00:07, 1.15MB/s]
53%|███████████████████▌ | 9.12M/17.3M [00:08<00:07, 1.13MB/s]
54%|███████████████████▉ | 9.32M/17.3M [00:08<00:07, 1.10MB/s]
55%|████████████████████▍ | 9.56M/17.3M [00:08<00:06, 1.15MB/s]
56%|████████████████████▊ | 9.76M/17.3M [00:08<00:06, 1.11MB/s]
58%|█████████████████████▎ | 9.99M/17.3M [00:09<00:06, 1.13MB/s]
59%|█████████████████████▊ | 10.2M/17.3M [00:09<00:06, 1.10MB/s]
60%|██████████████████████▎ | 10.4M/17.3M [00:09<00:05, 1.18MB/s]
62%|██████████████████████▊ | 10.7M/17.3M [00:09<00:05, 1.21MB/s]
63%|███████████████████████▎ | 10.9M/17.3M [00:09<00:05, 1.15MB/s]
64%|███████████████████████▋ | 11.1M/17.3M [00:10<00:05, 1.13MB/s]
65%|████████████████████████ | 11.3M/17.3M [00:10<00:05, 1.07MB/s]
66%|████████████████████████▌ | 11.5M/17.3M [00:10<00:05, 1.08MB/s]
68%|█████████████████████████ | 11.7M/17.3M [00:10<00:05, 1.09MB/s]
69%|█████████████████████████▌ | 11.9M/17.3M [00:10<00:04, 1.12MB/s]
70%|█████████████████████████▉ | 12.1M/17.3M [00:11<00:04, 1.09MB/s]
71%|██████████████████████████▍ | 12.3M/17.3M [00:11<00:04, 1.09MB/s]
72%|██████████████████████████▊ | 12.5M/17.3M [00:11<00:04, 1.05MB/s]
74%|███████████████████████████▎ | 12.8M/17.3M [00:11<00:04, 1.11MB/s]
75%|███████████████████████████▊ | 13.0M/17.3M [00:11<00:03, 1.11MB/s]
76%|████████████████████████████▏ | 13.2M/17.3M [00:12<00:03, 1.11MB/s]
77%|████████████████████████████▋ | 13.4M/17.3M [00:12<00:03, 1.07MB/s]
79%|█████████████████████████████ | 13.6M/17.3M [00:12<00:03, 1.08MB/s]
80%|█████████████████████████████▌ | 13.8M/17.3M [00:12<00:03, 1.14MB/s]
81%|██████████████████████████████ | 14.0M/17.3M [00:12<00:02, 1.10MB/s]
82%|██████████████████████████████▍ | 14.2M/17.3M [00:13<00:02, 1.08MB/s]
83%|██████████████████████████████▊ | 14.4M/17.3M [00:13<00:02, 1.06MB/s]
85%|███████████████████████████████▎ | 14.7M/17.3M [00:13<00:02, 1.10MB/s]
86%|███████████████████████████████▋ | 14.8M/17.3M [00:13<00:02, 1.05MB/s]
88%|████████████████████████████████▍ | 15.1M/17.3M [00:13<00:01, 1.19MB/s]
89%|█████████████████████████████████ | 15.5M/17.3M [00:13<00:01, 1.34MB/s]
91%|█████████████████████████████████▌ | 15.7M/17.3M [00:14<00:01, 1.32MB/s]
92%|██████████████████████████████████ | 15.9M/17.3M [00:14<00:01, 1.23MB/s]
93%|██████████████████████████████████▌ | 16.2M/17.3M [00:14<00:00, 1.27MB/s]
95%|███████████████████████████████████ | 16.4M/17.3M [00:14<00:00, 1.27MB/s]
96%|███████████████████████████████████▌ | 16.6M/17.3M [00:14<00:00, 1.22MB/s]
97%|███████████████████████████████████▉ | 16.8M/17.3M [00:15<00:00, 1.16MB/s]
99%|████████████████████████████████████▋| 17.2M/17.3M [00:15<00:00, 1.35MB/s]
0%| | 0.00/17.3M [00:00<?, ?B/s]
100%|█████████████████████████████████████| 17.3M/17.3M [00:00<00:00, 59.8GB/s]
downloading PocilloporaDamicornisSkin_GeneratedMat2.png
0%| | 0.00/120k [00:00<?, ?B/s]
12%|████▋ | 14.3k/120k [00:00<00:00, 125kB/s]
62%|████████████████████████▎ | 74.8k/120k [00:00<00:00, 359kB/s]
0%| | 0.00/120k [00:00<?, ?B/s]
100%|████████████████████████████████████████| 120k/120k [00:00<00:00, 420MB/s]
Load the model#
Next, read the model data from the .obj file. Currently napari/vispy do not support reading material properties (.mtl files) nor separate texture and vertex indices (i.e. repeated vertices). Normal vectors read from the file are also ignored and re-calculated from the faces.
Notice reading .OBJ: material properties are ignored.
Load the textures#
This model comes with two textures: Texture_0 is generated from photogrammetry of the actual object, and GeneratedMat2 is a generated material to fill in parts of the model lacking photographic texture.
photo_texture = imread(tmp_dir / data_files['Texture_0'])
generated_texture = imread(tmp_dir / data_files['GeneratedMat2'])
This is what the texture images look like in 2D:
fig, axs = plt.subplots(1, 2)
axs[0].set_title(f'Texture_0 {photo_texture.shape}')
axs[0].imshow(photo_texture)
axs[0].set_xticks((0, photo_texture.shape[1]), labels=(0.0, 1.0))
axs[0].set_yticks((0, photo_texture.shape[0]), labels=(0.0, 1.0))
axs[1].set_title(f'GeneratedMat2 {generated_texture.shape}')
axs[1].imshow(generated_texture)
axs[1].set_xticks((0, generated_texture.shape[1]), labels=(0.0, 1.0))
axs[1].set_yticks((0, generated_texture.shape[0]), labels=(0.0, 1.0))
fig.show()

Create the napari layers#
Next create two separate layers with the same mesh - once with each texture. In this example the texture coordinates happen to be the same for each texture, but this is not a strict requirement.
photo_texture_layer = napari.layers.Surface(
(vertices, faces),
texture=photo_texture,
texcoords=texcoords,
name='Texture_0',
)
generated_texture_layer = napari.layers.Surface(
(vertices, faces),
texture=generated_texture,
texcoords=texcoords,
name='GeneratedMat2',
)
Add the layers to a viewer#
Finally, create the viewer and add the Surface layers. sphinx_gallery_thumbnail_number = 2
viewer = napari.Viewer(ndisplay=3)
viewer.add_layer(photo_texture_layer)
viewer.add_layer(generated_texture_layer)
viewer.camera.angles = (90.0, 0.0, -75.0)
viewer.camera.zoom = 75
if __name__ == '__main__':
napari.run()

Total running time of the script: (1 minutes 42.714 seconds)