GeometryService

顯示已棄用項目

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

無法建立
服務

包含幾何操作,但與特定對象無關。

概要

方法

屬性

方法

CalculateConstraintsToPreserve

返回 ConstraintsAttachments ,這些你可以選擇保留,以及它們的父親。在此表上迭代會讓你決定要否保留建議的限制和附件,並將其父親的父親添加到其父親的父親。

注意,options 表可以包含一個 tolerance 值 (數字) 和/或一個 WeldConstraintPreserve 值 (2>Enumerate.WeldConstraintsPreserve2>)。

  • tolerance – 距離忍容性,與原件零件表面上的附件最近點之間的距離,在附件和最近點上的原件零件表面之間的距離,與原件零件表面上的 Attachment 的附件和其附件所對應的 Class.Instance.
  • weldConstraintPreserve – 一個 Enum.WeldConstraintPreserve 枚值,描述如何在結果推薦表中保留 WeldConstraints

參數

source: Instance

原始對象,例如 partUnionAsync() 上執行的固體建模操作。

destination: Array
options: Dictionary

方法的選項表:

  • tolerance – 距離忍容性,與原件零件表面上的附件最近點之間的距離,在附件和最近點上的原件零件表面之間的距離,與原件零件表面上的 Attachment 的附件和其附件所對應的 Class.Instance.
  • weldConstraintPreserve – 一個 Enum.WeldConstraintPreserve 枚值,描述如何在結果推薦表中保留 WeldConstraints
預設值:"nil"

返回

含有關一般案例的信息 Constraints , NoCollisionConstraintsWeldConstraints 。在包含 1> Class.Attachment1> 或 4> Class.Constructor4> 時,其相關的父親將是

對於一般的情況 Constraints 如果 HingeConstraint :


<tbody>
<tr>
<td>附件</td>
<td><code>Class.Attachment</code></td>
</tr>
<tr>
<td>限制</td>
<td><code>Class.Constraint</code></td>
</tr>
<tr>
<td>附件父親</td>
<td><code>Class.BasePart</code> 或 <code>nil</code></td>
</tr>
<tr>
<td>限制器父親</td>
<td><code>Class.BasePart</code> 或 <code>nil</code></td>
</tr>
</tbody>
鑰匙類型

對於 WeldConstraints :


<tbody>
<tr>
<td>彈焊限制</td>
<td><code>Class.WeldConstraint</code></td>
</tr>
<tr>
<td>子母焊約束</td>
<td><code>Class.BasePart</code> 或 <code>nil</code></td>
</tr>
<tr>
<td>WeldConstraintPart0</td>
<td><code>Class.BasePart</code></td>
</tr>
<tr>
<td>Weld約束1</td>
<td><code>Class.BasePart</code></td>
</tr>
</tbody>
鑰匙類型

對於 NoCollisionConstraints :


<tbody>
<tr>
<td>無衝突約束</td>
<td><code>Class.NoCollisionConstraint</code></td>
</tr>
<tr>
<td>無衝突約束父親</td>
<td><code>Class.BasePart</code> 或 <code>nil</code></td>
</tr>
<tr>
<td>NoCollisionConstraintPart0</td>
<td><code>Class.BasePart</code></td>
</tr>
<tr>
<td>不可衝突約束零件1</td>
<td><code>Class.BasePart</code></td>
</tr>
</tbody>
鑰匙類型

範例程式碼

The following example shows how to preserve Attachments and Constraints based on a recommended table produced by CalculateConstraintsToPreserve().

Preserve Constraints

