GeometryService

顯示已棄用項目

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

無法建立
服務

包含不與特定對象直接相關的幾何操作的服務。

概要

方法

屬性

方法

CalculateConstraintsToPreserve

返回一個包含 ConstraintsAttachments 的表,你可以選擇保留它們各自的父輩。在這個表上循環可讓您決定是否將建議的限制和附件重新附加到各自的父處。

請注意,options辭典可包含以追蹤中內容:

  • — 附件與原始零件表面上最近點之間的距離容差,與最終零件表面上最近點之間的最近點相比。如果在固體模型操作後的結果距離大於此值,附件和其相關限制的 將在返回的建議表中。
  • weldConstraintPreserve — 一個 Enum.WeldConstraintPreserve 枚列值,描述如何在最終建議表中保留 WeldConstraints
  • dropAttachmentsWithoutConstraints — 使用預設值 true 的布林。如果設為 false,那些沒有 AttachmentsConstraints 將被保留。

參數

source: Instance

原始對象,例如在 part 中執行了固體模型操作,例如在 UnionAsync() 中。

預設值:""
destination: Array
預設值:""
options: Dictionary

方法的選項字典:

  • — 附件與原始零件表面上最近點之間的距離容差,與最終零件表面上最近點之間的最近點相比。如果在固體模型操作後的結果距離大於此值,附件和其相關限制的 將在返回的建議表中。
  • weldConstraintPreserve — 一個 Enum.WeldConstraintPreserve 枚列值,描述如何在最終建議表中保留 WeldConstraints
  • dropAttachmentsWithoutConstraints — 使用預設值 true 的布林。如果設為 false,那些沒有 AttachmentsConstraints 將被保留。
預設值:"nil"

返回

包含一般情況資訊的表ConstraintsNoCollisionConstraintsWeldConstraints。在必須刪除 AttachmentConstraint 的情況下,其各自的父將是 nil

對於一般情況 Constraints 例如 HingeConstraint :


<th>類型</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>附件</code></td>
<td><code>類別.附件</code></td>
</tr>
<tr>
<td><code>限制</code></td>
<td><code>類別約束</code> 或 <code>nil</code></td>
</tr>
<tr>
<td><code>附件父親</code></td>
<td><code>類別.BasePart</code> 或 <code>nil</code></td>
</tr>
<tr>
<td><code>限制父親</code></td>
<td><code>類別.BasePart</code> 或 <code>nil</code></td>
</tr>
</tbody>
關鍵

對於 WeldConstraints :


<th>類型</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>焊接限制</code></td>
<td><code>類別.WeldConstraint</code></td>
</tr>
<tr>
<td><code>焊接限制父</code></td>
<td><code>類別.BasePart</code> 或 <code>nil</code></td>
</tr>
<tr>
<td><code>焊接限制零件0</code></td>
<td><code>類別.BasePart</code></td>
</tr>
<tr>
<td><code>焊接限制部分1</code></td>
<td><code>類別.BasePart</code></td>
</tr>
</tbody>
關鍵

對於 NoCollisionConstraints :


<th>類型</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>無碰撞限制</code></td>
<td><code>類別.NoCollisionConstraint</code></td>
</tr>
<tr>
<td><code>無碰撞約束父</code></td>
<td><code>類別.BasePart</code> 或 <code>nil</code></td>
</tr>
<tr>
<td><code>無碰撞限制零件0</code></td>
<td><code>類別.BasePart</code></td>
</tr>
<tr>
<td><code>無碰撞限制方塊1</code></td>
<td><code>類別.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

暫停

從主部分和給定數陣列中的其他部分的交叉幾何中創建一個或多個PartOperations 。只支持原始 PartsPartOperations ,不支持 TerrainMeshParts。與 Clone() 類似,返回的零件沒有設置 Parent

從主部分()中的以下屬性被應用到結果的 》:

在下面的圖像比較中,IntersectAsync() 使用紫色方塊和包含藍色方磚塊的 array 來呼叫。最終得到的 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 作為主要部分,您可以通過 SubstituteGeometry() 來替換另一個 PartOperation 的幾何圖形,使其更容易使用操作的幾何圖形,但保留主要部分的特性、標籤、標籤和兒女,例如 Attachments , Constraints , ParticleEmitters ,光對象和裝飾。這種方法也可以避免完全替換原始 PartOperation 的潛在"閃爍"。

參數

part: Instance

