How to subtract a intersection between two meshes in GDSCRIPT

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JayJay99

I’m aiming create a house procedural generator, for now I can create 4 walls in a rectangle shape, here is the code:

var myMesh = MeshInstance.new()
myMesh.mesh = CubeMesh.new()
myMesh.mesh.size = Vector3(x, y, wall_thickness)
myMesh.create_trimesh_collision()
add_child(myMesh)

var myMesh2 = MeshInstance.new()
myMesh2.mesh = CubeMesh.new()
myMesh2.mesh.size = Vector3(x, y, wall_thickness)
myMesh2.translate(Vector3(0, 0, z))
myMesh2.create_trimesh_collision()

add_child(myMesh2)

var myMesh3 = MeshInstance.new()
myMesh3.mesh = CubeMesh.new()
myMesh3.mesh.size = Vector3(wall_thickness, y, z)
myMesh3.translate(Vector3(x/2, 0, z/2))
myMesh3.create_trimesh_collision()

add_child(myMesh3)

var myMesh4 = myMesh3.duplicate()
myMesh4.translate(Vector3(-x, 0, 0))
myMesh4.create_trimesh_collision()

add_child(myMesh4)

Now I want to add doors but I can’t find out a manner to do that, the best way I tought of was to subract the door passage and then add the door mesh, but don’t find any exemple for mesh subtraction in code

:bust_in_silhouette: Reply From: Snail0259

You can use a GSGcombiner with it’s children as CSGboxes (and other GSGshapes).

Thanks, here is an example in code, I added in the CSGcombiner node script

	var wall = CSGBox.new()
wall.width = x
wall.height = y
wall.depth = 0.2
wall.translate(Vector3(0, y/2, 0))  

add_child(wall)
	
var door_passage = CSGBox.new()
door_passage.width = 2
door_passage.height = 4
door_passage.depth = 1
door_passage.operation = OPERATION_SUBTRACTION 
door_passage.translate(Vector3(0, door_passage.height/2, 0))  	
add_child(door_passage)

JayJay99 | 2021-07-18 01:09