A minimal graphics library in PyTorch
Project description
gffx - a minimal library for (differentiable) graphics
import gffx
import torch
import matplotlib.pyplot as plt
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Setup Camera
camera = gffx.ray.Camera(
width = 512,
height = 512,
pos = [0, 0, 3],
dir = [0, 0, -1],
device = device
)
# Setup list of meshes
vertices = torch.load('path/to/vertices.pt').to(device)
faces = torch.load('path/to/vertices.pt').to(device)
object_list = [
gffx.obj.mesh_from_vertices_and_faces(
vertices = vertices,
faces = faces,
init_translation = [0, 0.0, 2],
init_rotation = [0, 0, 0],
init_scale = [1, 1, 1],
ambient_color = [0.5, 0.5, 0.5],
diffuse_color = [0.5, 0.5, 0.5],
specular_color = [0.5, 0.5, 0.5],
specular_coefficient = 1,
device = device
)
]
# Ray Trace Render
images = gffx.ray.mesh_render(
meshes = object_list,
camera = camera,
light_intensity = 1.0,
ambient_intensity = 0.2,
light_pos = [5, 5, 5],
background_color = [0, 0, 0],
ray_chunk_size = 4096,
device = device
)
plt.imshow((images[0].cpu()).permute(1, 0, 2))
plt.gca().invert_yaxis()
plt.show()
[WIP] CLI
python -m gffx --vertices '/path/to/vertices.pt' --faces 'path/to/faces.pt'
python -m gffx --vertices '/path/to/vertices.pt' --faces 'path/to/faces.pt'\
--center_and_scale --camera_width 512 --camera_height 512\
--camera_pos "[0,0,1.2]" --camera_dir "[0,0,-1]"\
--camera_screen_distance 1.0 --ambient_color "[0.5, 0.5, 0.5]"\
--diffuse_color "[0.5, 0.5, 0.5]" --specular_color "[0.5, 0.5, 0.5]"\
--specular_coefficient 1.0 --light_intensity 1.0\
--ambient_intensity 0.2 --light_pos "[5, 5, 5]"\
--background_color "[0, 0, 0]" --ray_chunk_size 4096\
--outimg './out.png'
python -m gffx --vertices --faces /mnt/d/_doctorate/cache/vocaset/170725_00137/faces_template.npy --center_and_scale --camera_width 512 --camera_height 512 --camera_pos "[0,0,1.2]" --camera_dir "[0,0,-1]" --camera_screen_distance 1.0 --outimg ./outimg.png
Motivation
- Installing PyTorch3D everytime in colab is a hassle. This library's first aim is to render a mesh using native operations in PyTorch.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gffx-0.1.4.tar.gz
(14.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
gffx-0.1.4-py3-none-any.whl
(17.5 kB
view details)
File details
Details for the file gffx-0.1.4.tar.gz.
File metadata
- Download URL: gffx-0.1.4.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e333da40add65d272d7feae3d20b73fd498ba2df7c9a870b372ee689c4c9d946
|
|
| MD5 |
06fe2c9e5ac4b07518fcc1e3d361e8fc
|
|
| BLAKE2b-256 |
4c786eaa71d0b858969e00063a76ac94ce5f6107fce09bf6563bfff6b5893e67
|
File details
Details for the file gffx-0.1.4-py3-none-any.whl.
File metadata
- Download URL: gffx-0.1.4-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92e7fff975a7f4e33f0b70370791a0e3ad45bf48a09d3a1abb60a007cac2abe4
|
|
| MD5 |
3125a5df2c0d67329a3e7cd4ff567e92
|
|
| BLAKE2b-256 |
b74d7d9cdc3b2c4cec67722c0a17fbc962722c95ae1a4466dee96d7fc8b094ed
|