Lớp công cụ
PartOperation
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Phương Pháp
SubstituteGeometry(source: Instance):() |
Thành viên kế thừa
3 thành viên kế thừa từ TriangleMeshPart
105 thành viên kế thừa từ BasePart
4 thành viên kế thừa từ PVInstance
57 thành viên kế thừa từ Instance
6 thành viên kế thừa từ Object
Được kế thừa bởi
Tài Liệu Tham Khảo API
Thuộc Tính
Phương Pháp
SubstituteGeometry
Tham Số
Lợi Nhuận
()
Mẫu mã
Thay thế Hình học và Ràng buộc Thả
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,
}
-- Thực hiện phép toán hợp nhất trong pcall() vì nó là bất đồng bộ
local success, newParts = pcall(function()
return GeometryService:UnionAsync(mainPart, otherParts, options)
end)
if success and #newParts > 0 and mainPart:IsA("PartOperation") then
-- Đặt phần đầu tiên trong phép toán kết quả làm phần để sử dụng cho thay thế
-- Phần đầu tiên chỉ đơn giản là một tùy chọn; điều này có thể là bất kỳ PartOperation nào
local substitutePart = newParts[1]
-- Định vị lại phần này đến vị trí của phần chính
substitutePart.CFrame = mainPart.CFrame
-- Tính toán các ràng buộc/gắn kết để bảo tồn hoặc thả
local recommendedTable = GeometryService:CalculateConstraintsToPreserve(mainPart, newParts, constraintOptions)
-- Thay thế hình học của phần chính với hình học thay thế
mainPart:SubstituteGeometry(substitutePart)
-- Thả các ràng buộc/gắn kết không được tự động bảo tồn với thay thế
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
-- Hủy bỏ các phần khác
for _, otherPart in pairs(otherParts) do
otherPart.Parent = nil
otherPart:Destroy()
end
end