I think I figured out a way to uv unwrap meshes for the mesh data resource editor. Started implementing it. Mesh partitioning is done.

This commit is contained in:
Relintai 2021-09-26 23:02:51 +02:00
parent ed3c6eb19d
commit 2c266711a3
2 changed files with 140 additions and 3 deletions

View File

@ -113,9 +113,146 @@ func set_axis_z(on : bool) -> void:
g.set_axis_z(on)
func uv_unwrap() -> void:
var mdr : MeshDataResource = null
if current_mesh_data_instance && current_mesh_data_instance.mesh_data:
current_mesh_data_instance.mesh_data.uv_unwrap()
#
#current_mesh_data_instance.mesh_data.uv_unwrap()
mdr = current_mesh_data_instance.mesh_data
if !mdr:
return
var mesh : Array = mdr.get_array()
# partition the meshes along the already existing seams (no new vertices)
var partitioned_meshes : Array = partition_mesh(mesh)
for m in partitioned_meshes:
m.print()
#m.unwrap()
class STriangle:
var i1 : int = 0
var i2 : int = 0
var i3 : int = 0
var index : int = 0
func set_indices(pi1 : int, pi2 : int, pi3 : int, pindex : int):
i1 = pi1
i2 = pi2
i3 = pi3
index = pindex
func is_neighbour(pi1 : int, pi2 : int, pi3 : int) -> bool:
var c : int = 0
if i1 == pi1 || i1 == pi2 || i1 == pi3:
c += 1
if i2 == pi1 || i2 == pi2 || i2 == pi3:
c += 1
if i3 == pi1 || i3 == pi2 || i3 == pi3:
c += 1
if c >= 1:
return true
else:
return false
func print():
print("[ Tri: " + str(i1) + ", " + str(i2) + ", " + str(i3) + ", " + str(index) + ", ]")
class SMesh:
var indices : PoolIntArray
var vertices : PoolVector3Array
var uvs : PoolVector2Array
var triangles : Array
func is_triangle_neighbour(tri : STriangle) -> bool:
for t in triangles:
if t.is_neighbour(tri.i1, tri.i2, tri.i3):
return true
return false
func try_to_merge(o : SMesh) -> bool:
for t in o.triangles:
if is_triangle_neighbour(t):
triangles.append_array(o.triangles)
return true
return false
func unwrap():
pass
func print():
print("[ SMesh:")
for t in triangles:
t.print()
print("]")
func partition_mesh(mesh : Array) -> Array:
var meshes : Array = Array()
if mesh.size() != ArrayMesh.ARRAY_MAX:
return meshes
var vertices : PoolVector3Array = mesh[ArrayMesh.ARRAY_VERTEX]
var indices : PoolIntArray = mesh[ArrayMesh.ARRAY_INDEX]
if vertices.size() == 0:
return meshes
if indices.size() == 0:
return meshes
var tricount : int = indices.size() / 3
for it in range(tricount):
var iit : int = it * 3
var tri : STriangle = STriangle.new()
tri.set_indices(indices[iit], indices[iit + 1], indices[iit + 2], it)
var found : bool = false
for m in meshes:
if m.is_triangle_neighbour(tri):
m.triangles.append(tri)
found = true
break
if !found:
var sm : SMesh = SMesh.new()
sm.triangles.append(tri)
meshes.append(sm)
var changed : bool = true
while changed:
changed = false
for i in range(meshes.size() - 1):
if meshes[i].try_to_merge(meshes[i + 1]):
changed = true
meshes.remove(i + 1)
break
for m in meshes:
m.vertices = vertices
m.indices = indices
m.uvs.resize(vertices.size())
return meshes
#func forward_spatial_gui_input(camera, event):
# for g in active_gizmos:
# if g.forward_spatial_gui_input(0, camera, event):

View File

@ -286,7 +286,7 @@ window/size/ui_scale_touch=1.0
[editor_plugins]
enabled=PoolStringArray( "res://addons/Godoxel/plugin.cfg", "res://addons/bone_editor/plugin.cfg" )
enabled=PoolStringArray( "res://addons/Godoxel/plugin.cfg", "res://addons/mesh_data_resource_editor/plugin.cfg" )
[ess]