GeometryService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
特定のオブジェクトに直接関連しない幾何操作を含むサービス。
概要
方法
保存することを選択できる Constraints と Attachments のテーブルを返し、それぞれの親と一緒に。
1つまたは複数の PartOperations を、1つのパーツと他のパーツの交差する幾何学から作成します。
1つまたは複数の PartOperations を、他のパーツによって占有された幾何学を除いて、1部から作成します。
1つまたは複数の PartOperations を、1部分と他の部分によって占有された幾何学から作成します。
プロパティ
方法
CalculateConstraintsToPreserve
保存することを選択できる Constraints と Attachments のテーブルを返し、それぞれの親と一緒に。このテーブルを反復すると、推奨される制約と付属物をそれぞれの親に再付与するかどうかを決定できます。
注:options 辞書にはフォロー中のものが含まれることに注意してください:
- tolerance — 添付ファイルと結果部品の表面の最も近いポイントと原始部品の表面の最も近いポイントの間の距離許容、Attachment 保存に関連して。ソリッドモデリング操作の結果として生じる距離がこの値より大きい場合、添付ファイルとそれらの制約は、返された推奨テーブルに となります。
- — 結果の推奨テーブルに保存される方法を説明する 枚列値。
- — デフォルトが のブール。 に設定すると、 がないものが保存されます。
パラメータ
ソリッドモデリング操作が実行されたオリジナルオブジェクト、例えば part は UnionAsync() です。
メソッドのオプション辞書:
- tolerance — 添付ファイルと結果部品の表面の最も近いポイントと原始部品の表面の最も近いポイントの間の距離許容、Attachment 保存に関連して。ソリッドモデリング操作の結果として生じる距離がこの値より大きい場合、添付ファイルとそれらの制約は、返された推奨テーブルに となります。
- — 結果の推奨テーブルに保存される方法を説明する 枚列値。
- — デフォルトが のブール。 に設定すると、 がないものが保存されます。
戻り値
一般的なケースの情報を含むテーブル Constraints、NoCollisionConstraints、および WeldConstraints。 または が削除されるべき場合、それぞれの親は になります。
一般の場合 Constraints のように HingeConstraint :
<th>種類</th></tr></thead><tbody><tr><td><code>添付ファイル</code></td><td><code>クラス.Attachment</code></td></tr><tr><td><code>制約</code></td><td><code>クラス.Constraint</code> または <code>nil</code></td></tr><tr><td><code>付属の親</code></td><td><code>Class.BasePart</code> または <code>nil</code></td></tr><tr><td><code>制約親</code></td><td><code>Class.BasePart</code> または <code>nil</code></td></tr></tbody>
キー |
---|
For WeldConstraints :
<th>種類</th></tr></thead><tbody><tr><td><code>接着制限</code></td><td><code>クラス.WeldConstraint</code></td></tr><tr><td><code>ウェルド制約親</code></td><td><code>Class.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>
キー |
---|
For NoCollisionConstraints :
<th>種類</th></tr></thead><tbody><tr><td><code>ノーコリジョン制約</code></td><td><code>クラス.NoCollisionConstraint</code></td></tr><tr><td><code>ノーコリジョン制約の親</code></td><td><code>Class.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().
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
メインパーツと指定された配列の交差する幾何学から、1つまたは複数の PartOperations を作成します。単純な Parts と PartOperations のみがサポートされ、Terrain または MeshParts はサポートされません。Clone() と同様、返されたパーツには設定がありません Parent。
メインパーツからの次のプロパティ(part)が、結果の PartOperations に適用されます:
次の画像比較では、IntersectAsync() は紫のブロックとブルーブロックを含む配列を使用して呼び出されます。結果の PartOperation は、両方のパーツの交差する幾何学の形に解決します。

<figcaption>個別のパーツ</figcaption>

