Skip to content

Instantly share code, notes, and snippets.

@justinhchae
justinhchae / sample_points_from_obj_pytorch3d.py
Last active June 22, 2023 03:50
Sampling points with PyTorch3D
# install direct from our forked repository: https://github.com/Esri/pytorch3d/tree/multitexture-obj-high-precision
!pip install 'git+https://github.com/Esri/pytorch3d.git@multitexture-obj-high-precision'
from pytorch3d.ops import sample_points_from_obj
(
points, # points sampled proportional to face area
normals, # point normals based on mesh verts
textures, # point textures sampled from faces
mappers # an index to each points origin face
@justinhchae
justinhchae / subset_obj_pytorch3d.py
Last active June 22, 2023 03:50
Example Usage to Subset an Obj with PyTorch3D
# install direct from our forked repository: https://github.com/Esri/pytorch3d/tree/multitexture-obj-high-precision
!pip install 'git+https://github.com/Esri/pytorch3d.git@multitexture-obj-high-precision'
from pytorch3d.io import subset_obj
faces_to_subset = <a torch tensor of face indices to subset>
# all obj objects are subset to the selected face indices
obj_subset = subset_obj(
obj=obj,
@justinhchae
justinhchae / save_obj_multitexture.py
Last active June 22, 2023 03:49
Example Usage for save_obj with multiple textures in PyTorch3D
# install direct from our forked repository: https://github.com/Esri/pytorch3d/tree/multitexture-obj-high-precision
!pip install 'git+https://github.com/Esri/pytorch3d.git@multitexture-obj-high-precision'
from pytorch3d.io import save_obj
# save_obj now allows for saving objs with multiple textures and control over the texture outputs
save_obj(
f=obj_filename,
verts=obj[0],
faces=obj[1].verts_idx,