ue4 动态创建meshh,为什么会提示有内存泄漏

&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!2463人阅读
Unity3D(129)
using UnityE
using System.C
/* ==============================================================================
* 功能描述:测试Mesh创建
* 创 建 者:cjunhong
* 创建日期: 11:23:58
* ==============================================================================*/
[RequireComponent(typeof(MeshRenderer), typeof(MeshFilter))]
public class TestMesh : MonoBehaviour {
public float radius = 2;
public float angleDegree = 100;
public int segments = 10;
public int angleDegreePrecision = 1000;
public int radiusPrecision = 1000;
private MeshFilter meshF
private SectorMeshCreator creator = new SectorMeshCreator();
[ExecuteInEditMode]
private void Awake()
meshFilter = GetComponent&MeshFilter&();
private void Update()
meshFilter.mesh = creator.CreateMesh(radius, angleDegree, segments, angleDegreePrecision, radiusPrecision);
void OnDrawGizmos()
Gizmos.color = Color.
DrawMesh();
void OnDrawGizmosSelected()
Gizmos.color = Color.
DrawMesh();
private void DrawMesh()
Mesh mesh = creator.CreateMesh(radius, angleDegree, segments, angleDegreePrecision, radiusPrecision);
int[] tris = mesh.
for (int i = 0; i & tris.L i+=3)
Gizmos.DrawLine(convert2World(mesh.vertices[tris[i]]), convert2World(mesh.vertices[tris[i + 1]]));
Gizmos.DrawLine(convert2World(mesh.vertices[tris[i]]), convert2World(mesh.vertices[tris[i + 2]]));
Gizmos.DrawLine(convert2World(mesh.vertices[tris[i+1]]), convert2World(mesh.vertices[tris[i + 2]]));
private Vector3 convert2World(Vector3 src)
return transform.TransformPoint(src);
private class SectorMeshCreator
private float angleD
private Mesh cacheM
/// &summary&
/// 创建一个扇形Mesh
/// &/summary&
/// &param name=&radius&&扇形半价&/param&
/// &param name=&angleDegree&&扇形角度&/param&
/// &param name=&segments&&扇形弧线分段数&/param&
/// &param name=&angleDegreePrecision&&扇形角度精度(在满足精度范围内,认为是同个角度)&/param&
/// &param name=&radiusPrecision&&
/// 扇形半价精度(在满足半价精度范围内,被认为是同个半价)。
/// 比如:半价精度为1000,则:1.001和1.002不被认为是同个半径。因为放大1000倍之后不相等。
/// 如果半价精度设置为100,则1.001和1.002可认为是相等的。
/// &/pre&
/// &/param&
/// &returns&&/returns&
public Mesh CreateMesh(float radius, float angleDegree, int segments, int angleDegreePrecision, int radiusPrecision)
if (checkDiff(radius, angleDegree, segments, angleDegreePrecision, radiusPrecision))
Mesh newMesh = Create(radius, angleDegree, segments);
if (newMesh != null)
cacheMesh = newM
this.radius =
this.angleDegree = angleD
this.segments =
return cacheM
private Mesh Create(float radius, float angleDegree, int segments)
if (segments == 0)
segments = 1;
#if UNITY_EDITOR
Debug.Log(&segments must be larger than zero.&);
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[3 + segments - 1];
vertices[0] = new Vector3(0, 0, 0);
float angle = Mathf.Deg2Rad * angleD
float currAngle = angle / 2;
float deltaAngle = angle /
for (int i = 1; i & vertices.L i++)
vertices[i] = new Vector3(Mathf.Cos(currAngle) * radius, 0, Mathf.Sin(currAngle) * radius);
currAngle -= deltaA
int[] triangles = new int[segments * 3];
for (int i = 0, vi = 1; i & triangles.L i += 3, vi++)
triangles[i] = 0;
triangles[i + 1] =
triangles[i + 2] = vi + 1;
mesh.vertices =
mesh.triangles =
Vector2[] uvs = new Vector2[vertices.Length];
for (int i = 0; i & uvs.L i++)
uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
private bool checkDiff(float radius, float angleDegree, int segments, int angleDegreePrecision, int radiusPrecision)
return segments != this.segments || (int)((angleDegree - this.angleDegree) * angleDegreePrecision) != 0 ||
(int)((radius - this.radius) * radiusPrecision) != 0;
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:740393次
积分:8254
积分:8254
排名:第1787名
原创:100篇
转载:85篇
评论:294条
(2)(2)(16)(2)(1)(2)(1)(1)(7)(10)(2)(8)(4)(7)(2)(8)(6)(3)(1)(3)(11)(9)(8)(21)(5)(11)(12)(4)(14)(12)创建mesh范例_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
创建mesh范例
上传于||暂无简介
你可能喜欢蓝牙技术联盟几个月前公布2016年蓝牙(Bluetooth(R))技术路线图时,引起了业内的广泛关注。路线图中有了更广的传播距离、更快的速度和Mesh联网功能,就能给诸多垂直领域带来完全的改观,包括智能家居、工业自动化、基于位置的服务和智能基础设施等。&Mesh联网功能无疑是最热的话题。蓝牙技术联盟开发计划总监何根飞先生最近,探讨了蓝牙技术和Mesh联网功能能够为智能家居产业带来的生机。&也表示,“Mesh技术被认为是诸多物联网应用的关键,尤其对于那些需要更长通信距离或点对点通信的应用。”Yoshida还解释了蓝牙技术联盟如何建立了Mesh工作组,为广泛的业内应用建立标准的配置文件。在文章中,针对产业为何如此迫切地需要添加Mesh的提问,蓝牙技术联盟市场副总裁柯瑞德(ErrettKroeter)回答道:“有些应用需要较好的覆盖,如扩展至整个建筑物。中央枢纽对于有些应用可能并不适用,用户希望信息在没有中枢设备的条件下也能自如地传输。”&智能家居中的Mesh技术&的报道中将蓝牙称为互联家居中的备用技术。“Mesh网络为智能家居产品也带来了希望。它无需通过一个控制中继路由一切设备,而是构建了一个去中心化的设备系统”&&近期的一篇文章也探索了带有低功耗蓝牙技术的Mesh功能缘何被越来越多的人看作是其他居家联网技术的替代物,如其他短距离无线技术。&作者深入审视了在智能家居和工业自动化应用中利用带有低功耗蓝牙技术的Mesh功能的优势。文章解释说,最为重要的一个方面是其普遍支持智能手机、平板电脑、笔记本电脑等消费者既有的设备。这意味着智能家居的设备与设备间的控制已经整装待发,而且兼具低成本及易于部署等特点。在今年晚些配置文件发布之前,人们会继续探索Mesh和蓝牙作为物联网主要推进者的优势,相关讨论也会持续进行。我们视Mesh为完完全全的行业游戏规则颠覆者,它让诸多垂直领域内的不同产品能够互操作、协同工作。我们会持续通过和为您带来有关Mesh的更多最新资讯。&&更多中文文章,请造访蓝牙开发者门户网站。蓝牙技术联盟(gh_d) 
 文章为作者独立观点,不代表大不六文章网立场
gh_d欢迎访问蓝牙技术联盟服务号。
蓝牙无线技术是一项全球通用的无线标准,它为越来越多的设备赋予了简便、安全的连接,同时也是互联世界的主要技术之一。热门文章最新文章gh_d欢迎访问蓝牙技术联盟服务号。
蓝牙无线技术是一项全球通用的无线标准,它为越来越多的设备赋予了简便、安全的连接,同时也是互联世界的主要技术之一。

我要回帖

更多关于 unity3d 创建mesh 的文章

 

随机推荐