改变锚点双向控制应该怎么做?
发布网友
发布时间:2022-05-18 20:22
我来回答
共1个回答
热心网友
时间:2023-10-30 23:01
模型软件中
模型-模型层次-轴调整改变到想要的位置,然后输出想要的模型格式
unity
创建空物体作为父物体,坐标(0,0,0),新建cube作为子物体(0.5,0.5,0.5),那么轴心如图示,就可以整体调用了。
代码设置
/// <summary>
/// 重置模型中心点
/// </summary>
[MenuItem("Tool/ResetCenterPosition")]
public static void ResetCenterPosition()
{
Transform transform = Selection.activeTransform;
Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
Vector3 center = Vector3.zero;
//获取物体Bound
foreach (var item in transform.GetComponentsInChildren<MeshRenderer>())
{
bounds.Encapsulate(item.bounds);
}
center = bounds.center;
//新建空物体,将原来中心点有问题的物体放置到该物体下作为子物体
GameObject obj = new GameObject();
obj.name = transform.name;
obj.transform.position = center;
obj.transform.rotation = Quaternion.identity;
//获取原物体在模型中的路径
string selectedObjPath = "";
Transform currentSelectTransform = transform;
while (currentSelectTransform.parent != null)
{
selectedObjPath = currentSelectTransform.parent.name + "/" + selected