diff --git a/library/voxel_surface.cpp b/library/voxel_surface.cpp index 742c74c..eb38a99 100644 --- a/library/voxel_surface.cpp +++ b/library/voxel_surface.cpp @@ -49,6 +49,23 @@ Vector2 VoxelSurface::transform_uv(const VoxelSurfaceSides p_side, const Vector2 return uv; } +Vector2 VoxelSurface::transform_uv_scaled(const VoxelSurfaceSides p_side, const Vector2 p_uv, int p_current_x, int p_current_y, int p_max) const { + Vector2 uv = p_uv; + + Rect2 r = _rects[p_side]; + + float sizex = r.size.x / static_cast(p_max); + float sizey = r.size.x / static_cast(p_max); + + uv.x *= sizex; + uv.y *= sizey; + + uv.x += r.position.x + sizex * p_current_x; + uv.y += r.position.y + sizey * p_current_y; + + return uv; +} + void VoxelSurface::refresh_rects() { } @@ -81,6 +98,7 @@ void VoxelSurface::_bind_methods() { ClassDB::bind_method(D_METHOD("set_rect", "side", "rect"), &VoxelSurface::set_rect); ClassDB::bind_method(D_METHOD("transform_uv", "side", "uv"), &VoxelSurface::transform_uv); + ClassDB::bind_method(D_METHOD("transform_uv_scaled", "side", "uv", "p_current_x", "p_current_y", "max"), &VoxelSurface::transform_uv_scaled); ClassDB::bind_method(D_METHOD("refresh_rects"), &VoxelSurface::refresh_rects); diff --git a/library/voxel_surface.h b/library/voxel_surface.h index 36540b0..cba43dc 100644 --- a/library/voxel_surface.h +++ b/library/voxel_surface.h @@ -59,7 +59,8 @@ public: Ref get_library() const; void set_library(Ref library); - Vector2 transform_uv(const VoxelSurfaceSides side, const Vector2 uv) const; + Vector2 transform_uv(const VoxelSurfaceSides p_side, const Vector2 p_uv) const; + Vector2 transform_uv_scaled(const VoxelSurfaceSides p_side, const Vector2 p_uv, int p_current_x, int p_current_y, int p_max) const; virtual void refresh_rects();