local GeometryService = game:GetService("GeometryService")
local mainPart = workspace.PurpleBlock
local otherParts = {workspace.BlueBlock}
local options = {
CollisionFidelity = Enum.CollisionFidelity.Default,
RenderFidelity = Enum.RenderFidelity.Automatic,
SplitApart = true
}
local constraintOptions = {
tolerance = 0.1,
weldConstraintPreserve = Enum.WeldConstraintPreserve.All,
dropAttachmentsWithoutConstraints = false
}
-- Perform subtract operation in pcall() since it's asyncronous
local success, newParts = pcall(function()
return GeometryService:SubtractAsync(mainPart, otherParts, options)
end)
if success and newParts then
-- Loop through resulting parts to reparent/reposition
for _, newPart in pairs(newParts) do
newPart.Parent = mainPart.Parent
newPart.CFrame = mainPart.CFrame
newPart.Anchored = mainPart.Anchored
end
-- Calculate constraints/attachments to either preserve or drop
local recommendedTable = GeometryService:CalculateConstraintsToPreserve(mainPart, newParts, constraintOptions)
-- Preserve constraints/attachments based on recommended table
for _, item in pairs(recommendedTable) do
if item.Attachment then
item.Attachment.Parent = item.AttachmentParent
if item.Constraint then
item.Constraint.Parent = item.ConstraintParent
end
elseif item.NoCollisionConstraint then
local newNoCollision = Instance.new("NoCollisionConstraint")
newNoCollision.Part0 = item.NoCollisionPart0
newNoCollision.Part1 = item.NoCollisionPart1
newNoCollision.Parent = item.NoCollisionParent
elseif item.WeldConstraint then
local newWeldConstraint = Instance.new("WeldConstraint")
newWeldConstraint.Part0 = item.WeldConstraintPart0
newWeldConstraint.Part1 = item.WeldConstraintPart1
newWeldConstraint.Parent = item.WeldConstraintParent
end
end
-- Destroy original parts
mainPart.Parent = nil
mainPart:Destroy()
for _, otherPart in pairs(otherParts) do
otherPart.Parent = nil
otherPart:Destroy()
end
end

IntersectAsync

暫停

在主要部分和其他部分的交叉 геометrie中創建一個或多個 PartOperations 。只有原始 Parts 和 Class.PartOperation

主要部分的下列屬性 (part ) 適用於結果的 PartOperations :

在下圖中,IntersectAsync() 使用紫色方塊和一個包含藍色方磚塊的陣列來創建結果。結果的 PartOperation 以兩個零件的交叉形狀來解決。

Two block parts overlapping

<figcaption>分離零件</figcaption>
Parts intersected into a new solid model

<figcaption>結果 <code>Class.PartOperation</code></figcaption>

注意

  • BasePart:IntersectAsync() 相比,此方法有如下差別:

    • 輸入零件不需要與場景相對應,允許背景操作。
    • SplitApart 選項設為 true (預設) 時,每個不同的身體將在其自己的 PartOperation 中返回。
    • 每個返回的零件都位於主要零件的坐標空間中。這意味著任何返回的零件的(0,0,0)不是必須位於其身體的中心。
    • 您可以在客戶端呼叫此方法,但有一些限制。首先,它目前必須在客戶端上創建的對象上執行。第二,沒有從客戶端服務伺服器上提供的複製。
  • 原始零件在成功運行後保持完整。在大多數情況下,您應該將返回的 PartOperations 親指盤,然後 Destroy() 所有原始零件。

  • 由預設情況下,結果的 PartOperations 的面色都會從原始零件的 Color 屬性借鑑,雖然您可以啟用其 UsePartColor 屬性來變更它們為特定顏色。

  • 如果交叉運算將結果為超過 20,000 個三角形的任何 PartOperations ,它們將被簡化為 20,000 個。這將導致代碼 -14 的錯誤。

  • 如果主要部分在運算中移動,您可以將返回的零件設置為主要部分的更新 CFrame,因為返回的零件位於主要部分的相同坐標空間。

  • 如果使用此方法使用 PartOperation 作為主要部分,

參數

part: Instance

主要 PartPartOperation 來操作。

parts: Array

與主部分交叉的零件。

options: Dictionary

方法的所有控制項的選項表:

  • CollisionFidelity – 結果零件中的 CollisionFidelity 值。
  • RenderFidelity – 結果零件中的 RenderFidelity 值。
  • FluidFidelity – 結果零件中的 FluidFidelity 值。
  • SplitApart – 控制對象是否要保持整體或正確地分開。預設值是 true (分裂)。
預設值:"nil"

返回

一個或多個 PartOperations 從主部分的交叉 геометrie( part )和其他部分。

範例程式碼

This example intersects the geometry of mainPart and the parts in the otherParts array, splitting them into distinct PartOperations. Then it destroys the original parts involved in the operation.

