Ported the logic of the mesh outline generator.

This commit is contained in:
Relintai 2022-04-11 20:56:59 +02:00
parent 4af170d9fb
commit f5c1a5eec1
3 changed files with 136 additions and 110 deletions

View File

@ -28,7 +28,7 @@ if 'TOOLS_ENABLED' in env["CPPDEFINES"]:
module_env.add_source_files(env.modules_sources,"plugin_gltf/editor_plugin_gltf_mdr.cpp")
module_env.add_source_files(env.modules_sources,"editor/utilities/mdr_ed_mesh_decompose.cpp")
#module_env.add_source_files(env.modules_sources,"editor/utilities/mdr_ed_mesh_outline.cpp")
module_env.add_source_files(env.modules_sources,"editor/utilities/mdr_ed_mesh_outline.cpp")
#module_env.add_source_files(env.modules_sources,"editor/utilities/mdr_ed_mesh_utils.cpp")
module_env.add_source_files(env.modules_sources,"nodes/mesh_data_instance.cpp")

View File

@ -22,6 +22,8 @@ SOFTWARE.
#include "mdr_ed_mesh_outline.h"
#include "../../mesh_data_resource.h"
void MDREDMeshOutline::setup(Ref<MeshDataResource> mdr) {
_mdr = mdr;
}
@ -33,160 +35,181 @@ void MDREDMeshOutline::reset() {
_indices.resize(0);
}
bool MDREDMeshOutline::initialize() {
/*
if !_mdr:
return false
if (!_mdr.is_valid()) {
return false;
}
if _mdr.array.size() != ArrayMesh.ARRAY_MAX:
return false
Array arr = _mdr->get_array();
if _mdr.array[ArrayMesh.ARRAY_VERTEX] == null || _mdr.array[ArrayMesh.ARRAY_INDEX] == null:
return false
if (arr.size() != ArrayMesh::ARRAY_MAX) {
return false;
}
var arr : Array = _mdr.array
if (arr[ArrayMesh::ARRAY_VERTEX].is_null() || arr[ArrayMesh::ARRAY_INDEX].is_null()) {
return false;
}
_vertices = arr[ArrayMesh.ARRAY_VERTEX]
_vertices = arr[ArrayMesh::ARRAY_VERTEX];
if _mdr.array[ArrayMesh.ARRAY_NORMAL] != null:
_normals = arr[ArrayMesh.ARRAY_NORMAL]
if (!arr[ArrayMesh::ARRAY_NORMAL].is_null()) {
_normals = arr[ArrayMesh::ARRAY_NORMAL];
}
_indices = arr[ArrayMesh.ARRAY_INDEX]
_indices = arr[ArrayMesh::ARRAY_INDEX];
if _vertices.size() == 0:
return false
if (_vertices.size() == 0) {
return false;
}
return true
*/
return true;
}
Vector3 MDREDMeshOutline::get_vertex(int index) {
/*
if index > _vertices.size():
return Vector3()
if (index > _vertices.size()) {
return Vector3();
}
var v : Vector3 = _vertices[index]
Vector3 v = _vertices[index];
# This should reduce z fighting
if _normals.size() > 0:
var n : Vector3 = _normals[index]
// This should reduce z fighting
if (_normals.size() > 0) {
Vector3 n = _normals[index];
v += n * 0.001
v += n * 0.001;
}
return v
*/
return v;
}
void MDREDMeshOutline::generate(bool mark_outline, bool mark_handles) {
/*
reset()
reset();
if !initialize():
return
if (!initialize()) {
return;
}
if mark_outline:
for i in range(0, _indices.size(), 3):
for j in range(3):
lines.append(get_vertex(_indices[i + j]))
lines.append(get_vertex(_indices[i + ((j + 1) % 3)]))
if (mark_outline) {
for (int i = 0; i < _indices.size(); i += 3) {
for (int j = 0; j < 4; ++j) {
lines.append(get_vertex(_indices[i + j]));
lines.append(get_vertex(_indices[i + ((j + 1) % 3)]));
}
}
}
if mark_handles:
for i in range(_vertices.size()):
var v : Vector3 = get_vertex(i)
if (mark_handles) {
for (int i = 0; i < _vertices.size(); ++i) {
Vector3 v = get_vertex(i);
var l : float = marker_size
float l = marker_size;
lines.append(v + Vector3(l, 0, 0))
lines.append(v + Vector3(-l, 0, 0))
lines.append(v + Vector3(0, 0, l))
lines.append(v + Vector3(0, 0, -l))
lines.append(v + Vector3(0, l, 0))
lines.append(v + Vector3(0, -l, 0))
lines.append(v + Vector3(l, 0, 0));
lines.append(v + Vector3(-l, 0, 0));
lines.append(v + Vector3(0, 0, l));
lines.append(v + Vector3(0, 0, -l));
lines.append(v + Vector3(0, l, 0));
lines.append(v + Vector3(0, -l, 0));
}
}
var seams : PoolIntArray = _mdr.seams
PoolIntArray seams = _mdr->get_seams();
for i in range(0, seams.size(), 2):
seam_lines.append(get_vertex(seams[i]))
seam_lines.append(get_vertex(seams[i + 1]))
*/
for (int i = 0; i < seams.size(); i += 2) {
seam_lines.append(get_vertex(seams[i]));
seam_lines.append(get_vertex(seams[i + 1]));
}
}
void MDREDMeshOutline::generate_mark_edges(bool mark_outline, bool mark_handles) {
/*
reset()
reset();
if !initialize():
return
if (!initialize()) {
return;
}
for i in range(0, _indices.size(), 3):
for j in range(3):
var i0 : int = _indices[i + j]
var i1 : int = _indices[i + ((j + 1) % 3)]
for (int i = 0; i < _indices.size(); i += 3) {
for (int j = 0; j < 3; ++j) {
int i0 = _indices[i + j];
int i1 = _indices[i + ((j + 1) % 3)];
var v0 : Vector3 = get_vertex(i0)
var v1 : Vector3 = get_vertex(i1)
Vector3 v0 = get_vertex(i0);
Vector3 v1 = get_vertex(i1);
if mark_outline:
lines.append(v0)
lines.append(v1)
if (mark_outline) {
lines.append(v0);
lines.append(v1);
}
if mark_handles:
var pmid : Vector3 = lerp(v0, v1, 0.5)
var l : float = marker_size
if (mark_handles) {
Vector3 pmid = v0.linear_interpolate(v1, 0.5);
float l = marker_size;
lines.append(pmid + Vector3(l, 0, 0))
lines.append(pmid + Vector3(-l, 0, 0))
lines.append(pmid + Vector3(0, 0, l))
lines.append(pmid + Vector3(0, 0, -l))
lines.append(pmid + Vector3(0, l, 0))
lines.append(pmid + Vector3(0, -l, 0))
lines.append(pmid + Vector3(l, 0, 0));
lines.append(pmid + Vector3(-l, 0, 0));
lines.append(pmid + Vector3(0, 0, l));
lines.append(pmid + Vector3(0, 0, -l));
lines.append(pmid + Vector3(0, l, 0));
lines.append(pmid + Vector3(0, -l, 0));
}
}
}
PoolIntArray seams = _mdr->get_seams();
var seams : PoolIntArray = _mdr.seams
for i in range(0, seams.size(), 2):
seam_lines.append(get_vertex(seams[i]))
seam_lines.append(get_vertex(seams[i + 1]))
*/
for (int i = 0; i < seams.size(); i += 2) {
seam_lines.append(get_vertex(seams[i]));
seam_lines.append(get_vertex(seams[i + 1]));
}
}
void MDREDMeshOutline::generate_mark_faces(bool mark_outline, bool mark_handles) {
/*
reset()
reset();
if !initialize():
return
if (!initialize()) {
return;
}
if mark_outline:
for i in range(0, _indices.size(), 3):
for j in range(3):
lines.append(get_vertex(_indices[i + j]))
lines.append(get_vertex(_indices[i + ((j + 1) % 3)]))
if (mark_outline) {
for (int i = 0; i < _indices.size(); i += 3) {
for (int j = 0; j < 3; ++j) {
lines.append(get_vertex(_indices[i + j]));
lines.append(get_vertex(_indices[i + ((j + 1) % 3)]));
}
}
}
if mark_handles:
for i in range(0, _indices.size(), 3):
var i0 : int = _indices[i + 0]
var i1 : int = _indices[i + 1]
var i2 : int = _indices[i + 2]
if (mark_handles) {
for (int i = 0; i < _indices.size(); i += 3) {
int i0 = _indices[i + 0];
int i1 = _indices[i + 1];
int i2 = _indices[i + 2];
var v0 : Vector3 = get_vertex(i0)
var v1 : Vector3 = get_vertex(i1)
var v2 : Vector3 = get_vertex(i2)
Vector3 v0 = get_vertex(i0);
Vector3 v1 = get_vertex(i1);
Vector3 v2 = get_vertex(i2);
var pmid : Vector3 = v0 + v1 + v2
pmid /= 3
var l : float = marker_size
Vector3 pmid = v0 + v1 + v2;
pmid /= 3;
float l = marker_size;
lines.append(pmid + Vector3(l, 0, 0))
lines.append(pmid + Vector3(-l, 0, 0))
lines.append(pmid + Vector3(0, 0, l))
lines.append(pmid + Vector3(0, 0, -l))
lines.append(pmid + Vector3(0, l, 0))
lines.append(pmid + Vector3(0, -l, 0))
lines.append(pmid + Vector3(l, 0, 0));
lines.append(pmid + Vector3(-l, 0, 0));
lines.append(pmid + Vector3(0, 0, l));
lines.append(pmid + Vector3(0, 0, -l));
lines.append(pmid + Vector3(0, l, 0));
lines.append(pmid + Vector3(0, -l, 0));
}
}
var seams : PoolIntArray = _mdr.seams
PoolIntArray seams = _mdr->get_seams();
for i in range(0, seams.size(), 2):
seam_lines.append(get_vertex(seams[i]))
seam_lines.append(get_vertex(seams[i + 1]))
*/
for (int i = 0; i < seams.size(); i += 2) {
seam_lines.append(get_vertex(seams[i]));
seam_lines.append(get_vertex(seams[i + 1]));
}
}
MDREDMeshOutline::MDREDMeshOutline() {
marker_size = 0.05;
}
void MDREDMeshOutline::_bind_methods() {
}

View File

@ -55,6 +55,9 @@ public:
PoolVector3Array _vertices;
PoolVector3Array _normals;
PoolIntArray _indices;
protected:
static void _bind_methods();
};
#endif