X
X
xLivan2017-02-13 22:03:26
3D
xLivan, 2017-02-13 22:03:26

How to "cut" a piece of a mesh over another mesh?

Hello. Recently there was a need to implement an algorithm that would "cut" / "saw out" an object on another object. For example, there are 2 such meshes (mesh):
cd40b902dbc04795bd563be754e88de1.png
Imagine that the white plane is actually a large box, but we see only a small part of its surface. It is necessary to "cut out" a piece from it, which occupies the lower part of the red parallelepiped, i.e. add the corresponding vertices and triangles. As a result, the following object should be obtained (part of this object is marked in red for clarity):
4d55b900a34444d9b864686ff44691d9.png
Example No. 2.
Initial data:
a12f34d565b34ccbb4c0cdf3f73e5226.png
A red ellipsoid is "cut out" from a white parallelepiped. In this case, the original mesh is divided into 2 parts. Result:
b261224b3eaa4814833fa925a5129b7a.png
At the input, the algorithm has for each mesh:
1. Vector3[] (Vector3 is a class that has float x, float y, float z) - an array of mesh vertex coordinates (example: {(0,0,0),(1,0,0),(0, 0,1),(1,0,1)})
2. int[] - array of vertex indices that make up mesh triangles (example: {0, 1, 2, 1, 2, 3} - 2 triangles forming square in the XZ plane)
The output should be an array of vertices Vector3[] and an array of triangles int[].
How can this be implemented? What can be read about this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Pavlyuk, 2017-02-14
@xLivan

It's called boolean operations, and it's pretty tricky to implement on your own. It is better to take a ready-made library, for example https://github.com/gilbo/cork
You can start reading from here https://en.wikipedia.org/wiki/Constructive_solid_g...

O
Oleg Pogrebnyak, 2017-02-13
@S0HardCore

What can be read about this?

catlikecoding.com/unity/tutorials
Chapters 1.2 and 1.6.

A
Alexander Skusnov, 2017-02-14
@AlexSku

In my opinion, a stencil buffer (stencil) is used for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question