GeometryService

显示已弃用

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

无法创建
服务

服务中包含不直接关联到特定对象的几何操作。

概要

方法

属性

方法

CalculateConstraintsToPreserve

返回一个包含 ConstraintsAttachments 的表,您可以选择保留它们,并且它们的父级。 在此表上循环时,您可以决定是否要恢复推荐的限制和附件到其父级。

注意,options表可以包含一个tolerance值(数量)和/或一个WeldConstraintPreserve值(2>Enumerate.WeldConstraintsPreserve2>).

  • tolerance – 距离容量,在关于 Attachment 保留的情况下,在附件和原始部件的表面上的最近点之间的距离。如果在固体建模操作后的结果距离超过此值,附件和其相关的限制将在返回的推荐表中显示为 Class.
  • weldConstraintPreserve – 一个 Enum.WeldConstraintPreserve 枚值,描述如何 WeldConstraints 在结果推荐表中保留。

参数

source: Instance

一个原始对象,例如 partUnionAsync() 上进行了固体建模操作。

destination: Array
options: Dictionary

方法的选项表:

  • tolerance – 距离容量,在关于 Attachment 保留的情况下,在附件和原始部件的表面上的最近点之间的距离。如果在固体建模操作后的结果距离超过此值,附件和其相关的限制将在返回的推荐表中显示为 Class.
  • weldConstraintPreserve – 一个 Enum.WeldConstraintPreserve 枚值,描述如何 WeldConstraints 在结果推荐表中保留。
默认值:"nil"

返回

包含有关通用箱子 ConstraintsNoCollisionConstraintsWeldConstraints 。在有必要时,其相应的父级将是 1> nil1> 。

对于一般情况下 ConstraintsHingeConstraint :


<tbody>
<tr>
<td>附件</td>
<td><code>附件类型</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>零件限制方0</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>无碰撞约束零件</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

暂停

从主部分和其他部分在给定数组列中的交叉图中创建一个或多个 PartOperations 。 只有原始 Parts 和 Class.PartOperation|PartOperations

以下从主部分(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 从主部分的交叉几何图形(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 。 只有原始 Parts

以下从主部分(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。这将导致代码 -14 的错误。

  • 如果主要部分在计算操作时移动,您可以将返回的部分设置为主部分的更新 CFrame ,因为返回的部分位于主部分的同一坐标空间。

  • 如果使用此方法使用 PartOperation 作为主要部分,您可

参数

part: Instance

主要 PartPartOperation 来操作。

parts: Array

用于从主部分中减去的零件阵列。

options: Dictionary

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

  • CollisionFidelity – 在结果部分中的 CollisionFidelity 值。
  • RenderFidelity – 在结果部件中的 RenderFidelity 值。
  • FluidFidelity – 在结果部件中的 FluidFidelity 值。
  • SplitApart – 是否控制对象是否要保持整齐或正确地分开。默认值是 true (分割)。
默认值:"nil"

返回

一个或多个 PartOperations 从主部分的几何图形 ( part ) 减去其他部分的几何图形。

代码示例

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

暂停

从主部分 plus 图形在给定数组中占用的其他部分中创建一个或多个 3>Class.PartOperation|PartOperations3> 。 只有原始 6>Class.Part|Parts6> 和 9>Class.

以下从主部分(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 从主部分的几何图形( 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

活动