Giter VIP home page Giter VIP logo

mogwai's Introduction

Mogwai

Graphic utility used to manipulate objects in 3D for scene editing (commonly called Gizmo).

It's a straightforward and simple Gizmo, all the manipulation is computed in this library while it gives you all the verticies for your renderer; At the end, you'll get a decomposed matrix (three vec3 for translation/rotation/scale).

This library uses only zalgebra and the std!

preview

Examples

usingnamespace @import("mogwai");

pub fn main () void {
  var gizmo = Mogwai(.{
    .screen_width   = 800,
    .screen_height  = 600,
    .snap_axis = 0.5,
    .snap_angle = 5 
  });

  // Get all vertices for your renderer.
  const xy_panel = gizmo.meshes.move_panels.xy;
  const yz_panel = gizmo.meshes.move_panels.yz
  // See https://github.com/kooparse/mogwai/blob/master/exemples/_glfw_opengl.zig#L62-L73
  // for all meshes.

  // Mode is an enum containing all different modes
  // for the gizmo (move, rotate, scale, none).
  var gizmo_mode = Mode.Move;

  while(true) {
    // After pulling cursor state and positions:
    gizmo.setCursor(pos_x, pos_y, is_pressed);
    // After updating the view matrix (camera moving...).
    gizmo.setCamera(view, proj);

    // You just have to pass a mode and the model matrix from the
    // selected object from your scene.
    if (gizmo.manipulate(target_model_matrix, gizmo_mode)) |result| {
        switch (result.mode) {
            Mode.Move => {
                target.transform.position = result.position;
            },
            Mode.Rotate => {
                target.transform.rotation = result.rotation.extractRotation();
            },
            Mode.Scale => {
                target.transform.scale = result.scale;
            },
            else => {},
        }
    }

    // Draw all the meshes
    your_renderer.draw(&yz_panel, gizmo.is_hover(GizmoItem.PanelYZ));
  }
}

See https://github.com/kooparse/mogwai/blob/master/exemples/_glfw_opengl.zig for a real exemple.

Documentation

Config

Field Type Description
screen_width i32 Width of the screen (required)
screen_height i32 Height of the screen (required)
dpi i32 Pixel ratio of your monitor
snap ?f32 Snap when dragging gizmo, value is equals to floor factor
arcball_radius f32 Radius of the rotation circles
arcball_thickness f32 Width of the rotation circle borders
panel_size f32 The width/height of panels
panel_offset f32 Offset of the panels from the origin position
panel_width f32 Plans width for panels
axis_length f32 Length of arrows
axis_size f32 The width/height of arrows
scale_box_size f32 Size of the scaler boxes

Contributing to the project

Don’t be shy about shooting any questions you may have. If you are a beginner/junior, don’t hesitate, I will always encourage you. It’s a safe place here. Also, I would be very happy to receive any kind of pull requests, you will have (at least) some feedback/guidance rapidly.

Behind screens, there are human beings, living any sort of story. So be always kind and respectful, because we all sheer to learn new things.

Thanks

This project is inspired by tinygizmo and ImGuizmo.

mogwai's People

Contributors

kooparse avatar ni-achene avatar

Stargazers

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

Watchers

 avatar  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.