Reference API Roblox

Engine API

Website

Related

Reference API Roblox

EditableMesh

Instance which allows for the runtime creation and manipulation of meshes.

This class is not creatable. Instances of this class cannot be created with Instance.new.
Tags: [NotCreatable]

Member index 50

HistoryMember
648FixedSize: bool
648SkinningEnabled: bool
640AddColor(color: Color3, alpha: float): int64
640AddNormal(normal: Vector3?): int64
604AddTriangle(vertexId0: int64, vertexId1: int64, vertexId2: int64): int64
640AddUV(uv: Vector2): int64
604AddVertex(p: Vector3): int64
649CreateMeshPartAsync(initialSize: Vector3, options: Dictionary = nil): MeshPart
649Destroy(): null
602FindClosestPointOnSurface(point: Vector3): Tuple
604FindClosestVertex(toThisPoint: Vector3): int64
602FindVerticesWithinSphere(center: Vector3, radius: float): Array
640GetAdjacentFaces(faceId: int64): Array
604GetAdjacentVertices(vertexId: int64): Array
650GetCenter(): Vector3
640GetColor(colorId: int64): Color3?
640GetColorAlpha(colorId: int64): float?
644GetColors(): Array
644GetFaceColors(faceId: int64): Array
644GetFaceNormals(faceId: int64): Array
644GetFaceUVs(faceId: int64): Array
644GetFaceVertices(faceId: int64): Array
644GetFaces(): Array
640GetFacesWithAttribute(id: int64): Array
640GetNormal(normalId: int64): Vector3?
644GetNormals(): Array
604GetPosition(vertexId: int64): Vector3
650GetSize(): Vector3
640GetUV(uvId: int64): Vector2?
644GetUVs(): Array
602GetVertices(): Array
640GetVerticesWithAttribute(id: int64): Array
640IdDebugString(id: int64): string
640MergeVertices(mergeTolerance: float): Map
604RaycastLocal(origin: Vector3, direction: Vector3): Tuple
640RemoveFace(faceId: int64): null
640RemoveUnused(): Array
640ResetNormal(normalId: int64): null
640SetColor(colorId: int64, color: Color3): null
640SetColorAlpha(colorId: int64, alpha: float): null
644SetFaceColors(faceId: int64, ids: Array): null
644SetFaceNormals(faceId: int64, ids: Array): null
644SetFaceUVs(faceId: int64, ids: Array): null
644SetFaceVertices(faceId: int64, ids: Array): null
640SetNormal(normalId: int64, normal: Vector3): null
604SetPosition(vertexId: int64, p: Vector3): null
640SetUV(uvId: int64, uv: Vector2): null
640Triangulate(): null
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Removed member index 14

HistoryMember
648GetAdjacentTriangles(triangleId: int64): Array
649GetContent(): Content
648GetTriangleVertices(triangleId: int64): Tuple
648GetTriangles(): Array
648GetVertexColor(vertexId: int64): Color3
648GetVertexColorAlpha(vertexId: int64): float
648GetVertexNormal(vertexId: int64): Vector3
604Raycast(origin: Vector3, direction: Vector3): Tuple
648RemoveTriangle(triangleId: int64): null
648RemoveVertex(vertexId: int64): null
648SetVertexColor(vertexId: int64, color: Color3): null
648SetVertexColorAlpha(vertexId: int64, alpha: float): null
648SetVertexNormal(vertexId: int64, vnormal: Vector3): null

Description

EditableMesh changes the applied visual mesh when linked to a MeshPart, allowing for querying and modification of the mesh both in Studio and in experience.

An EditableMesh can be created from an existing Content of a MeshPart or a mesh ID using AssetService:CreateEditableMeshAsync(), or a blank EditableMesh can be created with AssetService:CreateEditableMesh(). It can then be displayed, modified, and its collision model updated. Not all of the steps are necessary; for example, you might want to create an EditableMesh just to raycast without ever displaying it.

An EditableMesh is displayed when it's linked to a new MeshPart, through AssetService:CreateMeshPartAsync(). You can create more MeshPart instances that reference the same EditableMesh content, or link to an existing MeshPart through MeshPart:ApplyMesh().

To recalculate collision and fluid geometry after editing, you can again call AssetService:CreateMeshPartAsync() and MeshPart:ApplyMesh() to update an existing MeshPart. It's generally recommended to do this at the end of a conceptual edit, not after individual calls to methods that manipulate geometry. Visual changes to the mesh will always be immediately reflected by the engine, without the need to call AssetService:CreateMeshPartAsync().

Enabling EditableMesh for Published Experiences

