The documentation for the functions ToWorldSpace
, ToObjectSpace
, PointToWorldSpace
, PointToObjectSpace
, VectorToWorldSpace
, and VectorToObjectSpace
don’t mention taking variable arguments or returning multiple values.
CFrames CFrame:ToWorldSpace(CFrames)
CFrames CFrame:ToObjectSpace(CFrames)
Vector3s CFrame:PointToWorldSpace(Vector3s)
Vector3s CFrame:PointToObjectSpace(Vector3s)
Vector3s CFrame:VectorToWorldSpace(Vector3s)
Vector3s CFrame:VectorToObjectSpace(Vector3s)
7 Likes
Bumping this thread because these CFrame methods provide significant performance improvements!
Here are two benchmarks: The first compares CFrame * Vector3
to CFrame:PointToWorldSpace(Vector3)
, and the second compare CFrame * CFrame
to CFrame:ToWorldSpace(CFrame)
. In both benchmarks, there are 3999 multiplies per iteration, which is the maximum amount of inputs that the CFrame methods will accept on my machine.
Benchmarks
Benchmarked using boatbomer’s Benchmarker plugin.
return {
ParameterGenerator = function()
local cf = CFrame.Angles(math.random(), math.random(), math.random())
local random = Random.new()
local vectors = {}
for i = 1, 3999 do
vectors[i] = random:NextUnitVector() * math.random(10)
end
return cf, vectors
end,
Functions = {
["CFrame * Vector3"] = function(profiler, cf, vectors)
for _, vector in vectors do
local a = cf * vector
end
end,
["PointToWorldSpace"] = function(profiler, cf, vectors)
cf:PointToWorldSpace(table.unpack(vectors))
end,
},
}
return {
ParameterGenerator = function()
local cframes = {}
for i = 1, 3999 do
cframes[i] = CFrame.Angles(math.random(), math.random(), math.random())
end
return cframes
end,
Functions = {
["CFrame * CFrame"] = function(profiler, cframes)
local first = cframes[1]
for _, cf in cframes do
local a = first * cf
end
end,
["ToWorldSpace"] = function(profiler, cframes)
cframes[1]:ToWorldSpace(table.unpack(cframes))
end,
},
}
1 Like