当前位置:网站首页>Unity3d 模型中心点的转换(源代码)
Unity3d 模型中心点的转换(源代码)
2022-07-17 13:31:00 【范小多】
我们在使用Unity3d模型时,从3DS导出的模型可能中心点不在轴对称点,需要重新在3DS编辑后导出,很不方便。用以下代码可直接在Unity3d中转换 中心点。

将下面代码拷贝 到你工程后边即可,Unity3d->tools-MyTool 点击重新设置即可
public class MyTool : ScriptableObject
{
//重置模型的轴心为中心
[MenuItem("Tools/MyTool/ResetPivot")]
static void ResetPivot()
{
//获取选中的物体
GameObject target = Selection.activeGameObject;
string dialogTitle = "Tools/MyTool/ResetPivot";
if (target == null)
{
EditorUtility.DisplayDialog(dialogTitle, "没有选中需要重置轴心的物体!!!", "确定");
return;
}
//获取目标物体下所有网格渲染
MeshRenderer[] meshRenderers = target.GetComponentsInChildren<MeshRenderer>(true);
if (meshRenderers.Length == 0)
{
EditorUtility.DisplayDialog(dialogTitle, "选中的物体不是有效模型物体!!!", "确定");
return;
}
//将所有的网格渲染的边界进行合并
Bounds centerBounds = meshRenderers[0].bounds;
for (int i = 1; i < meshRenderers.Length; i++)
{
centerBounds.Encapsulate(meshRenderers[i].bounds);
}
//创建目标的父物体
Transform targetParent = new GameObject(target.name + "-Parent").transform;
//如果目标原来已有父物体,则将创建目标父物体的父物体设为原父物体;
Transform originalParent = target.transform.parent;
if (originalParent != null)
{
targetParent.SetParent(originalParent);
}
//设置目标父物体的位置为合并后的网格渲染边界中心
targetParent.position = centerBounds.center;
//设置目标物体的父物体
target.transform.parent = targetParent;
Selection.activeGameObject = targetParent.gameObject;
EditorUtility.DisplayDialog(dialogTitle, "重置模型物体的轴心完成!", "确定");
}
}
边栏推荐
- LeetCode 2331. 计算布尔二叉树的值(树的遍历)
- Mobile keyboard (simulation question)
- 发明闪存能赚多少钱?这是一个日本的狗血故事
- High number_ Chapter 1 space analytic geometry and vector algebra__ Distance from point to plane
- 【手写数字识别】基于Lenet网络实现手写数字识别附matlab代码
- Vérification logique complexe personnalisée lors de l'ajout et de la modification - 2022 nouvel élément
- 论文笔记:Mind the Gap An Experimental Evaluation of Imputation ofMissing Values Techniques in TimeSeries
- Pytorch手动实现多层感知机
- 人大、微软等提出InclusiveFL:异构设备上的包容性联邦学习
- 从预测到决策,九章云极DataCanvas推出YLearn因果学习开源项目
猜你喜欢

Beego框架实现文件上传+七牛云存储

LeetCode 2335. Minimum total time required to fill the cup

Opencv programming: opencv3 X trains its own classifier

LeetCode 2319. 判断矩阵是否是一个 X 矩阵

SVN学习

LeetCode 2315. Statistical asterisk (string)

High number_ Chapter 1 space analytic geometry and vector algebra__ Distance from point to plane

LeetCode 2331. 计算布尔二叉树的值(树的遍历)

Beego framework realizes file upload + seven cattle cloud storage

Find balanced binary tree
随机推荐
Know what it is, and know why, JS object creation and inheritance
unity3d中的旋转
[LeetCode周赛复盘] 第 302 场周赛20220717
Pytoch framework learning record 1 cifar-10 classification
(一)了解MySQL
Input number pure digital input limit length limit maximum value
[Acwing]第 60 场周赛 B- 4495. 数组操作
军品研制过程所需文件-进阶版
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(下)
Find balanced binary tree
Take a look at this ugly face | MathWorks account unavailable - technical issue
【设计过程】.NET ORM FreeSql WhereDynamicFilter 动态表格查询功能
Pytorch与权重衰减(L2范数)
JSP based novel writing and creation website
2022/7/16
Prospect of 6G global convergence network
Redis集群、一主二从三哨兵的搭建
连通图(并查集)
反向散射通信的未来应用与技术挑战
基于网络编码的卫星网络容量提升方法