@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Threading;
|
||||
using Unity.Profiling;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
@@ -10,6 +11,10 @@ namespace Dreamteck.Splines
|
||||
public class MeshGenerator : SplineUser
|
||||
{
|
||||
protected const int UNITY_16_VERTEX_LIMIT = 65535;
|
||||
private static readonly ProfilerMarker AllocateMeshMarker = new ProfilerMarker("Dreamteck.MeshGenerator.AllocateMesh");
|
||||
private static readonly ProfilerMarker BuildMarker = new ProfilerMarker("Dreamteck.MeshGenerator.Build");
|
||||
private static readonly ProfilerMarker BuildMeshMarker = new ProfilerMarker("Dreamteck.MeshGenerator.BuildMesh");
|
||||
private static readonly ProfilerMarker PostBuildMarker = new ProfilerMarker("Dreamteck.MeshGenerator.PostBuild");
|
||||
|
||||
public float size
|
||||
{
|
||||
@@ -439,26 +444,35 @@ namespace Dreamteck.Splines
|
||||
|
||||
protected override void Build()
|
||||
{
|
||||
base.Build();
|
||||
if (_tsMesh == null || _mesh == null)
|
||||
using (BuildMarker.Auto())
|
||||
{
|
||||
CreateMesh();
|
||||
}
|
||||
base.Build();
|
||||
if (_tsMesh == null || _mesh == null)
|
||||
{
|
||||
CreateMesh();
|
||||
}
|
||||
|
||||
if (sampleCount > 1)
|
||||
{
|
||||
BuildMesh();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearMesh();
|
||||
if (sampleCount > 1)
|
||||
{
|
||||
using (BuildMeshMarker.Auto())
|
||||
{
|
||||
BuildMesh();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearMesh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PostBuild()
|
||||
{
|
||||
base.PostBuild();
|
||||
WriteMesh();
|
||||
using (PostBuildMarker.Auto())
|
||||
{
|
||||
base.PostBuild();
|
||||
WriteMesh();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ClearMesh()
|
||||
@@ -518,30 +532,33 @@ namespace Dreamteck.Splines
|
||||
|
||||
protected virtual void AllocateMesh(int vertexCount, int trisCount)
|
||||
{
|
||||
if (trisCount < 0)
|
||||
using (AllocateMeshMarker.Auto())
|
||||
{
|
||||
trisCount = 0;
|
||||
}
|
||||
if (vertexCount < 0)
|
||||
{
|
||||
vertexCount = 0;
|
||||
}
|
||||
if (_doubleSided)
|
||||
{
|
||||
vertexCount *= 2;
|
||||
trisCount *= 2;
|
||||
}
|
||||
if (_tsMesh.vertexCount != vertexCount)
|
||||
{
|
||||
_tsMesh.vertices = new Vector3[vertexCount];
|
||||
_tsMesh.normals = new Vector3[vertexCount];
|
||||
_tsMesh.tangents = new Vector4[vertexCount];
|
||||
_tsMesh.colors = new Color[vertexCount];
|
||||
_tsMesh.uv = new Vector2[vertexCount];
|
||||
}
|
||||
if (_tsMesh.triangles.Length != trisCount)
|
||||
{
|
||||
_tsMesh.triangles = new int[trisCount];
|
||||
if (trisCount < 0)
|
||||
{
|
||||
trisCount = 0;
|
||||
}
|
||||
if (vertexCount < 0)
|
||||
{
|
||||
vertexCount = 0;
|
||||
}
|
||||
if (_doubleSided)
|
||||
{
|
||||
vertexCount *= 2;
|
||||
trisCount *= 2;
|
||||
}
|
||||
if (_tsMesh.vertexCount != vertexCount)
|
||||
{
|
||||
_tsMesh.vertices = new Vector3[vertexCount];
|
||||
_tsMesh.normals = new Vector3[vertexCount];
|
||||
_tsMesh.tangents = new Vector4[vertexCount];
|
||||
_tsMesh.colors = new Color[vertexCount];
|
||||
_tsMesh.uv = new Vector2[vertexCount];
|
||||
}
|
||||
if (_tsMesh.triangles.Length != trisCount)
|
||||
{
|
||||
_tsMesh.triangles = new int[trisCount];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user