Mesh.GetBonesPerVertex

매뉴얼로 전환
public NativeArray<byte> GetBonesPerVertex ();

반환

NativeArray<byte> Returns the number of non-zero bone weights for each vertex.

설명

The number of non-zero bone weights for each vertex.

The size of the returned array is either Mesh.vertexCount or zero. The array is sorted in vertex index order.

Use in combination with Mesh.GetAllBoneWeights to get bone weights for the vertices in the Mesh.

See Also: Mesh.GetAllBoneWeights, Mesh.SetBoneWeights, 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++; } } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961