Issue with EditableMesh

Right now I’m trying to use an editable mesh to generate a ring as a basis for modeling a tornado.
However I’m having an issue with EditableMesh where no matter what I do my mesh doesn’t really render as the shape I provide it with, in this case it’s supposed to be a ring. The interesting thing is that that the collision system seems to handle it perfectly fine and is mostly accurate (inside collision appears to model that of a diamond shape, while the outside accurately appears to be a circle. But as seen in the gif below, the mesh is clearly showing up as a rectangular prism.
ezgif-895c550ad936ee

I have tried changing the order I put vertices on the list, I’ve limited the distance from the origin of local space to be within -1 to 1 (as a devforum said that having numbers above 1 can be an issue)

Heres my code that generates these shapes

@Script
--//Services//--
local AssetService: AssetService = game:GetService("AssetService")
local MeshService = require(script.Parent.MeshService)
--//End of "Services"//--
--//Misc.//--
local Object = script.Parent
--//End of "Misc."//--
--//Connections//--
local Mesh: MeshService.CMesh = MeshService.new_ring()
Mesh:generate(workspace)
Mesh.Object.Anchored = true
Mesh.Object.Position = Vector3.new(0, 5, 0)
--//End of "Connections"//--

This is referencing a modulescript I made which references three methods, here are those three methods.

@MeshService
local function GenerateRing(Mesh: CMesh, Resolution: number): ()
	local MeshData = Mesh.MeshData
	for i = 0,Resolution - 1 do
		local v1 = i * 2 * math.pi / Resolution
		local v2 = (i+1) * 2 * math.pi / Resolution
		local Z1, X1, Z2, X2 = math.sin(v1), math.cos(v1), math.sin(v2), math.cos(v2)
		local Vertex1 = MeshData:AddVertex(Vector3.new(X1, 1, Z1))
		local Vertex2 = MeshData:AddVertex(Vector3.new(X2, 1, Z2))
		local Vertex3 = MeshData:AddVertex(Vector3.new(X2, -1, Z2))
		local Vertex4 = MeshData:AddVertex(Vector3.new(X1, -1, Z1))
		
		local Triangle1 = MeshData:AddTriangle(Vertex1, Vertex2, Vertex3)
		local Triangle2 = MeshData:AddTriangle(Vertex1, Vertex4, Vertex3)
		
	end
	MeshData:RemoveUnused()
end
function Service.new_ring(): CMesh
	local Mesh = Service.new()
	GenerateRing(Mesh, 500)
	return Mesh
end
function Service.new(): CMesh
	local Data: EditableMesh = AssetService:CreateEditableMesh()
	
	local Mesh: CMesh_fluid = {
		MeshData = Data
	}
	--/generate_macro!
	function Mesh:generate(Parent: Instance?): ()
		Service.generate(self, Parent)
	end
	
	--/transform_macro!
	function Mesh:transform_vertices(Transformer: CMesh_transform_vertex): ()
		Service.transform_vertices(self, Transformer)
	end
	
	--/ Solidfy and Return CMesh.
	return Mesh :: CMesh
end

Here are the custom types I use

export type CMesh_transform_vertex = (vertexId: number, vertexPos: Vector3) -> Vector3
export type CMesh_mut_func = (...any) -> ()
export type CMesh_fluid = {
	--/ Fields
	MeshData: EditableMesh,
	Object: MeshPart?,
	
	--/ Methods
	generate: CMesh_mut_func?,
	transform_vertices: CMesh_mut_func?,
}
export type CMesh = {
	--/ Fields
	MeshData: EditableMesh,
	Object: MeshPart?,

	--/ Methods
	generate: CMesh_mut_func,
	transform_vertices: CMesh_mut_func,
}

Any ideas where/what I am doing wrong?

1 Like

I totally misread some of the stuff in the beginning, ignore me lol

1 Like

Editable mesh instances are not shared between the server and client. You need to either render them directly on the client or if you want interactivity you can edit them via remote events from the server to the client.

2 Likes

Oh what??? thats wild


Anyway, thanks for giving me a valid solution cheers to you man.

1 Like

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