Esempio n. 1
0
    private void ReparameterizeCurve( )
    {
        if (lengthData == null)
        {
            lengthData = new LengthData( );
        }

        lengthData.Calculate(this);
    }
Esempio n. 2
0
    //Recalculate the spline parameter for constant-velocity interpolation
    private SegmentParameter RecalculateParameter(double param)
    {
        if (param <= 0)
        {
            return(new SegmentParameter(0, 0));
        }
        if (param > 1)
        {
            return(new SegmentParameter(MaxNodeIndex( ), 1));
        }

        double invertedAccuracy = InvertedAccuracy;

        if (lengthData == null)
        {
            lengthData = new LengthData( );
        }

        if (lengthData.subSegmentPosition == null)
        {
            lengthData.Calculate(this);
        }

        for (int i = lengthData.subSegmentPosition.Length - 1; i >= 0; i--)
        {
            if (lengthData.subSegmentPosition[i] < param)
            {
                int floorIndex = (i - (i % (interpolationAccuracy)));

                int    normalizedIndex = floorIndex * NodesPerSegment / interpolationAccuracy;
                double normalizedParam = invertedAccuracy * (i - floorIndex + (param - lengthData.subSegmentPosition[i]) / lengthData.subSegmentLength[i]);

                if (normalizedIndex >= ControlNodeCount - 1)
                {
                    return(new SegmentParameter(MaxNodeIndex( ), 1.0));
                }

                return(new SegmentParameter(normalizedIndex, normalizedParam));
            }
        }

        return(new SegmentParameter(MaxNodeIndex( ), 1));
    }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(LengthData obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Esempio n. 4
0
        override public void UpdatePathPoint()
        {
            if (transform.lossyScale == Vector3.zero)
            {
                Debug.LogError("UCL_Curve UpdatePathPoint() Error, transform.lossyScale == Vector3.zero");
                return;
            }
            if (m_Points == null)
            {
                m_Points = new List <Vector3>();
                m_Points.Add(Vector3.zero);
                m_Points.Add(Vector3.right);
            }
            //Debug.LogWarning("UpdatePathPoint()");
            if (m_Points == null)
            {
                m_Points = new List <Vector3>();
            }
            if (m_Points.Count == 0)
            {
                return;
            }
            m_SegLengthDatas.Clear();
            if (m_Loop && m_Points.Count > 2)
            {
                m_Points[m_Points.Count - 1] = m_Points[0];
            }
            m_GenStartPos   = transform.position;
            m_GenStartRot   = transform.rotation;
            m_GenStartScale = transform.lossyScale;

            UpdateWorldSpacePoint();

            if (m_Points.Count > 1)
            {
                m_PathSegLength = new float[m_Points.Count - 1];
                Vector3 prev = GetPoint(0);
                Vector3 cur  = prev;

                float total_len = 0;
                float cur_len   = 0;

                for (int i = 0; i < m_Points.Count - 1; i++)
                {
                    float seg_len = 0;
                    float p       = (i / (float)(m_Points.Count - 1));

                    if (m_FixLength)
                    {
                        LengthData ld = new LengthData();
                        ld.m_Data.Add(0);

                        for (int j = 0; j < m_SmoothSeg; j++)
                        {
                            float p2  = ((j + 1) / (float)m_SmoothSeg);
                            float pos = p + (p2 / (m_Points.Count - 1));
                            cur = GetPoint(pos);
                            float dis = (cur - prev).magnitude;
                            seg_len += dis;
                            cur_len += dis;

                            prev = cur;
                            ld.m_Data.Add(seg_len);
                        }
                        for (int j = 1; j < ld.m_Data.Count; j++)
                        {
                            ld.m_Data[j] = ld.m_Data[j] / seg_len;
                        }

                        m_SegLengthDatas.Add(ld);
                    }
                    else
                    {
                        for (int j = 0; j < m_SmoothSeg; j++)
                        {
                            float p2  = ((j + 1) / (float)m_SmoothSeg);
                            float pos = p + (p2 / (m_Points.Count - 1));
                            cur = GetPoint(pos);
                            float dis = (cur - prev).magnitude;
                            seg_len += dis;
                            cur_len += dis;

                            prev = cur;
                        }
                    }

                    m_PathSegLength[i] = seg_len;
                    total_len         += seg_len;
                }
                m_PathLength = total_len;
            }
            else
            {
                m_PathSegLength = null;
                m_PathLength    = 0;
            }

#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
        }
Esempio n. 5
0
	private void ReparameterizeCurve( )
	{
		if( lengthData == null )
			lengthData = new LengthData( );
		
		lengthData.Calculate( this );
	}