How Can I Calculate The Highest Number of Vertices Without Exceeding the Limit?

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)
2 Likes

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?

Yeah, that’s what I am looking to do.

1 Like

ima go in studio to do some testing, i think i have an idea of what to do

2 Likes

ok i think i made it work, so i did this:

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
2 Likes

lmk if it works, post must be 30 letters

1 Like

Thank you for the post! This is how I applied it:

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

3 Likes

This post might help,

2 Likes

oh yeah i forgot about the triangles, sorry about that, are you using this for flightpoint btw, like editable planes?

1 Like

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

1 Like

ahh thats why, well thanks for letting me know, thats why you needed it to be high quality, so it looks good

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.