• Stars
    star
    339
  • Rank 120,782 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

generate 3D wireframes as vector art

This is a single-file Python library for generating 3D wireframes in SVG format.

For a description of how the library was designed and implemented, check out this blog post.

Usage example

import numpy, svg3d, pyrr, math

def get_octahedron_faces():
    f = math.sqrt(2.0) / 2.0
    verts = numpy.float32([ ( 0, -1,  0), (-f,  0,  f), ( f,  0,  f), ( f,  0, -f), (-f,  0, -f), ( 0,  1,  0) ])
    triangles = numpy.int32([ (0, 2, 1), (0, 3, 2), (0, 4, 3), (0, 1, 4), (5, 1, 2), (5, 2, 3), (5, 3, 4), (5, 4, 1) ])
    return 15.0 * verts[triangles]

def generate_svg(filename):
    view = pyrr.matrix44.create_look_at(eye=[50, 40, 120], target=[0, 0, 0], up=[0, 1, 0])
    projection = pyrr.matrix44.create_perspective_projection(fovy=15, aspect=1, near=10, far=200)
    camera = svg3d.Camera(view, projection)

    style = dict(
        fill="white", fill_opacity="0.75",
        stroke="black", stroke_linejoin="round", stroke_width="0.005")

    mesh = svg3d.Mesh(get_octahedron_faces(), style=style)
    view = svg3d.View(camera, svg3d.Scene([mesh]))
    svg3d.Engine([view]).render(filename)

generate_svg("octahedron.svg")

The above code snippet generates an image like this:

Running the test script

pipenv shell
pipenv install
cd extras
./test.py && open gallery.html

More Repositories

1

par

single-file C libraries from Philip Allan Rideout
C
848
star
2

heman

C99 heightmap utilities.
C
462
star
3

snowy

Small Image Library for Python 3
Python
417
star
4

aobaker

ambient occlusion baking tool
C++
229
star
5

fluidsim

GPU fluid simulation
C
164
star
6

recipes

collection of tiny OpenGL demos
C
60
star
7

parg

tiny C library of various graphics utilities and GL demos
C++
55
star
8

lava

toy C++ Vulkan library
C++
49
star
9

clumpy

create or transform numpy images from the command line
C++
47
star
10

parm

minimal macOS Metal application
Objective-C++
41
star
11

polygon.js

tessellation of concave polygons with holes in Javascript
JavaScript
39
star
12

iphone-3d-programming

sample code from my O'Reilly book
C
39
star
13

distortion

Fisheye Distortion in OpenGL
C
36
star
14

knotgl

Mathematical Knots in WebGL
JavaScript
34
star
15

streamlines_demo

sample app for par_streamlines
C
27
star
16

pez

teeny tiny platform layer for simple OpenGL demos
C
26
star
17

opengl-insights

source code for "An Introduction to Tessellation Shaders"
C
22
star
18

quadmesh

Animated quad meshes and smooth normal computation with Modern OpenGL.
C
21
star
19

hexgl

HexGL clone using Filament and TypeScript
TypeScript
19
star
20

sympy-fun

use SymPy to generate equations for parametric surfaces
C
17
star
21

nile

fractal terrain generator in Nim
Nim
16
star
22

giza

low-level utility layer for WebGL
JavaScript
16
star
23

coregl-python

simple example of using the OpenGL Core Profile with PyQt, numpy, and PyOpenGL
Python
15
star
24

gltumble

spin a 3D object with a bit of inertia
JavaScript
14
star
25

knotess

prime knot tessellation
JavaScript
13
star
26

rwt

Recursive Wang tiles dataset for blue noise
C
13
star
27

euler

scrollytelling and Filament
TypeScript
11
star
28

flatbin

Tiny JavaScript utility for parsing simple binary files.
JavaScript
10
star
29

effects-salad

C++
10
star
30

camera_demo

demo for par_camera_control.h
C
9
star
31

govmath

vector math in go for 3D graphics
Go
9
star
32

reba-island

generate simple island shapes
C++
8
star
33

monarchy

demonstrates high-performance 2D graphics with giza
JavaScript
8
star
34

pageturn

TypeScript
8
star
35

modern-opengl-prezo

HTML Slideshow on Modern OpenGL
C
7
star
36

lsystem

lsystem evaluation in C++, Go, and Python
C++
7
star
37

skia

fork of skia that is CMake-buildable
C++
6
star
38

ribarchive

random renderman stuff
Slash
5
star
39

sfpaths

Download and visualize Strava paths with D3 and Google Maps.
Python
5
star
40

blog-source

my old graphics blog
C
3
star
41

gorman

renderman bindings for the go language
Go
3
star
42

d3cpp

sweep and prune demo
JavaScript
3
star
43

heman-python

work in progress
C
2
star
44

book-webgl

JavaScript
2
star
45

reba

dev machine for building server-side renderers
Shell
1
star
46

filasize

HTML
1
star
47

shaderhud

quick shader editor overlay for debugging
JavaScript
1
star
48

knot-data

Data for Mathematical Knots
CoffeeScript
1
star