學習
引擎類別
GeometryService
無法建立
服務

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡。


概要

繼承成員

API 參考
方法
CalculateConstraintsToPreserve
功能: CSG
GeometryService:CalculateConstraintsToPreserve(
source:Instance, destination:{any}, options:Dictionary
參數
source:Instance
destination:{any}
options:Dictionary
預設值:nil
返回
範例程式碼
保留約束
local GeometryService = game:GetService("GeometryService")
local main, other = workspace.Part1, workspace.Part2
local success, newParts = pcall(function()
return GeometryService:SubtractAsync(main, {other})
end)
if success and newParts then
for _, p in newParts do p.Parent = workspace end
for _, rec in GeometryService:CalculateConstraintsToPreserve(main, newParts) do
if rec.Constraint then
rec.Constraint.Parent = rec.ConstraintParent
end
end
end
main:Destroy()
other:Destroy()

FragmentAsync
暫停
功能: CSG
GeometryService:FragmentAsync(
part:BasePart, sites:{any}, options:Dictionary
參數
sites:{any}
options:Dictionary
預設值:nil
返回
範例程式碼
碎片化一個部件
local GeometryService = game:GetService("GeometryService")
local inputPart = Instance.new("Part")
inputPart.Position = Vector3.new(0, 0.7, 20)
local sites = GeometryService:GenerateFragmentSites(inputPart)
local success, fragments = pcall( function()
return GeometryService:FragmentAsync(inputPart, sites)
end)
if success and fragments then
for _, item in fragments do
local instance = item.Instance
instance.Parent = workspace
end
end

GenerateFragmentSites
功能: CSG
GeometryService:GenerateFragmentSites(
part:BasePart, options:Dictionary
參數
options:Dictionary
預設值:nil
返回
範例程式碼
本地化片段
local GeometryService = game:GetService("GeometryService")
local inputPart = workspace.Part
local pos = inputPart.Position + inputPart.Size / 2
local sites = GeometryService:GenerateFragmentSites(inputPart, {Origin = pos, Radius = 1.5})
local success, fragments = pcall( function()
return GeometryService:FragmentAsync(inputPart, sites)
end)
if success and fragments then
for _, item in fragments do
local instance = item.Instance
instance.Parent = inputPart.Parent
end
inputPart:Destroy()
end

IntersectAsync
暫停
功能: CSG
GeometryService:IntersectAsync(
part:Instance, parts:{any}, options:Dictionary
參數
parts:{any}
options:Dictionary
預設值:nil
返回
範例程式碼
合併兩個部件
local GeometryService = game:GetService("GeometryService")
local mainPart = Instance.new("Part")
local otherPart = Instance.new("Part")
otherPart.Position = Vector3.new(1, 0.5, 1)
local success, newParts = pcall(function()
return GeometryService:IntersectAsync(mainPart, {otherPart})
end)
if success and newParts then
for _, newPart in pairs(newParts) do
newPart.Parent = workspace
end
end

SubtractAsync
暫停
功能: CSG
GeometryService:SubtractAsync(
part:Instance, parts:{any}, options:Dictionary
參數
parts:{any}
options:Dictionary
預設值:nil
返回
範例程式碼
減去兩個部分
local GeometryService = game:GetService("GeometryService")
local mainPart = Instance.new("Part")
local otherPart = Instance.new("Part")
otherPart.Position = Vector3.new(1, 0.5, 1)
local success, newParts = pcall(function()
return GeometryService:SubtractAsync(mainPart, {otherPart})
end)
if success and newParts then
for _, newPart in pairs(newParts) do
newPart.Parent = workspace
end
end

SplitApartAsync
暫停
功能: CSG
GeometryService:SplitApartAsync(
parts:{any}, options:Dictionary
參數
parts:{any}
options:Dictionary
預設值:nil
返回
範例程式碼
拆分聯合
local GeometryService = game:GetService("GeometryService")
local blockA = Instance.new("Part")
blockA.Size = Vector3.new(4, 4, 4)
blockA.Position = Vector3.new(0, 2, 20)
blockA.Anchored = true
blockA.Parent = workspace
local blockB = blockA:Clone()
blockB.Position = Vector3.new(10, 2, 20)
blockB.Parent = workspace
local union = GeometryService:UnionAsync(blockA, { blockB }, { SplitApart = false })[1]
union.Parent = workspace
blockA:Destroy()
blockB:Destroy()
local inputs = { union }
local success, pieces = pcall(function()
return GeometryService:SplitApartAsync(inputs)
end)
if success and pieces then
for _, item in pieces do
item.Instance.Parent = inputs[item.Index].Parent
end
if #pieces > 0 then
union:Destroy()
end
end

SweepPartAsync
暫停
功能: CSG
GeometryService:SweepPartAsync(
part:BasePart, cframes:{any}, options:Dictionary
參數
cframes:{any}
options:Dictionary
預設值:nil
返回
範例程式碼
掃描一個零件
local GeometryService = game:GetService("GeometryService")
local inputPart = Instance.new("Part")
inputPart.Shape = Enum.PartType.Ball
local cframeList = {}
for i = 1, 50 do
local rotation = CFrame.Angles(0, i * 0.2, 0)
local position = Vector3.new(0, i * 0.1, -1)
table.insert(cframeList, rotation * CFrame.new(position))
end
local success, sweptPart = pcall( function()
return GeometryService:SweepPartAsync(inputPart, cframeList)
end)
if success and sweptPart then
sweptPart.Parent = workspace
end

UnionAsync
暫停
功能: CSG
GeometryService:UnionAsync(
part:Instance, parts:{any}, options:Dictionary
參數
parts:{any}
options:Dictionary
預設值:nil
返回
範例程式碼
合併兩個部件
local GeometryService = game:GetService("GeometryService")
local mainPart = Instance.new("Part")
local otherPart = Instance.new("Part")
otherPart.Position = Vector3.new(1, 0.5, 1)
local success, newParts = pcall(function()
return GeometryService:UnionAsync(mainPart, {otherPart})
end)
if success and newParts then
for _, newPart in pairs(newParts) do
newPart.Parent = workspace
end
end

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。