For security purposes, using EditableMesh fails by default for published experiences. To enable usage, EditableMesh, you must be 13+ age verified and ID verified. After you are verified, open Studio's Game Settings, select Security, and enable the Allow Mesh & Image APIs toggle. Remember to review the Terms of Use before enabling the toggle.

Permissions

To prevent misuse, AssetService:CreateEditableMeshAsync() will only allow you to load and edit mesh assets:

  • That are owned by the creator of the experience (if the experience is owned by an individual).
  • That are owned by a group (if the experience is owned by the group).
  • That are owned by the logged in Studio user (if the place file has not yet been saved or published to Roblox).

The APIs throw an error if they are used to load an asset that does not meet the criteria above.

Fixed-Size Meshes

When creating an EditableMesh from an existing mesh asset (via AssetService:CreateEditableMeshAsync()), the resulting editable mesh is fixed-size by default. Fixed-size meshes are more efficient in terms of memory but you cannot change the number of vertices, faces, or attributes. Only the values of vertex attributes and positions can be edited.

Stable Vertex/Face IDs

Many EditableMesh methods take vertex, normal, UV, color and face IDs. These are represented as integers in Luau but they require some special handling. The main difference is that IDs are stable and they remain the same even if other parts of the mesh change. For example, if an EditableMesh has five vertices {1, 2, 3, 4, 5} and you remove vertex 4, the new vertices will be {1, 2, 3, 5}.

Note that the IDs are not guaranteed to be in order and there may be holes in the numbering, so when iterating through vertices or faces, you should iterate through the table returned by GetVertices() or GetFaces().

Split Vertex Attributes

A vertex is a corner of a face, and topologically connects faces together. Vertices can have several attributes: position, normal, UV coordinate, color, and transparency.

Sometimes it's useful for all faces that touch a vertex to use the same attribute values, but sometimes you'll want different faces to use different attribute values on the same vertex. For example, on a smooth sphere, each vertex will only have a single normal. In contrast, at the corner of a cube, the vertex will have 3 different normals (one for each adjacent face). You can also have seams in the UV coordinates or sharp changes in the vertex colors.

When creating faces, every vertex will by default have one of each attribute: one normal, one UV coordinate, and one color/transparency. If you want to create a seam, you should create new attributes and set them on the face. For example, this code will create a sharp cube:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
local AssetService = game:GetService("AssetService")

-- Given 4 vertex IDs, adds a new normal and 2 triangles, making a sharp quad
local function addSharpQuad(eMesh, vid0, vid1, vid2, vid3)
	local nid = eMesh:AddNormal()  -- This creates a normal ID which is automatically computed

	local fid1 = eMesh:AddTriangle(vid0, vid1, vid2)
	eMesh:SetFaceNormals(fid1, {nid, nid, nid})

	local fid2 = eMesh:AddTriangle(vid0, vid2, vid3)
	eMesh:SetFaceNormals(fid2, {nid, nid, nid})
end

-- Makes a cube with creased edges between the 6 sides
local function makeSharpCube()
	local eMesh = AssetService:CreateEditableMesh()

	local v1 = eMesh:AddVertex(Vector3.new(0, 0, 0))
	local v2 = eMesh:AddVertex(Vector3.new(1, 0, 0))
	local v3 = eMesh:AddVertex(Vector3.new(0, 1, 0))
	local v4 = eMesh:AddVertex(Vector3.new(1, 1, 0))
	local v5 = eMesh:AddVertex(Vector3.new(0, 0, 1))
	local v6 = eMesh:AddVertex(Vector3.new(1, 0, 1))
	local v7 = eMesh:AddVertex(Vector3.new(0, 1, 1))
	local v8 = eMesh:AddVertex(Vector3.new(1, 1, 1))

	addSharpQuad(eMesh, v5, v6, v8, v7)  -- Front
	addSharpQuad(eMesh, v1, v3, v4, v2)  -- Back
	addSharpQuad(eMesh, v1, v5, v7, v3)  -- Left
	addSharpQuad(eMesh, v2, v4, v8, v6)  -- Right
	addSharpQuad(eMesh, v1, v2, v6, v5)  -- Bottom
	addSharpQuad(eMesh, v3, v7, v8, v4)  -- Top

	eMesh:RemoveUnused()
	return eMesh
end

Winding

Mesh faces have a front side and a back side. When drawing meshes, only the front of the faces are drawn by default, although you can change this by setting the mesh' DoubleSided property to true.

The order of the vertices around the face determines whether you are looking at the front or the back. The front of the face is visible when the vertices go counterclockwise around it.

Order of the vertices around the face

Limitations

EditableMesh currently has a limit of 60,000 vertices and 20,000 triangles. Attempting to add too many vertices or triangles will cause an error.