<figcaption>結果の <code>Class.PartOperation</code></figcaption>
ノート
比較対象の BasePart:IntersectAsync() と比べて、このメソッドは以下で異なります:
- 入力パーツは場面に親属する必要はなく、背景操作を可能にします。
- 返された各パーツは、メインパーツの座標空間にあります。これは、返されたパーツの (0, 0, 0) が必ずしもボディの中心にあるわけではないことを意味します。
- クライアントでこのメソッドを呼び出すことは可能ですが、いくつかの制限があります。まず、現在クライアント上で作成されたオブジェクト で行われなければなりません 。2番目に、クライアントからサーバーへのレプリケーションは利用できません。
オリジナルのパーツは、成功した操作の後、そのまま残ります。ほとんどの場合、返された PartOperations をメインパーツと同じ場所に親にし、その後、Destroy() すべてのオリジナルパーツを親にします。
デフォルトでは、結果の PartOperations の顔色は、元のパーツの Color プロパティから借用されますが、特定の色に変更するための UsePartColor プロパティを有効にすることができます。
交差操作により、20,000以上のトライアングルが生じた場合、20,000に単純化されます。これにより、コード -14 でエラーが発生します。
操作の計算中にメイン部分が移動している場合、返されたパーツがメイン部分と同じ座標空間にあるため、結果のパーツをメイン部分の更新済み CFrame に設定できます。
この方法を主な部分として で使用すると、 を介して別の の幾何を置き換えることができ、操作の幾何を使用しながらもプロパティ、属性、タグ、およびメイン部分の子、ライトオブジェクト、デカル、およびデカルを維持することができます。このアプローチは、オリジナルの PartOperation を完全に置き換える可能性の「フリッカー」を回避することもできます。
パラメータ
メイン Part または PartOperation で操作します。
メインパーツと交差するパーツのアレイ。
メソッドのすべてのコントロールを含むオプションテーブル:
- CollisionFidelity — 結果のパーツにおける CollisionFidelity の値。
- RenderFidelity — 結果のパーツにおける RenderFidelity の値。
- FluidFidelity — 結果のパーツにおける FluidFidelity の値。
- SplitApart — オブジェクト全体をまとめて保持するか、適切に分離するかをブールで制御します。デフォルトは true (分離) です。
戻り値
メインパーツの交差する幾何学から 1つまたは複数の および他のパーツ。
コードサンプル
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.
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 を 1つまたは複数作成し、指定された配列内の他のパーツによって占有された幾何学を除きます。単純な Parts と PartOperations のみがサポートされ、Terrain または MeshParts はサポートされません。Clone() と同様、返されたパーツには設定がありません Parent。
メインパーツからの次のプロパティ(part)が、結果の PartOperations に適用されます:
次の画像比較では、SubtractAsync() は青いシリンダーと紫のブロックを含む配列を使用して呼び出されます。結果の PartOperation は、ブロックの幾何学をシリンダーから削除する形状に解決します。

<figcaption>個別のパーツ</figcaption>

