Coder Social home page Coder Social logo

oll3 / kiss3d Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sebcrozet/kiss3d

0.0 1.0 0.0 10.91 MB

Keep it simple, stupid 3d graphics engine for Rust.

Home Page: http://kiss3d.org

License: BSD 3-Clause "New" or "Revised" License

Rust 99.74% GLSL 0.26%

kiss3d's Introduction

Kiss3d

Keep It Simple, Stupid 3d graphics engine.

This library is born from the frustration in front of the fact that today’s 3D graphics library are:

  • either too low level: you have to write your own shaders and opening a window steals you 8 hours, 300 lines of code and 10L of coffee.
  • or high level but too hard to understand/use: those are libraries made to write beautiful animations or games. They have a lot of feature; too much feature if you only want to draw a few geometries on the screen.

kiss3d is not designed to be feature-complete or fast. It is designed to be able to draw simple geometric figures and play with them with one-liners.

An on-line version of this documentation is available here.

Features

Most features are one-liners.

  • WASM compatibility.
  • open a window with a default arc-ball camera and a point light.
  • a first-person camera is available too and user-defined cameras are possible.
  • display boxes, spheres, cones, cylinders, quads and lines.
  • change an object color or texture.
  • change an object transform (we use the nalgebra library to do that).
  • create basic post-processing effects.

As an example, having a red, rotating cube with the light attached to the camera is as simple as (NOTE: this will not compile when targeting WASM):

extern crate kiss3d;
extern crate nalgebra as na;

use na::{Vector3, UnitQuaternion};
use kiss3d::window::Window;
use kiss3d::light::Light;

fn main() {
    let mut window = Window::new("Kiss3d: cube");
    let mut c      = window.add_cube(1.0, 1.0, 1.0);

    c.set_color(1.0, 0.0, 0.0);

    window.set_light(Light::StickToCamera);

    let rot = UnitQuaternion::from_axis_angle(&Vector3::y_axis(), 0.014);

    while window.render() {
        c.prepend_to_local_rotation(&rot);
    }
}

The same example, but that will compile for both WASM and native platforms is slightly more complicated because kiss3d must control the render loop:

extern crate kiss3d;
extern crate nalgebra as na;

use kiss3d::light::Light;
use kiss3d::scene::SceneNode;
use kiss3d::window::{State, Window};
use na::{UnitQuaternion, Vector3};

struct AppState {
    c: SceneNode,
    rot: UnitQuaternion<f32>,
}

impl State for AppState {
    fn step(&mut self, _: &mut Window) {
        self.c.prepend_to_local_rotation(&self.rot)
    }
}

fn main() {
    let mut window = Window::new("Kiss3d: wasm example");
    let mut c = window.add_cube(1.0, 1.0, 1.0);

    c.set_color(1.0, 0.0, 0.0);

    window.set_light(Light::StickToCamera);

    let rot = UnitQuaternion::from_axis_angle(&Vector3::y_axis(), 0.014);
    let state = AppState { c, rot };

    window.render_loop(state)
}

Some controls are handled by default by the engine (they can be overridden by the user):

  • scroll: zoom in / zoom out.
  • left click + drag: look around.
  • right click + drag: translate the view point.
  • enter: look at the origin (0.0, 0.0, 0.0).

Compilation

You will need the last stable build of the rust compiler and the official package manager: cargo.

Simply add the following to your Cargo.toml file:

[dependencies]
kiss3d = "0.23"

Contributions

I’d love to see people improving this library for their own needs. However, keep in mind that kiss3d is KISS. One-liner features (from the user point of view) are preferred.

Acknowledgements

Thanks to all the Rustaceans for their help, and their OpenGL bindings.

kiss3d's People

Contributors

1011x avatar alon avatar alvinhochun avatar borgel avatar candunc avatar dhardy avatar dns2utf8 avatar exists-forall avatar gachapen avatar jaredly avatar jendrikw avatar joshlambda avatar kloumpt avatar kphelps avatar krdln avatar kudohamu avatar martinellison avatar mjohnson459 avatar mokona avatar mrrobb avatar natal avatar nicozet avatar oli-obk avatar rosievers avatar rparrett avatar samoylovfp avatar sebcrozet avatar serprex avatar slyklaw avatar wackywendell avatar

Watchers

 avatar

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.