1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

CSG Support for Godot!

-Missing Icons
-Missing freezing option (for baking light and faster load)
-Missing a way to export from Godot (GLTF2?)
-Probably buggy (may freeze editor, can be worked around easily, but let me know if this happens so it's easier to catch bugs)
Happy testing!
This commit is contained in:
Juan Linietsky
2018-04-27 21:52:15 -03:00
parent b22f048700
commit 8d199a9b2c
18 changed files with 4715 additions and 42 deletions

View File

@@ -36,7 +36,7 @@
#include "scene/3d/camera.h"
#include "spatial_editor_plugin.h"
void CollisionPolygonEditor::_notification(int p_what) {
void Polygon3DEditor::_notification(int p_what) {
switch (p_what) {
@@ -53,15 +53,15 @@ void CollisionPolygonEditor::_notification(int p_what) {
return;
}
if (node->get_depth() != prev_depth) {
if (_get_depth() != prev_depth) {
_polygon_draw();
prev_depth = node->get_depth();
prev_depth = _get_depth();
}
} break;
}
}
void CollisionPolygonEditor::_node_removed(Node *p_node) {
void Polygon3DEditor::_node_removed(Node *p_node) {
if (p_node == node) {
node = NULL;
@@ -72,7 +72,7 @@ void CollisionPolygonEditor::_node_removed(Node *p_node) {
}
}
void CollisionPolygonEditor::_menu_option(int p_option) {
void Polygon3DEditor::_menu_option(int p_option) {
switch (p_option) {
@@ -91,10 +91,10 @@ void CollisionPolygonEditor::_menu_option(int p_option) {
}
}
void CollisionPolygonEditor::_wip_close() {
void Polygon3DEditor::_wip_close() {
undo_redo->create_action(TTR("Create Poly3D"));
undo_redo->add_undo_method(node, "set_polygon", node->get_polygon());
undo_redo->add_undo_method(node, "set_polygon", node->call("get_polygon"));
undo_redo->add_do_method(node, "set_polygon", wip);
undo_redo->add_do_method(this, "_polygon_draw");
undo_redo->add_undo_method(this, "_polygon_draw");
@@ -107,14 +107,14 @@ void CollisionPolygonEditor::_wip_close() {
undo_redo->commit_action();
}
bool CollisionPolygonEditor::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
bool Polygon3DEditor::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!node)
return false;
Transform gt = node->get_global_transform();
Transform gi = gt.affine_inverse();
float depth = node->get_depth() * 0.5;
float depth = _get_depth() * 0.5;
Vector3 n = gt.basis.get_axis(2).normalized();
Plane p(gt.origin + n * depth, n);
@@ -137,7 +137,7 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera *p_camera, const R
cpoint = CanvasItemEditor::get_singleton()->snap_point(cpoint);
Vector<Vector2> poly = node->get_polygon();
Vector<Vector2> poly = node->call("get_polygon");
//first check if a point is to be added (segment split)
real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
@@ -226,7 +226,7 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera *p_camera, const R
poly.insert(closest_idx + 1, cpoint);
edited_point = closest_idx + 1;
edited_point_pos = cpoint;
node->set_polygon(poly);
node->call("set_polygon", poly);
_polygon_draw();
return true;
}
@@ -341,7 +341,16 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera *p_camera, const R
return false;
}
void CollisionPolygonEditor::_polygon_draw() {
float Polygon3DEditor::_get_depth() {
if (bool(node->call("_has_editable_3d_polygon_no_depth")))
return 0;
return float(node->call("get_depth"));
}
void Polygon3DEditor::_polygon_draw() {
if (!node)
return;
@@ -351,9 +360,9 @@ void CollisionPolygonEditor::_polygon_draw() {
if (wip_active)
poly = wip;
else
poly = node->get_polygon();
poly = node->call("get_polygon");
float depth = node->get_depth() * 0.5;
float depth = _get_depth() * 0.5;
imgeom->clear();
imgeom->set_material_override(line_material);
@@ -464,13 +473,13 @@ void CollisionPolygonEditor::_polygon_draw() {
m->surface_set_material(0, handle_material);
}
void CollisionPolygonEditor::edit(Node *p_collision_polygon) {
void Polygon3DEditor::edit(Node *p_collision_polygon) {
if (p_collision_polygon) {
node = Object::cast_to<CollisionPolygon>(p_collision_polygon);
node = Object::cast_to<Spatial>(p_collision_polygon);
//Enable the pencil tool if the polygon is empty
if (node->get_polygon().size() == 0) {
if (Vector<Vector2>(node->call("get_polygon")).size() == 0) {
_menu_option(MODE_CREATE);
}
wip.clear();
@@ -491,14 +500,14 @@ void CollisionPolygonEditor::edit(Node *p_collision_polygon) {
}
}
void CollisionPolygonEditor::_bind_methods() {
void Polygon3DEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_menu_option"), &CollisionPolygonEditor::_menu_option);
ClassDB::bind_method(D_METHOD("_polygon_draw"), &CollisionPolygonEditor::_polygon_draw);
ClassDB::bind_method(D_METHOD("_node_removed"), &CollisionPolygonEditor::_node_removed);
ClassDB::bind_method(D_METHOD("_menu_option"), &Polygon3DEditor::_menu_option);
ClassDB::bind_method(D_METHOD("_polygon_draw"), &Polygon3DEditor::_polygon_draw);
ClassDB::bind_method(D_METHOD("_node_removed"), &Polygon3DEditor::_node_removed);
}
CollisionPolygonEditor::CollisionPolygonEditor(EditorNode *p_editor) {
Polygon3DEditor::Polygon3DEditor(EditorNode *p_editor) {
node = NULL;
editor = p_editor;
@@ -545,22 +554,22 @@ CollisionPolygonEditor::CollisionPolygonEditor(EditorNode *p_editor) {
pointsm->set_transform(Transform(Basis(), Vector3(0, 0, 0.00001)));
}
CollisionPolygonEditor::~CollisionPolygonEditor() {
Polygon3DEditor::~Polygon3DEditor() {
memdelete(imgeom);
}
void CollisionPolygonEditorPlugin::edit(Object *p_object) {
void Polygon3DEditorPlugin::edit(Object *p_object) {
collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
}
bool CollisionPolygonEditorPlugin::handles(Object *p_object) const {
bool Polygon3DEditorPlugin::handles(Object *p_object) const {
return p_object->is_class("CollisionPolygon");
return Object::cast_to<Spatial>(p_object) && bool(p_object->call("_is_editable_3d_polygon"));
}
void CollisionPolygonEditorPlugin::make_visible(bool p_visible) {
void Polygon3DEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
collision_polygon_editor->show();
@@ -571,14 +580,14 @@ void CollisionPolygonEditorPlugin::make_visible(bool p_visible) {
}
}
CollisionPolygonEditorPlugin::CollisionPolygonEditorPlugin(EditorNode *p_node) {
Polygon3DEditorPlugin::Polygon3DEditorPlugin(EditorNode *p_node) {
editor = p_node;
collision_polygon_editor = memnew(CollisionPolygonEditor(p_node));
collision_polygon_editor = memnew(Polygon3DEditor(p_node));
SpatialEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor);
collision_polygon_editor->hide();
}
CollisionPolygonEditorPlugin::~CollisionPolygonEditorPlugin() {
Polygon3DEditorPlugin::~Polygon3DEditorPlugin() {
}