动态导入模型后 动态创建Avatar骨骼映射
根据某位博主提供的思路动态创建Avatar时出现报错 hips not find
使用trilib预设的动态导入模型场景导入了一个有骨骼的模型
然后出现了报错
模型动态加载是没有错的
//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
public class Skeleton : MonoBehaviour
{
public static SkeletonBone[] CreateSkeleton(GameObject avatarRoot)
{
List<SkeletonBone> skeleton = new List<SkeletonBone>();
Transform[] avatarTransforms = avatarRoot.GetComponentsInChildren<Transform>();
foreach (Transform avatarTransform in avatarTransforms)
{
SkeletonBone bone = new SkeletonBone()
{
name = avatarTransform.name,
position = avatarTransform.localPosition,
rotation = avatarTransform.localRotation,
scale = avatarTransform.localScale
};
skeleton.Add(bone);
}
return skeleton.ToArray();
}
}
//这是动态创建Avatar的skeleton脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dictionary : MonoBehaviour
{
public static GameObject A;
public static Dictionary<string, string> HumanSkeletonMap = new Dictionary<string, string>()
{ {"00", "Hips" },
{"03", "Spine" },
{"06", "Chest"},
{"09", "UpperChest" },
{"13" ,"Shoulder"},
{"16" ,"UpperArm"},
{"18" ,"LowerArm"},
{"20" ,"Hand"},
{"14" ,"Shoulder"},
{"17" ,"UpperArm"},
{"19" ,"LowerArm"},
{"21" ,"Hand"},
{"01" ,"UpperLeg"},
{"04" ,"LowerLeg"},
{"07" ,"Foot"},
{"10" ,"Toes"},
{"02" ,"UpperLeg"},
{"05" ,"LowerLeg"},
{"08" ,"Foot"},
{"11" ,"Toes"},
{"12", "Neck" },
{"15", "Head" },
//{ "eye_EyeJoint_L", "LeftEye" },
//{ "eye_EyeJoint_R", "RightEye" },
//{ "mouth_JawJoint_M", "Jaw" },
//这里的映射关系是根据手动导入模型后 rig -create from this model 后形成的骨骼映射关系填写补充的

如图所示
};
public static HumanBone[] CreateHuman(GameObject avatarRoot)
{
List<HumanBone> human = new List<HumanBone>();
Transform[] avatarTransforms = avatarRoot.GetComponentsInChildren<Transform>();
foreach (Transform avatarTransform in avatarTransforms)
{
if (HumanSkeletonMap.TryGetValue(avatarTransform.name, out string humanName))
{
HumanBone bone = new HumanBone
{
boneName = avatarTransform.name,
humanName = humanName,
limit = new HumanLimit()
};
bone.limit.useDefaultValues = true;
//bone.Equals(human);
human.Add(bone);
}
}
return human.ToArray();
}
HumanDescription humanDescription = new HumanDescription()
{
armStretch = 0.05f,
feetSpacing = 0.0f,
hasTranslationDoF = false,
legStretch = 0.05f,
lowerArmTwist = 0.5f,
lowerLegTwist = 0.5f,
upperArmTwist = 0.5f,
upperLegTwist = 0.5f,
skeleton = Skeleton.CreateSkeleton(A),
human = CreateHuman(A),
};
public void createAvatarTest()
{
A = GameObject.Find("output");
//因为导入的模型名称为output,这里就简单用此获得模型
A.AddComponent<Animator>();
Avatar avatar = AvatarBuilder.BuildHumanAvatar(A, humanDescription);
Animator animator =A.GetComponent<Animator>();
animator.runtimeAnimatorController =
Resources.Load<RuntimeAnimatorController>("jump");
animator.avatar = avatar;
}//此方法用于测设动态创建一个avatar并为他添加animator组件,并加载Resources文件夹下的jump controller使得能够动态导入一个有骨骼的模型,再点击button调用这个方法后,模型能够jump起来
}
然后出现报错
//
```c#
```如果觉得便宜了,可以再商量
第一个错误信息应该是:
"Avatar creation failed: hips bone was not found in the model. Make sure your model has a 'hips' bone, or adjust the bone mapping accordingly."
这意味着在创建 Avatar 的过程中,系统没有找到模型中的"hips"骨骼。"hips"骨骼是用来定位角色根节点的骨骼,是非常重要的。
造成这个问题的原因可能是模型导入后,在骨骼映射上出现问题。您可以尝试以下步骤来解决问题:
确保模型中存在 "hips" 骨骼,如果没有请确保你的模型格式支持骨骼
检查 Unity 项目中骨骼映射设置是否正确,尤其是检查 "hips" 骨骼是否正确映射。
3.检查骨骼的轴向是否正确设置, 如果骨骼的轴向不是x轴方向,请确保将其设置为x轴方向。
4.尝试在模型导入时使用其他工具重新处理骨骼信息。
希望这些建议能帮助您解决问题。望采纳
在创建Avatar时,Unity需要通过模型的骨骼信息来构建人物的骨骼结构,如果缺少必要的骨骼信息,就会出现这种错误。
你可以尝试检查你动态加载的模型是否完整,是否包含所有必要的骨骼信息。如果模型有缺陷,你可以尝试使用3D建模软件修复它。
另外,你也可以尝试使用其他方法来加载模型,例如使用AssetBundle加载模型,或者使用动态加载方法加载模型。
这个报错大概率是创建骨骼映射的时候有问题,你看看这篇博文对你是否有帮助https://blog.csdn.net/Nbin_Newby/article/details/128045244
[12:11:10] AvatarBuilder 'Button': Required human bone 'Hips' not found
报错含义:
[12:11:10]AvatarBuilder“Button”:未找到所需的人体骨骼“Hips”
从报错上分析:有可能是模型本身的骨骼问题,你的模型的骨骼是不是缺少了Hips对应的那个关节点,或者命名不对?
这个错误发生在调用 Skeleton.CreateSkeleton 函数时,并且指向了 Skeleton.cs 第17行。另外这个错误发生在 Dictionary.cs 的第39行,也就是调用了 Start 函数。
为了更准确地解决问题,需要查看这两个文件的第17和第39行的代码,看看是否有未赋值的变量被使用了。
仅供参考,望采纳,谢谢。
在使用 Unity 的 Avatar 功能时,如果出现了 "hips not find" 的错误信息,可能是因为你的模型的骨骼结构不符合要求导致的。Avatar 的骨骼映射是基于人体骨骼结构的,如果你的模型的骨骼结构与人体不同,那么就可能会出现这个错误。
你可以尝试检查你的模型的骨骼结构,确保它与人体骨骼结构相似。你可以参考 Unity 官方文档中关于 Avatar 的要求,看看你的模型是否满足要求。你还可以尝试使用其他模型测试 Avatar 功能,看看是否存在相同的问题。
你好,根据你描述的问题,我猜测你在 Unity 中使用 trilib 动态导入了一个模型,然后使用了某位博主提供的思路动态创建 Avatar 时出现了错误:hips not find。
这个错误可能是由于你在创建 Avatar 时缺少了必要的骨骼对应信息导致的。在创建 Avatar 时,需要给它指定一个骨骼对应信息(HumanBone)列表,该列表包含了所有骨骼的名称和对应的 Transform。如果你没有提供这个列表或者列表中的某个骨骼的信息不正确,就可能出现这个错误。
为了解决这个问题,你可以尝试检查你的骨骼对应信息列表是否完整,并确保所有骨骼的名称和对应的 Transform 都是正确的。你也可以尝试使用 trilib 提供的 Avatar 构建工具来自动生成 Avatar,这样就不用手动创建 Avatar 了。
希望这些信息能帮到你。望采纳。
可能是因为在创建 Avatar 的过程中,Unity 找不到模型中的骨骼。你可以试试以下方法:
确保模型的骨骼层级结构正确。如果模型的骨骼层级结构不正确,例如有些骨骼没有被正确的连接到根骨骼(通常是 "hips"),也会导致创建 Avatar 失败。
确保模型的骨骼没有被破坏。如果模型的骨骼被损坏,例如有些骨骼没有被正确的连接到其他骨骼,也会导致创建 Avatar 失败。