Unity 自动计算所有物体包围盒的中心点
来源:互联网 发布:网络110报警平台官网 编辑:程序博客网 时间:2024/05/22 16:56
美术在做场景的时候可能会出现这个情况? 如下图所示,这个地块的中心点远离模型十万八千里?与其相信美术或者策划我觉得程序要更相信自己!!
[MenuItem ("MyMenu/Do Test")]static void Test () {Transform parent = Selection.activeGameObject.transform;Vector3 postion = parent.position;Quaternion rotation = parent.rotation;Vector3 scale = parent.localScale;parent.position = Vector3.zero;parent.rotation = Quaternion.Euler(Vector3.zero);parent.localScale = Vector3.one; Vector3 center = Vector3.zero;Renderer[] renders = parent.GetComponentsInChildren<Renderer>();foreach (Renderer child in renders){center += child.bounds.center; }center /= parent.GetComponentsInChildren<Transform>().Length; Bounds bounds = new Bounds(center,Vector3.zero);foreach (Renderer child in renders){bounds.Encapsulate(child.bounds); }parent.position = postion;parent.rotation = rotation;parent.localScale = scale; foreach(Transform t in parent){t.position = t.position - bounds.center;}parent.transform.position = bounds.center + parent.position; }
OK 大功告成。 中心点居中了。。
0 0
- Unity 自动计算所有物体包围盒的中心点
- unity计算多个物体的的中心点
- 在Hololens创建可编辑物体的第一步:包围盒计算
- 【unity学习】包围盒的自适应
- Torquescript学习笔记:画物体的包围盒
- unity获取物体下的所有子物体
- unity 找到当前物体下的所有物体
- 包围球的计算
- 求取多边形矩形包围框的中心点方法
- untiy3d修改物体的中心点坐标
- 在Unity中获得一个物体的所有子物体包括孙物体。
- 获得当前图形中所有实体的最小包围盒
- 计算多个点的中心点坐标
- unity中如何获取所有子物体的组件
- 控制unity对象下所有子物体的显示状态
- unity 动态改变所有子物体的shader
- 使用EmguCv计算包围物体的最小圆与最小可旋转矩形和不可选择矩形
- 计算获取Unity物体下面的地面的坐标点
- jvm参数详解
- Python使用struct处理二进制
- linux复习
- 使用Selector时增加渐入渐出动画效果
- 《javascript pattern》— javascript的继承
- Unity 自动计算所有物体包围盒的中心点
- ubuntu创建用户命令
- 添加真机调试版本
- Vuejs的学习笔记1---------响应式原理
- 57.Python项目在Jenkins中的自动化测试实践
- Android BroadcastReceiver
- Unexpected resin.home mismatch
- MYSQL中设置的索引不起作用
- QT调用DLL库小结