mirror of
https://github.com/Relintai/broken_seals.git
synced 2025-01-22 02:17:18 +01:00
Also implemented add quad to edge operation.
This commit is contained in:
parent
5185d29150
commit
0019d2f784
@ -521,7 +521,49 @@ func add_triangle_to_edge(edge : int) -> void:
|
||||
ei1 = t
|
||||
|
||||
MDRMeshUtils.append_triangle_to_tri_edge(_mdr, _vertices[ei0], _vertices[ei1], _vertices[erefind])
|
||||
|
||||
func add_quad_to_edge(edge : int) -> void:
|
||||
var triangle_index : int = find_first_triangle_for_edge(edge)
|
||||
|
||||
var inds : int = triangle_index * 3
|
||||
|
||||
var ti0 : int = _indices[inds]
|
||||
var ti1 : int = _indices[inds + 1]
|
||||
var ti2 : int = _indices[inds + 2]
|
||||
|
||||
var ps : PoolIntArray = _handle_to_vertex_map[edge]
|
||||
|
||||
if ps.size() == 0:
|
||||
return
|
||||
|
||||
var ei0 : int = 0
|
||||
var ei1 : int = 0
|
||||
var erefind : int = 0
|
||||
|
||||
if !pool_int_arr_contains(ps, ti0):
|
||||
ei0 = ti1
|
||||
ei1 = ti2
|
||||
erefind = ti0
|
||||
elif !pool_int_arr_contains(ps, ti1):
|
||||
ei0 = ti0
|
||||
ei1 = ti2
|
||||
erefind = ti1
|
||||
elif !pool_int_arr_contains(ps, ti2):
|
||||
ei0 = ti0
|
||||
ei1 = ti1
|
||||
erefind = ti2
|
||||
|
||||
var fo : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ti0], _vertices[ti1], _vertices[ti2])
|
||||
var fn : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ei0], _vertices[ei1], _vertices[erefind])
|
||||
|
||||
if fo.dot(fn) < 0:
|
||||
var t : int = ei0
|
||||
ei0 = ei1
|
||||
ei1 = t
|
||||
|
||||
MDRMeshUtils.append_quad_to_tri_edge(_mdr, _vertices[ei0], _vertices[ei1], _vertices[erefind])
|
||||
|
||||
|
||||
func add_triangle_at() -> void:
|
||||
if !_mdr:
|
||||
return
|
||||
@ -536,7 +578,17 @@ func add_triangle_at() -> void:
|
||||
add_triangle()
|
||||
|
||||
func add_quad_at() -> void:
|
||||
pass
|
||||
if !_mdr:
|
||||
return
|
||||
|
||||
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
||||
#todo
|
||||
pass
|
||||
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
||||
for sp in _selected_points:
|
||||
add_quad_to_edge(sp)
|
||||
else:
|
||||
add_triangle()
|
||||
|
||||
func add_box() -> void:
|
||||
if _mdr:
|
||||
|
@ -51,7 +51,55 @@ static func add_triangle(mdr : MeshDataResource) -> void:
|
||||
st.generate_normals()
|
||||
|
||||
merge_in_surface_tool(mdr, st)
|
||||
|
||||
# Appends a quad to the mesh. It's created to the opposite side of v2 to the ev0, and ev1 edge
|
||||
static func append_quad_to_tri_edge(mdr : MeshDataResource, ev0 : Vector3, ev1 : Vector3, v2 : Vector3) -> void:
|
||||
var vref : Vector3 = reflect_vertex(ev0, ev1, v2)
|
||||
var vproj : Vector3 = (vref - ev0).project(ev1 - ev0)
|
||||
var eoffs : Vector3 = (vref - ev0) - vproj
|
||||
|
||||
var qv0 : Vector3 = ev0
|
||||
var qv1 : Vector3 = ev0 + eoffs
|
||||
var qv2 : Vector3 = ev1 + eoffs
|
||||
var qv3 : Vector3 = ev1
|
||||
|
||||
add_quad_at(mdr, qv0, qv1, qv2, qv3, false)
|
||||
|
||||
static func add_quad_at(mdr : MeshDataResource, v0 : Vector3, v1 : Vector3, v2 : Vector3, v3 : Vector3, flip : bool = false) -> void:
|
||||
var st : SurfaceTool = SurfaceTool.new()
|
||||
|
||||
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||
|
||||
st.add_uv(Vector2(0, 1))
|
||||
st.add_vertex(v0)
|
||||
st.add_uv(Vector2(0, 0))
|
||||
st.add_vertex(v1)
|
||||
st.add_uv(Vector2(1, 0))
|
||||
st.add_vertex(v2)
|
||||
st.add_uv(Vector2(1, 1))
|
||||
st.add_vertex(v3)
|
||||
|
||||
|
||||
if !flip:
|
||||
st.add_index(0)
|
||||
st.add_index(1)
|
||||
st.add_index(2)
|
||||
|
||||
st.add_index(0)
|
||||
st.add_index(2)
|
||||
st.add_index(3)
|
||||
else:
|
||||
st.add_index(2)
|
||||
st.add_index(1)
|
||||
st.add_index(0)
|
||||
|
||||
st.add_index(3)
|
||||
st.add_index(2)
|
||||
st.add_index(0)
|
||||
|
||||
st.generate_normals()
|
||||
|
||||
merge_in_surface_tool(mdr, st)
|
||||
|
||||
static func add_quad(mdr : MeshDataResource) -> void:
|
||||
var st : SurfaceTool = SurfaceTool.new()
|
||||
|
Loading…
Reference in New Issue
Block a user