About Store Forum Documentation Contact
Donations:
158$/mo



Post Reply 
Cutting a hole in a mesh
Author Message
Myx Offline
Member

Post: #1
Cutting a hole in a mesh
Hello there!

I've had the engine for about 2 weeks and decided to make my first project a day ago or so.
However I have naturally encountered a problem I can't seem to solve.

In my project I generate a number of rooms which are represented by box-meshes.
I pick a room and find a random neighbour room, then I place a box on a wall that they share to mark the placement of a door.
As the title states I'm looking for a method to "cut a hole" in these meshes.
I want to cut away the wall-part that is inside my placed box.

My first thought was to use the Csg function with SEL_SUB displayed in one of the tutorials to push the unwanted section out and then somehow chop it off. So far I've had no success in the chop-off department though.

Any suggestions or ideas are welcome!

// Myx


P.S - Brilliant engine. Best I've ever worked with.
08-25-2009 07:05 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: Cutting a hole in a mesh
Hi,

Yes you're on good tracks, Csg would definitely be the thing you need.

You can check the csg tutorial for help.

I think in your case it is important to remember about box faces sides (check Mesh::reverse method which switches sides of the faces)

in your case you should make 2 reversed boxes, and SEL_ADD them
Mesh room; room.createbox.reverse
Mesh corridor; corridor.createbox.reverse

Csg(room,corridor,SEL_ADD)

you can try also SEL_SUB instead of SEL_ADD

if both dont work, please paste your code, and ill see what could be the problem wink
08-25-2009 07:26 PM
Find all posts by this user Quote this message in a reply
Myx Offline
Member

Post: #3
Re: Cutting a hole in a mesh
Esenthel Wrote:in your case you should make 2 reversed boxes, and SEL_ADD them
Mesh room; room.createbox.reverse
Mesh corridor; corridor.createbox.reverse

Csg(room,corridor,SEL_ADD)

you can try also SEL_SUB instead of SEL_ADD

Yes, that's basically what I've been doing.
Soo code and pictures of the result incomming.

First a few explanations:
cuttingBox is a box placed at the place where the opening should be (the white lines in the picture is the box).
Rooms is a Memb of my Room struct.
m_RoomBox is the mesh of a Room, it is created the following way:
m_RoomBox.create(1).base(0)
.create(Box(m_XW, m_YW, m_ZW, m_Pos), VTX_TEX0|VTX_NRM|VTX_TNG).reverse();
m_RoomBox.setMaterial(material).setRender().setBox();


Now for the "chopp" part:

Mesh theCut;
theCut.create(1).base(0).create(cuttingBox, VTX_TEX0|VTX_NRM|VTX_TNG);

Csg(Rooms[i].m_RoomBox.base(0), theCut.base(0), SEL_SUB);
Rooms[i].m_RoomBox.setRender();
Rooms[i].m_RoomBox.setBox();

Results in:
[attachment=3]


Mesh theCut;
theCut.create(1).base(0).create(cuttingBox, VTX_TEX0|VTX_NRM|VTX_TNG).reverse();

Csg(Rooms[i].m_RoomBox.base(0), theCut.base(0), SEL_SUB);
Rooms[i].m_RoomBox.setRender();
Rooms[i].m_RoomBox.setBox();

Results in:
[attachment=2]


Mesh theCut;
theCut.create(1).base(0).create(cuttingBox, VTX_TEX0|VTX_NRM|VTX_TNG);

Csg(Rooms[i].m_RoomBox.base(0), theCut.base(0), SEL_ADD);
Rooms[i].m_RoomBox.setRender();
Rooms[i].m_RoomBox.setBox();

Results in:
[attachment=1]


Mesh theCut;
theCut.create(1).base(0).create(cuttingBox, VTX_TEX0|VTX_NRM|VTX_TNG).reverse();

Csg(Rooms[i].m_RoomBox.base(0), theCut.base(0), SEL_ADD);
Rooms[i].m_RoomBox.setRender();
Rooms[i].m_RoomBox.setBox();

Results in:
[attachment=0]



// Myx
08-25-2009 08:11 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
Re: Cutting a hole in a mesh
looks like it works
08-25-2009 08:17 PM
Find all posts by this user Quote this message in a reply
Myx Offline
Member

Post: #5
Re: Cutting a hole in a mesh
Hmm, I suppose I didn't explain properly.

Yes I manage to do an indent, but what I want to do is make a hole in the mesh.
The mesh is still an enclosed space after doing the Csg, no one can come in or out.
So, I want an opening.
08-25-2009 08:19 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
Re: Cutting a hole in a mesh
I see, but what for you need opening?

if for another room, then you shouldnt make an empty hole, but just apply another box

room+corridor+room

you can always manually delete faces (using methods or in Mesh Editor \ Vertex/Face mode when a MeshPart is selected)
08-25-2009 08:28 PM
Find all posts by this user Quote this message in a reply
Myx Offline
Member

Post: #7
Re: Cutting a hole in a mesh
My test-project is to generate a "labyrinth mansion", I'm not using any premade meshes.

I start by creating a center room, and then new rooms are added.
A room can only be added if it "shares wall" with an already existing room.
The rooms width and depth are randomized with a min and max value.

Generating all the rooms is no problem, however opening doors between them is.
I don't want doors between every room, it wouldn't be much of a labyrinth then.

Is it possible to delete the part of the mesh that is within my cuttingBox?
08-25-2009 08:43 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
Re: Cutting a hole in a mesh
shouldnt you make it this way:
room+corridor+room?

if not then show me a simple pic what you want to achieve

(the image below is view from the top)
08-25-2009 08:47 PM
Find all posts by this user Quote this message in a reply
Myx Offline
Member

Post: #9
Re: Cutting a hole in a mesh
1: A basic unmodified room.
2: What I'm currently getting.
3: What I want.

And below them a simple layout on what it would look like.

[attachment=0]
08-25-2009 08:54 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
Re: Cutting a hole in a mesh
yes, you should use the way I proposed above.
08-25-2009 08:57 PM
Find all posts by this user Quote this message in a reply
Myx Offline
Member

Post: #11
Re: Cutting a hole in a mesh
Okay, I'll give it a go.

Thanks alot for all the help, excellent support response!
08-25-2009 09:02 PM
Find all posts by this user Quote this message in a reply
Post Reply