主要 PartPartOperation 操作。

預設值:""
parts: Array

與主要部分交叉的零件群。

預設值:""
options: Dictionary

包含方法所有控件的選項表:

  • CollisionFidelity — 結果零件中的 CollisionFidelity 值。
  • RenderFidelity — 結果零件中的 RenderFidelity 值。
  • FluidFidelity — 結果零件中的 FluidFidelity 值。
  • SplitApart — 使用 Boolean 來控制對象應該全部保留在一起還是正確地分開。默認值為 true (分開)。
預設值:"nil"

返回

來自主要部分(part)和其他部分的交叉幾何中的一個或多個PartOperations

範例程式碼

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從主部分中減去給定數組中其他部分所佔的幾何,創建一個或多個 只支持原始 PartsPartOperations ,不支持 TerrainMeshParts。與 Clone() 類似,返回的零件沒有設置 Parent

從主部分()中的以下屬性被應用到結果的 》:

在下面的圖像比較中,SubtractAsync() 使用藍色圓筒和包含紫色方磚塊的 array 來呼叫。最終得到的 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 個三角形的任何 PartOperations,它們將被簡化為 20,000 個。這將導致代碼錯誤 -14

  • 如果操作計算期間主部分移動,您可以將結果部分設置為主部分的更新 CFrame,因為返回的部分與主部分處於同一坐標空間。

  • 如果使用此方法與 PartOperation 作為主要部分,您可以通過 SubstituteGeometry() 來替換另一個 PartOperation 的幾何圖形,使其更容易使用操作的幾何圖形,但保留主要部分的特性、標籤、標籤和兒女,例如 Attachments , Constraints , ParticleEmitters ,光對象和裝飾。這種方法也可以避免完全替換原始 PartOperation 的潛在"閃爍"。

參數

part: Instance

主要 PartPartOperation 操作。

預設值:""
parts: Array

從主部分減除的零件數組。

預設值:""
options: Dictionary

包含方法所有控件的選項表:

  • CollisionFidelity — 結果零件中的 CollisionFidelity 值。
  • RenderFidelity — 結果零件中的 RenderFidelity 值。
  • FluidFidelity — 結果零件中的 FluidFidelity 值。
  • SplitApart — 使用 Boolean 來控制對象應該全部保留在一起還是正確地分開。默認值為 true (分開)。
預設值:"nil"

返回

從主部分的幾何中,一個或多個 減去其他部分所佔的幾何,

範例程式碼

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,以及主部分所佔用的幾何體。只支持原始 PartsPartOperations ,不支持 TerrainMeshParts。與 Clone() 類似,返回的零件沒有設置 Parent

從主部分()中的以下屬性被應用到結果的 》:

在下面的圖像比較中,UnionAsync() 使用藍色方塊和包含紫色圓柱的 array 來呼叫。最終得到的 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 屬性中借用,雖然您可以啟用其 UsePartColor 屬性來將它們變更為特定顏色。

  • 如果聯盟操作會導致超過 20,000 個三角形的任何 PartOperations,它們將被簡化為 20,000 個。這將導致代碼錯誤 -14

  • 如果操作計算期間主部分移動,您可以將結果部分設置為主部分的更新 CFrame,因為返回的部分與主部分處於同一坐標空間。

  • 如果使用此方法與 PartOperation 作為主要部分,您可以通過 SubstituteGeometry() 來替換另一個 PartOperation 的幾何圖形,使其更容易使用操作的幾何圖形,但保留主要部分的特性、標籤、標籤和兒女,例如 Attachments , Constraints , ParticleEmitters ,光對象和裝飾。這種方法也可以避免完全替換原始 PartOperation 的潛在"閃爍"。

參數

part: Instance

主要 PartPartOperation 操作。

預設值:""
parts: Array

與主要部分結合的零件群。

預設值:""
options: Dictionary

包含方法所有控件的選項表:

  • CollisionFidelity — 結果零件中的 CollisionFidelity 值。
  • RenderFidelity — 結果零件中的 RenderFidelity 值。
  • FluidFidelity — 結果零件中的 FluidFidelity 值。
  • SplitApart — 使用 Boolean 來控制對象應該全部保留在一起還是正確地分開。默認值為 true (分開)。
預設值:"nil"

返回

來自主要部分的一個或多個 PartOperations 的幾何圖形(part)加上其他部分所佔的幾何圖形。

範例程式碼

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

活動