https://github.com/bjornbytes/lovr-icosphere
Make spheres with LÖVR
https://github.com/bjornbytes/lovr-icosphere
lovr
Last synced: 12 months ago
JSON representation
Make spheres with LÖVR
- Host: GitHub
- URL: https://github.com/bjornbytes/lovr-icosphere
- Owner: bjornbytes
- License: mit
- Created: 2017-02-27T08:02:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-09T18:16:52.000Z (about 2 years ago)
- Last Synced: 2024-05-02T00:44:06.540Z (about 2 years ago)
- Topics: lovr
- Language: Lua
- Size: 2.93 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
lovr-icosphere
===
A small library to generate icospheres with Lua and [LÖVR](https://github.com/bjornbytes/lovr).
Inspired by [this blog post](http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html).
> Note: In LÖVR 0.7.1 and on, you can use the `lovr.graphics.sphere` function to draw filled
> spheres. This library is still useful for drawing wireframe spheres or "low-poly" spheres.
Usage
---
```lua
local icosphere = require 'icosphere'
function lovr.load()
local vertices, indices = icosphere(2)
mesh = lovr.graphics.newMesh(vertices, 'triangles')
mesh:setVertexMap(indices)
end
function lovr.draw()
lovr.graphics.setWireframe(true)
mesh:draw(0, 0, -1, .3, lovr.timer.getTime() * .3)
end
```
Documentation
---
```lua
vertices, indices = icosphere(n)
```
The library exports a single function. The function accepts a single integer parameter `n`
representing the number of times to subdivide the sphere. Higher numbers will yield smoother
geometry, but each subdivision will quadruple the number of vertices. If `n` is zero or `nil`,
an the function will generate a regular convex icosahedron with 12 vertices and 20 triangles.
The list of vertices can be passed directly to `lovr.graphics.newMesh`, and list of indices can
be used as the Mesh's vertex map.
License
---
MIT, see [LICENSE](LICENSE) for details.