When trying to update a MeshPart
with a EditableMesh
via ApplyMesh
the result is not correct most of the time
in this video we can see that it does not work twice but on the third play it works
here is the project:
EditableMesh.rbxl (52.3 KB)
and this is the code used in the project
local AssetService = game:GetService("AssetService")
local RunService = game:GetService("RunService")
local options = {CollisionFidelity = Enum.CollisionFidelity.Hull, RenderFidelity = Enum.RenderFidelity.Precise, FluidFidelity = Enum.FluidFidelity.UseCollisionGeometry}
local mesh = AssetService:CreateEditableMesh()
local content = Content.fromObject(mesh)
local vertex1 = mesh:AddVertex(Vector3.new(0, 1, 0))
local vertex2 = mesh:AddVertex(Vector3.new(-2, -1, 0))
local vertex3 = mesh:AddVertex(Vector3.new(2, -1, 0))
local vertex4 = mesh:AddVertex(Vector3.new(0, -1, 2))
local face1 = mesh:AddTriangle(vertex1, vertex3, vertex2)
local face2 = mesh:AddTriangle(vertex1, vertex4, vertex3)
local face3 = mesh:AddTriangle(vertex1, vertex2, vertex4)
local face4 = mesh:AddTriangle(vertex2, vertex3, vertex4)
local normal1 = mesh:AddNormal()
local normal2 = mesh:AddNormal()
local normal3 = mesh:AddNormal()
local normal4 = mesh:AddNormal()
mesh:SetFaceNormals(face1, {normal1, normal1, normal1})
mesh:SetFaceNormals(face2, {normal2, normal2, normal2})
mesh:SetFaceNormals(face3, {normal3, normal3, normal3})
mesh:SetFaceNormals(face4, {normal4, normal4, normal4})
local part = AssetService:CreateMeshPartAsync(content, options)
part.Position = Vector3.new(0, 1, 0)
part.Parent = script.Parent
local attachment = Instance.new("Attachment")
attachment.Visible = true
attachment.Position = mesh:GetPosition(vertex1)
attachment.Parent = part
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
workspace.CurrentCamera.CameraSubject = part
local timer = 0
while true do
local s = 2 + math.sin(timer)
local c = 2 + math.cos(timer)
mesh:SetPosition(vertex1, Vector3.new(s, c, 0))
attachment.Position = mesh:GetPosition(vertex1)
part:ApplyMesh(AssetService:CreateMeshPartAsync(content, options))
task.wait()
timer += 0.1
end
if you comment out part:ApplyMesh(AssetService:CreateMeshPartAsync(content, options))
then it will work 100% of the time