Classe de moteur
PartOperation
*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.
Résumé
Propriétés
Méthodes
SubstituteGeometry(source: Instance):() |
Membres hérités
3 hérité du TriangleMeshPart
105 hérité du BasePart
4 hérité du PVInstance
57 hérité du Instance
6 hérité du Object
Hérité par
Référence API
Propriétés
Méthodes
SubstituteGeometry
Paramètres
Retours
()
Échantillons de code
Géométrie de substitution et contraintes de suppression
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,
}
-- Effectuer l'opération d'union dans pcall() car elle est asynchrone
local success, newParts = pcall(function()
return GeometryService:UnionAsync(mainPart, otherParts, options)
end)
if success and #newParts > 0 and mainPart:IsA("PartOperation") then
-- Définir la première partie de l'opération résultante comme partie à utiliser pour la substitution
-- La première partie est simplement une option ; cela peut être n'importe quelle PartOperation
local substitutePart = newParts[1]
-- Repositionner la partie à la position de la partie principale
substitutePart.CFrame = mainPart.CFrame
-- Calculer les contraintes/attachements à préserver ou à supprimer
local recommendedTable = GeometryService:CalculateConstraintsToPreserve(mainPart, newParts, constraintOptions)
-- Substituer la géométrie de la partie principale avec la géométrie de substitution
mainPart:SubstituteGeometry(substitutePart)
-- Supprimer les contraintes/attachements qui ne sont pas automatiquement préservés avec la substitution
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
-- Détruire les autres parties
for _, otherPart in pairs(otherParts) do
otherPart.Parent = nil
otherPart:Destroy()
end
end