PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

Region3

Region3

Region3 is a data type that describes a volume in 3D space similar to an axis-aligned rectangular prism. It is commonly used with Terrain functions and functions that detect parts within a volume, such as Workspace/FindPartsInRegion3.

  • The prism’s center can be accessed using the datatype/CFrame CFrame property.
  • The prism’s size is available in the datatype/Vector3 Size property. Note that the components of this property may be negative!

When converted to a articles/String|string, the output format is CFrame; Size where each of these is the respective property also converted to a string.

The only operation that can be done on a Region3 is Region3.ExpandToGrid(resolution), which returns a new Region3 whose bounds comply with a provided resolution value. The resulting volume may be equal to or greater than the original volume, but never smaller.

See also

  • datatype/Region3int16, a similar data type
  • /articles/Scripting With Terrain, an article describing how to generate terrain of different sizes and shapes using voxel-based code

Constructors

Region3.new ( Vector3 min, Vector3 max )

Creates a new Region3 given the datatype/Vector3 bounds of a the rectangular prism volume.

Note that the order of the provided bounds matters: by switching them, the polarity of the Size components will switch. It is possible to create a Region3 with a negative volume.


Region3.new Example

This code sample constructs a Region3 using two Vector3s describing its bounds. It then prints information about the Region3.

Properties

CFrame Region3.CFrame

The center location and rotation of the Region3

Vector3 Region3.Size

The 3D size of the Region3

Functions

Region3 Region3:ExpandToGrid ( int Region )

A function that expands the Region3 so that it is aligned with a voxel grid based on the provided resolution and returns the expanded Region3.

All you need to do is perform the method on the Region3 you have defined, providing a resolution. Then, the function will align the region so that it is compatible with the Terrain grid.


Expanding a Region3 to a Grid

This code sample creates a datatype/Region3 centered at (0, 0, -3) with a size of (4, 4, 4). It then expands the region with a resolution of 4 to align it with a voxel grid using ExpandToGrid. Once the region is compatible with the terrain grid, it fills the region with water terrain using Terrain/FillRegion.