How I Built A Simple (Horrible) 3D Graphics Engine in python matplotlib - Part 1: Intro

published-date: 17 Jan 2023 20:04 +0700
categories: dumber-day-by-day python-hijinks
tags: python matplotlib

Posts in This Series


Around mid 2022 when I was working at Pertamina, I was assigned into various AI/ML related projects. Needless to say, I was thrilled and enjoyed the audacity to fuck-around and try new things. There’s one particular project gave me an option to come up with a new idea to process an already trained image processing object detection ML model and evaluates some-kind of warning to another system whether someone is violating crane-operation-OSHA-regulation thing (and I believe I cannot disclose which ML model was used).

Problem being, to make a system that able to convert 2D bitmap data and detected object bounding box coordinate into 3D data equivalent representation for further analysis, requires additional processing with OpenCV, linear transformation, fuck-me-plenty-point-set-registration algorithm, all that jazz. Building another AI to do these kind of processing is was the recommended alternative. But we were short for training bounding-box-coordinate datasets (not images).

Then comes my dumbass brain, which unconsciously made a proposal to augment or “synthesize” entire dataset out of 3D modelling software Blender. But to do that I’d need some kind of proof-of-concept that actually works.

Thus I decided to write a 3D object constructor, for matplotlib, in pure python (no extern libs apart from numpy) in just one month iirc.

Long story short, I left Pertamina, and decided to let the code open to public.

In the next few posts, I’ll be explaining more in depth on how the code works. In the mean time, enjoy this graphics of generated rotation permutations.

image

Spoiler: Source Code [google.colab]. It’s horrid.

A little side note, I also made a three.js webapp for presentation use. But most of the features went unfinished, unfortunately.