Class ProBuilderMesh
Represents the ProBuilder MeshFilter component, which is responsible for storing all the data necessary for editing and compiling Mesh objects.
Implements
Inherited Members
Namespace: UnityEngine.ProBuilder
Assembly: Unity.ProBuilder.dll
Syntax
[AddComponentMenu("//ProBuilder MeshFilter")]
[RequireComponent(typeof(MeshRenderer))]
[DisallowMultipleComponent]
[ExecuteInEditMode]
[ExcludeFromPreset]
[ExcludeFromObjectFactory]
public sealed class ProBuilderMesh : MonoBehaviour, ISerializationCallbackReceiver
Fields
Name | Description |
---|---|
maxVertexCount | The maximum number of vertices that a ProBuilderMesh can accomodate. |
Properties
Name | Description |
---|---|
colors | Gets or sets a collecton of the vertex colors for this mesh. When setting, the value must match the length of the positions. |
edgeCount | Gets the number of edges that compose this mesh. |
faceCount | Gets the number of faces that this mesh has. |
faces | Gets or sets the faces that ProBuilder uses to compile a mesh. Meshes are composed of vertices and faces. Faces primarily contain triangles and material information. |
indexCount | Gets the number of vertex indices that compose this mesh. |
meshSyncState | Gets a flag that indicates whether the Mesh is in sync with the ProBuilderMesh. |
normals | Gets the normals for this mesh. |
positions | Gets or sets the vertex positions that compose this mesh. |
preserveMeshAssetOnDestroy | Gets or sets whether to destroy the mesh asset if this ProBuilderMesh is deleted. In the Editor, when you delete a ProBuilderMesh you usually also want to destroy the mesh asset. However, there are situations you'd want to keep the mesh around, like when stripping ProBuilder scripts. |
selectable | Gets or sets whether elements can be selected. Used by UnityEditor.ProBuilder.ProBuilderEditor. |
selectedEdgeCount | Gets the number of selected edges. |
selectedEdges | Gets a collection of the currently selected edges. |
selectedFaceCount | Gets the number of faces that are currently selected on this object. |
selectedFaceIndexes | Gets a collection of the currently selected faces by their index in the faces array. |
selectedVertexCount | Gets the number of selected vertex indices. |
selectedVertices | Gets a collection of the currently selected vertices by their index in the positions array. |
sharedVertices | Gets or sets the sharedVertices for this ProBuilderMesh object. ProBuilder makes the assumption that no Face references a vertex used by another. However, ProBuilder needs to be able to associate vertices in the Editor for many operations. These vertices are usually called coincident, or "shared" vertices. ProBuilder manages these associations with the sharedIndexes array. Each array contains a list of triangles that points to vertices considered to be coincident. When ProBuilder compiles a Mesh from the ProBuilderMesh, it condenses these vertices to a single vertex where possible. |
tangents | Gets or sets the array of tangents that the user explicitly set for this mesh. |
textures | Gets or sets the UV0 channel. |
triangleCount | Gets the number of triangles that compose this mesh. |
unwrapParameters | UV2 generation parameters. |
userCollisions | If false, ProBuilder will automatically create and scale colliders. |
vertexCount | Gets the number of vertices in the positions array. |
Methods
Name | Description |
---|---|
Clear() | Resets (empties) all the attribute arrays on this object and clears any selected elements. The attribute arrays include faces, positions, texture UVs, tangents, shared vertices, shared textures, and vertex colors. |
ClearSelection() | Clears the arrays of selected faces, edges, and vertices. You don't need to call this when setting an individual array, as the setter methods handle updating the associated caches. |
CopyFrom(ProBuilderMesh) | Copies the mesh data from another mesh to this one. |
Create() | Creates a new GameObject with a ProBuilderMesh, MeshFilter, and MeshRenderer component but leaves the position and face information empty. |
Create(IEnumerable<Vector3>, IEnumerable<Face>) | Creates a new GameObject with a ProBuilderMesh, MeshFilter, and MeshRenderer component. Then it initializes the ProBuilderMesh with the specified sets of positions and faces. |
Create(IList<Vertex>, IList<Face>, IList<SharedVertex>, IList<SharedVertex>, IList<Material>) | Creates a new GameObject with a ProBuilderMesh, MeshFilter, and MeshRenderer component. Then it initializes the ProBuilderMesh with the specified sets of positions and faces, and if specified, coincident vertices, texture coordinates, and materials. |
GetCoincidentVertices(IEnumerable<int>) | Returns a list of vertices that are coincident to any of the specified vertices. |
GetCoincidentVertices(IEnumerable<int>, List<int>) | Populates a list of vertices that are coincident to any of the specified vertices. |
GetCoincidentVertices(IEnumerable<Edge>, List<int>) | Populates a list of vertices that are coincident to any of the specified vertices. |
GetCoincidentVertices(IEnumerable<Face>, List<int>) | Populates a list of vertices that are coincident to any of the specified vertices. |
GetCoincidentVertices(int, List<int>) | Populates a list with all the vertices that are coincident to the specified vertex. |
GetColors() | Returns the Color values from the mesh. |
GetNormals() | Gets the normals array for this mesh. |
GetSelectedFaces() | Returns a copy of the array of selected faces. |
GetTangents() | Returns the tangents applied to the mesh. If they haven't been initialized yet, it creates and caches them. |
GetUVs(int, List<Vector4>) | Copies values from the specified UV channel to the list of texture UVs. |
GetVertices(IList<int>) | Creates a new array of vertices with values from a ProBuilderMesh component. |
HasArrays(MeshArrays) | Tests whether the mesh contains the requested arrays. |
MakeUnique() | Ensures that the UnityEngine.Mesh associated with this object is unique. When instantiating a ProBuilderMesh, the mesh asset will reference the original instance. If you are making a copy to edit, you must call MakeUnique to avoid modifying a shared mesh asset. |
OnAfterDeserialize() | |
OnBeforeSerialize() | |
RebuildWithPositionsAndFaces(IEnumerable<Vector3>, IEnumerable<Face>) | Clears all mesh attributes and reinitializes the mesh with new positions and face collections. |
Refresh(RefreshMask) | Recalculates mesh attributes: normals, collisions, UVs, tangents, and colors. |
RefreshUV(IEnumerable<Face>) | Rebuilds the UV arrays on the specified faces. This usually applies only to faces set to use Auto UVs. However, if ProBuilder can't detect any valid UV arrays, it resets the faces from Manual to Auto before rebuilding them. |
SetFaceColor(Face, Color) | Applies a vertex color to the specified Face. |
SetMaterial(IEnumerable<Face>, Material) | Sets a specific material on a collection of faces. |
SetSelectedEdges(IEnumerable<Edge>) | Sets the edge selection for this mesh. Also sets the vertex selection to match and clears the selected faces. |
SetSelectedFaces(IEnumerable<Face>) | Sets the face selection for this mesh. Also sets the vertex and edge selection to match. |
SetSelectedVertices(IEnumerable<int>) | Sets the selected vertices array. Clears the selected faces and selected edges arrays. |
SetUVs(int, List<Vector4>) | Sets the mesh UVs per channel. Channels 0 and 1 are cast to Vector2, but channels 2 and 3 remain Vector4. |
SetVertices(IList<Vertex>, bool) | Sets the vertex element arrays on this mesh. |
SetVerticesCoincident(IEnumerable<int>) | Marks the specified vertices as coincident on this mesh. |
ToMesh(MeshTopology) | Rebuilds the mesh positions and submeshes. If the vertex count matches the new positions array, the existing attributes are kept (except for UV2s, which are always cleared). Otherwise, the mesh is cleared. |
Events
Name | Description |
---|---|
elementSelectionChanged | Invoked when the element selection changes on any ProBuilderMesh. |
meshWillBeDestroyed | Invoked when this ProBuilderMesh is deleted. In the Editor, when a ProBuilderMesh is destroyed it also destroys the sharedMesh that it finds with the parent GameObject. To override the default behavior, subscribe to onDestroyObject. When onDestroyObject has a subscriber, ProBuilder invokes it instead of cleaning up unused meshes by itself. |