Mesh.GetBonesPerVertex

切换到手册
public NativeArray<byte> GetBonesPerVertex ();

返回

NativeArray<byte> 返回每个顶点的非零骨骼权重数量。

描述

每个顶点的非零骨骼权重数量。

返回数组的大小为 Mesh.vertexCount 或 0。此数组按顶点索引顺序进行排序。

Mesh.GetAllBoneWeights 结合使用来获取网格中顶点的骨骼权重。

另请参阅:Mesh.GetAllBoneWeightsMesh.SetBoneWeightsModelImporter.maxBonesPerVertexQualitySettings.skinWeightsSkinnedMeshRenderer.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++; } } } }