Finished the initial logic port for mdr ed's classses.

This commit is contained in:
Relintai 2022-04-13 14:59:40 +02:00
parent b0c2deab78
commit bb4504d2f7
8 changed files with 969 additions and 826 deletions

View File

@ -37,10 +37,10 @@ if 'TOOLS_ENABLED' in env["CPPDEFINES"]:
module_env.add_source_files(env.modules_sources,"editor/uv_editor/mdr_uv_rect_view_popup.cpp") module_env.add_source_files(env.modules_sources,"editor/uv_editor/mdr_uv_rect_view_popup.cpp")
module_env.add_source_files(env.modules_sources,"editor/uv_editor/mdr_uv_rect_view.cpp") module_env.add_source_files(env.modules_sources,"editor/uv_editor/mdr_uv_rect_view.cpp")
#module_env.add_source_files(env.modules_sources,"editor/mdi_ed_plugin.cpp") module_env.add_source_files(env.modules_sources,"editor/mdi_ed_plugin.cpp")
#module_env.add_source_files(env.modules_sources,"editor/mdi_ed.cpp") module_env.add_source_files(env.modules_sources,"editor/mdi_ed.cpp")
#module_env.add_source_files(env.modules_sources,"editor/mdi_gizmo_plugin.cpp") module_env.add_source_files(env.modules_sources,"editor/mdi_gizmo_plugin.cpp")
#module_env.add_source_files(env.modules_sources,"editor/mdi_gizmo.cpp") module_env.add_source_files(env.modules_sources,"editor/mdi_gizmo.cpp")
module_env.add_source_files(env.modules_sources,"nodes/mesh_data_instance.cpp") module_env.add_source_files(env.modules_sources,"nodes/mesh_data_instance.cpp")
module_env.add_source_files(env.modules_sources,"nodes/mesh_data_instance_2d.cpp") module_env.add_source_files(env.modules_sources,"nodes/mesh_data_instance_2d.cpp")

View File

