mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-08 20:09:36 +01:00
Added skeleton classes for mesh data resource editor's utilities.
This commit is contained in:
parent
d3118e1d4b
commit
eff1e7d5a9
@ -1,20 +1,41 @@
|
||||
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())
|
||||
|
||||
|
||||
if handle_points.size() == 0:
|
||||
return handle_to_vertex_map
|
||||
|
||||
|
||||
if arrays.size() != ArrayMesh.ARRAY_MAX || arrays[ArrayMesh.ARRAY_INDEX] == null:
|
||||
return handle_to_vertex_map
|
||||
|
||||
|
||||
var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX]
|
||||
|
||||
|
||||
if vertices.size() == 0:
|
||||
return handle_to_vertex_map
|
||||
|
||||
@ -25,119 +46,47 @@ static func get_handle_vertex_to_vertex_map(arrays : Array, handle_points : Pool
|
||||
#find all verts that have the same position as the handle
|
||||
for j in range(vertices.size()):
|
||||
var vn : Vector3 = vertices[j]
|
||||
|
||||
|
||||
if is_equal_approx(hv.x, vn.x) && is_equal_approx(hv.y, vn.y) && is_equal_approx(hv.z, vn.z):
|
||||
iarr.append(j)
|
||||
|
||||
|
||||
handle_to_vertex_map[i] = iarr
|
||||
|
||||
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:
|
||||
*/
|
||||
}
|
||||
|
||||
//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) {
|
||||
/*
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
//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
|
||||
|
||||
|
||||
if arrays.size() != ArrayMesh.ARRAY_MAX || arrays[ArrayMesh.ARRAY_INDEX] == null:
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
|
||||
var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX]
|
||||
|
||||
|
||||
if vertices.size() == 0:
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
|
||||
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:
|
||||
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 ]
|
||||
|
||||
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]
|
||||
@ -148,7 +97,7 @@ static func get_handle_face_to_vertex_map(arrays : Array) -> Array:
|
||||
var i0 : int = optimized_indices[i + 0]
|
||||
var i1 : int = optimized_indices[i + 1]
|
||||
var i2 : int = optimized_indices[i + 2]
|
||||
|
||||
|
||||
var v0 : Vector3 = optimized_verts[i0]
|
||||
var v1 : Vector3 = optimized_verts[i1]
|
||||
var v2 : Vector3 = optimized_verts[i2]
|
||||
@ -156,11 +105,11 @@ static func get_handle_face_to_vertex_map(arrays : Array) -> Array:
|
||||
var pmid : Vector3 = v0 + v1 + v2
|
||||
pmid /= 3
|
||||
handle_points.append(pmid)
|
||||
|
||||
|
||||
var vm0 : PoolIntArray = vert_to_optimized_vert_map[i0]
|
||||
var vm1 : PoolIntArray = vert_to_optimized_vert_map[i1]
|
||||
var vm2 : PoolIntArray = vert_to_optimized_vert_map[i2]
|
||||
|
||||
|
||||
var vm : PoolIntArray = PoolIntArray()
|
||||
vm.append_array(vm0)
|
||||
|
||||
@ -170,94 +119,102 @@ static func get_handle_face_to_vertex_map(arrays : Array) -> Array:
|
||||
if vi == vit:
|
||||
found = true
|
||||
break
|
||||
|
||||
|
||||
if !found:
|
||||
vm.append(vi)
|
||||
|
||||
|
||||
for vi in vm2:
|
||||
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 ]
|
||||
|
||||
static func calculate_map_midpoints(mesh : Array, vertex_map : Array) -> PoolVector3Array:
|
||||
return [ handle_points, handle_to_vertex_map ]
|
||||
*/
|
||||
}
|
||||
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:
|
||||
return false
|
||||
*/
|
||||
}
|
||||
Array MDREDMeshDecompose::partition_mesh(Ref<MeshDataResource> mdr) {
|
||||
/*
|
||||
var partitions : Array = Array()
|
||||
|
||||
|
||||
var arrays : Array = mdr.get_array()
|
||||
|
||||
|
||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||
return partitions
|
||||
|
||||
|
||||
if arrays[ArrayMesh.ARRAY_INDEX] == null:
|
||||
return partitions
|
||||
|
||||
|
||||
var indices : PoolIntArray = arrays[ArrayMesh.ARRAY_INDEX]
|
||||
|
||||
|
||||
var triangle_count : int = indices.size() / 3
|
||||
var processed_triangles : PoolIntArray = PoolIntArray()
|
||||
|
||||
|
||||
while triangle_count != processed_triangles.size():
|
||||
var partition : PoolIntArray = PoolIntArray()
|
||||
|
||||
|
||||
var first : bool = true
|
||||
var triangle_added : bool = true
|
||||
while triangle_added:
|
||||
triangle_added = false
|
||||
for i in range(indices.size()):
|
||||
var triangle_index : int = i / 3
|
||||
|
||||
|
||||
if pool_int_arr_contains(processed_triangles, triangle_index):
|
||||
continue
|
||||
|
||||
|
||||
if first:
|
||||
first = false
|
||||
|
||||
|
||||
# We have to be at the 0th index of a triangle
|
||||
partition.append(indices[i])
|
||||
partition.append(indices[i + 1])
|
||||
partition.append(indices[i + 2])
|
||||
|
||||
|
||||
triangle_added = true
|
||||
break
|
||||
|
||||
|
||||
var index : int = indices[i]
|
||||
|
||||
|
||||
if pool_int_arr_contains(partition, index):
|
||||
processed_triangles.append(triangle_index)
|
||||
|
||||
|
||||
var tri_start_index : int = i - (i % 3)
|
||||
|
||||
var i0 : int = indices[tri_start_index]
|
||||
var i1 : int = indices[tri_start_index + 1]
|
||||
var i2 : int = indices[tri_start_index + 2]
|
||||
|
||||
|
||||
partition.append(i0)
|
||||
partition.append(i1)
|
||||
partition.append(i2)
|
||||
|
||||
|
||||
triangle_added = true
|
||||
break
|
||||
|
||||
|
||||
|
||||
partitions.append(partition)
|
||||
|
||||
|
||||
|
||||
|
||||
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,99 +1,116 @@
|
||||
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
|
||||
|
||||
|
||||
if _mdr.array.size() != ArrayMesh.ARRAY_MAX:
|
||||
return false
|
||||
|
||||
|
||||
if _mdr.array[ArrayMesh.ARRAY_VERTEX] == null || _mdr.array[ArrayMesh.ARRAY_INDEX] == null:
|
||||
return false
|
||||
|
||||
var arr : Array = _mdr.array
|
||||
|
||||
|
||||
_vertices = arr[ArrayMesh.ARRAY_VERTEX]
|
||||
|
||||
if _mdr.array[ArrayMesh.ARRAY_NORMAL] != null:
|
||||
_normals = arr[ArrayMesh.ARRAY_NORMAL]
|
||||
|
||||
|
||||
_indices = arr[ArrayMesh.ARRAY_INDEX]
|
||||
|
||||
if _vertices.size() == 0:
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
func get_vertex(index : int) -> Vector3:
|
||||
*/
|
||||
}
|
||||
Vector3 MDREDMeshOutline::get_vertex(int index) {
|
||||
/*
|
||||
if index > _vertices.size():
|
||||
return Vector3()
|
||||
|
||||
|
||||
var v : Vector3 = _vertices[index]
|
||||
|
||||
|
||||
# This should reduce z fighting
|
||||
if _normals.size() > 0:
|
||||
var n : Vector3 = _normals[index]
|
||||
|
||||
v += n * 0.001
|
||||
|
||||
return v
|
||||
|
||||
func generate(mark_outline : bool, mark_handles : bool):
|
||||
v += n * 0.001
|
||||
|
||||
return v
|
||||
*/
|
||||
}
|
||||
void MDREDMeshOutline::generate(bool mark_outline, bool mark_handles) {
|
||||
/*
|
||||
reset()
|
||||
|
||||
|
||||
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_handles:
|
||||
for i in range(_vertices.size()):
|
||||
var v : Vector3 = get_vertex(i)
|
||||
|
||||
var l : float = 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))
|
||||
|
||||
|
||||
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]))
|
||||
|
||||
func generate_mark_edges(mark_outline : bool, mark_handles : bool):
|
||||
*/
|
||||
}
|
||||
void MDREDMeshOutline::generate_mark_edges(bool mark_outline, bool mark_handles) {
|
||||
/*
|
||||
reset()
|
||||
|
||||
|
||||
if !initialize():
|
||||
return
|
||||
|
||||
@ -101,35 +118,37 @@ func generate_mark_edges(mark_outline : bool, mark_handles : bool):
|
||||
for j in range(3):
|
||||
var i0 : int = _indices[i + j]
|
||||
var i1 : int = _indices[i + ((j + 1) % 3)]
|
||||
|
||||
|
||||
var v0 : Vector3 = get_vertex(i0)
|
||||
var v1 : Vector3 = get_vertex(i1)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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():
|
||||
return
|
||||
|
||||
@ -144,7 +163,7 @@ func generate_mark_faces(mark_outline : bool, mark_handles : bool):
|
||||
var i0 : int = _indices[i + 0]
|
||||
var i1 : int = _indices[i + 1]
|
||||
var i2 : int = _indices[i + 2]
|
||||
|
||||
|
||||
var v0 : Vector3 = get_vertex(i0)
|
||||
var v1 : Vector3 = get_vertex(i1)
|
||||
var v2 : Vector3 = get_vertex(i2)
|
||||
@ -152,16 +171,22 @@ func generate_mark_faces(mark_outline : bool, mark_handles : bool):
|
||||
var pmid : Vector3 = v0 + v1 + v2
|
||||
pmid /= 3
|
||||
var l : float = 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))
|
||||
|
||||
|
||||
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]))
|
||||
*/
|
||||
}
|
||||
|
||||
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