aboutsummaryrefslogtreecommitdiff
path: root/modules/csg
diff options
context:
space:
mode:
Diffstat (limited to 'modules/csg')
-rw-r--r--modules/csg/csg.cpp28
-rw-r--r--modules/csg/csg.h2
-rw-r--r--modules/csg/csg_shape.cpp255
-rw-r--r--modules/csg/csg_shape.h27
4 files changed, 149 insertions, 163 deletions
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp
index f399466fe..c1fe11d6a 100644
--- a/modules/csg/csg.cpp
+++ b/modules/csg/csg.cpp
@@ -409,6 +409,9 @@ void CSGBrushOperation::BuildPoly::clip(const CSGBrush *p_brush, int p_face, Mes
//transform A points to 2D
+ if (segment[0].distance_to(segment[1]) < CMP_EPSILON)
+ return; //too small
+
_clip_segment(p_brush, p_face, segment, mesh_merge, p_for_B);
}
@@ -586,8 +589,6 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
edge_stack.push_back(es);
}
- int limit = p_poly.points.size() * 4;
-
//attempt to empty the stack.
while (edge_stack.size()) {
@@ -608,7 +609,9 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
edge_process[e.edge] = true; //mark as processed
- while (to_point != e.prev_point) {
+ int limit = p_poly.points.size() * 4; //avoid infinite recursion
+
+ while (to_point != e.prev_point && limit) {
Vector2 segment[2] = { p_poly.points[prev_point].point, p_poly.points[to_point].point };
@@ -618,6 +621,9 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
t2d[1] = Vector2(-t2d[0].y, t2d[0].x); // use as tangent
t2d[2] = segment[1]; //origin
+ if (t2d.basis_determinant() == 0)
+ break; //abort poly
+
t2d.affine_invert();
//push all edges found here, they will be sorted by minimum angle later.
@@ -674,6 +680,8 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
to_point = next_point;
edge_process[next_edge] = true; //mark this edge as processed
current_edge = next_edge;
+
+ limit--;
}
//if more than 2 points were added to the polygon, add it to the list of polygons.
@@ -696,7 +704,9 @@ void CSGBrushOperation::_add_poly_outline(const BuildPoly &p_poly, int p_from_po
int prev_point = p_from_point;
int to_point = p_to_point;
- while (to_point != p_from_point) {
+ int limit = p_poly.points.size() * 4; //avoid infinite recursion
+
+ while (to_point != p_from_point && limit) {
Vector2 segment[2] = { p_poly.points[prev_point].point, p_poly.points[to_point].point };
//again create a transform to compute the angle.
@@ -704,6 +714,10 @@ void CSGBrushOperation::_add_poly_outline(const BuildPoly &p_poly, int p_from_po
t2d[0] = (segment[1] - segment[0]).normalized(); //use as Y
t2d[1] = Vector2(-t2d[0].y, t2d[0].x); // use as tangent
t2d[2] = segment[1]; //origin
+
+ if (t2d.basis_determinant() == 0)
+ break; //abort poly
+
t2d.affine_invert();
float max_angle;
@@ -731,6 +745,8 @@ void CSGBrushOperation::_add_poly_outline(const BuildPoly &p_poly, int p_from_po
r_outline.push_back(to_point);
prev_point = to_point;
to_point = next_point_angle;
+
+ limit--;
}
}
@@ -1216,7 +1232,7 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() {
center /= 3.0;
Plane plane(points[faces[i].points[0]], points[faces[i].points[1]], points[faces[i].points[2]]);
- Vector3 target = center + plane.normal * max_distance;
+ Vector3 target = center + plane.normal * max_distance + Vector3(0.0001234, 0.000512, 0.00013423); //reduce chance of edge hits by doing a small increment
int intersections = _bvh_count_intersections(bvh, max_depth, max_alloc - 1, center, target, i);
@@ -1239,7 +1255,7 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 &p_a, const Vector3 &p
vk.z = int((double(src_points[i].z) + double(vertex_snap) * 0.31234) / double(vertex_snap));
int res;
- if (snap_cache.lookup(vk, &res)) {
+ if (snap_cache.lookup(vk, res)) {
indices[i] = res;
} else {
indices[i] = points.size();
diff --git a/modules/csg/csg.h b/modules/csg/csg.h
index d89e542b5..bb67e1fb3 100644
--- a/modules/csg/csg.h
+++ b/modules/csg/csg.h
@@ -108,7 +108,7 @@ struct CSGBrushOperation {
}
};
- OAHashMap<VertexKey, int, 64, VertexKeyHash> snap_cache;
+ OAHashMap<VertexKey, int, VertexKeyHash> snap_cache;
Vector<Vector3> points;
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp
index 4da94c3ba..1f2f12f54 100644
--- a/modules/csg/csg_shape.cpp
+++ b/modules/csg/csg_shape.cpp
@@ -34,6 +34,14 @@ bool CSGShape::is_root_shape() const {
return !parent;
}
+void CSGShape::set_snap(float p_snap) {
+ snap = p_snap;
+}
+
+float CSGShape::get_snap() const {
+ return snap;
+}
+
void CSGShape::_make_dirty() {
if (!is_inside_tree())
@@ -60,7 +68,61 @@ CSGBrush *CSGShape::_get_brush() {
memdelete(brush);
}
brush = NULL;
- brush = _build_brush(&node_aabb);
+
+ CSGBrush *n = _build_brush();
+
+ for (int i = 0; i < get_child_count(); i++) {
+
+ CSGShape *child = Object::cast_to<CSGShape>(get_child(i));
+ if (!child)
+ continue;
+ if (!child->is_visible_in_tree())
+ continue;
+
+ CSGBrush *n2 = child->_get_brush();
+ if (!n2)
+ continue;
+ if (!n) {
+ n = memnew(CSGBrush);
+
+ n->copy_from(*n2, child->get_transform());
+
+ } else {
+
+ CSGBrush *nn = memnew(CSGBrush);
+ CSGBrush *nn2 = memnew(CSGBrush);
+ nn2->copy_from(*n2, child->get_transform());
+
+ CSGBrushOperation bop;
+
+ switch (child->get_operation()) {
+ case CSGShape::OPERATION_UNION: bop.merge_brushes(CSGBrushOperation::OPERATION_UNION, *n, *nn2, *nn, snap); break;
+ case CSGShape::OPERATION_INTERSECTION: bop.merge_brushes(CSGBrushOperation::OPERATION_INTERSECTION, *n, *nn2, *nn, snap); break;
+ case CSGShape::OPERATION_SUBTRACTION: bop.merge_brushes(CSGBrushOperation::OPERATION_SUBSTRACTION, *n, *nn2, *nn, snap); break;
+ }
+ memdelete(n);
+ memdelete(nn2);
+ n = nn;
+ }
+ }
+
+ if (n) {
+ AABB aabb;
+ for (int i = 0; i < n->faces.size(); i++) {
+ for (int j = 0; j < 3; j++) {
+ if (i == 0 && j == 0)
+ aabb.position = n->faces[i].vertices[j];
+ else
+ aabb.expand_to(n->faces[i].vertices[j]);
+ }
+ }
+ node_aabb = aabb;
+ } else {
+ node_aabb = AABB();
+ }
+
+ brush = n;
+
dirty = false;
}
@@ -95,7 +157,7 @@ void CSGShape::_update_shape() {
for (int j = 0; j < 3; j++) {
Vector3 v = n->faces[i].vertices[j];
Vector3 add;
- if (vec_map.lookup(v, &add)) {
+ if (vec_map.lookup(v, add)) {
add += p.normal;
} else {
add = p.normal;
@@ -171,7 +233,7 @@ void CSGShape::_update_shape() {
Vector3 normal = p.normal;
- if (n->faces[i].smooth && vec_map.lookup(v, &normal)) {
+ if (n->faces[i].smooth && vec_map.lookup(v, normal)) {
normal.normalize();
}
@@ -226,6 +288,9 @@ AABB CSGShape::get_aabb() const {
PoolVector<Vector3> CSGShape::get_brush_faces() {
ERR_FAIL_COND_V(!is_inside_tree(), PoolVector<Vector3>());
CSGBrush *b = _get_brush();
+ if (!b) {
+ return PoolVector<Vector3>();
+ }
PoolVector<Vector3> faces;
int fc = b->faces.size();
@@ -304,23 +369,6 @@ void CSGShape::_validate_property(PropertyInfo &property) const {
//hide collision if not root
property.usage = PROPERTY_USAGE_NOEDITOR;
}
- if (is_inside_tree() && property.name.begins_with("operation")) {
- //hide operation for first node or root
- if (is_root_shape()) {
- property.usage = PROPERTY_USAGE_NOEDITOR;
- } else {
- for (int i = 0; i < get_parent()->get_child_count(); i++) {
- CSGShape *s = Object::cast_to<CSGShape>(get_parent()->get_child(i));
- if (!s)
- continue;
-
- if (s == this) {
- property.usage = PROPERTY_USAGE_NOEDITOR;
- }
- break;
- }
- }
- }
}
void CSGShape::_bind_methods() {
@@ -334,8 +382,12 @@ void CSGShape::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_collision", "operation"), &CSGShape::set_use_collision);
ClassDB::bind_method(D_METHOD("is_using_collision"), &CSGShape::is_using_collision);
+ ClassDB::bind_method(D_METHOD("set_snap", "snap"), &CSGShape::set_snap);
+ ClassDB::bind_method(D_METHOD("get_snap"), &CSGShape::get_snap);
+
ADD_PROPERTY(PropertyInfo(Variant::INT, "operation", PROPERTY_HINT_ENUM, "Union,Intersection,Subtraction"), "set_operation", "get_operation");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_collision"), "set_use_collision", "is_using_collision");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "snap", PROPERTY_HINT_RANGE, "0.0001,1,0.001"), "set_snap", "get_snap");
BIND_CONSTANT(OPERATION_UNION);
BIND_CONSTANT(OPERATION_INTERSECTION);
@@ -349,6 +401,7 @@ CSGShape::CSGShape() {
parent = NULL;
use_collision = false;
operation = OPERATION_UNION;
+ snap = 0.001;
}
CSGShape::~CSGShape() {
@@ -359,79 +412,12 @@ CSGShape::~CSGShape() {
}
//////////////////////////////////
-CSGBrush *CSGCombiner::_build_brush(AABB *r_aabb) {
-
- CSGBrush *n = NULL;
-
- for (int i = 0; i < get_child_count(); i++) {
-
- CSGShape *child = Object::cast_to<CSGShape>(get_child(i));
- if (!child)
- continue;
- if (!child->is_visible_in_tree())
- continue;
-
- CSGBrush *n2 = child->_get_brush();
- if (!n2)
- continue;
- if (!n) {
- n = memnew(CSGBrush);
-
- n->copy_from(*n2, child->get_transform());
-
- } else {
-
- CSGBrush *nn = memnew(CSGBrush);
- CSGBrush *nn2 = memnew(CSGBrush);
- nn2->copy_from(*n2, child->get_transform());
-
- CSGBrushOperation bop;
-
- switch (child->get_operation()) {
- case CSGShape::OPERATION_UNION: bop.merge_brushes(CSGBrushOperation::OPERATION_UNION, *n, *nn2, *nn, snap); break;
- case CSGShape::OPERATION_INTERSECTION: bop.merge_brushes(CSGBrushOperation::OPERATION_INTERSECTION, *n, *nn2, *nn, snap); break;
- case CSGShape::OPERATION_SUBTRACTION: bop.merge_brushes(CSGBrushOperation::OPERATION_SUBSTRACTION, *n, *nn2, *nn, snap); break;
- }
- memdelete(n);
- memdelete(nn2);
- n = nn;
- }
- }
-
- if (n) {
- AABB aabb;
- for (int i = 0; i < n->faces.size(); i++) {
- for (int j = 0; j < 3; j++) {
- if (i == 0 && j == 0)
- aabb.position = n->faces[i].vertices[j];
- else
- aabb.expand_to(n->faces[i].vertices[j]);
- }
- }
- *r_aabb = aabb;
- } else {
- *r_aabb = AABB();
- }
- return n;
-}
-
-void CSGCombiner::set_snap(float p_snap) {
- snap = p_snap;
-}
-
-float CSGCombiner::get_snap() const {
- return snap;
-}
-
-void CSGCombiner::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_snap", "snap"), &CSGCombiner::set_snap);
- ClassDB::bind_method(D_METHOD("get_snap"), &CSGCombiner::get_snap);
+CSGBrush *CSGCombiner::_build_brush() {
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "snap", PROPERTY_HINT_RANGE, "0.0001,1,0.001"), "set_snap", "get_snap");
+ return NULL; //does not build anything
}
CSGCombiner::CSGCombiner() {
- snap = 0.001;
}
/////////////////////
@@ -481,7 +467,7 @@ CSGPrimitive::CSGPrimitive() {
/////////////////////
-CSGBrush *CSGMesh::_build_brush(AABB *r_aabb) {
+CSGBrush *CSGMesh::_build_brush() {
if (!mesh.is_valid())
return NULL;
@@ -491,8 +477,6 @@ CSGBrush *CSGMesh::_build_brush(AABB *r_aabb) {
PoolVector<Ref<Material> > materials;
PoolVector<Vector2> uvs;
- *r_aabb = AABB();
-
for (int i = 0; i < mesh->get_surface_count(); i++) {
if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
@@ -662,7 +646,7 @@ Ref<Mesh> CSGMesh::get_mesh() {
////////////////////////////////
-CSGBrush *CSGSphere::_build_brush(AABB *r_aabb) {
+CSGBrush *CSGSphere::_build_brush() {
// set our bounding box
@@ -778,9 +762,6 @@ CSGBrush *CSGSphere::_build_brush(AABB *r_aabb) {
brush->build_from_faces(faces, uvs, smooth, materials, invert);
- if (r_aabb) {
- *r_aabb = AABB(Vector3(-radius, -radius, -radius), Vector3(radius * 2, radius * 2, radius * 2));
- }
return brush;
}
@@ -867,7 +848,7 @@ CSGSphere::CSGSphere() {
///////////////
-CSGBrush *CSGBox::_build_brush(AABB *r_aabb) {
+CSGBrush *CSGBox::_build_brush() {
// set our bounding box
@@ -969,9 +950,6 @@ CSGBrush *CSGBox::_build_brush(AABB *r_aabb) {
brush->build_from_faces(faces, uvs, smooth, materials, invert);
- if (r_aabb) {
- *r_aabb = AABB(Vector3(-width / 2, -height / 2, -depth / 2), Vector3(width, height, depth));
- }
return brush;
}
@@ -1045,7 +1023,7 @@ CSGBox::CSGBox() {
///////////////
-CSGBrush *CSGCylinder::_build_brush(AABB *r_aabb) {
+CSGBrush *CSGCylinder::_build_brush() {
// set our bounding box
@@ -1178,9 +1156,6 @@ CSGBrush *CSGCylinder::_build_brush(AABB *r_aabb) {
brush->build_from_faces(faces, uvs, smooth, materials, invert);
- if (r_aabb) {
- *r_aabb = AABB(Vector3(-radius, -height / 2, -radius), Vector3(radius * 2, height, radius * 2));
- }
return brush;
}
@@ -1283,7 +1258,7 @@ CSGCylinder::CSGCylinder() {
///////////////
-CSGBrush *CSGTorus::_build_brush(AABB *r_aabb) {
+CSGBrush *CSGTorus::_build_brush() {
// set our bounding box
@@ -1406,10 +1381,6 @@ CSGBrush *CSGTorus::_build_brush(AABB *r_aabb) {
brush->build_from_faces(faces, uvs, smooth, materials, invert);
- if (r_aabb) {
- *r_aabb = AABB(Vector3(-max_radius, -radius, -max_radius), Vector3(max_radius * 2, radius * 2, max_radius * 2));
- }
-
return brush;
}
@@ -1513,14 +1484,20 @@ CSGTorus::CSGTorus() {
///////////////
-CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
+CSGBrush *CSGPolygon::_build_brush() {
// set our bounding box
if (polygon.size() < 3)
return NULL;
- Vector<int> triangles = Geometry::triangulate_polygon(polygon);
+ Vector<Point2> final_polygon = polygon;
+
+ if (Triangulate::get_area(final_polygon) > 0) {
+ final_polygon.invert();
+ }
+
+ Vector<int> triangles = Geometry::triangulate_polygon(final_polygon);
if (triangles.size() < 3)
return NULL;
@@ -1564,12 +1541,12 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
int face_count;
switch (mode) {
- case MODE_DEPTH: face_count = triangles.size() * 2 / 3 + (polygon.size()) * 2; break;
- case MODE_SPIN: face_count = (spin_degrees < 360 ? triangles.size() * 2 / 3 : 0) + (polygon.size()) * 2 * spin_sides; break;
+ case MODE_DEPTH: face_count = triangles.size() * 2 / 3 + (final_polygon.size()) * 2; break;
+ case MODE_SPIN: face_count = (spin_degrees < 360 ? triangles.size() * 2 / 3 : 0) + (final_polygon.size()) * 2 * spin_sides; break;
case MODE_PATH: {
float bl = curve->get_baked_length();
int splits = MAX(2, Math::ceil(bl / path_interval));
- face_count = triangles.size() * 2 / 3 + splits * polygon.size() * 2;
+ face_count = triangles.size() * 2 / 3 + splits * final_polygon.size() * 2;
} break;
}
@@ -1609,7 +1586,7 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
for (int j = 0; j < triangles.size(); j += 3) {
for (int k = 0; k < 3; k++) {
int src[3] = { 0, i == 0 ? 1 : 2, i == 0 ? 2 : 1 };
- Vector2 p = polygon[triangles[j + src[k]]];
+ Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(p.x, p.y, 0);
if (i == 0) {
v.z -= depth;
@@ -1625,15 +1602,15 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
}
//add triangles for depth
- for (int i = 0; i < polygon.size(); i++) {
+ for (int i = 0; i < final_polygon.size(); i++) {
- int i_n = (i + 1) % polygon.size();
+ int i_n = (i + 1) % final_polygon.size();
Vector3 v[4] = {
- Vector3(polygon[i].x, polygon[i].y, -depth),
- Vector3(polygon[i_n].x, polygon[i_n].y, -depth),
- Vector3(polygon[i_n].x, polygon[i_n].y, 0),
- Vector3(polygon[i].x, polygon[i].y, 0),
+ Vector3(final_polygon[i].x, final_polygon[i].y, -depth),
+ Vector3(final_polygon[i_n].x, final_polygon[i_n].y, -depth),
+ Vector3(final_polygon[i_n].x, final_polygon[i_n].y, 0),
+ Vector3(final_polygon[i].x, final_polygon[i].y, 0),
};
Vector2 u[4] = {
@@ -1689,15 +1666,15 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
Vector3 normali_n = Vector3(Math::cos(angi_n), 0, Math::sin(angi_n));
//add triangles for depth
- for (int j = 0; j < polygon.size(); j++) {
+ for (int j = 0; j < final_polygon.size(); j++) {
- int j_n = (j + 1) % polygon.size();
+ int j_n = (j + 1) % final_polygon.size();
Vector3 v[4] = {
- Vector3(normali.x * polygon[j].x, polygon[j].y, normali.z * polygon[j].x),
- Vector3(normali.x * polygon[j_n].x, polygon[j_n].y, normali.z * polygon[j_n].x),
- Vector3(normali_n.x * polygon[j_n].x, polygon[j_n].y, normali_n.z * polygon[j_n].x),
- Vector3(normali_n.x * polygon[j].x, polygon[j].y, normali_n.z * polygon[j].x),
+ Vector3(normali.x * final_polygon[j].x, final_polygon[j].y, normali.z * final_polygon[j].x),
+ Vector3(normali.x * final_polygon[j_n].x, final_polygon[j_n].y, normali.z * final_polygon[j_n].x),
+ Vector3(normali_n.x * final_polygon[j_n].x, final_polygon[j_n].y, normali_n.z * final_polygon[j_n].x),
+ Vector3(normali_n.x * final_polygon[j].x, final_polygon[j].y, normali_n.z * final_polygon[j].x),
};
Vector2 u[4] = {
@@ -1743,7 +1720,7 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
for (int j = 0; j < triangles.size(); j += 3) {
for (int k = 0; k < 3; k++) {
int src[3] = { 0, 2, 1 };
- Vector2 p = polygon[triangles[j + src[k]]];
+ Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(p.x, p.y, 0);
facesw[face * 3 + k] = v;
}
@@ -1760,7 +1737,7 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
for (int j = 0; j < triangles.size(); j += 3) {
for (int k = 0; k < 3; k++) {
int src[3] = { 0, 1, 2 };
- Vector2 p = polygon[triangles[j + src[k]]];
+ Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(normali_n.x * p.x, p.y, normali_n.z * p.x);
facesw[face * 3 + k] = v;
}
@@ -1822,15 +1799,15 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
if (i > 0) {
//put triangles where they belong
//add triangles for depth
- for (int j = 0; j < polygon.size(); j++) {
+ for (int j = 0; j < final_polygon.size(); j++) {
- int j_n = (j + 1) % polygon.size();
+ int j_n = (j + 1) % final_polygon.size();
Vector3 v[4] = {
- prev_xf.xform(Vector3(polygon[j].x, polygon[j].y, 0)),
- prev_xf.xform(Vector3(polygon[j_n].x, polygon[j_n].y, 0)),
- xf.xform(Vector3(polygon[j_n].x, polygon[j_n].y, 0)),
- xf.xform(Vector3(polygon[j].x, polygon[j].y, 0)),
+ prev_xf.xform(Vector3(final_polygon[j].x, final_polygon[j].y, 0)),
+ prev_xf.xform(Vector3(final_polygon[j_n].x, final_polygon[j_n].y, 0)),
+ xf.xform(Vector3(final_polygon[j_n].x, final_polygon[j_n].y, 0)),
+ xf.xform(Vector3(final_polygon[j].x, final_polygon[j].y, 0)),
};
Vector2 u[4] = {
@@ -1877,7 +1854,7 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
for (int j = 0; j < triangles.size(); j += 3) {
for (int k = 0; k < 3; k++) {
int src[3] = { 0, 1, 2 };
- Vector2 p = polygon[triangles[j + src[k]]];
+ Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(p.x, p.y, 0);
facesw[face * 3 + k] = xf.xform(v);
}
@@ -1894,7 +1871,7 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
for (int j = 0; j < triangles.size(); j += 3) {
for (int k = 0; k < 3; k++) {
int src[3] = { 0, 2, 1 };
- Vector2 p = polygon[triangles[j + src[k]]];
+ Vector2 p = final_polygon[triangles[j + src[k]]];
Vector3 v = Vector3(p.x, p.y, 0);
facesw[face * 3 + k] = xf.xform(v);
}
@@ -1926,10 +1903,6 @@ CSGBrush *CSGPolygon::_build_brush(AABB *r_aabb) {
brush->build_from_faces(faces, uvs, smooth, materials, invert);
- if (r_aabb) {
- *r_aabb = aabb;
- }
-
return brush;
}
diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h
index 24d5dfb29..c1d2cce60 100644
--- a/modules/csg/csg_shape.h
+++ b/modules/csg/csg_shape.h
@@ -27,6 +27,7 @@ private:
AABB node_aabb;
bool dirty;
+ float snap;
bool use_collision;
Ref<ConcavePolygonShape> root_collision_shape;
@@ -59,7 +60,7 @@ private:
protected:
void _notification(int p_what);
- virtual CSGBrush *_build_brush(AABB *r_aabb) = 0;
+ virtual CSGBrush *_build_brush() = 0;
void _make_dirty();
static void _bind_methods();
@@ -81,6 +82,9 @@ public:
void set_use_collision(bool p_enable);
bool is_using_collision() const;
+ void set_snap(float p_snap);
+ float get_snap() const;
+
bool is_root_shape() const;
CSGShape();
~CSGShape();
@@ -91,16 +95,9 @@ VARIANT_ENUM_CAST(CSGShape::Operation)
class CSGCombiner : public CSGShape {
GDCLASS(CSGCombiner, CSGShape)
private:
- float snap;
- virtual CSGBrush *_build_brush(AABB *r_aabb);
-
-protected:
- static void _bind_methods();
+ virtual CSGBrush *_build_brush();
public:
- void set_snap(float p_snap);
- float get_snap() const;
-
CSGCombiner();
};
@@ -124,7 +121,7 @@ public:
class CSGMesh : public CSGPrimitive {
GDCLASS(CSGMesh, CSGPrimitive)
- virtual CSGBrush *_build_brush(AABB *r_aabb);
+ virtual CSGBrush *_build_brush();
Ref<Mesh> mesh;
@@ -141,7 +138,7 @@ public:
class CSGSphere : public CSGPrimitive {
GDCLASS(CSGSphere, CSGPrimitive)
- virtual CSGBrush *_build_brush(AABB *r_aabb);
+ virtual CSGBrush *_build_brush();
Ref<Material> material;
bool smooth_faces;
@@ -174,7 +171,7 @@ public:
class CSGBox : public CSGPrimitive {
GDCLASS(CSGBox, CSGPrimitive)
- virtual CSGBrush *_build_brush(AABB *r_aabb);
+ virtual CSGBrush *_build_brush();
Ref<Material> material;
float width;
@@ -203,7 +200,7 @@ public:
class CSGCylinder : public CSGPrimitive {
GDCLASS(CSGCylinder, CSGPrimitive)
- virtual CSGBrush *_build_brush(AABB *r_aabb);
+ virtual CSGBrush *_build_brush();
Ref<Material> material;
float radius;
@@ -240,7 +237,7 @@ public:
class CSGTorus : public CSGPrimitive {
GDCLASS(CSGTorus, CSGPrimitive)
- virtual CSGBrush *_build_brush(AABB *r_aabb);
+ virtual CSGBrush *_build_brush();
Ref<Material> material;
float inner_radius;
@@ -292,7 +289,7 @@ public:
};
private:
- virtual CSGBrush *_build_brush(AABB *r_aabb);
+ virtual CSGBrush *_build_brush();
Vector<Vector2> polygon;
Ref<Material> material;