Adjust EditableMesh faces

This creates an EditableMesh for a rectangle. I store the Faces too.

local WALL_HEIGHT = 14
local WALL_THICKNESS = 0.5

local AssetService = game:GetService("AssetService")

local function AddQuad(mesh, A, B, C, D)
	local i = mesh:AddVertex(A)
	local j = mesh:AddVertex(B)
	local k = mesh:AddVertex(C)
	local l = mesh:AddVertex(D)
	local f1 = mesh:AddTriangle(i, k, j)
	local f2 = mesh:AddTriangle(i, l, k)

	local Center = (A + B + C + D) / 4

	return {
		Vertices = { i, j, k, l },
		Faces = { f1, f2 },
		Center = Center
	}
end

return function(length)
	local OriginalEditableMesh = AssetService:CreateEditableMesh()

	local hl, hh, ht = length / 2, WALL_HEIGHT / 2, WALL_THICKNESS / 2
	local LF, RF, LB, RB = -hl, hl, -hl, hl

	local B, T = -hh, hh
	local F, BK = -ht, ht
	
	local MeshFaces = {}

	local Front = AddQuad(
		OriginalEditableMesh,
		Vector3.new(LF, B, F),
		Vector3.new(RF, B, F),
		Vector3.new(RF, T, F),
		Vector3.new(LF, T, F)
	)

	local Back = AddQuad(
		OriginalEditableMesh,
		Vector3.new(RB, B, BK),
		Vector3.new(LB, B, BK),
		Vector3.new(LB, T, BK),
		Vector3.new(RB, T, BK)
	)

	local Top = AddQuad(
		OriginalEditableMesh,
		Vector3.new(LB, T, BK),
		Vector3.new(LF, T, F),
		Vector3.new(RF, T, F),
		Vector3.new(RB, T, BK)
	)

	local Bottom = AddQuad(
		OriginalEditableMesh,
		Vector3.new(LF, B, F),
		Vector3.new(LB, B, BK),
		Vector3.new(RB, B, BK),
		Vector3.new(RF, B, F)
	)

	local Left = AddQuad(
		OriginalEditableMesh,
		Vector3.new(LB, B, BK),
		Vector3.new(LF, B, F),
		Vector3.new(LF, T, F),
		Vector3.new(LB, T, BK)
	)

	local Right = AddQuad(
		OriginalEditableMesh,
		Vector3.new(RF, B, F),
		Vector3.new(RB, B, BK),
		Vector3.new(RB, T, BK),
		Vector3.new(RF, T, F)
	)

	MeshFaces["Front"] = Front
	MeshFaces["Back"] = Back
	MeshFaces["Top"] = Top
	MeshFaces["Bottom"] = Bottom
	MeshFaces["Left"] = Left
	MeshFaces["Right"] = Right

	return OriginalEditableMesh, MeshFaces
end

This creates the MeshPart

local NewEditableMesh, MeshFaces = require(script.CreateEditableMesh)(SegmentLength)
local MeshPart = AssetService:CreateMeshPartAsync(
	Content.fromObject(NewEditableMesh),
	{ CollisionFidelity = Enum.CollisionFidelity.Box }
)

And I Store MeshFaces

{
    Right = MeshFaces["Right"]
    Left = MeshFaces["Left"]
}

I want to be able to adjust these faces (trim/extend) and apply that to the mesh

All you need to do is call SetPosition on the vertexId you want to change (vertexId are returned from AddVertex).

Do I need to generate a new MeshPart or anything? Or would it automatically update??

Nope! It will update automatically

Thought this’d work but I need scaling on too :smiling_face_with_tear:as I need collisions to change as these faces change.

And it doesn’t look like this replication is enabled yet either :sob: