Home

Awesome

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!

<img src="https://github.com/kooparse/mogwai/blob/master/.github/mogwai.png" alt="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

FieldTypeDescription
screen_widthi32Width of the screen (required)
screen_heighti32Height of the screen (required)
dpii32Pixel ratio of your monitor
snap?f32Snap when dragging gizmo, value is equals to floor factor
arcball_radiusf32Radius of the rotation circles
arcball_thicknessf32Width of the rotation circle borders
panel_sizef32The width/height of panels
panel_offsetf32Offset of the panels from the origin position
panel_widthf32Plans width for panels
axis_lengthf32Length of arrows
axis_sizef32The width/height of arrows
scale_box_sizef32Size 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.