Skip to content

Commit

Permalink
Allow to use CSG without nodes
Browse files Browse the repository at this point in the history
Add CSG shape resources.
Add CSGTool for CSG operations.
Make CSG nodes using CSG resources and CSGTool.
  • Loading branch information
trollodel committed Sep 18, 2021
1 parent 181d93e commit c792597
Show file tree
Hide file tree
Showing 29 changed files with 2,540 additions and 1,618 deletions.
48 changes: 48 additions & 0 deletions doc/classes/CSGTool.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="CSGTool" inherits="RefCounted" version="4.0">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="add_primitive">
<return type="void" />
<argument index="0" name="primitive" type="CSGPrimitiveShape3D" />
<argument index="1" name="operation" type="int" enum="CSGTool.Operation" default="0" />
<argument index="2" name="xform" type="Transform3D" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)" />
<argument index="3" name="vertex_snap" type="float" default="0.001" />
<description>
</description>
</method>
<method name="commit">
<return type="ArrayMesh" />
<argument index="0" name="existing" type="ArrayMesh" default="null" />
<argument index="1" name="generate_tangents" type="bool" default="false" />
<description>
</description>
</method>
<method name="create_trimesh_shape" qualifiers="const">
<return type="ConcavePolygonShape3D" />
<description>
</description>
</method>
<method name="get_aabb" qualifiers="const">
<return type="AABB" />
<description>
</description>
</method>
</methods>
<constants>
<constant name="OPERATION_UNION" value="0" enum="Operation">
Geometry of both primitives is merged, intersecting geometry is removed.
</constant>
<constant name="OPERATION_INTERSECTION" value="1" enum="Operation">
Only intersecting geometry remains, the rest is removed.
</constant>
<constant name="OPERATION_SUBTRACTION" value="2" enum="Operation">
The second shape is subtracted from the first, leaving a dent with its shape.
</constant>
</constants>
</class>
7 changes: 7 additions & 0 deletions modules/csg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def get_doc_classes():
"CSGShape3D",
"CSGSphere3D",
"CSGTorus3D",
"CSGBoxShape3D",
"CSGCylinderShape3D",
"CSGMeshShape3D",
"CSGPolygonShape3D",
"CSGPrimitiveShape3D",
"CSGSphereShape3D",
"CSGTorusShape3D"
]


Expand Down
18 changes: 9 additions & 9 deletions modules/csg/csg_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,16 @@ void CSGShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
}
}

CSGTool::Operation op = static_cast<CSGTool::Operation>(cs->get_operation());
Ref<Material> material;
switch (cs->get_operation()) {
case CSGShape3D::OPERATION_UNION:
switch (op) {
case CSGTool::OPERATION_UNION:
material = get_material("shape_union_material", p_gizmo);
break;
case CSGShape3D::OPERATION_INTERSECTION:
case CSGTool::OPERATION_INTERSECTION:
material = get_material("shape_intersection_material", p_gizmo);
break;
case CSGShape3D::OPERATION_SUBTRACTION:
case CSGTool::OPERATION_SUBTRACTION:
material = get_material("shape_subtraction_material", p_gizmo);
break;
}
Expand All @@ -352,14 +352,14 @@ void CSGShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, array);

Ref<Material> solid_material;
switch (cs->get_operation()) {
case CSGShape3D::OPERATION_UNION:
switch (op) {
case CSGTool::OPERATION_UNION:
solid_material = get_material("shape_union_solid_material", p_gizmo);
break;
case CSGShape3D::OPERATION_INTERSECTION:
case CSGTool::OPERATION_INTERSECTION:
solid_material = get_material("shape_intersection_solid_material", p_gizmo);
break;
case CSGShape3D::OPERATION_SUBTRACTION:
case CSGTool::OPERATION_SUBTRACTION:
solid_material = get_material("shape_subtraction_solid_material", p_gizmo);
break;
}
Expand Down
Loading

0 comments on commit c792597

Please sign in to comment.