History 181

Members 50

AddColor

Parameters (2)
colorColor3
alphafloat
Returns (1)
int64

Adds a new color to the geometry and returns a stable color ID.

History 1

AddNormal

Parameters (1)
normalVector3?
Returns (1)
int64

Adds a new normal to the geometry and returns a stable normal ID. If the normal value isn't specified, the normal will be automatically calculated.

History 1

AddTriangle

Parameters (3)
vertexId0int64
vertexId1int64
vertexId2int64
Returns (1)
int64

Adds a new triangle to the mesh and returns a stable face ID.

History 7

AddUV

Parameters (1)
uvVector2
Returns (1)
int64

Adds a new UV to the geometry and returns a stable UV ID.

History 1

AddVertex

Parameters (1)
pVector3
Returns (1)
int64

Adds a new vertex to the geometry and returns a stable vertex ID.

History 4

CreateMeshPartAsync

Parameters (2)Default
initialSizeVector3
optionsDictionarynil
Returns (1)
MeshPart
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.
This function yields. It will block the calling thread until completion.

History 5

Tags: [Yields, Deprecated]

Destroy

Parameters (0)
No parameters.
Returns (1)
null

Destroys the contents of the mesh, immediately reclaiming used memory.

History 1

FindClosestPointOnSurface

Parameters (1)
pointVector3
Returns (1)
Tuple

Finds the closest point on the mesh's surface. Returns the face ID, point on the mesh in local object space, and the barycentric coordinate of the position within the face. See RaycastLocal() for more information on barycentric coordinates.

History 1

FindClosestVertex

Parameters (1)
toThisPointVector3
Returns (1)
int64

Finds the closest vertex to a specific point in space and returns a stable vertex ID.

History 4

FindVerticesWithinSphere

Parameters (2)
centerVector3
radiusfloat
Returns (1)
Array

Finds all vertices within a specific sphere and returns a list of stable vertex IDs.

History 1

FixedSize

TypeDefault
bool__api_dump_failed_to_create_class__

Fixed-sized meshes allow changing the values of vertex attributes but do not allow vertices and triangles to be added or deleted.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 1

Tags: [ReadOnly, NotReplicated]

GetAdjacentFaces

Parameters (1)
faceIdint64
Returns (1)
Array

Given a stable face ID, returns a list of adjacent faces.

Adjacent faces indicated around requested face

History 1

GetAdjacentVertices

Parameters (1)
vertexIdint64
Returns (1)
Array

Given a stable vertex ID, returns a list of adjacent vertices.

Adjacent vertices indicated around requested vertex

History 4

GetCenter

Parameters (0)
No parameters.
Returns (1)
Vector3

History 1

GetColor

Parameters (1)
colorIdint64
Returns (1)
Color3?

Returns the color for the given color ID.

History 1

GetColorAlpha

Parameters (1)
colorIdint64
Returns (1)
float?

Returns the color alpha (transparency) at the given stable color ID.

History 1

GetColors

Parameters (0)
No parameters.
Returns (1)
Array

Returns all colors of the mesh as a list of stable color IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetFaceColors

Parameters (1)
faceIdint64
Returns (1)
Array

Returns the face's color IDs for the vertices on the face.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetFaceNormals

Parameters (1)
faceIdint64
Returns (1)
Array

Returns the face's normal IDs for the vertices on the face.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetFaceUVs

Parameters (1)
faceIdint64
Returns (1)
Array

Returns the face's UV IDs for the vertices on the face.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetFaceVertices

Parameters (1)
faceIdint64
Returns (1)
Array

Returns the face's vertex IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetFaces

Parameters (0)
No parameters.
Returns (1)
Array

Returns all faces of the mesh as a list of stable face IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetFacesWithAttribute

Parameters (1)
idint64
Returns (1)
Array

Returns a list of faces that use a given vertex ID, normal ID, UV ID, or color ID.

History 1

GetNormal

Parameters (1)
normalIdint64
Returns (1)
Vector3?

Returns the normal vector for the given normal ID.

History 1

GetNormals

Parameters (0)
No parameters.
Returns (1)
Array

Returns all normals of the mesh as a list of stable normal IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetPosition

Parameters (1)
vertexIdint64
Returns (1)
Vector3

Gets the position of a vertex in the mesh's local object space.

History 4

GetSize

Parameters (0)
No parameters.
Returns (1)
Vector3

History 1

GetUV

Parameters (1)
uvIdint64
Returns (1)
Vector2?

Returns UV coordinates at the given UV ID.

History 6

GetUVs

Parameters (0)
No parameters.
Returns (1)
Array

Returns all UVs of the mesh as a list of stable UV IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

