GeometryService

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
服务

包含与特定对象无关的几何操作的服务。

概要

方法

属性

方法

CalculateConstraintsToPreserve

返回一个包含 ConstraintsAttachments 的表,你可以选择保留它们的各自父辈。遍历这个表可让你决定是否将推荐的约束和附件重新附加到各自的父辈。

请注意,options 词典可以包含以关注中/正在关注内容:

  • — 附件和原部件表面上最近点之间的距离公差,与最终部件表面上最近点相比。如果在固体模型操作后得到的距离大于此值,附件和其相关约束的 Parent 将在返回的推荐表中显示为 nil
  • weldConstraintPreserve — 一个 Enum.WeldConstraintPreserve 枚列值,描述如何在最终推荐表中保存 WeldConstraints
  • — 使用默认值 的布尔。如果设置为 ,那些没有 的将被保留。

参数

source: Instance

原始对象,例如在 part 中执行了固体模型操作,例如 UnionAsync()

默认值:""
destination: Array
默认值:""
options: Dictionary

方法的选项词典:

  • — 附件和原部件表面上最近点之间的距离公差,与最终部件表面上最近点相比。如果在固体模型操作后得到的距离大于此值,附件和其相关约束的 Parent 将在返回的推荐表中显示为 nil
  • weldConstraintPreserve — 一个 Enum.WeldConstraintPreserve 枚列值,描述如何在最终推荐表中保存 WeldConstraints
  • — 使用默认值 的布尔。如果设置为 ,那些没有 的将被保留。
默认值:"nil"

返回

包含一般情况信息的表 Constraints , NoCollisionConstraints , 和 WeldConstraints 。在需要丢弃 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>类.NoCollision约束</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

从主部分(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 作为主要部分,您可以通过 SubstituteGeometry() 来替换另一个 PartOperation 的几何图形,使其更容易使用操作的几何图形,但保留主要部分的属性、标签、标签和子部件,例如 Attachments , Constraints , ParticleEmitters ,轻型对象和装饰。这种方法也可以避免完全替换原始 PartOperation 的潜在"闪烁"。

参数

part: Instance

主要 PartPartOperation 来操作。

默认值:""
parts: Array

与主部分交叉的零件阵列。

默认值:""
options: Dictionary

包含方法所有控件的选项表:

  • CollisionFidelity — 结果零件中的 CollisionFidelity 值。
  • RenderFidelity — 结果零件中的 RenderFidelity 值。
  • FluidFidelity — 结果零件中的 FluidFidelity 值。
  • SplitApart — 布尔控制对象是否应保持在一起或分开正确。默认值为 true (分开)。
默认值:"nil"

返回

一个或多个PartOperations从主部分(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 从主部分减去其他部分在给定数组列中占用的几何图形。只支持原始 PartsPartOperations ,不支持 TerrainMeshParts。与 Clone() 类似,返回的零件没有设置 Parent

从主部分(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 个三角形的任何 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 — 布尔控制对象是否应保持在一起或分开正确。默认值为 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

从主部分(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 属性中借用,尽管您可以启用其 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 — 布尔控制对象是否应保持在一起或分开正确。默认值为 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

活动