Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 StanislavPetrovV
Copyright (c) 2025 tantock

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file removed __pycache__/camera.cpython-39.pyc
Binary file not shown.
Binary file removed __pycache__/matrix_functions.cpython-39.pyc
Binary file not shown.
Binary file removed __pycache__/object_3d.cpython-39.pyc
Binary file not shown.
Binary file removed __pycache__/projection.cpython-39.pyc
Binary file not shown.
87 changes: 0 additions & 87 deletions camera.py

This file was deleted.

57 changes: 11 additions & 46 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
from object_3d import *
from camera import *
from projection import *
import pygame as pg


class SoftwareRender:
def __init__(self):
pg.init()
self.RES = self.WIDTH, self.HEIGHT = 1600, 900
self.H_WIDTH, self.H_HEIGHT = self.WIDTH // 2, self.HEIGHT // 2
self.FPS = 60
self.screen = pg.display.set_mode(self.RES)
self.clock = pg.time.Clock()
self.create_objects()

def create_objects(self):
self.camera = Camera(self, [-5, 6, -55])
self.projection = Projection(self)
self.object = self.get_object_from_file('resources/t_34_obj.obj')
self.object.rotate_y(-math.pi / 4)

def get_object_from_file(self, filename):
vertex, faces = [], []
with open(filename) as f:
for line in f:
if line.startswith('v '):
vertex.append([float(i) for i in line.split()[1:]] + [1])
elif line.startswith('f'):
faces_ = line.split()[1:]
faces.append([int(face_.split('/')[0]) - 1 for face_ in faces_])
return Object3D(self, vertex, faces)

def draw(self):
self.screen.fill(pg.Color('darkslategray'))
self.object.draw()

def run(self):
while True:
self.draw()
self.camera.control()
[exit() for i in pg.event.get() if i.type == pg.QUIT]
pg.display.set_caption(str(self.clock.get_fps()))
pg.display.flip()
self.clock.tick(self.FPS)

from obj4drender.render import SoftwareRender
from obj4drender.object import Axes4
import math

if __name__ == '__main__':
app = SoftwareRender()
tesseract_id = app.load_object_from_file('resources/tesseract.obj4')
tank_id = app.load_object_from_file('resources/t_34_obj.obj')
axis_id = app.add_object(Axes4(app))
app.get_object(tesseract_id).rotate_y(-math.pi / 4)
app.get_object(tesseract_id).scale(10)
app.get_object(tesseract_id).translate([10,10,10,0])
app.get_object(tank_id).rotate_y(-math.pi / 4)
app.get_object(tank_id).scale(1/5)
app.run()
48 changes: 0 additions & 48 deletions matrix_functions.py

This file was deleted.

31 changes: 0 additions & 31 deletions projection.py

This file was deleted.

21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[project]
name = "obj4drender"
version = "0.0.1"
dependencies = ["pygame","numpy","numba"]
requires-python = ">=3.10"
classifiers = ["License :: OSI Approved :: MIT License"]
readme = "README.md"

[project.optional-dependencies]
dev = ["pytest", "coverage"]

[build-system]
requires = [
"wheel",
"setuptools-scm[toml]>=8.0",
]
build-backend = "setuptools.build_meta"

[project.urls]
Homepage = "https://github.com/tantock/Software_3D_engine"

4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
setuptools
setuptools_scm
wheel
81 changes: 81 additions & 0 deletions resources/tesseract.obj4
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#
# object tesseract
#

v 0.0000 0.0000 0.0000 0.0000
v 0.0000 1.0000 0.0000 0.0000
v 1.0000 1.0000 0.0000 0.0000
v 1.0000 0.0000 0.0000 0.0000
v 0.0000 0.0000 1.0000 0.0000
v 0.0000 1.0000 1.0000 0.0000
v 1.0000 1.0000 1.0000 0.0000
v 1.0000 0.0000 1.0000 0.0000
v 0.0000 0.0000 0.0000 1.0000
v 0.0000 1.0000 0.0000 1.0000
v 1.0000 1.0000 0.0000 1.0000
v 1.0000 0.0000 0.0000 1.0000
v 0.0000 0.0000 1.0000 1.0000
v 0.0000 1.0000 1.0000 1.0000
v 1.0000 1.0000 1.0000 1.0000
v 1.0000 0.0000 1.0000 1.0000
# 16 vertices

f 1 2 3 4
f 3 4 8 7
f 2 3 7 6
f 1 2 6 5
f 1 4 8 5
f 5 8 7 6
f 9 10 11 12
f 11 12 16 15
f 10 11 15 14
f 9 10 14 13
f 9 12 16 13
f 13 16 15 14
f 3 4 8 7
f 8 7 15 16
f 4 8 16 12
f 3 4 12 11
f 3 7 15 11
f 11 15 16 12
f 1 2 3 4
f 3 4 12 11
f 2 3 11 10
f 1 2 10 9
f 1 4 12 9
f 9 12 11 10
f 2 3 7 6
f 7 6 14 15
f 3 7 15 11
f 2 3 11 10
f 2 6 14 10
f 10 14 15 11
f 1 2 6 5
f 6 5 13 14
f 2 6 14 10
f 1 2 10 9
f 1 5 13 9
f 9 13 14 10
f 5 6 7 8
f 7 8 16 15
f 6 7 15 14
f 5 6 14 13
f 5 8 16 13
f 13 16 15 14
f 1 4 8 5
f 8 5 13 16
f 4 8 16 12
f 1 4 12 9
f 1 5 13 9
f 9 13 16 12

c 1 2 3 4 5 6
c 7 8 9 10 11 12
c 13 14 15 16 17 18
c 19 20 21 22 23 24
c 25 26 27 28 29 30
c 31 32 33 34 35 36
c 37 38 39 40 41 42
c 43 44 45 46 47 48

# 8 cells
Empty file added src/obj4drender/__init__.py
Empty file.
Loading