优化
This commit is contained in:
@@ -68,7 +68,7 @@ namespace Dreamteck.Splines
|
||||
{
|
||||
float last = _spline.knotParametrization;
|
||||
_spline.knotParametrization = value;
|
||||
if(last != _spline.knotParametrization)
|
||||
if (last != _spline.knotParametrization)
|
||||
{
|
||||
Rebuild(true);
|
||||
}
|
||||
@@ -217,7 +217,7 @@ namespace Dreamteck.Splines
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public SplineSample this [int index]
|
||||
public SplineSample this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -239,7 +239,8 @@ namespace Dreamteck.Splines
|
||||
/// </summary>
|
||||
public Vector3 position
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!_editorIsPlaying) return transform.position;
|
||||
#endif
|
||||
@@ -251,7 +252,8 @@ namespace Dreamteck.Splines
|
||||
/// </summary>
|
||||
public Quaternion rotation
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!_editorIsPlaying) return transform.rotation;
|
||||
#endif
|
||||
@@ -263,7 +265,8 @@ namespace Dreamteck.Splines
|
||||
/// </summary>
|
||||
public Vector3 scale
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!_editorIsPlaying) return transform.lossyScale;
|
||||
#endif
|
||||
@@ -419,7 +422,7 @@ namespace Dreamteck.Splines
|
||||
private void RunUpdate(bool immediate = false)
|
||||
{
|
||||
bool transformChanged = ResampleTransformIfNeeded();
|
||||
if(_sampleCollection.samples.Length != _rawSamples.Length)
|
||||
if (_sampleCollection.samples.Length != _rawSamples.Length)
|
||||
{
|
||||
transformChanged = true;
|
||||
}
|
||||
@@ -440,7 +443,8 @@ namespace Dreamteck.Splines
|
||||
if (transformChanged)
|
||||
{
|
||||
SplineThreading.Run(CalculateWithoutTransform);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
SplineThreading.Run(CalculateWithTransform);
|
||||
}
|
||||
@@ -732,7 +736,7 @@ namespace Dreamteck.Splines
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
SplinePoint newPoint = points[i];
|
||||
if(_spline.points.Length > i)
|
||||
if (_spline.points.Length > i)
|
||||
{
|
||||
newPoint.isDirty = _spline.points[i].isDirty;
|
||||
}
|
||||
@@ -966,7 +970,7 @@ namespace Dreamteck.Splines
|
||||
if (_originalSamplePercents[i] < percent)
|
||||
{
|
||||
double inverseLerp = DMath.InverseLerp(_originalSamplePercents[i], _originalSamplePercents[i + 1], percent);
|
||||
return DMath.Lerp(_rawSamples[i].percent, _rawSamples[i+1].percent, inverseLerp);
|
||||
return DMath.Lerp(_rawSamples[i].percent, _rawSamples[i + 1].percent, inverseLerp);
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
@@ -1098,7 +1102,8 @@ namespace Dreamteck.Splines
|
||||
{
|
||||
_spline.Evaluate(percent, ref result);
|
||||
TransformSample(ref result);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateSampleCollection();
|
||||
_sampleCollection.Evaluate(percent, ref result);
|
||||
@@ -1446,7 +1451,8 @@ namespace Dreamteck.Splines
|
||||
if (_sampleMode == SampleMode.Optimized && _rawSamples.Length > 2)
|
||||
{
|
||||
OptimizeSamples(_space == Space.Local);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < _rawSamples.Length; i++)
|
||||
{
|
||||
@@ -1468,7 +1474,7 @@ namespace Dreamteck.Splines
|
||||
int from = currentPoint - 1;
|
||||
int to = currentPoint + 2;
|
||||
|
||||
if(_spline.type == Spline.Type.Bezier || _spline.type == Spline.Type.Linear)
|
||||
if (_spline.type == Spline.Type.Bezier || _spline.type == Spline.Type.Linear)
|
||||
{
|
||||
from = currentPoint;
|
||||
to = currentPoint + 1;
|
||||
@@ -1487,7 +1493,7 @@ namespace Dreamteck.Splines
|
||||
|
||||
if (_spline.isClosed)
|
||||
{
|
||||
if(from < 0)
|
||||
if (from < 0)
|
||||
{
|
||||
for (int i = from + _spline.points.Length; i < _spline.points.Length; i++)
|
||||
{
|
||||
@@ -1498,7 +1504,7 @@ namespace Dreamteck.Splines
|
||||
}
|
||||
}
|
||||
|
||||
if(to >= _spline.points.Length)
|
||||
if (to >= _spline.points.Length)
|
||||
{
|
||||
for (int i = 0; i <= to - _spline.points.Length; i++)
|
||||
{
|
||||
@@ -1519,7 +1525,7 @@ namespace Dreamteck.Splines
|
||||
}
|
||||
double currentPointPercent = (double)currentPoint / count;
|
||||
|
||||
if(Mathf.Abs((float)(currentPointPercent - percent)) <= 0.00001f)
|
||||
if (Mathf.Abs((float)(currentPointPercent - percent)) <= 0.00001f)
|
||||
{
|
||||
return _spline.points[currentPoint - 1].isDirty;
|
||||
}
|
||||
@@ -1557,14 +1563,16 @@ namespace Dreamteck.Splines
|
||||
{
|
||||
if (!_spline.isClosed)
|
||||
{
|
||||
if(_spline.points.Length >= 3)
|
||||
if (_spline.points.Length >= 3)
|
||||
{
|
||||
_spline.Close();
|
||||
SetAllDirty();
|
||||
Rebuild();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Spline " + name + " needs at least 3 points before it can be closed. Current points: " + _spline.points.Length);
|
||||
this.name = "Error:Spline " + name + " needs at least 3 points before it can be closed.";
|
||||
//Debug.LogError("Spline " + name + " needs at least 3 points before it can be closed. Current points: " + _spline.points.Length);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1591,7 +1599,7 @@ namespace Dreamteck.Splines
|
||||
/// <param name="hitTriggers">Should hit triggers? (not supported in 5.1)</param>
|
||||
/// <param name="address">Node address of junctions</param>
|
||||
/// <returns></returns>
|
||||
public bool Raycast(out RaycastHit hit, out double hitPercent, LayerMask layerMask, double resolution = 1.0, double from = 0.0, double to = 1.0 , QueryTriggerInteraction hitTriggers = QueryTriggerInteraction.UseGlobal)
|
||||
public bool Raycast(out RaycastHit hit, out double hitPercent, LayerMask layerMask, double resolution = 1.0, double from = 0.0, double to = 1.0, QueryTriggerInteraction hitTriggers = QueryTriggerInteraction.UseGlobal)
|
||||
{
|
||||
resolution = DMath.Clamp01(resolution);
|
||||
Spline.FormatFromTo(ref from, ref to, false);
|
||||
@@ -1680,7 +1688,7 @@ namespace Dreamteck.Splines
|
||||
|
||||
public void RemoveTrigger(int triggerGroup, int triggerIndex)
|
||||
{
|
||||
if(triggerGroups.Length <= triggerGroup || triggerGroup < 0)
|
||||
if (triggerGroups.Length <= triggerGroup || triggerGroup < 0)
|
||||
{
|
||||
Debug.LogError("Cannot delete trigger - trigger group " + triggerIndex + " does not exist");
|
||||
return;
|
||||
@@ -1733,7 +1741,7 @@ namespace Dreamteck.Splines
|
||||
{
|
||||
for (int i = 0; i < _nodes.Length; i++)
|
||||
{
|
||||
if(_nodes[i].pointIndex == pointIndex) return _nodes[i].GetConnections(this);
|
||||
if (_nodes[i].pointIndex == pointIndex) return _nodes[i].GetConnections(this);
|
||||
}
|
||||
return new List<Node.Connection>();
|
||||
}
|
||||
@@ -1862,7 +1870,7 @@ namespace Dreamteck.Splines
|
||||
|
||||
public void TransferNode(int pointIndex, int newPointIndex)
|
||||
{
|
||||
if(newPointIndex < 0 || newPointIndex >= _spline.points.Length)
|
||||
if (newPointIndex < 0 || newPointIndex >= _spline.points.Length)
|
||||
{
|
||||
Debug.LogError("Invalid new point index " + newPointIndex);
|
||||
return;
|
||||
@@ -1873,7 +1881,7 @@ namespace Dreamteck.Splines
|
||||
return;
|
||||
}
|
||||
Node node = GetNode(pointIndex);
|
||||
if(node == null)
|
||||
if (node == null)
|
||||
{
|
||||
Debug.LogError("No node connected to point " + pointIndex);
|
||||
return;
|
||||
@@ -1889,7 +1897,7 @@ namespace Dreamteck.Splines
|
||||
{
|
||||
int from = endIndex;
|
||||
int to = startIndex;
|
||||
if(startIndex > endIndex)
|
||||
if (startIndex > endIndex)
|
||||
{
|
||||
from = startIndex;
|
||||
to = endIndex;
|
||||
@@ -1930,7 +1938,8 @@ namespace Dreamteck.Splines
|
||||
{
|
||||
if (direction == Spline.Direction.Forward) condition = _nodes[i].pointIndex >= pointValue;
|
||||
else condition = _nodes[i].pointIndex <= pointValue;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1939,7 +1948,8 @@ namespace Dreamteck.Splines
|
||||
Node.Connection[] connections = _nodes[i].node.GetConnections();
|
||||
for (int j = 0; j < connections.Length; j++)
|
||||
{
|
||||
if (connections[j].spline != this) {
|
||||
if (connections[j].spline != this)
|
||||
{
|
||||
computers.Add(connections[j].spline);
|
||||
connectionIndices.Add(_nodes[i].pointIndex);
|
||||
connectedIndices.Add(connections[j].pointIndex);
|
||||
@@ -2035,9 +2045,9 @@ namespace Dreamteck.Splines
|
||||
continue;
|
||||
}
|
||||
bool found = false;
|
||||
foreach(Node.Connection connection in _nodes[i].node.GetConnections())
|
||||
foreach (Node.Connection connection in _nodes[i].node.GetConnections())
|
||||
{
|
||||
if(connection.spline == this)
|
||||
if (connection.spline == this)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@@ -2071,7 +2081,7 @@ namespace Dreamteck.Splines
|
||||
Node.Connection[] connections = _nodes[i].node.GetConnections();
|
||||
for (int j = 0; j < connections.Length; j++)
|
||||
{
|
||||
if(connections[j].spline == this && connections[j].pointIndex == _nodes[i].pointIndex)
|
||||
if (connections[j].spline == this && connections[j].pointIndex == _nodes[i].pointIndex)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@@ -2080,7 +2090,8 @@ namespace Dreamteck.Splines
|
||||
if (found)
|
||||
{
|
||||
_nodes[i].node.UpdatePoint(this, _nodes[i].pointIndex, GetPoint(_nodes[i].pointIndex));
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveNodeLinkAt(i);
|
||||
Rebuild();
|
||||
|
||||
Reference in New Issue
Block a user