<figcaption>結果の <code>Class.PartOperation</code></figcaption>
ノート
比較対象の BasePart:SubtractAsync() と比べて、このメソッドは以下で異なります:
- 入力パーツは場面に親属する必要はなく、背景操作を可能にします。
- 返された各パーツは、メインパーツの座標空間にあります。これは、返されたパーツの (0, 0, 0) が必ずしもボディの中心にあるわけではないことを意味します。
- クライアントでこのメソッドを呼び出すことは可能ですが、いくつかの制限があります。まず、現在クライアント上で作成されたオブジェクト で行われなければなりません 。2番目に、クライアントからサーバーへのレプリケーションは利用できません。
オリジナルのパーツは、成功した操作の後、そのまま残ります。ほとんどの場合、返された PartOperations をメインパーツと同じ場所に親にし、その後、Destroy() すべてのオリジナルパーツを親にします。
デフォルトでは、結果の PartOperations の顔色は、元のパーツの Color プロパティから借用されますが、特定の色に変更するための UsePartColor プロパティを有効にすることができます。
差し引き操作により、20,000以上のトライアングルが生じた場合、20,000に単純化されます。これにより、コード -14 でエラーが発生します。
操作の計算中にメイン部分が移動している場合、返されたパーツがメイン部分と同じ座標空間にあるため、結果のパーツをメイン部分の更新済み CFrame に設定できます。
この方法を主な部分として で使用すると、 を介して別の の幾何を置き換えることができ、操作の幾何を使用しながらもプロパティ、属性、タグ、およびメイン部分の子、ライトオブジェクト、デカル、およびデカルを維持することができます。このアプローチは、オリジナルの PartOperation を完全に置き換える可能性の「フリッカー」を回避することもできます。
パラメータ
メイン Part または PartOperation で操作します。
メインパーツから削除するパーツのアレイ。
メソッドのすべてのコントロールを含むオプションテーブル:
- CollisionFidelity — 結果のパーツにおける CollisionFidelity の値。
- RenderFidelity — 結果のパーツにおける RenderFidelity の値。
- FluidFidelity — 結果のパーツにおける FluidFidelity の値。
- SplitApart — オブジェクト全体をまとめて保持するか、適切に分離するかをブールで制御します。デフォルトは true (分離) です。
戻り値
メインパーツの幾何学から 1つまたは複数の を減算し、他のパーツによって占有された幾何学を除きます。
コードサンプル
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.
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
メインパーツと、指定されたアレイに含まれる他のパーツによって占有された幾何学から、1つまたは複数の PartOperations を作成します。単純な Parts と PartOperations のみがサポートされ、Terrain または MeshParts はサポートされません。Clone() と同様、返されたパーツには設定がありません Parent。
メインパーツからの次のプロパティ(part)が、結果の PartOperations に適用されます:
次の画像比較では、UnionAsync() は青いブロックと紫の円筒を含む配列を使用して呼び出されます。結果の PartOperation は、両方のパーツの組み合わせた幾何学の形に解決します。

<figcaption>個別のパーツ</figcaption>

<figcaption>結果の <code>Class.PartOperation</code></figcaption>
ノート
比較対象の BasePart:UnionAsync() と比べて、このメソッドは以下で異なります:
- 入力パーツは場面に親属する必要はなく、背景操作を可能にします。
- 返された各パーツは、メインパーツの座標空間にあります。これは、返されたパーツの (0, 0, 0) が必ずしもボディの中心にあるわけではないことを意味します。
- クライアントでこのメソッドを呼び出すことは可能ですが、いくつかの制限があります。まず、現在クライアント上で作成されたオブジェクト で行われなければなりません 。2番目に、クライアントからサーバーへのレプリケーションは利用できません。
オリジナルのパーツは、成功した操作の後、そのまま残ります。ほとんどの場合、返された PartOperations をメインパーツと同じ場所に親にし、その後、Destroy() すべてのオリジナルパーツを親にします。
デフォルトでは、結果の PartOperations の色は、オリジナルのパーツの Color プロパティから借用されますが、特定の色に変更するための UsePartColor プロパティを有効にすることができます。
ユニオン操作が 20,000 以上のトライアングルを含むPartOperationsに結果する場合、20,000に単純化されます。これにより、コード -14 でエラーが発生します。
操作の計算中にメイン部分が移動している場合、返されたパーツがメイン部分と同じ座標空間にあるため、結果のパーツをメイン部分の更新済み CFrame に設定できます。
この方法を主な部分として で使用すると、 を介して別の の幾何を置き換えることができ、操作の幾何を使用しながらもプロパティ、属性、タグ、およびメイン部分の子、ライトオブジェクト、デカル、およびデカルを維持することができます。このアプローチは、オリジナルの PartOperation を完全に置き換える可能性の「フリッカー」を回避することもできます。
パラメータ
メイン Part または PartOperation で操作します。
メインパーツと結合するパーツのアレイ。
メソッドのすべてのコントロールを含むオプションテーブル:
- CollisionFidelity — 結果のパーツにおける CollisionFidelity の値。
- RenderFidelity — 結果のパーツにおける RenderFidelity の値。
- FluidFidelity — 結果のパーツにおける FluidFidelity の値。
- SplitApart — オブジェクト全体をまとめて保持するか、適切に分離するかをブールで制御します。デフォルトは true (分離) です。
戻り値
メインパーツの幾何学から 1つまたは複数の と、他のパーツによって占有された幾何学を加えて、
コードサンプル
This example combines the geometry of mainPart and the parts in the otherParts array, then it destroys the original parts involved in the operation.
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