There a huge issue where a mesh generated when I play test server, it generates correctly, but when I play solo it is messed up?
local WALL_THICKNESS = 0.8
local WALL_HEIGHT = 14
local AssetService = game:GetService("AssetService")
-- Given 4 vertex IDs, adds a new normal and 2 triangles, making a sharp quad
local function addSharpQuad(eMesh, vid0, vid1, vid2, vid3)
local nid = eMesh:AddNormal()
local fid1 = eMesh:AddTriangle(vid0, vid1, vid2)
eMesh:SetFaceNormals(fid1, {nid, nid, nid})
local fid2 = eMesh:AddTriangle(vid0, vid2, vid3)
eMesh:SetFaceNormals(fid2, {nid, nid, nid})
end
-- Creates a wall mesh between two points
local function makeWallBetweenPoints(startPos, endPos)
local eMesh = AssetService:CreateEditableMesh()
-- Calculate wall direction and length
local wallVector = endPos - startPos
local wallLength = wallVector.Magnitude
-- Calculate rotation angle around Y axis
local angle = math.atan2(wallVector.X, wallVector.Z)
local cs = math.cos(angle)
local sn = math.sin(angle)
-- Function to rotate a point around Y axis
local function rotatePoint(x, y, z)
local rotatedX = x * cs - z * sn
local rotatedZ = x * sn + z * cs
return Vector3.new(
rotatedX + startPos.X,
y + startPos.Y,
rotatedZ + startPos.Z
)
end
-- Create vertices for the wall
local v1 = eMesh:AddVertex(rotatePoint(0, 0, 0))
local v2 = eMesh:AddVertex(rotatePoint(wallLength, 0, 0))
local v3 = eMesh:AddVertex(rotatePoint(0, WALL_HEIGHT, 0))
local v4 = eMesh:AddVertex(rotatePoint(wallLength, WALL_HEIGHT, 0))
local v5 = eMesh:AddVertex(rotatePoint(0, 0, WALL_THICKNESS))
local v6 = eMesh:AddVertex(rotatePoint(wallLength, 0, WALL_THICKNESS))
local v7 = eMesh:AddVertex(rotatePoint(0, WALL_HEIGHT, WALL_THICKNESS))
local v8 = eMesh:AddVertex(rotatePoint(wallLength, WALL_HEIGHT, WALL_THICKNESS))
-- Create the faces
addSharpQuad(eMesh, v5, v6, v8, v7) -- Front
addSharpQuad(eMesh, v1, v3, v4, v2) -- Back
addSharpQuad(eMesh, v1, v5, v7, v3) -- Left
addSharpQuad(eMesh, v2, v4, v8, v6) -- Right
addSharpQuad(eMesh, v1, v2, v6, v5) -- Bottom
addSharpQuad(eMesh, v3, v7, v8, v4) -- Top
eMesh:RemoveUnused()
return eMesh
end
local function createWallBetweenParts(partA, partB)
local startPos = partA.Position
local endPos = partB.Position
local wallMesh = makeWallBetweenPoints(startPos, endPos)
local meshPart = AssetService:CreateMeshPartAsync(Content.fromObject(wallMesh))
meshPart.Parent = workspace
return meshPart
end
local wallMesh = makeWallBetweenPoints(Vector3.new(0, 0, 0), Vector3.new(10, 0, 10))
local meshPart = AssetService:CreateMeshPartAsync(Content.fromObject(wallMesh))
meshPart.Anchored = true
meshPart.Parent = workspace
EDIT Further testing on the above, it seems EditableMeshes only load based on if it server or client script? Can see I render the above code using a server script, and it’s visually there on the server + collisions exist but it does not render on client
Also, there’s an unloading bug
More bugs to report. Unsure if I’m mis-interpreting. But I run this is in RenderStepped. I basically want to visualize the mesh.
-- Example usage:
local Start, End = DragTracker.StartPos, DragTracker.CurrentPos
local wallMesh = makeCurvedWall(Start, End, (End + Start) / 2, 15)
if not meshPart then
meshPart = AssetService:CreateMeshPartAsync(Content.fromObject(wallMesh))
meshPart.Anchored = true
meshPart.CanCollide = false
meshPart.Parent = workspace
else
meshPart:ApplyMesh(AssetService:CreateMeshPartAsync(Content.fromObject(wallMesh)))
end
I obviously don’t want to destroy and recreate a mesh constantly, so was trying to basically just “edit” the EditableMesh and apply it to the mesh. But my studio will crash doing this after a few seconds