10 releases
0.2.7 | Apr 16, 2023 |
---|---|
0.2.6 | Apr 5, 2023 |
0.2.4 | Jan 9, 2023 |
0.2.3 | Apr 19, 2021 |
0.1.3 | Nov 24, 2020 |
#72 in Rendering
84 downloads per month
Used in 2 crates
2.5MB
3.5K
SLoC
Polyhedron Operators
This crate implements the Conway Polyhedron Operators and their extensions by George W. Hart and others.
Some brutalist polyhedron; rendered with 3Delight|ɴsɪ and post processed in Darktable.
This is an experiment to improve my understanding of iterators in Rust. It is based on Kit Wallace’s OpenSCAD code. As OpenSCAD Language is functional it lends itself well to translation into functional Rust.
use polyhedron_ops::Polyhedron;
use std::path::Path;
// Conway notation: gapcD
let polyhedron =
Polyhedron::dodecahedron() // D
.chamfer(None, true) // c
.propellor(None, true) // p
.ambo(None, true) // a
.gyro(None, None, true) // g
.finalize();
// Export as ./polyhedron-gapcD.obj
polyhedron.write_to_obj(&Path::new("."), false);
The above code starts from a dodecahedron and iteratively applies four operators.
The resulting shape is shown below.
Caveat
This is in a semi-polised shape. Documentation could be better (open an issue if you feel something is particualrly lacking).
In short: use at your own risk.
Cargo Features
-
bevy
– Adds support for converting a polyhedron into abevy
Mesh
. -
nsi
– Adds support for sending a polyhedron to an offline renderer via the ɴsɪ crate. -
obj
– Adds support for writing data out as Wavefront OBJ. -
parser
– Add support for parsing strings in Conway Polyhedron Notation. This feature implementsPolyhedron::TryFrom<&str>
.
Base Shapes
- Platonic solids
- Prisms
- Antiprisms
- Pyramids
- Johnson Solids
Supported Operators
- a – ambo
- b – bevel (equiv. to ta)
- c – chamfer
- d – dual
- e – expand (a.k.a. explode, equiv. to aa)
- g – gyro
- i – inset/loft (equiv. to x,N)
- j – join (equiv. to dad)
- K – Quick & dirty canonicalization
- k – kis
- M – medial (equiv. to dta)
- m – meta (equiv. to k,,3j)
- n – needle (equiv. to dt)
- o – ortho (equiv. to jj)
- p – propellor
- q – quinto
- r – reflect
- S – spherize
- s – snub (equiv. to dgd)
- t – truncate (equiv. to dkd)
- v – subdivide (Catmull-Clark)
- w – whirl
- x – extrude
- z – zip (equiv. to dk)
Other Operators
- H – hollow (called ‘intrude’ in Wings3D)
- h – hexpropellor
- l – stellate
- ? – triangulate
Playing
There is a playground example app to test things & have fun:
cargo run --release --example playground --features obj
If you want to produce images like the ones above you need to download the free version of the 3Delight renderer and install that. After that, run the example with ɴsɪ support:
cargo run --release --example playground --features nsi,obj
Keyboard Commands
Use keys matching the operator name from the above list to apply.
Use Up
and Down
to adjust the parameter of the the last operator.
Combine with Shift
for 10× the change.
Delete
undoes the last (and only the last) operation.
Press F1
to render with 3Delight (requires a 3Delight|ɴsɪ
installation).
Combine with Shift
to render with 3Delight Cloud (requires registration).
Press Space
to save as $HOME/polyhedron-<type>.obj
.
I use kiss3d
for realtime preview which, for now,
limits meshes to 64k vertices. This means the preview will be broken/missing bits
once your mesh hits this limit.
Export & render will always yield a correct OBJ though. Which you can view in Wings, Blender or another DCC app.
Dependencies
~3–41MB
~647K SLoC