2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* multimesh_editor_plugin.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "multimesh_editor_plugin.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "editor/editor_node.h"
|
2023-09-13 13:14:07 +02:00
|
|
|
#include "editor/editor_string_names.h"
|
2023-04-07 18:59:49 +02:00
|
|
|
#include "editor/gui/scene_tree_editor.h"
|
|
|
|
#include "editor/plugins/node_3d_editor_plugin.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/mesh_instance_3d.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/box_container.h"
|
2022-11-19 12:45:49 +01:00
|
|
|
#include "scene/gui/menu_button.h"
|
|
|
|
#include "scene/gui/option_button.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void MultiMeshEditor::_node_removed(Node *p_node) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_node == node) {
|
2020-04-02 01:20:12 +02:00
|
|
|
node = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiMeshEditor::_populate() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!node) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Ref<Mesh> mesh;
|
|
|
|
|
2021-12-09 10:42:46 +01:00
|
|
|
if (mesh_source->get_text().is_empty()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
Ref<MultiMesh> multimesh;
|
|
|
|
multimesh = node->get_multimesh();
|
|
|
|
if (multimesh.is_null()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
err_dialog->set_text(TTR("No mesh source specified (and no MultiMesh set in node)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (multimesh->get_mesh().is_null()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
err_dialog->set_text(TTR("No mesh source specified (and MultiMesh contains no Mesh)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh = multimesh->get_mesh();
|
|
|
|
} else {
|
|
|
|
Node *ms_node = node->get_node(mesh_source->get_text());
|
|
|
|
|
|
|
|
if (!ms_node) {
|
2016-05-19 00:08:12 +02:00
|
|
|
err_dialog->set_text(TTR("Mesh source is invalid (invalid path)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
MeshInstance3D *ms_instance = Object::cast_to<MeshInstance3D>(ms_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!ms_instance) {
|
2020-03-30 18:22:57 +02:00
|
|
|
err_dialog->set_text(TTR("Mesh source is invalid (not a MeshInstance3D)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh = ms_instance->get_mesh();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (mesh.is_null()) {
|
2016-05-19 00:08:12 +02:00
|
|
|
err_dialog->set_text(TTR("Mesh source is invalid (contains no Mesh resource)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-09 10:42:46 +01:00
|
|
|
if (surface_source->get_text().is_empty()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
err_dialog->set_text(TTR("No surface source specified."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *ss_node = node->get_node(surface_source->get_text());
|
|
|
|
|
|
|
|
if (!ss_node) {
|
2016-05-19 00:08:12 +02:00
|
|
|
err_dialog->set_text(TTR("Surface source is invalid (invalid path)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-10 08:17:38 +01:00
|
|
|
MeshInstance3D *ss_instance = Object::cast_to<MeshInstance3D>(ss_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-10 08:17:38 +01:00
|
|
|
if (!ss_instance || !ss_instance->get_mesh().is_valid()) {
|
2016-05-19 00:08:12 +02:00
|
|
|
err_dialog->set_text(TTR("Surface source is invalid (no geometry)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D geom_xform = node->get_global_transform().affine_inverse() * ss_instance->get_global_transform();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-10 08:17:38 +01:00
|
|
|
Vector<Face3> geometry = ss_instance->get_mesh()->get_faces();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (geometry.size() == 0) {
|
2016-05-19 00:08:12 +02:00
|
|
|
err_dialog->set_text(TTR("Surface source is invalid (no faces)."));
|
2020-03-06 18:00:16 +01:00
|
|
|
err_dialog->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//make all faces local
|
|
|
|
|
|
|
|
int gc = geometry.size();
|
2020-02-17 22:06:54 +01:00
|
|
|
Face3 *w = geometry.ptrw();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Face3> faces = geometry;
|
2017-03-05 16:44:50 +01:00
|
|
|
int facecount = faces.size();
|
2019-08-15 04:57:49 +02:00
|
|
|
ERR_FAIL_COND_MSG(!facecount, "Parent has no solid faces to populate.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
const Face3 *r = faces.ptr();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float area_accum = 0;
|
2022-05-13 15:04:37 +02:00
|
|
|
RBMap<float, int> triangle_area_map;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < facecount; i++) {
|
2017-01-14 18:03:38 +01:00
|
|
|
float area = r[i].get_area();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (area < CMP_EPSILON) {
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
triangle_area_map[area_accum] = i;
|
|
|
|
area_accum += area;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-08-15 04:57:49 +02:00
|
|
|
ERR_FAIL_COND_MSG(triangle_area_map.size() == 0, "Couldn't map area.");
|
|
|
|
ERR_FAIL_COND_MSG(area_accum == 0, "Couldn't map area.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<MultiMesh> multimesh = memnew(MultiMesh);
|
2014-02-10 02:10:30 +01:00
|
|
|
multimesh->set_mesh(mesh);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int instance_count = populate_amount->get_value();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-11-22 05:26:56 +01:00
|
|
|
multimesh->set_transform_format(MultiMesh::TRANSFORM_3D);
|
2019-09-14 05:37:42 +02:00
|
|
|
multimesh->set_use_colors(false);
|
2014-02-10 02:10:30 +01:00
|
|
|
multimesh->set_instance_count(instance_count);
|
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
float _tilt_random = populate_tilt_random->get_value();
|
|
|
|
float _rotate_random = populate_rotate_random->get_value();
|
|
|
|
float _scale_random = populate_scale_random->get_value();
|
|
|
|
float _scale = populate_scale->get_value();
|
2014-02-10 02:10:30 +01:00
|
|
|
int axis = populate_axis->get_selected();
|
|
|
|
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D axis_xform;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (axis == Vector3::AXIS_Z) {
|
|
|
|
axis_xform.rotate(Vector3(1, 0, 0), -Math_PI * 0.5);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (axis == Vector3::AXIS_X) {
|
|
|
|
axis_xform.rotate(Vector3(0, 0, 1), -Math_PI * 0.5);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < instance_count; i++) {
|
|
|
|
float areapos = Math::random(0.0f, area_accum);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
RBMap<float, int>::Iterator E = triangle_area_map.find_closest(areapos);
|
2019-06-11 14:49:34 +02:00
|
|
|
ERR_FAIL_COND(!E);
|
2022-05-13 15:04:37 +02:00
|
|
|
int index = E->value;
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(index, facecount);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
// ok FINALLY get face
|
|
|
|
Face3 face = r[index];
|
|
|
|
//now compute some position inside the face...
|
|
|
|
|
|
|
|
Vector3 pos = face.get_random_point_inside();
|
|
|
|
Vector3 normal = face.get_plane().normal;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 op_axis = (face.vertex[0] - face.vertex[1]).normalized();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D xform;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
xform.set_look_at(pos, pos + op_axis, normal);
|
2014-02-10 02:10:30 +01:00
|
|
|
xform = xform * axis_xform;
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Basis post_xform;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-05-03 14:50:35 +02:00
|
|
|
post_xform.rotate(xform.basis.get_column(1), -Math::random(-_rotate_random, _rotate_random) * Math_PI);
|
|
|
|
post_xform.rotate(xform.basis.get_column(2), -Math::random(-_tilt_random, _tilt_random) * Math_PI);
|
|
|
|
post_xform.rotate(xform.basis.get_column(0), -Math::random(-_tilt_random, _tilt_random) * Math_PI);
|
2017-01-05 18:31:39 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
xform.basis = post_xform * xform.basis;
|
|
|
|
//xform.basis.orthonormalize();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
xform.basis.scale(Vector3(1, 1, 1) * (_scale + Math::random(-_scale_random, _scale_random)));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
multimesh->set_instance_transform(i, xform);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
node->set_multimesh(multimesh);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void MultiMeshEditor::_browsed(const NodePath &p_path) {
|
|
|
|
NodePath path = node->get_path_to(get_node(p_path));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (browsing_source) {
|
2014-02-10 02:10:30 +01:00
|
|
|
mesh_source->set_text(path);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
surface_source->set_text(path);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiMeshEditor::_menu_option(int p_option) {
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_option) {
|
2014-02-10 02:10:30 +01:00
|
|
|
case MENU_OPTION_POPULATE: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (_last_pp_node != node) {
|
2014-02-10 02:10:30 +01:00
|
|
|
surface_source->set_text("..");
|
|
|
|
mesh_source->set_text("..");
|
|
|
|
populate_axis->select(1);
|
2017-01-04 05:16:14 +01:00
|
|
|
populate_rotate_random->set_value(0);
|
|
|
|
populate_tilt_random->set_value(0);
|
|
|
|
populate_scale_random->set_value(0);
|
|
|
|
populate_scale->set_value(1);
|
|
|
|
populate_amount->set_value(128);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_last_pp_node = node;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_dialog->popup_centered(Size2(250, 380));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void MultiMeshEditor::edit(MultiMeshInstance3D *p_multimesh) {
|
2017-03-05 16:44:50 +01:00
|
|
|
node = p_multimesh;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiMeshEditor::_browse(bool p_source) {
|
2017-03-05 16:44:50 +01:00
|
|
|
browsing_source = p_source;
|
|
|
|
std->get_scene_tree()->set_marked(node, false);
|
2020-07-11 18:45:19 +02:00
|
|
|
std->popup_scenetree_dialog();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_source) {
|
2016-05-04 03:25:37 +02:00
|
|
|
std->set_title(TTR("Select a Source Mesh:"));
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2016-05-04 03:25:37 +02:00
|
|
|
std->set_title(TTR("Select a Target Surface:"));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiMeshEditor::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiMeshEditor::MultiMeshEditor() {
|
2017-03-05 16:44:50 +01:00
|
|
|
options = memnew(MenuButton);
|
2019-04-25 15:27:33 +02:00
|
|
|
options->set_switch_on_hover(true);
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditor::get_singleton()->add_control_to_menu_panel(options);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
options->set_text("MultiMesh");
|
2023-09-13 13:14:07 +02:00
|
|
|
options->set_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("MultiMeshInstance3D"), EditorStringName(EditorIcons)));
|
2015-08-29 22:16:11 +02:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
options->get_popup()->add_item(TTR("Populate Surface"));
|
2020-02-21 18:28:45 +01:00
|
|
|
options->get_popup()->connect("id_pressed", callable_mp(this, &MultiMeshEditor::_menu_option));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_dialog = memnew(ConfirmationDialog);
|
2016-05-04 03:25:37 +02:00
|
|
|
populate_dialog->set_title(TTR("Populate MultiMesh"));
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(populate_dialog);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_dialog->add_child(vbc);
|
2017-01-10 05:49:55 +01:00
|
|
|
//populate_dialog->set_child_rect(vbc);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
surface_source = memnew(LineEdit);
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(surface_source);
|
|
|
|
surface_source->set_h_size_flags(SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
Button *b = memnew(Button);
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(b);
|
|
|
|
b->set_text("..");
|
2022-07-28 22:56:41 +02:00
|
|
|
b->connect("pressed", callable_mp(this, &MultiMeshEditor::_browse).bind(false));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Target Surface:"), hbc);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
hbc = memnew(HBoxContainer);
|
|
|
|
mesh_source = memnew(LineEdit);
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(mesh_source);
|
|
|
|
mesh_source->set_h_size_flags(SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
b = memnew(Button);
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(b);
|
|
|
|
b->set_text("..");
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Source Mesh:"), hbc);
|
2022-07-28 22:56:41 +02:00
|
|
|
b->connect("pressed", callable_mp(this, &MultiMeshEditor::_browse).bind(true));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_axis = memnew(OptionButton);
|
2016-05-04 03:25:37 +02:00
|
|
|
populate_axis->add_item(TTR("X-Axis"));
|
|
|
|
populate_axis->add_item(TTR("Y-Axis"));
|
|
|
|
populate_axis->add_item(TTR("Z-Axis"));
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_axis->select(2);
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Mesh Up Axis:"), populate_axis);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_rotate_random = memnew(HSlider);
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_rotate_random->set_max(1);
|
|
|
|
populate_rotate_random->set_step(0.01);
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Random Rotation:"), populate_rotate_random);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_tilt_random = memnew(HSlider);
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_tilt_random->set_max(1);
|
|
|
|
populate_tilt_random->set_step(0.01);
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Random Tilt:"), populate_tilt_random);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_scale_random = memnew(SpinBox);
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_scale_random->set_min(0);
|
|
|
|
populate_scale_random->set_max(1);
|
2017-01-04 05:16:14 +01:00
|
|
|
populate_scale_random->set_value(0);
|
2016-11-22 05:26:56 +01:00
|
|
|
populate_scale_random->set_step(0.01);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Random Scale:"), populate_scale_random);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_scale = memnew(SpinBox);
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_scale->set_min(0.001);
|
|
|
|
populate_scale->set_max(4096);
|
2017-01-04 05:16:14 +01:00
|
|
|
populate_scale->set_value(1);
|
2016-11-22 05:26:56 +01:00
|
|
|
populate_scale->set_step(0.01);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Scale:"), populate_scale);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_amount = memnew(SpinBox);
|
2020-12-22 17:24:29 +01:00
|
|
|
populate_amount->set_anchor(SIDE_RIGHT, ANCHOR_END);
|
2017-03-05 16:44:50 +01:00
|
|
|
populate_amount->set_begin(Point2(20, 232));
|
2017-07-06 09:16:27 +02:00
|
|
|
populate_amount->set_end(Point2(-5, 237));
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_amount->set_min(1);
|
|
|
|
populate_amount->set_max(65536);
|
2017-01-04 05:16:14 +01:00
|
|
|
populate_amount->set_value(128);
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->add_margin_child(TTR("Amount:"), populate_amount);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-08 02:31:19 +02:00
|
|
|
populate_dialog->set_ok_button_text(TTR("Populate"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-12-14 19:37:30 +01:00
|
|
|
populate_dialog->get_ok_button()->connect("pressed", callable_mp(this, &MultiMeshEditor::_populate));
|
2017-03-05 16:44:50 +01:00
|
|
|
std = memnew(SceneTreeDialog);
|
2023-11-15 12:21:50 +01:00
|
|
|
Vector<StringName> valid_types;
|
|
|
|
valid_types.push_back("MeshInstance3D");
|
|
|
|
std->set_valid_types(valid_types);
|
2014-02-10 02:10:30 +01:00
|
|
|
populate_dialog->add_child(std);
|
2020-02-21 18:28:45 +01:00
|
|
|
std->connect("selected", callable_mp(this, &MultiMeshEditor::_browsed));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
_last_pp_node = nullptr;
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
err_dialog = memnew(AcceptDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(err_dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiMeshEditorPlugin::edit(Object *p_object) {
|
2020-03-26 22:49:16 +01:00
|
|
|
multimesh_editor->edit(Object::cast_to<MultiMeshInstance3D>(p_object));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MultiMeshEditorPlugin::handles(Object *p_object) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
return p_object->is_class("MultiMeshInstance3D");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiMeshEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
if (p_visible) {
|
2015-04-09 14:48:46 +02:00
|
|
|
multimesh_editor->options->show();
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2015-04-09 14:48:46 +02:00
|
|
|
multimesh_editor->options->hide();
|
2020-04-02 01:20:12 +02:00
|
|
|
multimesh_editor->edit(nullptr);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
MultiMeshEditorPlugin::MultiMeshEditorPlugin() {
|
2017-03-05 16:44:50 +01:00
|
|
|
multimesh_editor = memnew(MultiMeshEditor);
|
2022-09-07 01:30:54 +02:00
|
|
|
EditorNode::get_singleton()->get_main_screen_control()->add_child(multimesh_editor);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-04-09 14:48:46 +02:00
|
|
|
multimesh_editor->options->hide();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MultiMeshEditorPlugin::~MultiMeshEditorPlugin() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|