GetVertices

Parameters (0)
No parameters.
Returns (1)
Array

Returns all vertices as a list of stable vertex IDs.

History 1

GetVerticesWithAttribute

Parameters (1)
idint64
Returns (1)
Array

Returns a list of vertices that use a given face ID, normal ID, UV ID, or color ID.

History 1

IdDebugString

Parameters (1)
idint64
Returns (1)
string

Returns a string describing a stable ID, useful for debugging purposes, like f17 or v12, containing the type, ID number, and version.

History 1

MergeVertices

Parameters (1)
mergeTolerancefloat
Returns (1)
Map

Merges vertices that touch together, to use a single vertex ID but keep the other original attribute IDs.

History 1

RaycastLocal

Parameters (2)
originVector3
directionVector3
Returns (1)
Tuple

Casts a ray and returns a point of intersection, face ID, and barycentric coordinates. The inputs and outputs of this method are in the mesh's local object space.

A barycentric coordinate is a way of specifying a point within a face as a weighted combination of the 3 vertices of the face. This is useful as a general way of blending vertex attributes. See this method's code sample as an illustration.

History 3

RemoveFace

Parameters (1)
faceIdint64
Returns (1)
null

Removes a face using its stable face ID.

History 1

RemoveUnused

Parameters (0)
No parameters.
Returns (1)
Array

Removes all vertices, normals, UVs, and colors which are not used in any face, and returns the removed IDs.

History 1

ResetNormal

Parameters (1)
normalIdint64
Returns (1)
null

Reset this normal ID to be automatically calculated based on the shape of the mesh, instead of manually set.

History 1

SetColor

Parameters (2)
colorIdint64
colorColor3
Returns (1)
null

Sets the color for a color ID.

History 1

SetColorAlpha

Parameters (2)
colorIdint64
alphafloat
Returns (1)
null

Sets the color alpha (transparency) for a color ID.

History 1

SetFaceColors

Parameters (2)
faceIdint64
idsArray
Returns (1)
null

Sets the face's vertex colors to new color IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

SetFaceNormals

Parameters (2)
faceIdint64
idsArray
Returns (1)
null

Sets the face's vertex normals to new normal IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

SetFaceUVs

Parameters (2)
faceIdint64
idsArray
Returns (1)
null

Sets the face's vertex UVs to new UV IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

SetFaceVertices

Parameters (2)
faceIdint64
idsArray
Returns (1)
null

Sets the face's vertices to new vertex IDs.

This function has a custom internal state. It may behave in a non-standard way.

History 2

Tags: [CustomLuaState]

SetNormal

Parameters (2)
normalIdint64
normalVector3
Returns (1)
null

Set the normal for a normal ID. This will change the normal value for every face vertex which is using the normal ID.

History 1

SetPosition

Parameters (2)
vertexIdint64
pVector3
Returns (1)
null

Sets a vertex position in the mesh's local object space.

History 4

SetUV

Parameters (2)
uvIdint64
uvVector2
Returns (1)
null

Sets UV coordinates for a UV ID.

History 5

SkinningEnabled

TypeDefault
bool__api_dump_failed_to_create_class__

History 2

Triangulate

Parameters (0)
No parameters.
Returns (1)
null

Splits all faces on the mesh to be triangles. Currently this does nothing since only triangles can be created, but if your code relies on triangles, it's recommended that you call this method after calling AssetService:CreateEditableMeshAsync().

History 1

Removed members 14

GetAdjacentTriangles

Parameters (1)
triangleIdint64
Returns (1)
Array
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

GetContent

Parameters (0)
No parameters.
Returns (1)
Content

History 2

GetTriangleVertices

Parameters (1)
triangleIdint64
Returns (1)
Tuple
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

GetTriangles

Parameters (0)
No parameters.
Returns (1)
Array
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 3

Tags: [Deprecated]

GetVertexColor

Parameters (1)
vertexIdint64
Returns (1)
Color3
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

GetVertexColorAlpha

Parameters (1)
vertexIdint64
Returns (1)
float
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

GetVertexNormal

Parameters (1)
vertexIdint64
Returns (1)
Vector3
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

Raycast

Parameters (2)
originVector3
directionVector3
Returns (1)
Tuple

History 4

RemoveTriangle

Parameters (1)
triangleIdint64
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

RemoveVertex

Parameters (1)
vertexIdint64
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

SetVertexColor

Parameters (2)
vertexIdint64
colorColor3
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

SetVertexColorAlpha

Parameters (2)
vertexIdint64
alphafloat
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

SetVertexNormal

Parameters (2)
vertexIdint64
vnormalVector3
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

Tags: [Deprecated]

Settings