Skip to main content

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'

Motivation

  1. 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.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gffx-0.1.2-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file gffx-0.1.2.tar.gz.

File metadata

  • Download URL: gffx-0.1.2.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for gffx-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f390771edf1532b8da603325c95098a35b4ae93df842aa3468f487dc2e89fee2
MD5 73e86f3c4bb62e8af6b063cfb8644657
BLAKE2b-256 62834ccdfdaafd641e640f295776f9de50e18b6c336f4a17978b0937ce40c116

See more details on using hashes here.

File details

Details for the file gffx-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gffx-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for gffx-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f5878449db06ce5bdd196afc9504847452fde94f9d5497dca4d6af5701bbb3b0
MD5 5ae49419ce98f4546f1ed0aebc10ac19
BLAKE2b-256 5c114180cb5f5caa114707b4152775ebdfc12f7f64a809413e1ebc261856042b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page