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.1.tar.gz (9.7 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.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gffx-0.1.1.tar.gz
  • Upload date:
  • Size: 9.7 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.1.tar.gz
Algorithm Hash digest
SHA256 01b7a579395a137bf5b9e5984edf8605501db81b0469eadec89ec9a9ba012b29
MD5 313584822b8c73a107e81d9a49b917fe
BLAKE2b-256 d1f075db030010d6abb349c378717fc412553ebe2d295ccce0f5cf817f312d47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gffx-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2dc39cff90c0c80207cb7786064ae96d7e50b389e131c6fefb6a079686adc26
MD5 5b7da3778030032cab75276bb6e61fcb
BLAKE2b-256 0e8761a5dd90fa06574fb1975ccff70ed9315e9d9dec049e12c1a7f9af033871

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