Engine Class
PartOperation
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
คุณสมบัติ
วิธีการ
SubstituteGeometry(source: Instance):() |
สมาชิกที่ได้รับทอด
สมาชิก 3 คนที่รับทอดมาจาก TriangleMeshPart
สมาชิก 105 คนที่รับทอดมาจาก BasePart
สมาชิก 4 คนที่รับทอดมาจาก PVInstance
สมาชิก 57 คนที่รับทอดมาจาก Instance
สมาชิก 6 คนที่รับทอดมาจาก Object
ได้รับทอดโดย
เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
วิธีการ
SubstituteGeometry
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
การแทนที่รูปทรงเรขาคณิตและการลดข้อจำกัด
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