GeometryService:IntersectAsync()

local GeometryService = game:GetService("GeometryService")
local mainPart = workspace.PurpleBlock
local otherParts = {workspace.BlueBlock}
local options = {
CollisionFidelity = Enum.CollisionFidelity.Default,
RenderFidelity = Enum.RenderFidelity.Automatic,
SplitApart = true
}
-- Perform intersect operation in pcall() since it's asyncronous
local success, newParts = pcall(function()
return GeometryService:IntersectAsync(mainPart, otherParts, options)
end)
if success and newParts then
-- Loop through resulting parts to reparent/reposition
for _, newPart in pairs(newParts) do
newPart.Parent = mainPart.Parent
newPart.CFrame = mainPart.CFrame
newPart.Anchored = mainPart.Anchored
end
-- Destroy original parts
mainPart.Parent = nil
mainPart:Destroy()
for _, otherPart in pairs(otherParts) do
otherPart.Parent = nil
otherPart:Destroy()
end
end

SubtractAsync

暫停

從主部分減去其他零件在指定陣列中佔用的地理,創建一個或多個 PartOperations 從主部分減去其他零件在指定�

主要部分的下列屬性 (part ) 適用於結果的 PartOperations :

在下列圖像比較中,SubtractAsync() 使用藍色圓柱和含有紫色方磚塊的陣列來調用。結果的 PartOperation 以形狀為隱藏方磚塊的幾何圖形而解決。

Longer block overlapping a cylinder

<figcaption>分離零件</figcaption>
Block part subtracted from cylinder

<figcaption>結果 <code>Class.PartOperation</code></figcaption>

注意

  • BasePart:SubtractAsync() 相比,此方法有如下差別:

    • 輸入零件不需要與場景相對應,允許背景操作。
    • SplitApart 選項設為 true (預設) 時,每個不同的身體將在其自己的 PartOperation 中返回。
    • 每個返回的零件都位於主要零件的坐標空間中。這意味著任何返回的零件的(0,0,0)不是必須位於其身體的中心。
    • 您可以在客戶端呼叫此方法,但有一些限制。首先,它目前必須在客戶端上創建的對象上執行。第二,沒有從客戶端服務伺服器上提供的複製。
  • 原始零件在成功運行後保持完整。在大多數情況下,您應該將返回的 PartOperations 親指盤,然後 Destroy() 所有原始零件。

  • 由預設情況下,結果的 PartOperations 的面色都會從原始零件的 Color 屬性借鑑,雖然您可以啟用其 UsePartColor 屬性來變更它們為特定顏色。

  • 如果子減算操作會結果在20,000個以上的三角形,它們將被簡化為20,000。這將導致代碼 PartOperations 的錯誤。

  • 如果主要部分在運算中移動,您可以將返回的零件設置為主要部分的更新 CFrame,因為返回的零件位於主要部分的相同坐標空間。

  • 如果使用此方法使用 PartOperation 作為主要部分,

參數

part: Instance

主要 PartPartOperation 來操作。

parts: Array

一組零件要從主要零件中減去的零件。

options: Dictionary

方法的所有控制項的選項表:

  • CollisionFidelity – 結果零件中的 CollisionFidelity 值。
  • RenderFidelity – 結果零件中的 RenderFidelity 值。
  • FluidFidelity – 結果零件中的 FluidFidelity 值。
  • SplitApart – 控制對象是否要保持整體或正確地分開。預設值是 true (分裂)。
預設值:"nil"

返回

一個或多個 PartOperations 從主部分的 геометrie ( part ) 減去其他部分的 геометrie。

範例程式碼

This example subtracts the geometry of the parts in the otherParts array from mainPart, splitting the results into distinct PartOperations. Then it destroys the original parts involved in the operation.

GeometryService:SubtractAsync()

