I have this Gerstner Waves skinned mesh and I’m trying to optimize performance as much as possible and I was wondering about this
So I ran a little test of my own and yeah setting the transform is definitely faster then setting the WorldPosition
local RunService = game:GetService("RunService")
local oceanModel = workspace:WaitForChild("OceanChunk")
local bones = {}
local isOptimized = false
local lastSwitch = os.clock()
local frameCount = 0
local totalTime = 0
for _, b in ipairs(oceanModel:GetDescendants()) do
if b:IsA("Bone") then
table.insert(bones, {bone = b, originalPos = b.WorldPosition})
end
end
print("Loaded " .. #bones .. " bones for benchmarking.")
RunService.RenderStepped:Connect(function(dt)
local start = os.clock()
local t = os.clock()
if os.clock() - lastSwitch > 5 then
isOptimized = not isOptimized
lastSwitch = os.clock()
print("------------------------------------------------")
print("SWITCHING MODE: " .. (isOptimized and "✅ OPTIMIZED (Transform)" or "❌ SLOW (WorldPosition)"))
print("------------------------------------------------")
end
for i, data in ipairs(bones) do
local yOffset = math.sin(t * 3 + data.originalPos.X * 0.1) * 2
if isOptimized then
data.bone.Transform = CFrame.new(0, yOffset, 0)
else
data.bone.WorldPosition = data.originalPos + Vector3.new(0, yOffset, 0)
end
end
local duration = (os.clock() - start) * 1000
totalTime += duration
frameCount += 1
if frameCount >= 60 then
local avg = totalTime / 60
totalTime = 0
frameCount = 0
end
end)
3 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.