Implemented outline for face selection. (Face selection itself is not yet implemented though.)

This commit is contained in:
Relintai 2021-12-31 08:54:12 +01:00
parent 6733787c46
commit 6629fa503c
2 changed files with 50 additions and 0 deletions

View File

@ -124,6 +124,8 @@ func redraw():
if selection_mode == SelectionMode.SELECTION_MODE_EDGE:
_mesh_outline_generator.generate_mark_edges()
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
_mesh_outline_generator.generate_mark_faces()
else:
_mesh_outline_generator.generate()

View File

@ -75,3 +75,51 @@ func generate_mark_edges():
lines.append(pmid + Vector3(0, 0, -l))
lines.append(pmid + Vector3(0, l, 0))
lines.append(pmid + Vector3(0, -l, 0))
func generate_mark_faces():
lines.resize(0)
if !_mdr:
return
if _mdr.array.size() != ArrayMesh.ARRAY_MAX:
return
if _mdr.array[ArrayMesh.ARRAY_VERTEX] == null || _mdr.array[ArrayMesh.ARRAY_INDEX] == null:
return
var arr : Array = _mdr.array
var vertices : PoolVector3Array = arr[ArrayMesh.ARRAY_VERTEX]
var indices : PoolIntArray = arr[ArrayMesh.ARRAY_INDEX]
if vertices.size() == 0:
return
if indices.size() % 3 != 0:
return
for i in range(0, indices.size(), 3):
for j in range(3):
lines.append(vertices[indices[i + j]])
lines.append(vertices[indices[i + ((j + 1) % 3)]])
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]
var v0 : Vector3 = vertices[i0]
var v1 : Vector3 = vertices[i1]
var v2 : Vector3 = vertices[i2]
var pmid : Vector3 = v0 + v1 + v2
pmid /= 3
var l : float = (v0 - v1).length() / 20.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))