@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -416,6 +416,11 @@ namespace Dreamteck.Splines
|
||||
}
|
||||
}
|
||||
|
||||
public void RunManualUpdate(bool immediate = false)
|
||||
{
|
||||
RunUpdate(immediate);
|
||||
}
|
||||
|
||||
private void RunUpdate(bool immediate = false)
|
||||
{
|
||||
bool transformChanged = ResampleTransformIfNeeded();
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
using UnityEngine;
|
||||
using Unity.Profiling;
|
||||
|
||||
namespace Dreamteck.Splines {
|
||||
[ExecuteInEditMode]
|
||||
public class SplineUser : MonoBehaviour, ISerializationCallbackReceiver, ISampleModifier
|
||||
{
|
||||
private static readonly ProfilerMarker RebuildImmediateMarker = new ProfilerMarker("Dreamteck.SplineUser.RebuildImmediate");
|
||||
private static readonly ProfilerMarker RebuildGetSamplesMarker = new ProfilerMarker("Dreamteck.SplineUser.RebuildImmediate.GetSamples");
|
||||
private static readonly ProfilerMarker RebuildBuildMarker = new ProfilerMarker("Dreamteck.SplineUser.RebuildImmediate.Build");
|
||||
private static readonly ProfilerMarker RebuildPostBuildMarker = new ProfilerMarker("Dreamteck.SplineUser.RebuildImmediate.PostBuild");
|
||||
|
||||
public enum UpdateMethod { Update, FixedUpdate, LateUpdate }
|
||||
[HideInInspector]
|
||||
public UpdateMethod updateMethod = UpdateMethod.Update;
|
||||
@@ -468,24 +474,38 @@ namespace Dreamteck.Splines {
|
||||
/// <param name="sampleComputer">Should the SplineUser sample the SplineComputer</param>
|
||||
public virtual void RebuildImmediate()
|
||||
{
|
||||
using (RebuildImmediateMarker.Auto())
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!_hasTransform)
|
||||
{
|
||||
CacheTransform();
|
||||
}
|
||||
if (!_hasTransform)
|
||||
{
|
||||
CacheTransform();
|
||||
}
|
||||
#endif
|
||||
try
|
||||
{
|
||||
GetSamples();
|
||||
Build();
|
||||
PostBuild();
|
||||
try
|
||||
{
|
||||
using (RebuildGetSamplesMarker.Auto())
|
||||
{
|
||||
GetSamples();
|
||||
}
|
||||
|
||||
using (RebuildBuildMarker.Auto())
|
||||
{
|
||||
Build();
|
||||
}
|
||||
|
||||
using (RebuildPostBuildMarker.Auto())
|
||||
{
|
||||
PostBuild();
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogError(ex.Message);
|
||||
}
|
||||
rebuild = false;
|
||||
getSamples = false;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogError(ex.Message);
|
||||
}
|
||||
rebuild = false;
|
||||
getSamples = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -516,6 +536,13 @@ namespace Dreamteck.Splines {
|
||||
#endif
|
||||
}
|
||||
|
||||
public void RunManualUpdate()
|
||||
{
|
||||
Run();
|
||||
RunUpdate();
|
||||
LateRun();
|
||||
}
|
||||
|
||||
/*private void FixedUpdate()
|
||||
{
|
||||
if (updateMethod == UpdateMethod.FixedUpdate)
|
||||
|
||||
@@ -3,9 +3,12 @@ namespace Dreamteck
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Profiling;
|
||||
//Thread-safe mesh & bounds classes for working with threads.
|
||||
public class TS_Mesh
|
||||
{
|
||||
private static readonly ProfilerMarker WriteMeshMarker = new ProfilerMarker("Dreamteck.TS_Mesh.WriteMesh");
|
||||
|
||||
public int vertexCount
|
||||
{
|
||||
get { return vertices.Length; }
|
||||
@@ -365,28 +368,31 @@ namespace Dreamteck
|
||||
|
||||
public void WriteMesh(ref Mesh input)
|
||||
{
|
||||
if (input == null) input = new Mesh();
|
||||
input.Clear();
|
||||
input.indexFormat = indexFormat;
|
||||
input.vertices = vertices;
|
||||
input.normals = normals;
|
||||
if (tangents.Length == vertices.Length) input.tangents = tangents;
|
||||
if (colors.Length == vertices.Length) input.colors = colors;
|
||||
if (uv.Length == vertices.Length) input.uv = uv;
|
||||
if (uv2.Length == vertices.Length) input.uv2 = uv2;
|
||||
if (uv3.Length == vertices.Length) input.uv3 = uv3;
|
||||
if (uv4.Length == vertices.Length) input.uv4 = uv4;
|
||||
input.triangles = triangles;
|
||||
if (subMeshes.Count > 0)
|
||||
using (WriteMeshMarker.Auto())
|
||||
{
|
||||
input.subMeshCount = subMeshes.Count;
|
||||
for (int i = 0; i < subMeshes.Count; i++)
|
||||
if (input == null) input = new Mesh();
|
||||
input.Clear();
|
||||
input.indexFormat = indexFormat;
|
||||
input.vertices = vertices;
|
||||
input.normals = normals;
|
||||
if (tangents.Length == vertices.Length) input.tangents = tangents;
|
||||
if (colors.Length == vertices.Length) input.colors = colors;
|
||||
if (uv.Length == vertices.Length) input.uv = uv;
|
||||
if (uv2.Length == vertices.Length) input.uv2 = uv2;
|
||||
if (uv3.Length == vertices.Length) input.uv3 = uv3;
|
||||
if (uv4.Length == vertices.Length) input.uv4 = uv4;
|
||||
input.triangles = triangles;
|
||||
if (subMeshes.Count > 0)
|
||||
{
|
||||
input.SetTriangles(subMeshes[i], i);
|
||||
input.subMeshCount = subMeshes.Count;
|
||||
for (int i = 0; i < subMeshes.Count; i++)
|
||||
{
|
||||
input.SetTriangles(subMeshes[i], i);
|
||||
}
|
||||
}
|
||||
input.RecalculateBounds();
|
||||
hasUpdate = false;
|
||||
}
|
||||
input.RecalculateBounds();
|
||||
hasUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user