Giter Site home page Giter Site logo

godot-mesh-slicer's Introduction

Mesh Slicer in the Godot Game Engine

An implementation and explanation for slicing an ArrayMesh with a Plane.

Sample 1 cut

About

There is a class called Slicer with one static function get_sliced_meshes that takes an ArrayMesh and a Plane as inputs and returns an array with two ArrayMesh's. The first one is the "upper" mesh, and the second is the "lower" mesh.

There is also an example project. The example slices the MeshInstance in the scene tree by the SlicePlane. These can be moved in the editor.

Installing

To use the utility, I recommend downloading make_mesh_slices.gd directly and adding it to your project. This file contains the Slicer class.

To use the example, pull this repository and import it as a Godot project.

Using

As long as make_mesh_slices.gd is in your project directory, you can use the slicing function by calling Slicer.get_sliced_meshes from any script. As stated above, this function takes an ArrayMesh and Plane as its two parameters, and it returns an array with two new ArrayMesh's.

This function was written to be as time-efficient as possible, intending for real-time slicing of meshes. As such, there may be redundant faces created as the result of a slice. I recommend using meshes that have lower polygon counts.

The slices created by this function have normals generated before being returned. However, they currently do not have UV coordinates. I hope to implement this in the future.

When creating the Plane, assume the mesh is centered at (0, 0, 0) and is not rotated. This is because mesh vertices have their own local coordinates. See the _ready function in SlicerExample.gd for a way to get the Plane based on global coordinates and rotations of a mesh and a slicing plane.

Explanation

There is a step-by-step explanation of how this implementation works in the in-line comments of make_mesh_slices.gd. This includes helpful links and higher-level interpretations. I recommend having the following pages open while reading:

Sample Photos

1.

Sample 1 uncut Sample 1 cut

2

Sample 2 uncut Sample 2 cut

godot-mesh-slicer's People

Contributors

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