学习
引擎类
PartOperation

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处



API 参考
属性
RenderFidelity
插件安全性
读取并联
功能: Basic, CSG
PartOperation.RenderFidelity:Enum.RenderFidelity

SmoothingAngle
插件安全性
读取并联
功能: Basic, CSG
PartOperation.SmoothingAngle:number

TriangleCount
Roblox 安全性
读取并联
功能: Basic, CSG
PartOperation.TriangleCount:number

UsePartColor
读取并联
功能: Basic, CSG
PartOperation.UsePartColor:boolean

方法
SubstituteGeometry
功能: Basic, CSG
PartOperation:SubstituteGeometry(source:Instance):()
参数
source:Instance
返回
()
代码示例
替代几何体和丢弃约束
local GeometryService = game:GetService("GeometryService")
local mainPart = workspace.PurpleBlock
local otherParts = { workspace.BlueBlock }
local options = {
CollisionFidelity = Enum.CollisionFidelity.Default,
RenderFidelity = Enum.RenderFidelity.Automatic,
SplitApart = false,
}
local constraintOptions = {
tolerance = 0.1,
weldConstraintPreserve = Enum.WeldConstraintPreserve.All,
}
-- 在 pcall() 中执行联合操作,因为它是异步的
local success, newParts = pcall(function()
return GeometryService:UnionAsync(mainPart, otherParts, options)
end)
if success and #newParts > 0 and mainPart:IsA("PartOperation") then
-- 将结果操作中的第一个部分设置为用于替代的部分
-- 第一个部分只是一个选项;这可以是任何 PartOperation
local substitutePart = newParts[1]
-- 将部分重新定位到主部分的位置
substitutePart.CFrame = mainPart.CFrame
-- 计算要保留或丢弃的约束/附件
local recommendedTable = GeometryService:CalculateConstraintsToPreserve(mainPart, newParts, constraintOptions)
-- 用替代几何体替换主部分的几何体
mainPart:SubstituteGeometry(substitutePart)
-- 丢弃在替代时未自动保留的约束/附件
for _, item in pairs(recommendedTable) do
if item.Attachment then
if item.ConstraintParent == nil then
item.Constraint.Parent = nil
end
if item.AttachmentParent == nil then
item.Attachment.Parent = nil
end
elseif item.WeldConstraint then
if item.Parent == nil then
item.WeldConstraint.Parent = nil
end
end
end
-- 销毁其他部分
for _, otherPart in pairs(otherParts) do
otherPart.Parent = nil
otherPart:Destroy()
end
end

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。