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.0.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.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gffx-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4dc855c22e8fb0e323d55cfcadbe095fa9735ba8df878575c8377a4ff5566e38
MD5 e6355fca0ee6c11232206bc77de0643e
BLAKE2b-256 38763b1e848b424dcaf432c9c9da3ede91a085bb3c0de810f321430471bdab2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gffx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb0eab8756967340bba4dfc7f2d4b26f6e83de00a7ee7318d2f5306cfedf06fa
MD5 0b8bb4141a90a7dfe60a4f28130a5d7c
BLAKE2b-256 8a85ab2ea663b0c5b8d29d6f48d6232bc530fe709d7d34a14aa0523117b7b26b

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