Applying editable mesh to plane causes it to stretch

I am trying to create a script where it generates 256x256 stud chunks which all possess the same editablemesh. I plan to adjust the position of each vertice but as of right now I’m facing an issue when I apply the editablemesh. The plane mesh gets created and placed correctly, but as soon as I apply the mesh using MeshPart:ApplyMesh(), the entire thing gets stretched beyond the horizon.

I have another script which does practically the same thing with a different instance of the same plane mesh and I basically directly ported over the code from the working script. I’m not sure why that script works and this one doesn’t.

I’ve tried running the faulty script in a standalone environment and the issue still persists.

Here is the function where the issue occurs:

function Terrain.LoadChunksAsync()
	while task.wait() do
		if Terrain._RenderQueue:IsEmpty() then
			continue
		end

		-- // get the next chunk in queue to be rendered
		local chunkPos: Vector3 = Terrain._RenderQueue:Dequeue()
		local terrainModel: Model = game.ReplicatedStorage.Assets.TerrainMesh:Clone()
		terrainModel.Name = "chunk" .. chunkIndex
		chunkIndex += 1

		local plane: MeshPart = terrainModel:WaitForChild("Plane", 2)
		if not plane then continue end
		terrainModel:PivotTo(CFrame.new(chunkPos))
		terrainModel.Parent = loadedChunkFolder

		-- if an editable mesh already exists, simply apply the mesh
		if Terrain.HostChunk then
			plane:ApplyMesh(Terrain.HostChunk)
			table.insert(Terrain.LoadedChunks, terrainModel)
			continue
		end

		-- if no host chunk, create a new editable mesh to be applied
		local editableMesh = Common.CreateEditableMesh(plane.MeshId)
		-- configureEditableMeshVertices(editableMesh)
		
		local mesh = assetService:CreateMeshPartAsync(Content.fromObject(editableMesh))
		task.wait(2)
		plane:ApplyMesh(mesh) -- stretch occurs at this point
		Terrain.HostChunk = mesh

		table.insert(Terrain.LoadedChunks, terrainModel)
	end
end

Here are the videos related to the issue:

Bugged result: Watch Desktop 2025.01.31 - 17.23.07.24 | Streamable

Expected result: Watch Desktop 2025.01.31 - 17.43.02.25 | Streamable

Try resetting the scale of the mesh to Vector3.new(1, 1, 1) and adjusting the pivot before applying the new mesh.

I tried resetting the sizes of both the plane mesh and the editable mesh before and after MeshPart:ApplyMesh() as you suggested and I’m still getting the same issue. By adjusting the pivot I assume you just mean positioning the meshes in the correct position before applying, and the issue still occurs.

I should include that in the workspace, the mesh planes still have the same expected size of (256, 0.001, 256), so I’d assume it has to do with the editable mesh causing this visual stretch (seeing as the collision model doesn’t get updated)

1 Like

Restarting studio appeared to fix this and it worked as intended.

1 Like

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