@ -136,16 +136,19 @@ bool MDIEd::get_axis_x() {
/* /*
return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisX.pressed return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisX.pressed
*/ */
return false;
} }
bool MDIEd::get_axis_y() { bool MDIEd::get_axis_y() {
/* /*
return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisY.pressed return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisY.pressed
*/ */
return false;
} }
bool MDIEd::get_axis_z() { bool MDIEd::get_axis_z() {
/* /*
return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisZ.pressed return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisZ.pressed
*/ */
return false;
} }
void MDIEd::set_axis_x(bool on) { void MDIEd::set_axis_x(bool on) {
/* /*

View File

@ -119,7 +119,7 @@ public:
~MDIEdPlugin(); ~MDIEdPlugin();
MDIGizmoPlugin *gizmo_plugin; MDIGizmoPlugin *gizmo_plugin;
MDIEd mdi_ed_gui; MDIEd *mdi_ed_gui;
Vector<Ref<MDIGizmo>> active_gizmos; Vector<Ref<MDIGizmo>> active_gizmos;

File diff suppressed because it is too large Load Diff

View File

@ -25,12 +25,12 @@ SOFTWARE.
#include "editor/plugins/spatial_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h"
#include "core/pool_vector.h"
#include "core/variant.h"
#include "core/math/vector3.h"
#include "core/reference.h"
#include "core/math/basis.h" #include "core/math/basis.h"
#include "core/math/transform.h" #include "core/math/transform.h"
#include "core/math/vector3.h"
#include "core/pool_vector.h"
#include "core/reference.h"
#include "core/variant.h"
class Camera; class Camera;
class MeshDataResource; class MeshDataResource;
@ -77,7 +77,7 @@ public:
void setup(); void setup();
void set_editor_plugin(EditorPlugin *editor_plugin); void set_editor_plugin(EditorPlugin *editor_plugin);
void set_handle(int index, Camera *camera, Vector2 point); void set_handle(int index, Camera *camera, const Point2 &point);
void redraw(); void redraw();
void apply(); void apply();
@ -123,7 +123,7 @@ public:
bool is_verts_equal(Vector3 v0, Vector3 v1); bool is_verts_equal(Vector3 v0, Vector3 v1);
Vector3 find_other_vertex_for_edge(int edge, Vector3 v0); Vector3 find_other_vertex_for_edge(int edge, Vector3 v0);
Array split_edge_indices(int edge); Vector<PoolIntArray> split_edge_indices(int edge);
bool pool_int_arr_contains(PoolIntArray arr, int val); bool pool_int_arr_contains(PoolIntArray arr, int val);
PoolIntArray find_triangles_for_edge(int edge); PoolIntArray find_triangles_for_edge(int edge);
int find_first_triangle_for_edge(int edge); int find_first_triangle_for_edge(int edge);
@ -140,7 +140,7 @@ public:
void create_face(); void create_face();
Array split_face_indices(int face); Vector<PoolIntArray> split_face_indices(int face);
int find_first_triangle_index_for_face(int face); int find_first_triangle_index_for_face(int face);
void delete_selected(); void delete_selected();
@ -221,7 +221,7 @@ public:
PoolVector3Array _vertices; PoolVector3Array _vertices;
PoolIntArray _indices; PoolIntArray _indices;
PoolVector3Array _handle_points; PoolVector3Array _handle_points;
Array _handle_to_vertex_map; Vector<PoolIntArray> _handle_to_vertex_map;
PoolIntArray _selected_points; PoolIntArray _selected_points;
Ref<MDREDMeshOutline> _mesh_outline_generator; Ref<MDREDMeshOutline> _mesh_outline_generator;

View File

@ -23,8 +23,8 @@ SOFTWARE.
#include "mdi_gizmo_plugin.h" #include "mdi_gizmo_plugin.h"
#include "../nodes/mesh_data_instance.h" #include "../nodes/mesh_data_instance.h"
#include "mdi_gizmo.h"
#include "mdi_ed_plugin.h" #include "mdi_ed_plugin.h"
#include "mdi_gizmo.h"
String MDIGizmoPlugin::get_name() const { String MDIGizmoPlugin::get_name() const {
return "MDIGizmo"; return "MDIGizmo";
@ -37,7 +37,7 @@ bool MDIGizmoPlugin::is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, in
} }
Ref<EditorSpatialGizmo> MDIGizmoPlugin::create_gizmo(Spatial *p_spatial) { Ref<EditorSpatialGizmo> MDIGizmoPlugin::create_gizmo(Spatial *p_spatial) {
MeshDataInstance* mdi = Object::cast_to<MeshDataInstance>(p_spatial); MeshDataInstance *mdi = Object::cast_to<MeshDataInstance>(p_spatial);
if (mdi) { if (mdi) {
Ref<MDIGizmo> gizmo; Ref<MDIGizmo> gizmo;

View File

@ -22,13 +22,13 @@ SOFTWARE.
#include "mdr_ed_mesh_decompose.h" #include "mdr_ed_mesh_decompose.h"
#include "../../mesh_data_resource.h"
#include "modules/mesh_utils/mesh_utils.h" #include "modules/mesh_utils/mesh_utils.h"
#include "scene/resources/mesh.h" #include "scene/resources/mesh.h"
#include "../../mesh_data_resource.h"
//you can use MeshUtils.merge_mesh_array(arr) to get optimalized handle points. Just get the vertices from it. //you can use MeshUtils.merge_mesh_array(arr) to get optimalized handle points. Just get the vertices from it.
Array MDREDMeshDecompose::get_handle_vertex_to_vertex_map(const Array &arrays, const PoolVector3Array &handle_points) { Vector<PoolIntArray> MDREDMeshDecompose::get_handle_vertex_to_vertex_map(const Array &arrays, const PoolVector3Array &handle_points) {
Array handle_to_vertex_map; Vector<PoolIntArray> handle_to_vertex_map;
handle_to_vertex_map.resize(handle_points.size()); handle_to_vertex_map.resize(handle_points.size());
if (handle_points.size() == 0) { if (handle_points.size() == 0) {
@ -58,7 +58,7 @@ Array MDREDMeshDecompose::get_handle_vertex_to_vertex_map(const Array &arrays, c
} }
} }
handle_to_vertex_map[i] = iarr; handle_to_vertex_map.write[i] = iarr;
} }
return handle_to_vertex_map; return handle_to_vertex_map;
@ -67,23 +67,16 @@ Array MDREDMeshDecompose::get_handle_vertex_to_vertex_map(const Array &arrays, c
//returns an array: //returns an array:
//index 0 is the handle_points //index 0 is the handle_points
//index 1 is the handle_to_vertex_map //index 1 is the handle_to_vertex_map
Array MDREDMeshDecompose::get_handle_edge_to_vertex_map(const Array &arrays) { MDREDMeshDecompose::HandleVertexMapResult MDREDMeshDecompose::get_handle_edge_to_vertex_map(const Array &arrays) {
Array handle_to_vertex_map; HandleVertexMapResult ret;
PoolVector3Array handle_points;
Array ret;
if (arrays.size() != ArrayMesh::ARRAY_MAX || arrays[ArrayMesh::ARRAY_INDEX].is_null()) { if (arrays.size() != ArrayMesh::ARRAY_MAX || arrays[ArrayMesh::ARRAY_INDEX].is_null()) {
ret.append(handle_points);
ret.append(handle_to_vertex_map);
return ret; return ret;
} }
PoolVector3Array vertices = arrays[ArrayMesh::ARRAY_VERTEX]; PoolVector3Array vertices = arrays[ArrayMesh::ARRAY_VERTEX];
if (vertices.size() == 0) { if (vertices.size() == 0) {
ret.append(handle_points);
ret.append(handle_to_vertex_map);
return ret; return ret;
} }
@ -96,7 +89,7 @@ Array MDREDMeshDecompose::get_handle_edge_to_vertex_map(const Array &arrays) {
PoolVector3Array optimized_verts = optimized_arrays[ArrayMesh::ARRAY_VERTEX]; PoolVector3Array optimized_verts = optimized_arrays[ArrayMesh::ARRAY_VERTEX];
PoolIntArray optimized_indices = optimized_arrays[ArrayMesh::ARRAY_INDEX]; PoolIntArray optimized_indices = optimized_arrays[ArrayMesh::ARRAY_INDEX];
Array vert_to_optimized_vert_map = get_handle_vertex_to_vertex_map(arrays, optimized_verts); Vector<PoolIntArray> vert_to_optimized_vert_map = get_handle_vertex_to_vertex_map(arrays, optimized_verts);
Dictionary edge_map; Dictionary edge_map;
@ -150,7 +143,7 @@ Array MDREDMeshDecompose::get_handle_edge_to_vertex_map(const Array &arrays) {
Vector3 v1 = optimized_verts[ei1]; Vector3 v1 = optimized_verts[ei1];
Vector3 emid = v0.linear_interpolate(v1, 0.5); Vector3 emid = v0.linear_interpolate(v1, 0.5);
handle_points.append(emid); ret.handle_points.append(emid);
//int hindx = handle_points.size() - 1; //int hindx = handle_points.size() - 1;
PoolIntArray vm0 = vert_to_optimized_vert_map[ei0]; PoolIntArray vm0 = vert_to_optimized_vert_map[ei0];
@ -184,35 +177,26 @@ Array MDREDMeshDecompose::get_handle_edge_to_vertex_map(const Array &arrays) {
vm1r.release(); vm1r.release();
handle_to_vertex_map.append(vm); ret.handle_to_vertex_map.push_back(vm);
} }
} }
ret.append(handle_points);
ret.append(handle_to_vertex_map);
return ret; return ret;
} }
//returns an array: //returns an array:
//index 0 is the handle_points //index 0 is the handle_points
//index 1 is the handle_to_vertex_map //index 1 is the handle_to_vertex_map
Array MDREDMeshDecompose::get_handle_face_to_vertex_map(const Array &arrays) { MDREDMeshDecompose::HandleVertexMapResult MDREDMeshDecompose::get_handle_face_to_vertex_map(const Array &arrays) {
Array handle_to_vertex_map; HandleVertexMapResult ret;
PoolVector3Array handle_points;
Array ret;
if (arrays.size() != ArrayMesh::ARRAY_MAX || arrays[ArrayMesh::ARRAY_INDEX].is_null()) { if (arrays.size() != ArrayMesh::ARRAY_MAX || arrays[ArrayMesh::ARRAY_INDEX].is_null()) {
ret.append(handle_points);
ret.append(handle_to_vertex_map);
return ret; return ret;
} }
PoolVector3Array vertices = arrays[ArrayMesh::ARRAY_VERTEX]; PoolVector3Array vertices = arrays[ArrayMesh::ARRAY_VERTEX];
if (vertices.size() == 0) { if (vertices.size() == 0) {
ret.append(handle_points);
ret.append(handle_to_vertex_map);
return ret; return ret;
} }
@ -225,7 +209,7 @@ Array MDREDMeshDecompose::get_handle_face_to_vertex_map(const Array &arrays) {
PoolVector3Array optimized_verts = optimized_arrays[ArrayMesh::ARRAY_VERTEX]; PoolVector3Array optimized_verts = optimized_arrays[ArrayMesh::ARRAY_VERTEX];
PoolIntArray optimized_indices = optimized_arrays[ArrayMesh::ARRAY_INDEX]; PoolIntArray optimized_indices = optimized_arrays[ArrayMesh::ARRAY_INDEX];
Array vert_to_optimized_vert_map = get_handle_vertex_to_vertex_map(arrays, optimized_verts); Vector<PoolIntArray> vert_to_optimized_vert_map = get_handle_vertex_to_vertex_map(arrays, optimized_verts);
for (int i = 0; i < optimized_indices.size(); i += 3) { for (int i = 0; i < optimized_indices.size(); i += 3) {
int i0 = optimized_indices[i + 0]; int i0 = optimized_indices[i + 0];
@ -238,7 +222,7 @@ Array MDREDMeshDecompose::get_handle_face_to_vertex_map(const Array &arrays) {
Vector3 pmid = v0 + v1 + v2; Vector3 pmid = v0 + v1 + v2;
pmid /= 3; pmid /= 3;
handle_points.append(pmid); ret.handle_points.append(pmid);
PoolIntArray vm0 = vert_to_optimized_vert_map[i0]; PoolIntArray vm0 = vert_to_optimized_vert_map[i0];
PoolIntArray vm1 = vert_to_optimized_vert_map[i1]; PoolIntArray vm1 = vert_to_optimized_vert_map[i1];
@ -297,11 +281,9 @@ Array MDREDMeshDecompose::get_handle_face_to_vertex_map(const Array &arrays) {
vm2r.release(); vm2r.release();
handle_to_vertex_map.append(vm); ret.handle_to_vertex_map.push_back(vm);
} }
ret.append(handle_points);
ret.append(handle_to_vertex_map);
return ret; return ret;
} }

View File

@ -25,25 +25,31 @@ SOFTWARE.
#include "core/array.h" #include "core/array.h"
#include "core/pool_vector.h" #include "core/pool_vector.h"
#include "core/variant.h"
#include "core/reference.h" #include "core/reference.h"
#include "core/variant.h"
#include "core/vector.h"
class MeshDataResource; class MeshDataResource;
class MDREDMeshDecompose { class MDREDMeshDecompose {
public: public:
struct HandleVertexMapResult {
Vector<PoolIntArray> handle_to_vertex_map;
PoolVector3Array handle_points;
};
//you can use MeshUtils.merge_mesh_array(arr) to get optimalized handle points. Just get the vertices from it. //you can use MeshUtils.merge_mesh_array(arr) to get optimalized handle points. Just get the vertices from it.
static Array get_handle_vertex_to_vertex_map(const Array &arrays, const PoolVector3Array &handle_points); static Vector<PoolIntArray> get_handle_vertex_to_vertex_map(const Array &arrays, const PoolVector3Array &handle_points);
//returns an array: //returns an array:
//index 0 is the handle_points //index 0 is the handle_points
//index 1 is the handle_to_vertex_map //index 1 is the handle_to_vertex_map
static Array get_handle_edge_to_vertex_map(const Array &arrays); static HandleVertexMapResult get_handle_edge_to_vertex_map(const Array &arrays);
//returns an array: //returns an array:
//index 0 is the handle_points //index 0 is the handle_points
//index 1 is the handle_to_vertex_map //index 1 is the handle_to_vertex_map
static Array get_handle_face_to_vertex_map(const Array &arrays); static HandleVertexMapResult get_handle_face_to_vertex_map(const Array &arrays);
static PoolVector3Array calculate_map_midpoints(Array mesh, Array vertex_map); static PoolVector3Array calculate_map_midpoints(Array mesh, Array vertex_map);
static bool pool_int_arr_contains(const PoolIntArray &arr, const int val); static bool pool_int_arr_contains(const PoolIntArray &arr, const int val);
static Vector<PoolIntArray> partition_mesh(Ref<MeshDataResource> mdr); static Vector<PoolIntArray> partition_mesh(Ref<MeshDataResource> mdr);