How to use an EditableMesh after the update?

Hello there!

Before the major updates to in-experience Mesh & Image APIs, adding an EditableMesh to a MeshPart was fairly simple. Just parent the EditableMesh to the MeshPart. But now after the update, things seem to have gotten a little more confusing and I can’t seem to figure out how to do so properly. There are a few examples in the update post and in the documentation, yet I wasn’t able to get them to work like I want.

I’m trying to clone a MeshPart “chunk” and then apply an EditableMesh to it, however none of my attempts have been successful. The last thing I tried was

local chunk = chunkPrefab:Clone()
chunk.Anchored = ...
...

-- Afaik this is the correct way to make an EditableMesh now
local mesh = AssetService:CreateEditableMesh()

-- Obviously this won't work, because the first and
-- only argument is a MeshPart not an EditableMesh
chunk:ApplyMesh(mesh)

If anyone has gotten this to work with the new update in a way similar to mine, I’d love to hear how.

1 Like

Just a bump cuz I haven’t found the solution yet and my post has been buried.

1 Like

This snippet is from the official update post:

-- Create a new MeshPart instance linked to this EditableMesh Content
-- Note: EditableMesh:CreateMeshPartAsync will be replaced with
-- AssetService:CreateMeshPartAsync(Content, …) before public release
local newMeshPart = myEditableMesh:CreateMeshPartAsync(computeExtents(myEditableMesh))

-- Apply newMeshPart which is linked to the EditableMesh onto myMeshPart
myMeshPart:ApplyMesh(newMeshPart)

it seems you need to make a mesh part using editableMesh:CreateMeshPartAsync(…) and supply that to :ApplyMesh()

Note: You need the computeExtents helper function from the blog post as well. Here it is in full:

-- Helper method to compute extents of a Mesh. This will eventually
-- be replaced with a direct getter method on EditableMesh
local function computeExtents(em: EditableMesh)
    local verts = em:GetVertices()
    if #verts == 0 then
        return Vector3.zero
    end
    local inf = math.huge
    local min = Vector3.new(inf, inf, inf)
    local max = Vector3.new(-inf, -inf, -inf)
    for _, id in verts do
        local v = em:GetPosition(id)
        min = min:Min(v)
        max = max:Max(v)
    end
    return max - min
end

I know about that snippet, however my main problem with it is that the function editableMesh:CreateMeshPartAsync is deprecated. It says that I should use AssetService instead, however I don’t understand how to make it work with AssetService

1 Like

However I suppose that before when I looked at the snippet and the documentation, I felt like none of it was remotely close to what I needed, but I guess that I could use this as well, even tho it’s deprecated, unless anyone knows any better.

local newMeshPart = AssetService:CreateMeshPartAsync(Content.fromObject(EditableMesh))

I’ve got problems with Editable Mesh too, I can’t get it to display…