1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

A Whole New World (clang-format edition)

I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?

I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon

A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format

A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
This commit is contained in:
Rémi Verschelde
2017-03-05 16:44:50 +01:00
parent 45438e9918
commit 5dbf1809c6
1318 changed files with 140051 additions and 166004 deletions

View File

@@ -28,29 +28,26 @@
/*************************************************************************/
#include "multimesh_editor_plugin.h"
#include "scene/gui/box_container.h"
#include "scene/3d/mesh_instance.h"
#include "scene/gui/box_container.h"
#include "spatial_editor_plugin.h"
void MultiMeshEditor::_node_removed(Node *p_node) {
if(p_node==node) {
node=NULL;
if (p_node == node) {
node = NULL;
hide();
}
}
void MultiMeshEditor::_populate() {
if(!node)
if (!node)
return;
Ref<Mesh> mesh;
if (mesh_source->get_text()=="") {
if (mesh_source->get_text() == "") {
Ref<MultiMesh> multimesh;
multimesh = node->get_multimesh();
@@ -88,7 +85,7 @@ void MultiMeshEditor::_populate() {
return;
}
mesh=ms_instance->get_mesh();
mesh = ms_instance->get_mesh();
if (mesh.is_null()) {
@@ -96,10 +93,9 @@ void MultiMeshEditor::_populate() {
err_dialog->popup_centered_minsize();
return;
}
}
if (surface_source->get_text()=="") {
if (surface_source->get_text() == "") {
err_dialog->set_text(TTR("No surface source specified."));
err_dialog->popup_centered_minsize();
@@ -128,7 +124,7 @@ void MultiMeshEditor::_populate() {
PoolVector<Face3> geometry = ss_instance->get_faces(VisualInstance::FACES_SOLID);
if (geometry.size()==0) {
if (geometry.size() == 0) {
err_dialog->set_text(TTR("Surface source is invalid (no faces)."));
err_dialog->popup_centered_minsize();
@@ -140,14 +136,12 @@ void MultiMeshEditor::_populate() {
int gc = geometry.size();
PoolVector<Face3>::Write w = geometry.write();
for(int i=0;i<gc;i++) {
for(int j=0;j<3;j++) {
w[i].vertex[j] = geom_xform.xform( w[i].vertex[j] );
for (int i = 0; i < gc; i++) {
for (int j = 0; j < 3; j++) {
w[i].vertex[j] = geom_xform.xform(w[i].vertex[j]);
}
}
w = PoolVector<Face3>::Write();
#if 0
node->get_multimesh()->set_instance_count(populate_amount->get_val());
@@ -167,34 +161,31 @@ void MultiMeshEditor::_populate() {
#endif
PoolVector<Face3> faces = geometry;
ERR_EXPLAIN(TTR("Parent has no solid faces to populate."));
int facecount=faces.size();
int facecount = faces.size();
ERR_FAIL_COND(!facecount);
PoolVector<Face3>::Read r = faces.read();
float area_accum=0;
Map<float,int> triangle_area_map;
for(int i=0;i<facecount;i++) {
float area_accum = 0;
Map<float, int> triangle_area_map;
for (int i = 0; i < facecount; i++) {
float area = r[i].get_area();
if (area<CMP_EPSILON)
if (area < CMP_EPSILON)
continue;
triangle_area_map[area_accum]=i;
area_accum+=area;
triangle_area_map[area_accum] = i;
area_accum += area;
}
ERR_EXPLAIN(TTR("Couldn't map area."));
ERR_FAIL_COND(triangle_area_map.size()==0);
ERR_FAIL_COND(triangle_area_map.size() == 0);
ERR_EXPLAIN(TTR("Couldn't map area."));
ERR_FAIL_COND(area_accum==0);
ERR_FAIL_COND(area_accum == 0);
Ref<MultiMesh> multimesh = memnew( MultiMesh );
Ref<MultiMesh> multimesh = memnew(MultiMesh);
multimesh->set_mesh(mesh);
int instance_count=populate_amount->get_value();
int instance_count = populate_amount->get_value();
multimesh->set_transform_format(MultiMesh::TRANSFORM_3D);
multimesh->set_color_format(MultiMesh::COLOR_NONE);
@@ -207,21 +198,21 @@ void MultiMeshEditor::_populate() {
int axis = populate_axis->get_selected();
Transform axis_xform;
if (axis==Vector3::AXIS_Z) {
axis_xform.rotate(Vector3(1,0,0),-Math_PI*0.5);
if (axis == Vector3::AXIS_Z) {
axis_xform.rotate(Vector3(1, 0, 0), -Math_PI * 0.5);
}
if (axis==Vector3::AXIS_X) {
axis_xform.rotate(Vector3(0,0,1),-Math_PI*0.5);
if (axis == Vector3::AXIS_X) {
axis_xform.rotate(Vector3(0, 0, 1), -Math_PI * 0.5);
}
for(int i=0;i<instance_count;i++) {
for (int i = 0; i < instance_count; i++) {
float areapos = Math::random(0.0f,area_accum);
float areapos = Math::random(0.0f, area_accum);
Map<float,int>::Element *E = triangle_area_map.find_closest(areapos);
Map<float, int>::Element *E = triangle_area_map.find_closest(areapos);
ERR_FAIL_COND(!E)
int index = E->get();
ERR_FAIL_INDEX(index,facecount);
ERR_FAIL_INDEX(index, facecount);
// ok FINALLY get face
Face3 face = r[index];
@@ -229,41 +220,33 @@ void MultiMeshEditor::_populate() {
Vector3 pos = face.get_random_point_inside();
Vector3 normal = face.get_plane().normal;
Vector3 op_axis = (face.vertex[0]-face.vertex[1]).normalized();
Vector3 op_axis = (face.vertex[0] - face.vertex[1]).normalized();
Transform xform;
xform.set_look_at(pos, pos+op_axis,normal);
xform.set_look_at(pos, pos + op_axis, normal);
xform = xform * axis_xform;
Basis post_xform;
post_xform.rotate(xform.basis.get_axis(1),-Math::random(-_rotate_random,_rotate_random)*Math_PI);
post_xform.rotate(xform.basis.get_axis(2),-Math::random(-_tilt_random,_tilt_random)*Math_PI);
post_xform.rotate(xform.basis.get_axis(0),-Math::random(-_tilt_random,_tilt_random)*Math_PI);
post_xform.rotate(xform.basis.get_axis(1), -Math::random(-_rotate_random, _rotate_random) * Math_PI);
post_xform.rotate(xform.basis.get_axis(2), -Math::random(-_tilt_random, _tilt_random) * Math_PI);
post_xform.rotate(xform.basis.get_axis(0), -Math::random(-_tilt_random, _tilt_random) * Math_PI);
xform.basis = post_xform * xform.basis;
//xform.basis.orthonormalize();
xform.basis.scale(Vector3(1, 1, 1) * (_scale + Math::random(-_scale_random, _scale_random)));
xform.basis.scale(Vector3(1,1,1)*(_scale+Math::random(-_scale_random,_scale_random)));
multimesh->set_instance_transform(i,xform);
multimesh->set_instance_transform(i, xform);
}
node->set_multimesh(multimesh);
}
void MultiMeshEditor::_browsed(const NodePath& p_path) {
void MultiMeshEditor::_browsed(const NodePath &p_path) {
NodePath path = node->get_path_to( get_node(p_path) );
NodePath path = node->get_path_to(get_node(p_path));
if (browsing_source)
mesh_source->set_text(path);
@@ -273,14 +256,11 @@ void MultiMeshEditor::_browsed(const NodePath& p_path) {
void MultiMeshEditor::_menu_option(int p_option) {
switch(p_option) {
switch (p_option) {
case MENU_OPTION_POPULATE: {
if (_last_pp_node!=node) {
if (_last_pp_node != node) {
surface_source->set_text("..");
mesh_source->set_text("..");
@@ -291,25 +271,23 @@ void MultiMeshEditor::_menu_option(int p_option) {
populate_scale->set_value(1);
populate_amount->set_value(128);
_last_pp_node=node;
_last_pp_node = node;
}
populate_dialog->popup_centered(Size2(250,380));
populate_dialog->popup_centered(Size2(250, 380));
} break;
}
}
void MultiMeshEditor::edit(MultiMeshInstance *p_multimesh) {
node=p_multimesh;
node = p_multimesh;
}
void MultiMeshEditor::_browse(bool p_source) {
browsing_source=p_source;
std->get_scene_tree()->set_marked(node,false);
browsing_source = p_source;
std->get_scene_tree()->set_marked(node, false);
std->popup_centered_ratio();
if (p_source)
std->set_title(TTR("Select a Source Mesh:"));
@@ -319,113 +297,108 @@ void MultiMeshEditor::_browse(bool p_source) {
void MultiMeshEditor::_bind_methods() {
ClassDB::bind_method("_menu_option",&MultiMeshEditor::_menu_option);
ClassDB::bind_method("_populate",&MultiMeshEditor::_populate);
ClassDB::bind_method("_browsed",&MultiMeshEditor::_browsed);
ClassDB::bind_method("_browse",&MultiMeshEditor::_browse);
ClassDB::bind_method("_menu_option", &MultiMeshEditor::_menu_option);
ClassDB::bind_method("_populate", &MultiMeshEditor::_populate);
ClassDB::bind_method("_browsed", &MultiMeshEditor::_browsed);
ClassDB::bind_method("_browse", &MultiMeshEditor::_browse);
}
MultiMeshEditor::MultiMeshEditor() {
options = memnew( MenuButton );
options = memnew(MenuButton);
SpatialEditor::get_singleton()->add_control_to_menu_panel(options);
options->set_text("MultiMesh");
options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MultiMeshInstance","EditorIcons"));
options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MultiMeshInstance", "EditorIcons"));
options->get_popup()->add_item(TTR("Populate Surface"));
options->get_popup()->connect("id_pressed", this,"_menu_option");
options->get_popup()->connect("id_pressed", this, "_menu_option");
populate_dialog = memnew( ConfirmationDialog );
populate_dialog = memnew(ConfirmationDialog);
populate_dialog->set_title(TTR("Populate MultiMesh"));
add_child(populate_dialog);
VBoxContainer *vbc = memnew( VBoxContainer );
VBoxContainer *vbc = memnew(VBoxContainer);
populate_dialog->add_child(vbc);
//populate_dialog->set_child_rect(vbc);
HBoxContainer *hbc = memnew( HBoxContainer );
HBoxContainer *hbc = memnew(HBoxContainer);
surface_source = memnew( LineEdit );
surface_source = memnew(LineEdit);
hbc->add_child(surface_source);
surface_source->set_h_size_flags(SIZE_EXPAND_FILL);
Button *b = memnew( Button );
Button *b = memnew(Button);
hbc->add_child(b);
b->set_text("..");
b->connect("pressed",this,"_browse",make_binds(false));
b->connect("pressed", this, "_browse", make_binds(false));
vbc->add_margin_child(TTR("Target Surface:"),hbc);
vbc->add_margin_child(TTR("Target Surface:"), hbc);
hbc = memnew( HBoxContainer );
mesh_source = memnew( LineEdit );
hbc = memnew(HBoxContainer);
mesh_source = memnew(LineEdit);
hbc->add_child(mesh_source);
mesh_source->set_h_size_flags(SIZE_EXPAND_FILL);
b = memnew( Button );
b = memnew(Button);
hbc->add_child(b);
b->set_text("..");
vbc->add_margin_child(TTR("Source Mesh:"),hbc);
b->connect("pressed",this,"_browse",make_binds(true));
vbc->add_margin_child(TTR("Source Mesh:"), hbc);
b->connect("pressed", this, "_browse", make_binds(true));
populate_axis = memnew( OptionButton );
populate_axis = memnew(OptionButton);
populate_axis->add_item(TTR("X-Axis"));
populate_axis->add_item(TTR("Y-Axis"));
populate_axis->add_item(TTR("Z-Axis"));
populate_axis->select(2);
vbc->add_margin_child(TTR("Mesh Up Axis:"),populate_axis);
vbc->add_margin_child(TTR("Mesh Up Axis:"), populate_axis);
populate_rotate_random = memnew( HSlider );
populate_rotate_random = memnew(HSlider);
populate_rotate_random->set_max(1);
populate_rotate_random->set_step(0.01);
vbc->add_margin_child(TTR("Random Rotation:"),populate_rotate_random);
vbc->add_margin_child(TTR("Random Rotation:"), populate_rotate_random);
populate_tilt_random = memnew( HSlider );
populate_tilt_random = memnew(HSlider);
populate_tilt_random->set_max(1);
populate_tilt_random->set_step(0.01);
vbc->add_margin_child(TTR("Random Tilt:"),populate_tilt_random);
vbc->add_margin_child(TTR("Random Tilt:"), populate_tilt_random);
populate_scale_random = memnew( SpinBox );
populate_scale_random = memnew(SpinBox);
populate_scale_random->set_min(0);
populate_scale_random->set_max(1);
populate_scale_random->set_value(0);
populate_scale_random->set_step(0.01);
vbc->add_margin_child(TTR("Random Scale:"),populate_scale_random);
vbc->add_margin_child(TTR("Random Scale:"), populate_scale_random);
populate_scale = memnew( SpinBox );
populate_scale = memnew(SpinBox);
populate_scale->set_min(0.001);
populate_scale->set_max(4096);
populate_scale->set_value(1);
populate_scale->set_step(0.01);
vbc->add_margin_child(TTR("Scale:"),populate_scale);
vbc->add_margin_child(TTR("Scale:"), populate_scale);
populate_amount = memnew( SpinBox );
populate_amount->set_anchor(MARGIN_RIGHT,ANCHOR_END);
populate_amount->set_begin( Point2(20,232));
populate_amount->set_end( Point2(5,237));
populate_amount = memnew(SpinBox);
populate_amount->set_anchor(MARGIN_RIGHT, ANCHOR_END);
populate_amount->set_begin(Point2(20, 232));
populate_amount->set_end(Point2(5, 237));
populate_amount->set_min(1);
populate_amount->set_max(65536);
populate_amount->set_value(128);
vbc->add_margin_child(TTR("Amount:"),populate_amount);
vbc->add_margin_child(TTR("Amount:"), populate_amount);
populate_dialog->get_ok()->set_text(TTR("Populate"));
populate_dialog->get_ok()->connect("pressed", this,"_populate");
std = memnew( SceneTreeDialog );
populate_dialog->get_ok()->connect("pressed", this, "_populate");
std = memnew(SceneTreeDialog);
populate_dialog->add_child(std);
std->connect("selected",this,"_browsed");
std->connect("selected", this, "_browsed");
_last_pp_node=NULL;
_last_pp_node = NULL;
err_dialog = memnew( AcceptDialog );
err_dialog = memnew(AcceptDialog);
add_child(err_dialog);
}
void MultiMeshEditorPlugin::edit(Object *p_object) {
multimesh_editor->edit(p_object->cast_to<MultiMeshInstance>());
@@ -445,21 +418,16 @@ void MultiMeshEditorPlugin::make_visible(bool p_visible) {
multimesh_editor->options->hide();
multimesh_editor->edit(NULL);
}
}
MultiMeshEditorPlugin::MultiMeshEditorPlugin(EditorNode *p_node) {
editor=p_node;
multimesh_editor = memnew( MultiMeshEditor );
editor = p_node;
multimesh_editor = memnew(MultiMeshEditor);
editor->get_viewport()->add_child(multimesh_editor);
multimesh_editor->options->hide();
}
MultiMeshEditorPlugin::~MultiMeshEditorPlugin()
{
MultiMeshEditorPlugin::~MultiMeshEditorPlugin() {
}