local GeometryService = game:GetService("GeometryService")
local mainPart = workspace.BlueCylinder
local otherParts = {workspace.PurpleBlock}
local options = {
CollisionFidelity = Enum.CollisionFidelity.Default,
RenderFidelity = Enum.RenderFidelity.Automatic,
SplitApart = true
}
-- Perform subtract operation in pcall() since it's asyncronous
local success, newParts = pcall(function()
return GeometryService:SubtractAsync(mainPart, otherParts, options)
end)
if success and newParts then
-- Loop through resulting parts to reparent/reposition
for _, newPart in pairs(newParts) do
newPart.Parent = mainPart.Parent
newPart.CFrame = mainPart.CFrame
newPart.Anchored = mainPart.Anchored
end
-- Destroy original parts
mainPart.Parent = nil
mainPart:Destroy()
for _, otherPart in pairs(otherParts) do
otherPart.Parent = nil
otherPart:Destroy()
end
end

UnionAsync

暫停

從主部分擷取一個或多個 PartOperations 從另一個零件在指定的陣列中所佔位置。只有原始 Parts

主要部分的下列屬性 (part ) 適用於結果的 PartOperations :

在下圖中,UnionAsync() 使用藍色方塊和含有紫色圓柱的陣列來調用。結果的 PartOperation 以兩個零件的結合形式解決。

Block and cylinder parts overlapping

<figcaption>分離零件</figcaption>
Parts joined together into a single solid union

<figcaption>結果 <code>Class.PartOperation</code></figcaption>

注意

  • 相較於 BasePart:UnionAsync() ,此方法有如下差別:

    • 輸入零件不需要與場景相對應,允許背景操作。
    • SplitApart 選項設為 true (預設) 時,每個不同的身體將在其自己的 PartOperation 中返回。
    • 每個返回的零件都位於主要零件的坐標空間中。這意味著任何返回的零件的(0,0,0)不是必須位於其身體的中心。
    • 您可以在客戶端呼叫此方法,但有一些限制。首先,它目前必須在客戶端上創建的對象上執行。第二,沒有從客戶端服務伺服器上提供的複製。
  • 原始零件在成功運行後保持完整。在大多數情況下,您應該將返回的 PartOperations 親指盤,然後 Destroy() 所有原始零件。

  • 由預設情況下,結果的顏色會從原始零件的 PartOperations 屬性上借鑑,雖然您可以啟用其 Color 屬性來變更它們為特定顏色。

  • 如果使用 PartOperations 以結果超過 20,000 個三角形,它們將被簡化為 20,000 個。這將導致代碼 -14 的錯誤。

  • 如果主要部分在運算中移動,您可以將返回的零件設置為主要部分的更新 CFrame,因為返回的零件位於主要部分的相同坐標空間。

  • 如果使用此方法使用 PartOperation 作為主要部分,

參數

part: Instance

主要 PartPartOperation 來操作。

parts: Array

與主部分結合的零件列。

options: Dictionary

方法的所有控制項的選項表:

  • CollisionFidelity – 結果零件中的 CollisionFidelity 值。
  • RenderFidelity – 結果零件中的 RenderFidelity 值。
  • FluidFidelity – 結果零件中的 FluidFidelity 值。
  • SplitApart – 控制對象是否要保持整體或正確地分開。預設值是 true (分裂)。
預設值:"nil"

返回

一個或多個 PartOperations 從主部分的 геометria ( part ) 以及其他零件的геометria。

範例程式碼

This example combines the geometry of mainPart and the parts in the otherParts array, then it destroys the original parts involved in the operation.

GeometryService:UnionAsync()

local GeometryService = game:GetService("GeometryService")
local mainPart = workspace.BlueBlock
local otherParts = {workspace.PurpleCylinder}
local options = {
CollisionFidelity = Enum.CollisionFidelity.Default,
RenderFidelity = Enum.RenderFidelity.Automatic,
SplitApart = false
}
-- Perform union operation in pcall() since it's asyncronous
local success, newParts = pcall(function()
return GeometryService:UnionAsync(mainPart, otherParts, options)
end)
if success and newParts then
-- Loop through resulting parts to reparent/reposition
for _, newPart in pairs(newParts) do
newPart.Parent = mainPart.Parent
newPart.CFrame = mainPart.CFrame
newPart.Anchored = mainPart.Anchored
end
-- Destroy original parts
mainPart.Parent = nil
mainPart:Destroy()
for _, otherPart in pairs(otherParts) do
otherPart.Parent = nil
otherPart:Destroy()
end
end

活動