# GeometryService

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Tags: Not creatable, Service
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/GeometryService/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/GeometryService

Service containing geometric operations.

## Methods

### CalculateConstraintsToPreserve

```luau
GeometryService:CalculateConstraintsToPreserve(source: Instance, destination: { any }, options: { [string]: any }? = nil): { any }
```

- Tags: Capabilities: CSG

Returns a table of `Constraints` and `Attachments` which you may choose to preserve, along with their respective parents.

Parameters:

- `source`: An original object that the solid modeling operation was performed on, for example `part` in [`UnionAsync()`](https://rapi.sleaze.dev/classes/GeometryService.md).
- `destination`: Array of resulting `BaseParts` from the solid modeling operation, for example the results of [`UnionAsync()`](https://rapi.sleaze.dev/classes/GeometryService.md).
- `options`: Options dictionary for the method:

- `tolerance` — The distance tolerance, in regards to [`Attachment`](https://rapi.sleaze.dev/classes/Attachment.md) preservation, between the attachment and the closest point on the original part's surface versus the closest point on the resulting part's surface. If the resulting distance following the solid modeling operation is greater than this value, the [`Parent`](https://rapi.sleaze.dev/classes/Instance.md) of attachments and their associated constraints will be `nil` in the returned recommendation table.
- `weldConstraintPreserve` — A `WeldConstraintPreserve` enum value describing how `WeldConstraints` are preserved in the resulting recommendation table.
- `dropAttachmentsWithoutConstraints` — Boolean with default of `true`. If set to `false`, `Attachments` that have no `Constraints` will be preserved.

Returns: Table containing information for general case `Constraints`, `NoCollisionConstraints`, and `WeldConstraints`. In cases where an [`Attachment`](https://rapi.sleaze.dev/classes/Attachment.md) or [`Constraint`](https://rapi.sleaze.dev/classes/Constraint.md) should be dropped, its respective parent will be `nil`. For general case `Constraints` such as [`HingeConstraint`](https://rapi.sleaze.dev/classes/HingeConstraint.md):    Key Type     [`Attachment`](https://rapi.sleaze.dev/classes/Attachment.md) `Class.Attachment`   [`Constraint`](https://rapi.sleaze.dev/classes/Constraint.md) `Class.Constraint` or `nil`   `AttachmentParent` `Class.BasePart` or `nil`   `ConstraintParent` `Class.BasePart` or `nil`    For `WeldConstraints`:    Key Type     [`WeldConstraint`](https://rapi.sleaze.dev/classes/WeldConstraint.md) `Class.WeldConstraint`   `WeldConstraintParent` `Class.BasePart` or `nil`   `WeldConstraintPart0` `Class.BasePart`   `WeldConstraintPart1` `Class.BasePart`    For `NoCollisionConstraints`:    Key Type     [`NoCollisionConstraint`](https://rapi.sleaze.dev/classes/NoCollisionConstraint.md) `Class.NoCollisionConstraint`   `NoCollisionConstraintParent` `Class.BasePart` or `nil`   `NoCollisionConstraintPart0` `Class.BasePart`   `NoCollisionConstraintPart1` `Class.BasePart`

### CreateBasicMeshPart

```luau
GeometryService:CreateBasicMeshPart(shape: Enum.BasicMeshPartShape, options: { [string]: any }? = nil): MeshPart
```

- Tags: Capabilities: CSG + InternalTest

### FragmentAsync

```luau
GeometryService:FragmentAsync(part: BasePart, sites: { any }, options: { [string]: any }? = nil): { any }
```

- Tags: Yields, Capabilities: CSG

Breaks a [`BasePart`](https://rapi.sleaze.dev/classes/BasePart.md) into multiple [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) instances, according to the pattern of points passed in, by using voronoi decomposition.

Parameters:

- `part`: A [`Part`](https://rapi.sleaze.dev/classes/Part.md), [`PartOperation`](https://rapi.sleaze.dev/classes/PartOperation.md), or [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) to operate on.
- `sites`: Array of [`Vector3`](https://rapi.sleaze.dev/index/types/Vector3.md) defining the site positions. Each site will become a separate part. You can also provide a jagged 2D array of [`Vector3`](https://rapi.sleaze.dev/index/types/Vector3.md) by including inner arrays of [`Vector3`](https://rapi.sleaze.dev/index/types/Vector3.md) as elements of the outer array. Each inner array will have all of its voronoi cells merged into a single part. [`GeometryService:GenerateFragmentSites`](https://rapi.sleaze.dev/classes/GeometryService.md) can be used to easily create this input.
- `options`: Options table containing all the controls for the method:

- `CollisionFidelity` — The value of `CollisionFidelity` in the resulting parts, with one caveat: If a 2D array of sites is provided, this collision fidelity will only be applied to parts which came from more than one site. The others will be given `Hull` precision.
- `RenderFidelity` — The value of `RenderFidelity` in the resulting parts.
- `FluidFidelity` — The value of `FluidFidelity` in the resulting parts.
- `SplitApart` — Boolean controlling whether a part should be split into multiple parts if it contains multiple connected components. Default is `true` (split).

Returns: Array of [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) along with mapping info. Each array element is a Dictionary with two elements: `{ "Instance": instance, "Index": index }`. `Index` is the index in the outer array of sites; in other words, it tells you which group of sites this instance came from. Note that it is possible for multiple instances to have the same index, if SplitApart is `true`.

### GenerateFragmentSites

```luau
GeometryService:GenerateFragmentSites(part: BasePart, options: { [string]: any }? = nil): { any }
```

- Tags: Capabilities: CSG

Provides an array of positions which can easily be passed into [`FragmentAsync`](https://rapi.sleaze.dev/classes/GeometryService.md) to perform simple types of destruction.

Parameters:

- `part`: The [`Part`](https://rapi.sleaze.dev/classes/Part.md), [`PartOperation`](https://rapi.sleaze.dev/classes/PartOperation.md), or [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) which you are planning to pass into [`FragmentAsync()`](https://rapi.sleaze.dev/classes/GeometryService.md). This is necessary to make the fragment site generation and the subsequent [`FragmentAsync()`](https://rapi.sleaze.dev/classes/GeometryService.md) call efficient.
- `options`: Options table containing all the controls for the method:

- `SiteSpacing` — The approximate distance between sites, which directly corresponds to the diameter of the resulting fragments. If not specified, a reasonable value will be chosen.
- `Origin` — If provided, this will be the center of the area to be fragmented. If not provided, the entire object will be fragmented.
- `Radius` — If provided, this will be the center of the area to be fragmented. Either `Origin` and `Radius` should both be provided, or neither.

Returns: An array of [`Vector3`](https://rapi.sleaze.dev/index/types/Vector3.md) which is typically passed into [`FragmentAsync()`](https://rapi.sleaze.dev/classes/GeometryService.md). The output depends on the options provided. If `Origin` and `Radius` are provided, then the output array will contain several [`Vector3`](https://rapi.sleaze.dev/index/types/Vector3.md) elements which will all be located within the radius, but the first element of the array will be an inner array containing many [`Vector3`](https://rapi.sleaze.dev/index/types/Vector3.md) sites which are outside the radius. If `Origin` and `Radius` are not provided, the output will simply be an array of [`Vector3`](https://rapi.sleaze.dev/index/types/Vector3.md) positions within the extents of the input `part`.

### HashMeshAsync

```luau
GeometryService:HashMeshAsync(meshId: string): string
```

- Tags: Yields, Roblox script security, Capabilities: CSG

### IntersectAsync

```luau
GeometryService:IntersectAsync(part: Instance, parts: { any }, options: { [string]: any }? = nil): { any }
```

- Tags: Yields, Capabilities: CSG

Creates one or more `PartOperations` or `MeshParts` from the intersecting geometry of multiple parts.

Parameters:

- `part`: Main [`Part`](https://rapi.sleaze.dev/classes/Part.md), [`PartOperation`](https://rapi.sleaze.dev/classes/PartOperation.md), or [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) to operate on.
- `parts`: Array of other parts to intersect with the main part.
- `options`: Options table containing all the controls for the method:

- `CollisionFidelity` — The value of `CollisionFidelity` in the resulting parts.
- `RenderFidelity` — The value of `RenderFidelity` or `RenderFidelity` in the resulting parts.
- `FluidFidelity` — The value of `FluidFidelity` in the resulting parts.
- `SplitApart` — Boolean controlling whether the objects should all be kept together or properly split apart. Default is `true` (split).

Returns: One or more `PartOperations` or `MeshParts`. If the input contained any `MeshParts`, then the results will always be `MeshParts`.

### SubtractAsync

```luau
GeometryService:SubtractAsync(part: Instance, parts: { any }, options: { [string]: any }? = nil): { any }
```

- Tags: Yields, Capabilities: CSG

Creates one or more `PartOperations` or `MeshParts` from one part minus the space occupied by other parts.

Parameters:

- `part`: Main [`Part`](https://rapi.sleaze.dev/classes/Part.md), [`PartOperation`](https://rapi.sleaze.dev/classes/PartOperation.md), or [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) to operate on.
- `parts`: Array of parts to subtract from the main part.
- `options`: Options table containing all the controls for the method:

- `CollisionFidelity` — The value of `CollisionFidelity` in the resulting parts.
- `RenderFidelity` — The value of `RenderFidelity` or `RenderFidelity` in the resulting parts.
- `FluidFidelity` — The value of `FluidFidelity` in the resulting parts.
- `SplitApart` — Boolean controlling whether the objects should all be kept together or properly split apart. Default is `true` (split).

Returns: One or more `PartOperations` or `MeshParts`. If the input contained any `MeshParts`, then the results will always be `MeshParts`.

### SweepPartAsync

```luau
GeometryService:SweepPartAsync(part: BasePart, cframes: { any }, options: { [string]: any }? = nil): MeshPart
```

- Tags: Yields, Capabilities: CSG

Creates a [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) which has the shape of the input part stretched/dragged through the given set of [`CFrame`](https://rapi.sleaze.dev/index/types/CFrame.md) positions.

Parameters:

- `part`: A [`Part`](https://rapi.sleaze.dev/classes/Part.md), [`PartOperation`](https://rapi.sleaze.dev/classes/PartOperation.md), or [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) to operate on.
- `cframes`: Array of coordinate frames to sweep parts through.
- `options`: Options table containing all the controls for the method:

- `CollisionFidelity` — The value of `CollisionFidelity` in the resulting parts.
- `RenderFidelity` — The value of `RenderFidelity` in the resulting parts.
- `FluidFidelity` — The value of `FluidFidelity` in the resulting parts.

Returns: A new [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) with the swept geometry.

### TranscodeMesh

```luau
GeometryService:TranscodeMesh(instance: Instance)
```

- Tags: Roblox script security, Capabilities: CSG

### TranscodeModel

```luau
GeometryService:TranscodeModel(instance: Instance): { any }
```

- Tags: Roblox script security, Capabilities: CSG

### UnionAsync

```luau
GeometryService:UnionAsync(part: Instance, parts: { any }, options: { [string]: any }? = nil): { any }
```

- Tags: Yields, Capabilities: CSG

Creates one or more `PartOperations` or `MeshParts` from one part plus the space occupied by other parts.

Parameters:

- `part`: Main [`Part`](https://rapi.sleaze.dev/classes/Part.md), [`PartOperation`](https://rapi.sleaze.dev/classes/PartOperation.md), or [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) to operate on.
- `parts`: Array of parts to union with the main part.
- `options`: Options table containing all the controls for the method:

- `CollisionFidelity` — The value of `CollisionFidelity` in the resulting parts.
- `RenderFidelity` — The value of `RenderFidelity` or `RenderFidelity` in the resulting parts.
- `FluidFidelity` — The value of `FluidFidelity` in the resulting parts.
- `SplitApart` — Boolean controlling whether the objects should all be kept together or properly split apart. Default is `true` (split).

Returns: One or more `PartOperations` or `MeshParts`. If the input contained any `MeshParts`, then the results will always be `MeshParts`.

## Inherited members

- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
