EditableMesh & Liquids

Here is what I’ve got so far in order to cache the verticies:

local function Liquidize(part: MeshPart)
	local mesh = game.AssetService:CreateEditableMeshAsync(part.MeshId)
	mesh.Parent = part; mesh.Name = 'EffectMesh'
	
	local MeshVerticies = {}
	for _, VertexID in mesh:GetVertices() do
		MeshVerticies[VertexID] = 
			{
				Position = mesh:GetPosition(VertexID),
				Viscoscity = 1,
				NextdoorVerticies = {}
			}
	end
	for _, TriangleID in mesh:GetTriangles() do
		local tVerts = {mesh:GetTriangleVertices(TriangleID)}
		for _, VertexId in tVerts do
			if MeshVerticies[VertexId].NextdoorVerticies[VertexId] then
				table.insert(MeshVerticies[VertexId].NextdoorVerticies[VertexId], TriangleID)
			else
				MeshVerticies[VertexId].NextdoorVerticies[VertexId] = {TriangleID}
			end
		end
	end
end

How can I use the viscoscity values in order to create a natural liquid?

3 Likes

Alright so by using assumptions on how blobs of liquid look, I’ve came to these 3 forces to simulate the behaviour:

2 Likes

I’ve cooked this up, but the mesh is not moving at all :sob:

yes, the EditableMesh is a child of the mesh

I’ve decided to cheat a bit by using Roblox’s engine to sort out gravity and collisions by making each vertex it’s own, invisible part:

	local vertexCache = {}
	for _, VertexID in ipairs(mesh:GetVertices()) do
		local newPart = Instance.new('Part')
		newPart.Parent = vPartFolder
		newPart.Size   = Vector3.new(0.05, 0.05, 0.05)
		newPart.Transparency = 1
		newPart.Shape = Enum.PartType.Ball
		newPart.Name = 'vPart #'..VertexID
		
		local attachment = Instance.new('Attachment')
		attachment.Parent = newPart
		attachment.Name = 'vPart Attachment'
		
		local forceValue = Instance.new('VectorForce')
		forceValue.Parent = newPart
		forceValue.Name = 'vPart Force'
		forceValue.Attachment0 =  attachment
		vertexCache[VertexID] =
			{
				ForcePart = forceValue,
				PhysiPart = newPart,
				Correction = 1 / newPart:GetMass() ,
				GeneralForce = Vector3.zero,
				TentionForce = Vector3.zero,
			}
	end

Using springs I accidently made a soft body