mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-09 12:29:35 +01:00
Added skeleton classes for mesh data resource editor's utilities.
This commit is contained in:
parent
d3118e1d4b
commit
eff1e7d5a9
@ -1,9 +1,30 @@
|
||||
tool
|
||||
extends Object
|
||||
/*
|
||||
Copyright (c) 2019-2022 Péter Magyar
|
||||
|
||||
#you can use MeshUtils.merge_mesh_array(arr) to get optimalized handle points. Just get the vertices from it.
|
||||
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:
|
||||
|
||||
static func get_handle_vertex_to_vertex_map(arrays : Array, handle_points : PoolVector3Array) -> Array:
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "mdr_ed_mesh_decompose.h"
|
||||
|
||||
//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(Array arrays, PoolVector3Array handle_points) {
|
||||
/*
|
||||
var handle_to_vertex_map : Array
|
||||
handle_to_vertex_map.resize(handle_points.size())
|
||||
|
||||
@ -33,95 +54,23 @@ static func get_handle_vertex_to_vertex_map(arrays : Array, handle_points : Pool
|
||||
|
||||
return handle_to_vertex_map
|
||||
|
||||
#returns an array:
|
||||
#index 0 is the handle_points
|
||||
#index 1 is the handle_to_vertex_map
|
||||
static func get_handle_edge_to_vertex_map(arrays : Array) -> Array:
|
||||
var handle_to_vertex_map : Array
|
||||
var handle_points : PoolVector3Array
|
||||
*/
|
||||
}
|
||||
|
||||
if arrays.size() != ArrayMesh.ARRAY_MAX || arrays[ArrayMesh.ARRAY_INDEX] == null:
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
//returns an array:
|
||||
//index 0 is the handle_points
|
||||
//index 1 is the handle_to_vertex_map
|
||||
Array MDREDMeshDecompose::get_handle_edge_to_vertex_map(Array arrays) {
|
||||
/*
|
||||
|
||||
var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX]
|
||||
*/
|
||||
}
|
||||
|
||||
if vertices.size() == 0:
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
|
||||
var arr : Array = Array()
|
||||
arr.resize(ArrayMesh.ARRAY_MAX)
|
||||
arr[ArrayMesh.ARRAY_VERTEX] = arrays[ArrayMesh.ARRAY_VERTEX]
|
||||
arr[ArrayMesh.ARRAY_INDEX] = arrays[ArrayMesh.ARRAY_INDEX]
|
||||
|
||||
var optimized_arrays : Array = MeshUtils.merge_mesh_array(arr)
|
||||
var optimized_verts : PoolVector3Array = optimized_arrays[ArrayMesh.ARRAY_VERTEX]
|
||||
var optimized_indices : PoolIntArray = optimized_arrays[ArrayMesh.ARRAY_INDEX]
|
||||
|
||||
var vert_to_optimized_vert_map : Array = get_handle_vertex_to_vertex_map(arrays, optimized_verts)
|
||||
|
||||
var edge_map : Dictionary = Dictionary()
|
||||
|
||||
for i in range(0, optimized_indices.size(), 3):
|
||||
for j in range(3):
|
||||
var i0 : int = optimized_indices[i + j]
|
||||
var i1 : int = optimized_indices[i + ((j + 1) % 3)]
|
||||
|
||||
var ei0 : int = min(i0, i1)
|
||||
var ei1 : int = max(i0, i1)
|
||||
|
||||
if !edge_map.has(ei0):
|
||||
edge_map[ei0] = PoolIntArray()
|
||||
|
||||
var etm : PoolIntArray = edge_map[ei0]
|
||||
|
||||
var found : bool = false
|
||||
for e in etm:
|
||||
if e == ei1:
|
||||
found = true
|
||||
break
|
||||
|
||||
if !found:
|
||||
etm.append(ei1)
|
||||
edge_map[ei0] = etm
|
||||
|
||||
for key in edge_map.keys():
|
||||
var indices : PoolIntArray = edge_map[key]
|
||||
|
||||
for indx in indices:
|
||||
var ei0 : int = key
|
||||
var ei1 : int = indx
|
||||
|
||||
var v0 : Vector3 = optimized_verts[ei0]
|
||||
var v1 : Vector3 = optimized_verts[ei1]
|
||||
|
||||
var emid : Vector3 = lerp(v0, v1, 0.5)
|
||||
handle_points.append(emid)
|
||||
var hindx : int = handle_points.size() - 1
|
||||
|
||||
var vm0 : PoolIntArray = vert_to_optimized_vert_map[ei0]
|
||||
var vm1 : PoolIntArray = vert_to_optimized_vert_map[ei1]
|
||||
|
||||
var vm : PoolIntArray = PoolIntArray()
|
||||
vm.append_array(vm0)
|
||||
|
||||
for vi in vm1:
|
||||
var found : bool = false
|
||||
for vit in vm:
|
||||
if vi == vit:
|
||||
found = true
|
||||
break
|
||||
|
||||
if !found:
|
||||
vm.append(vi)
|
||||
|
||||
handle_to_vertex_map.append(vm)
|
||||
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
|
||||
#returns an array:
|
||||
#index 0 is the handle_points
|
||||
#index 1 is the handle_to_vertex_map
|
||||
static func get_handle_face_to_vertex_map(arrays : Array) -> Array:
|
||||
//returns an array:
|
||||
//index 0 is the handle_points
|
||||
//index 1 is the handle_to_vertex_map
|
||||
Array MDREDMeshDecompose::get_handle_face_to_vertex_map(Array arrays) {
|
||||
/*
|
||||
var handle_to_vertex_map : Array
|
||||
var handle_points : PoolVector3Array
|
||||
|
||||
@ -187,18 +136,24 @@ static func get_handle_face_to_vertex_map(arrays : Array) -> Array:
|
||||
handle_to_vertex_map.append(vm)
|
||||
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
|
||||
static func calculate_map_midpoints(mesh : Array, vertex_map : Array) -> PoolVector3Array:
|
||||
*/
|
||||
}
|
||||
PoolVector3Array MDREDMeshDecompose::calculate_map_midpoints(Array mesh, Array vertex_map) {
|
||||
/*
|
||||
return PoolVector3Array()
|
||||
|
||||
static func pool_int_arr_contains(arr : PoolIntArray, val : int) -> bool:
|
||||
*/
|
||||
}
|
||||
bool MDREDMeshDecompose::pool_int_arr_contains(PoolIntArray arr, int val) {
|
||||
/*
|
||||
for a in arr:
|
||||
if a == val:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
static func partition_mesh(mdr : MeshDataResource) -> Array:
|
||||
*/
|
||||
}
|
||||
Array MDREDMeshDecompose::partition_mesh(Ref<MeshDataResource> mdr) {
|
||||
/*
|
||||
var partitions : Array = Array()
|
||||
|
||||
var arrays : Array = mdr.get_array()
|
||||
@ -261,3 +216,5 @@ static func partition_mesh(mdr : MeshDataResource) -> Array:
|
||||
|
||||
|
||||
return partitions
|
||||
*/
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
#ifndef MDR_ED_MESH_DECOMPOSE_H
|
||||
#define MDR_ED_MESH_DECOMPOSE_H
|
||||
|
||||
/*
|
||||
Copyright (c) 2019-2022 Péter Magyar
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "core/array.h"
|
||||
#include "core/pool_vector.h"
|
||||
#include "core/variant.h"
|
||||
#include "core/reference.h"
|
||||
|
||||
class MeshDataResource;
|
||||
|
||||
class MDREDMeshDecompose {
|
||||
public:
|
||||
//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(Array arrays, PoolVector3Array handle_points);
|
||||
|
||||
//returns an array:
|
||||
//index 0 is the handle_points
|
||||
//index 1 is the handle_to_vertex_map
|
||||
static Array get_handle_edge_to_vertex_map(Array arrays);
|
||||
|
||||
//returns an array:
|
||||
//index 0 is the handle_points
|
||||
//index 1 is the handle_to_vertex_map
|
||||
static Array get_handle_face_to_vertex_map(Array arrays);
|
||||
static PoolVector3Array calculate_map_midpoints(Array mesh, Array vertex_map);
|
||||
static bool pool_int_arr_contains(PoolIntArray arr, int val);
|
||||
static Array partition_mesh(Ref<MeshDataResource> mdr);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,28 +1,39 @@
|
||||
tool
|
||||
extends Reference
|
||||
/*
|
||||
Copyright (c) 2019-2022 Péter Magyar
|
||||
|
||||
var marker_size : float = 0.05
|
||||
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:
|
||||
|
||||
var _mdr : MeshDataResource
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
var lines : PoolVector3Array
|
||||
var seam_lines : PoolVector3Array
|
||||
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.
|
||||
*/
|
||||
|
||||
var _vertices : PoolVector3Array = PoolVector3Array()
|
||||
var _normals : PoolVector3Array = PoolVector3Array()
|
||||
var _indices : PoolIntArray = PoolIntArray()
|
||||
#include "mdr_ed_mesh_outline.h"
|
||||
|
||||
func setup(mdr : MeshDataResource) -> void:
|
||||
_mdr = mdr
|
||||
|
||||
func reset() -> void:
|
||||
lines.resize(0)
|
||||
seam_lines.resize(0)
|
||||
_normals.resize(0)
|
||||
_vertices.resize(0)
|
||||
_indices.resize(0)
|
||||
|
||||
func initialize() -> bool:
|
||||
void MDREDMeshOutline::setup(Ref<MeshDataResource> mdr) {
|
||||
_mdr = mdr;
|
||||
}
|
||||
void MDREDMeshOutline::reset() {
|
||||
lines.resize(0);
|
||||
seam_lines.resize(0);
|
||||
_normals.resize(0);
|
||||
_vertices.resize(0);
|
||||
_indices.resize(0);
|
||||
}
|
||||
bool MDREDMeshOutline::initialize() {
|
||||
/*
|
||||
if !_mdr:
|
||||
return false
|
||||
|
||||
@ -45,8 +56,10 @@ func initialize() -> bool:
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
func get_vertex(index : int) -> Vector3:
|
||||
*/
|
||||
}
|
||||
Vector3 MDREDMeshOutline::get_vertex(int index) {
|
||||
/*
|
||||
if index > _vertices.size():
|
||||
return Vector3()
|
||||
|
||||
@ -59,8 +72,10 @@ func get_vertex(index : int) -> Vector3:
|
||||
v += n * 0.001
|
||||
|
||||
return v
|
||||
|
||||
func generate(mark_outline : bool, mark_handles : bool):
|
||||
*/
|
||||
}
|
||||
void MDREDMeshOutline::generate(bool mark_outline, bool mark_handles) {
|
||||
/*
|
||||
reset()
|
||||
|
||||
if !initialize():
|
||||
@ -90,8 +105,10 @@ func generate(mark_outline : bool, mark_handles : bool):
|
||||
for i in range(0, seams.size(), 2):
|
||||
seam_lines.append(get_vertex(seams[i]))
|
||||
seam_lines.append(get_vertex(seams[i + 1]))
|
||||
|
||||
func generate_mark_edges(mark_outline : bool, mark_handles : bool):
|
||||
*/
|
||||
}
|
||||
void MDREDMeshOutline::generate_mark_edges(bool mark_outline, bool mark_handles) {
|
||||
/*
|
||||
reset()
|
||||
|
||||
if !initialize():
|
||||
@ -126,8 +143,10 @@ func generate_mark_edges(mark_outline : bool, mark_handles : bool):
|
||||
for i in range(0, seams.size(), 2):
|
||||
seam_lines.append(get_vertex(seams[i]))
|
||||
seam_lines.append(get_vertex(seams[i + 1]))
|
||||
|
||||
func generate_mark_faces(mark_outline : bool, mark_handles : bool):
|
||||
*/
|
||||
}
|
||||
void MDREDMeshOutline::generate_mark_faces(bool mark_outline, bool mark_handles) {
|
||||
/*
|
||||
reset()
|
||||
|
||||
if !initialize():
|
||||
@ -165,3 +184,9 @@ func generate_mark_faces(mark_outline : bool, mark_handles : bool):
|
||||
for i in range(0, seams.size(), 2):
|
||||
seam_lines.append(get_vertex(seams[i]))
|
||||
seam_lines.append(get_vertex(seams[i + 1]))
|
||||
*/
|
||||
}
|
||||
|
||||
MDREDMeshOutline::MDREDMeshOutline() {
|
||||
marker_size = 0.05;
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
#ifndef MDR_ED_MESH_OUTLINE_H
|
||||
#define MDR_ED_MESH_OUTLINE_H
|
||||
|
||||
/*
|
||||
Copyright (c) 2019-2022 Péter Magyar
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "core/array.h"
|
||||
#include "core/pool_vector.h"
|
||||
#include "core/variant.h"
|
||||
|
||||
class MeshDataResource;
|
||||
|
||||
class MDREDMeshOutline : public Reference {
|
||||
GDCLASS(MDREDMeshOutline, Reference);
|
||||
|
||||
public:
|
||||
void setup(Ref<MeshDataResource> mdr);
|
||||
void reset();
|
||||
bool initialize();
|
||||
Vector3 get_vertex(int index);
|
||||
void generate(bool mark_outline, bool mark_handles);
|
||||
void generate_mark_edges(bool mark_outline, bool mark_handles);
|
||||
void generate_mark_faces(bool mark_outline, bool mark_handles);
|
||||
|
||||
MDREDMeshOutline();
|
||||
|
||||
float marker_size;
|
||||
|
||||
Ref<MeshDataResource> _mdr;
|
||||
|
||||
PoolVector3Array lines;
|
||||
PoolVector3Array seam_lines;
|
||||
|
||||
PoolVector3Array _vertices;
|
||||
PoolVector3Array _normals;
|
||||
PoolIntArray _indices;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user