Metadata-Version: 2.4
Name: triview
Version: 1.0
Description-Content-Type: text/markdown
Dynamic: description
Dynamic: description-content-type

# Triview
A lightweight GUI-based Python library that renders .obj 3D models and polygon meshes entirely on the CPU without using a GPU or OpenGL. Built with Tkinter, it provides basic real-time 3D transformations, perspective projection, and interactive camera control.

Standard Libraries used :- tkinter (GUI), math (Math Operations)

## Features
- CPU-based 3D rendering (no GPU required)
- OBJ file loader (.obj support)
- Perspective projection system
- Camera movement (x, y, z)
- Yaw and pitch rotation
- Simple polygon mesh rendering
- Lightweight and easy to embed into projects

## Installation
```bash
pip install triview
```

## API
### Class 
```python
class TRIVIEW:
```
### Class Functions
```python
def initialize(self, window, bg, polygon_outline, polygon_fill, camera, zoom, yaw, pitch): # Initializes the Canvas for rendering
def project_vertices(self, vertices): # Takes 3D points and returns 2D screen points
def render_mesh(self, projected, faces): # Renders screen points as per faces
def load_obj(self, name): # Loads an obj file and returns [vertices, faces]
```

## Example of a Rotating Cube
```python
import tkinter as tk
import math
from triview import TRIVIEW

vertices = [
    [-1, -1, -1],
    [ 1, -1, -1],
    [ 1,  1, -1],
    [-1,  1, -1],
    [-1, -1,  1],
    [ 1, -1,  1],
    [ 1,  1,  1],
    [-1,  1,  1],
]

faces = [
    [2, 1, 0], [3, 2, 0],
    [6, 5, 4], [7, 6, 4],
    [5, 1, 0], [4, 5, 0],
    [7, 3, 2], [6, 7, 2],
    [6, 2, 1], [5, 6, 1],
    [7, 0, 3], [4, 7, 0],
]

def rotate_vertex(v, yaw, pitch):
    x, y, z = v
    x1 = x * math.cos(yaw) - z * math.sin(yaw)
    z1 = x * math.sin(yaw) + z * math.cos(yaw)
    y2 = y * math.cos(pitch) - z1 * math.sin(pitch)
    z2 = y * math.sin(pitch) + z1 * math.cos(pitch)

    return [x1, y2, z2]

window = tk.Tk()
window.geometry("600x500")
window.title("TRIVIEW - Rotating Cube")

tv = TRIVIEW()
tv.initialize(
    window=window,
    bg="gray15",
    polygon_outline="white",
    polygon_fill="",
    camera=[0, 0, -6],
    zoom=500,
    yaw=0,
    pitch=0
)

angle = 0
FPS = 60

def update():
    global angle

    rotated = [
        rotate_vertex(v, angle, angle * 0.5)
        for v in vertices
    ]

    projected = tv.project_vertices(rotated)
    tv.render_mesh(projected, faces)

    angle += 0.02
    window.after(int(1000/FPS), update)

update()
window.mainloop()
```

## Limitations
- CPU-based rendering only â†’ performance depends on system power
- Best suited for low-poly models (under ~2500 faces)
- No advanced lighting or shading (flat color only)
- No clipping system yet (can cause distortion at extreme angles)

## License
MIT LICENSED @2026
