Created
January 30, 2021 09:00
-
-
Save patricksnape/c77401540126be48d11f04bb8d22bd0d to your computer and use it in GitHub Desktop.
Create unwrapped UV texture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import menpo | |
import menpo3d | |
import numpy as np | |
template = menpo3d.io.import_builtin_asset.james_obj() | |
o_c_unwrap = menpo3d.unwrap.optimal_cylindrical_unwrap(template) | |
unwrapped_template = o_c_unwrap.apply(template) | |
u_t_aspect_ratio = np.divide(*unwrapped_template.range()[:2]) | |
u_t_clip_transform = menpo3d.rasterize.transform.model_to_clip_transform(unwrapped_template) | |
u_t_clip = u_t_clip_transform.apply(unwrapped_template) | |
u_t_im_width = 1024 | |
r = menpo3d.rasterize.GLRasterizer(width=u_t_im_width, height=int(u_t_im_width / u_t_aspect_ratio)) | |
u_t_image = r.rasterize_mesh(u_t_clip) | |
new_tcoords = u_t_clip.points[:, :2] / 2 + .5 | |
new_textured_mesh = menpo.shape.TexturedTriMesh(template.points, new_tcoords, u_t_image, trilist=template.trilist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment