{"id":15540472,"url":"https://github.com/rm-hull/wireframes","last_synced_at":"2025-07-07T11:12:22.853Z","repository":{"id":11054186,"uuid":"13393266","full_name":"rm-hull/wireframes","owner":"rm-hull","description":"A lightweight 3D graphics rendering engine in Clojure \u0026 ClojureScript.","archived":false,"fork":false,"pushed_at":"2018-10-05T20:51:37.000Z","size":59116,"stargazers_count":64,"open_issues_count":10,"forks_count":8,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-06-02T02:19:32.874Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rm-hull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-07T19:19:28.000Z","updated_at":"2025-04-28T04:36:05.000Z","dependencies_parsed_at":"2022-07-12T15:04:11.173Z","dependency_job_id":null,"html_url":"https://github.com/rm-hull/wireframes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rm-hull/wireframes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fwireframes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fwireframes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fwireframes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fwireframes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rm-hull","download_url":"https://codeload.github.com/rm-hull/wireframes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fwireframes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264067156,"owners_count":23552154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T12:13:50.763Z","updated_at":"2025-07-07T11:12:22.833Z","avatar_url":"https://github.com/rm-hull.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wireframes [![Build Status](https://secure.travis-ci.org/rm-hull/wireframes.png)](http://travis-ci.org/rm-hull/wireframes)\n\nA lightweight 3D rendering engine in Clojure \u0026 ClojureScript.\n\n![Aventador](https://raw.github.com/rm-hull/wireframes/master/doc/gallery/translucent/aventador.png)\n\nAdapted and extended from a javascript demo (originally by Kragen Javier Sitaker, see references below)\ninto a Clojure/ClojureScript library (that renders to SVG, an HTML5 Canvas or a Graphics2D object -\ndepending on the runtime environment, obviously).\n\nThis started out as a experiment to plot Lorenz attractors in 3D space, but it turns out to be a really\n*simple* way to programmatically generate three dimensional geometric shapes - basically a programmable\nCAD system - I'm pretty sure that AutoCAD could already do this (and much quicker too), but where I\nwould really like to go with this is:\n\n* build up a robust and idiomatic Clojure API for generating shapes\n* implement a wide variety of output renderers - potentially even a GLSL cross-compiler and\n  certainly a gcode output formatter suitable for 3D printers\n* maintain 100% compatibility with ClojureScript\n\nAs this is a *software* renderer, please don't expect OpenGL levels of performance (or until WebGL\nand OpenGL renderers have been written).\n\nA variety of (in-progress) generated shapes and demos:\n* A [gallery](https://github.com/rm-hull/wireframes/blob/master/GALLERY.md) of some shapes \n  and imports from common 3D formats, \n* An [animated torus tumbling in 3D space](http://programming-enchiladas.destructuring-bind.org/rm-hull/7098992), \n  and other shapes,\n* A [taxonomy of 3D polyhedra](http://programming-enchiladas.destructuring-bind.org/rm-hull/9261323).\n\n### Pre-requisites\n\nYou will need [Leiningen](https://github.com/technomancy/leiningen) 2.3.4 or above installed.\n\n### Building\n\nTo build and install the library locally, run:\n\n    $ lein test\n    $ lein install\n\nTo re-generate the examples in the ```doc/gallery``` directory, run:\n\n    $ lein test :examples\n\n### Including in your project\n\nThere is an 'alpha-quality' version hosted at [Clojars](https://clojars.org/rm-hull/wireframes).\nFor leiningen include a dependency:\n\n```clojure\n[rm-hull/wireframes \"0.0.1-SNAPSHOT\"]\n```\n\nFor maven-based projects, add the following to your `pom.xml`:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003erm-hull\u003c/groupId\u003e\n  \u003cartifactId\u003ewireframes\u003c/artifactId\u003e\n  \u003cversion\u003e0.0.1-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Basic Usage\n\nSee the [API Documentation](http://rm-hull.github.io/wireframes).\n\n### Creating shapes\n\nThere are some drawing primitives in the ```wireframes.shapes``` namespace to create\nobjects such as lines, bezier curves, polygons, circles, cuboids, cylinders and torus shapes.\n\nThe basic mechanism for *building* shapes is **extrusion**. For example, to create a cube,\nstart with a square polygon in the X-Y plane, and extrude that shape into a line along the\nZ-axis, as per the following code:\n\n```clojure\n(use 'wireframes.shapes.primitives)\n\n(-\u003e\n  (make-polygon\n    (make-point 0 0 0)\n    (make-point 0 1 0)\n    (make-point 1 1 0)\n    (make-point 1 0 0))\n  (extrude (translate 0 0 1) 1))\n```\n\n### Drawing shapes\n\nThere are various software renderers in the ```wireframes.renderer``` namespace for\noutput to java images, SVG or HTML5 canvas (the availability of which combinations\ndepends on whether you are executing the code in Clojure or ClojureScript).\n\n#### Clojure\n\nFor example, in Clojure, to generate a torus angled in the Y- and Z-axles, written\nout to a PNG file:\n\n```clojure\n(use 'wireframes.shapes.curved-solids)\n(use 'wireframes.transform)\n(use 'wireframes.renderer.bitmap)\n(use 'wireframes.renderer.color)\n\n(write-png\n  (-\u003eimg\n    #(draw-solid\n      {:focal-length 3\n       :color-fn (wireframe :white :transparent)\n       :style :transparent\n       :transform (combine\n                    (rotate :z (degrees-\u003eradians 65))\n                    (rotate :y (degrees-\u003eradians -30))\n                    (translate 0 0 16))\n       :shape (make-torus 1 3 60 60)} %)\n    [400 400])\n  \"torus-65.png\")\n```\nProduces:\n\n![Torus](https://raw.github.com/rm-hull/wireframes/master/doc/gallery/transparent/torus.png)\n\n### Surfaces and other primitives\n\nMATLAB-style function plots can be generated thus:\n\n```clojure\n(use 'wireframes.shapes.primitives)\n(use 'wireframes.transform)\n(use 'wireframes.renderer.bitmap)\n(use 'wireframes.renderer.lighting)\n(use 'wireframes.renderer.color)\n\n(defn sqr [x]\n  (* x x))\n\n(defn sinc\n  \"Unnormalized/cardinal sine function\"\n  [x] (if (zero? x)\n        1.0\n        (/ (Math/sin x) x)))\n\n(defn sombrero [x y]\n  (* 15 (sinc (Math/sqrt (+ (sqr x) (sqr y ))))))\n\n(write-png\n  (-\u003eimg\n    #(draw-solid\n      {:focal-length 30\n       :color-fn (comp\n                   black-edge                         ; [1]\n                   (positional-lighting-decorator     ; [2]\n                     default-position\n                     (spectral-z -6.5 15)))           ; [3]\n       :style :shaded\n       :transform (combine\n                    (rotate :z (degrees-\u003eradians 15))\n                    (rotate :x (degrees-\u003eradians 135))\n                    (scale 0.05)\n                    (translate 0 0 10))\n       :shape (make-surface                           ; [4]\n                (range -22 22 0.25)\n                (range -22 22 0.25)\n                sombrero)} %)                        ; [5]\n    [600 600])\n  \"sinc3D.png\")\n```\n\nResults in:\n\n![Hat](https://raw.github.com/rm-hull/wireframes/master/doc/gallery/shaded/sinc3D.png)\n\n#### Program Notes\nTODO\n\n### Loading common 3D shape files\n\nThe defacto/clichéd Utah teapot (or any patch/vertex 3D file) can be loaded in with the following\ncode sample:\n\n```clojure\n(use 'wireframes.shapes.patch-loader)\n(use 'wireframes.renderer.bitmap)\n(use 'wireframes.transform)\n\n(write-png\n  (-\u003eimg\n    #(draw-solid\n      {:focal-length 10\n       :fill-color Color/WHITE\n       :style :translucent\n       :transform (combine\n                    (rotate :z (degrees-\u003eradians 35))\n                    (rotate :x (degrees-\u003eradians -70))\n                    (translate 0 -1 40))\n       :shape (load-shape \"resources/newell-teapot/teapot\")} %)\n    [1000 900])\n  \"teapot.png\")\n```\nwhich generates:\n\n![Teapot](https://raw.github.com/rm-hull/wireframes/master/doc/gallery/translucent/teapot.png)\n\nThe following file formats support loading:\n\n* Patch files in the ```wireframes.shapes.patch-loader``` namespace,\n* Wavefront .obj files in the ```wireframes.shapes.wavefront-loader``` namespace,\n* Stereolithography .stl files in the ```wireframes.shapes.stl-loader``` namespace\n\n### Saving 3D shapes to STL-format files\n\nOnce generated or loaded by whatever means, a shape may be persisted in STL format with the following code sample:\n\n```clojure\n(use 'wireframes.shapes.stl-loader)\n(use 'wireframes.shapes.curved-solids)\n\n(save-shape\n  (make-torus 1 3 60 60)\n  \"a description which will get truncated to 80 chars\"\n  \"doc/gallery/torus.stl\")\n```\n\nThis specific [torus](https://github.com/rm-hull/wireframes/blob/master/doc/gallery/torus.stl), the\n[teapot](https://github.com/rm-hull/wireframes/blob/master/doc/gallery/teapot.stl) and a\n[wineglass](https://github.com/rm-hull/wireframes/blob/master/doc/gallery/wineglass.stl)\ncan then be viewed using the GitHub 3D viewer.\n\n## TODO\n\n* Investigate using primitive arrays (see [array](https://github.com/rm-hull/wireframes/tree/array) branch)\n* Use/implement a vector library\n* Geometric extension with Minkowski addition (see http://projecteuler.net/problem=228)\n* ~~Efficiently calculate polygons on extruded shapes~~\n* ~~Rewrite/rename wireframes.transform/concat - unroll loops for performance~~\n* ~~Complete Bezier patch code~~\n* ~~Rectilinear perspective mapping~~\n* ~~Stitch adjacent surface panels together~~\n* Renderer implementations:\n  - ~~Graphics2D~~\n  - ~~SVG~~\n  - ~~Canvas~~\n  - WebGL\n  - OpenGL\n* ~~Simple flat shading / lighting~~\n* ~~Configurable lighting position(s)~~\n* ~~Colours~~\n* Gourand shading\n* Texture mapping\n* ~~Backface removal~~\n* Z-buffer\n* Polygon inflation\n* ~~Compute shape bounds~~\n* ~~Center shape at origin function~~\n* gcode generation for 3D printers\n* ~~Support loading from \u0026 saving to .stl files~~\n* ~~Support loading from Wavefront .obj files~~\n* ~~Deprecate ```:lines``` - no longer used except in platonic solids~~\n* Improve documentation\n* Examples\n* ~~MATLAB style surface functions~~\n* ~~Integrate [Inkspot](https://github.com/rm-hull/inkspot) \u0026 custom vertex/fragment shader~~\n* Constructive Solid Geometry (CSG) boolean operators\n\n## Known Bugs\n\nSee open [issues](https://github.com/rm-hull/wireframes/issues?page=1\u0026state=open).\n\n# References\n\n* http://lists.canonical.org/pipermail/kragen-hacks/2007-February/000448.html\n* http://www.sjbaker.org/wiki/index.php?title=The_History_of_The_Teapot\n* http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-11-rendering-the-teapot-bezier-surfaces/b-zier-surface/\n* https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations\n* https://www.mathdisk.com/pub/safi/worksheets/Perspective_Projection\n* http://www.cs.berkeley.edu/~jrs/mesh/\n* http://www.victoriakirst.com/beziertool/\n* https://en.wikipedia.org/wiki/Wavefront_.obj_file\n* https://en.wikipedia.org/wiki/STL_(file_format)\n* https://github.com/colah/ImplicitCAD\n* http://evanw.github.io/csg.js/\n* http://www.opengl.org/wiki/Calculating_a_Surface_Normal\n* http://www.cs.utah.edu/~xchen/columbia/session1/lec24/html/\n* http://www.3dcadbrowser.com/3dmodels.aspx?word=star%20wars\n* http://derek.troywest.com/articles/by-example-gloss/\n* http://doc.cgal.org/latest/Manual/packages.html\n* http://stackoverflow.com/questions/3749678/expand-fill-of-convex-polygon\n* http://stackoverflow.com/questions/1109536/an-algorithm-for-inflating-deflating-offsetting-buffering-polygons\n* https://github.com/tsaastam/cljs-webgl-example\n* http://www.cs.arizona.edu/classes/cs437/fall11/ch3d.prn.pdf\n* https://github.com/rm-hull/project-euler/blob/master/src/util/geometry.clj#L55\n\n## Contributing\n\nYou're more than welcome to pitch in, there are loads of interesting computational\ngeometry features I'd like to implement (as well as a few bugs to squash) - take a\nlook at the TODO list and the references above.\n\nIf there's any you feel you'd specifically like to have a go at, create an\n[issue](https://github.com/rm-hull/wireframes/issues/new) and I'll back-fill it\nwith some background information to get you going, and it can then be used as\nthe discussion focus.\n\nFork the repo, create a feature branch and once the feature is complete, submit\na pull request. Also, please try and add some tests where practical (demo's and\nexamples even more so) and keep this README up-to-date, and make sure you've pulled\nfrom origin master before doing a PR.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Richard Hull\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-hull%2Fwireframes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frm-hull%2Fwireframes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-hull%2Fwireframes/lists"}