Mesh.GetAllBoneWeights

Switch to Manual
public NativeArray<BoneWeight1> GetAllBoneWeights ();

Returns

NativeArray<BoneWeight1> Returns all non-zero bone weights for the Mesh, in vertex index order.

Description

Gets the bone weights for the Mesh.

Within each BoneWeight1 struct in the array, the weights are in descending order and add up to 1.

Use Mesh.GetBonesPerVertex to get the number of non-zero weights for each vertex, and then use that to iterate over this data.

See Also: Mesh.SetBoneWeights, Mesh.GetBonesPerVertex, Mesh.boneWeights, Mesh.GetBoneWeights ModelImporter.maxBonesPerVertex, QualitySettings.skinWeights, SkinnedMeshRenderer.quality.

using UnityEngine;
using Unity.Collections;

public class SkinnedMeshExample : MonoBehaviour { void Start() { // Get a reference to the mesh var skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>(); var mesh = skinnedMeshRenderer.sharedMesh;

// Get the number of bone weights per vertex var bonesPerVertex = mesh.GetBonesPerVertex();

// Get all the bone weights, in vertex index order var boneWeights = mesh.GetAllBoneWeights();

// Keep track of where we are in the array of bones, as we iterate over the vertices var bonesIndex = 0;

// Iterate over the vertices for (var vertIndex = 0; vertIndex < mesh.vertexCount; vertIndex++) { var numberOfBonesForThisVertex = bonesPerVertex[vertIndex]; Debug.Log("This vertex has " + numberOfBonesForThisVertex + " bones");

// For each vertex, iterate over the array of bones the correct number of times for (var i = 0; i < numberOfBonesForThisVertex; i++) { var currentBoneWeight = boneWeights[bonesIndex]; Debug.Log("Bone weight " + currentBoneWeight.boneIndex + " == " + currentBoneWeight.weight); bonesIndex++; } } } }