How do I create editable meshes after update?

Hello, my chunk system broke after the update to editable meshes, I have been trying for the past hour to find a way to make editable meshes but they all error or don’t work at all.

Code:

local function createchunk(xpos, zpos, iteration)
	local mesh = Instance.new("MeshPart")
	mesh.Parent = OceanMeshes
	mesh.Position = Vector3.new(math.round(xpos / Grid)*Grid, Level, math.round(zpos / Grid)*Grid)
	mesh.Size = Vector3.new(1,1,1)
	mesh.Anchored = true
	mesh.CanCollide = false
	mesh.CastShadow = false
	
	local Vertices
	local Width
	local Height
	local Offset
	
	if iteration >= FarIteration then
		mesh.Name = "FarMesh"
		Vertices = 2
		Offset = Grid
	else
		mesh.Name = "CloseMesh"
		Vertices = MaxVertices
		Offset = Size
	end
	
	Width = Vertices
	Height = Vertices
	
	local editableMesh = AssetService:CreateEditableMesh()
    mesh.Content = editableMesh:GetContent()
	
	local VerticesTable = {}

	for y = 1, Height do
		local raw = {}
		for x = 1, Width do
			local vertexPosition = Vector3.new(x - 1, 0, y - 1) * Offset
			local vertexId = editableMesh:AddVertex(vertexPosition)

			raw[x] = {vertexId, vertexPosition}
		end
		VerticesTable[y] = raw
	end

	for y = 1, Height-1 do
		for x = 1, Width-1 do
			local vertex1 = VerticesTable[y][x][1] :: number
			local vertex2 = VerticesTable[y+1][x][1] :: number
			local vertex3 = VerticesTable[y][x+1][1] :: number
			local vertex4 = VerticesTable[y+1][x+1][1] :: number

			local triangle1 = editableMesh:AddTriangle(vertex1, vertex2, vertex3)
			local triangle2  = editableMesh:AddTriangle(vertex2, vertex4, vertex3)
		end
	end
	
	return mesh
end

When I try assigning the meshcontent it gives me this error:

"The current thread cannot write 'MeshContent' (lacking capability NotAccessible)"

When I try using the meshcontent in editable mesh async it gives me this error:

"Failed to load mesh"

I looked everywhere and could find barely any mentions about this new service and all the documentation is confusing on how to create a editable mesh now. Any help is appreciated!

4 Likes

I was able to create them, but now they don’t render in certain angles and the scaling is all messed up

local function createchunk(xpos, zpos, iteration)
    local mesh = Instance.new("MeshPart")
    mesh.Parent = OceanMeshes
    mesh.Position = Vector3.new(math.round(xpos / Grid) * Grid, Level, math.round(zpos / Grid) * Grid)
    mesh.Size = Vector3.new(1, 1, 1)
    mesh.Anchored = true
    mesh.CanCollide = false
    mesh.CastShadow = false

    local Vertices
    local Width
    local Height
    local Offset

    if iteration >= FarIteration then
        mesh.Name = "FarMesh"
        Vertices = 2
        Offset = Grid
    else
        mesh.Name = "CloseMesh"
        Vertices = MaxVertices
        Offset = Size
    end

    Width = Vertices
    Height = Vertices

    local editableMesh = AssetService:CreateEditableMesh()
    
    -- Create vertices
    local VerticesTable = {}
    for y = 1, Height do
        local raw = {}
        for x = 1, Width do
            local vertexPosition = Vector3.new(x - 1, 0, y - 1) * Offset
            local vertexId = editableMesh:AddVertex(vertexPosition)
            raw[x] = {vertexId, vertexPosition}
        end
        VerticesTable[y] = raw
    end

    -- Create triangles
    for y = 1, Height - 1 do
        for x = 1, Width - 1 do
            local vertex1 = VerticesTable[y][x][1]
            local vertex2 = VerticesTable[y + 1][x][1]
            local vertex3 = VerticesTable[y][x + 1][1]
            local vertex4 = VerticesTable[y + 1][x + 1][1]

            editableMesh:AddTriangle(vertex1, vertex2, vertex3)
            editableMesh:AddTriangle(vertex2, vertex4, vertex3)
        end
    end

    -- Assign the mesh content
    mesh.Content = editableMesh:GetContent()

    return mesh
end
1 Like

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