Skip to content

Commit

Permalink
Fixed lattice resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Jul 29, 2024
1 parent 8ec4094 commit 13e08c2
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions addons/material_maker/types/lattice.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,23 @@ func compare(lattice) -> bool:
return false
return true

static func get_point_from_array(v : Vector2i, size : Vector2i, points : PackedVector2Array) -> Vector2:
return points[v.x+(size.x+1)*v.y]

static func interpolate_point(v : Vector2, size : Vector2i, points : PackedVector2Array) -> Vector2:
#v *= Vector2(size)
return v
v *= Vector2(size)
var vs : Vector2i = Vector2i(floor(v.x), floor(v.y))
vs.x = clampi(vs.x, 0, size.x-1)
vs.y = clampi(vs.y, 0, size.y-1)
var vt : Vector2 = Vector2(v.x-vs.x, v.y-vs.y)
print(str(vs)+" "+str(vt))
var p00 : Vector2 = get_point_from_array(vs, size, points)
var p01 : Vector2 = get_point_from_array(vs+Vector2i(0, 1), size, points)
var p10 : Vector2 = get_point_from_array(vs+Vector2i(1, 0), size, points)
var p11 : Vector2 = get_point_from_array(vs+Vector2i(1, 1), size, points)
var p0 : Vector2 = lerp(p00, p01, vt.y)
var p1 : Vector2 = lerp(p10, p11, vt.y)
return lerp(p0, p1, vt.x)

func resize(sx : int, sy : int) -> void:
var old_size : Vector2i = size
Expand Down

0 comments on commit 13e08c2

Please sign in to comment.