Hello. I am making a program that generates an editablemesh plane. The inputs are a size vector2, and a frequency vector2.

The frequency int represents the number of studs between vertices. The size int represents the size of the plane.

To avoid going over both the triangle (20000) and vertex limit (60000), how could I fix my code to make it find the lowest frequency (for the most amount of vertices possible)?

Currently, it just isn’t working out right.

local size_value = 512
-- Determine the highest quality the meshes can go without exceeding the limit.
local squared_size = size_value ^ 2
local vertex_limit = math.floor(squared_size / 60000) - 1
local triangle_limit = math.floor(squared_size / 120000) - 1
-- The LOWEST possible frequency for the highest quality that doesn't exceed editablemesh limits.
local frequency = math.max(vertex_limit, triangle_limit)
print(size_factors)

im not really good with math which is why im asking, but by how could you find the lowest frequency your basically trying to find the smallest space between the studs to use the most amount of vertices without passing the threshhold?

local part = script.Parent
local squared_size
local vMax = 60000
local tMax = 120000
function calculateSmallestFrequency(squaredSize)
local edgeSize = math.sqrt(squaredSize)
local maxEdge = math.sqrt(vMax)
local edgeGap = edgeSize / maxEdge
return edgeGap, edgeSize
end
while task.wait(0.1) do
squared_size = part.Size.X ^ 2
local frequency, edgeSize = calculateSmallestFrequency(squared_size)
print(frequency)
print(edgeSize)
end

i used a part for example but the math should work with editable meshes also, tbh you can just take the function, and ignore the edgeSize variable, i was playing around with using orbs to visualize the gaps but it kept exhausting it, so you can delete the edge size thing

also i might aswell simplify the function to be this:

function calculateSmallestFrequency(squaredSize)
return math.sqrt(squaredSize) / math.sqrt(vMax)
end

function calculate_smallest_frequency(edge_size: number): number
local squared_size = edge_size ^ 2
local max_edge_size = math.sqrt(module.config.max_vertices)
local min_frequency = edge_size / max_edge_size
return min_frequency
end

How would I now continue on to calculate the number of triangles generated?

function calculate_smallest_frequency(edge_size: number): number
local squared_size = edge_size ^ 2
local max_edge_size = math.sqrt(module.config.max_vertices)
local min_frequency = edge_size / max_edge_size
return min_frequency
end
function calculate_triangle_count(edge_size: number): number
-- Number of quads is (edge_size - 1) x (edge_size - 1)
local number_of_quads = (edge_size - 1) * (edge_size - 1)
-- Each quad creates 2 triangles
local number_of_triangles = number_of_quads * 2
return number_of_triangles
end

messing around with some water! i made this a while ago, but i decided to work on tiling it today. it looks a little 2d here but all of the texturing is 3d which is why i am working with editablemeshes