Giter VIP home page Giter VIP logo

polyhedron-ops's Introduction

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ɪ

Some brutalist polyhedron; rendered with 3Delight|ɴsɪ and post processed in Ansel.

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_obj(&Path::new("."), false);

The above code starts from a dodecahedron and iteratively applies four operators.

The resulting shape is shown below.

A polyhedron

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 a bevy 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 implements Polyhedron::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.

Export & render will always yield a correct OBJ though. Which you can view in Wings, Blender or another DCC app.

Contributors

donbright

polyhedron-ops's People

Contributors

dependabot[bot] avatar donbright avatar virtualritz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

polyhedron-ops's Issues

Failed to run bevy

hello!

I have a problem when run:
cargo run --release --example bevy --features "bevy"

the output is:
error: failed to run custom build command for smithay-client-toolkit v0.16.0

The same error appears when I use the bevy feature in project integration.

Also, the version in crates.io is 0.2.3, can you update it please?

Publish v0.2.8 to crates.io

Currently, v0.2.7 is the latest version of this awesome library available on crates. But on GitHub there is already a v0.2.8 version available, which fixes some issues for the current version of Bevy.

Could you publish the v0.2.8 version to crates.io?

winding backwards?

The winding/ordering of the faces appears to possibly be backwards. The standard for OpenGL, viewed from outside of a polyhedron, is for the winding of faces to be counter-clockwise (anti-clockwise). However the polyhedra are being generated with the winding, viewed from outside the object, to be clockwise. This is visible in meshlab for example.

This causes the 'normals' for the faces to be pointing inwards by default rather than outwards as is likely intended.

For example on the cube the face between the points 0 1 2 3 is listed as 1,3,2,0 which gives the winding, viewed from outside the cube, as clockwise. Meshlab interprets the normals as pointing inside and is why all the faces look dark gray.

winding

cube

The OBJ format spec from Wavefront , linked off wikipedia, also appears to indicate counter-clockwise. http://fegemo.github.io/cefet-cg/attachments/obj-spec.pdf

i have a change in the works to make all polyhedron faces counter-clockwise but wanted to check first and have this issue as reference.

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.