Пример #1
0
        private void Start()
        {
            // Necessary
            if (TargetPathSpline != null)
            {
                TargetPathSpline.Refresh();
            }

            // Round-trip update and instantiate runtime materials
            Materials = Materials;
        }
Пример #2
0
        public void UpdateMeshWeights(bool affect_position, bool affect_rotation, bool affect_scale)
        {
            if (TargetPathSpline != null && Weights != null)
            {
                float      weights_length_m1 = (float)Weights.Length - 1f;
                Vector3    point, tangent;
                Quaternion rotation, rotation_initial;

                for (int i = 0; i < Weights.Length; i++)
                {
                    float t;
                    float x     = (float)i / weights_length_m1;
                    float x_min = StraightenEnds.x;
                    float x_max = StraightenEnds.y;
                    if (x < x_min || x > x_max)
                    {
                        if (x < x_min)
                        {
                            t = SegmentPathPosition + SegmentLength * x_min;
                        }
                        else
                        {
                            t = SegmentPathPosition + SegmentLength * x_max;
                        }
                        if (UseUniformSpacing)
                        {
                            t = TargetPathSpline.DistanceToTF(TargetPathSpline.Length * t);
                        }
                        tangent = TargetPathSpline.GetTangentFast(t);
                        point   = TargetPathSpline.InterpolateFast(t);
                        if (x < x_min)
                        {
                            point += (x - x_min) * SegmentLength * TargetPathSpline.Length * tangent;
                        }
                        else
                        {
                            point += (x - x_max) * SegmentLength * TargetPathSpline.Length * tangent;
                        }
                    }
                    else
                    {
                        t = SegmentPathPosition + SegmentLength * x;
                        if (UseUniformSpacing)
                        {
                            t = TargetPathSpline.DistanceToTF(TargetPathSpline.Length * t);
                        }
                        tangent = TargetPathSpline.GetTangentFast(t);
                        point   = TargetPathSpline.InterpolateFast(t);
                    }
                    rotation_initial = Quaternion.AngleAxis(SegmentAngle, SegmentForwardVector);
                    if (SegmentFlipWeightDirection)
                    {
                        Quaternion flip = Quaternion.FromToRotation(SegmentForwardVector, -SegmentForwardVector);
                        rotation_initial = rotation_initial * flip;
                    }
                    if (SegmentUseFixedAngle)
                    {
                        rotation = rotation_initial;
                    }
                    else
                    {
                        rotation = TargetPathSpline.GetOrientationFast(t) * rotation_initial;
                    }

                    point += rotation * SegmentNormalShift;

                    Transform weight = Weights[i];

                    if (Positioning == Positioning.WorldSpace)
                    {
                        if (affect_position)
                        {
                            weight.position = point;
                        }
                        if (affect_rotation)
                        {
                            weight.rotation = rotation;
                        }
                    }
                    else if (Positioning == Positioning.LocalSpace)
                    {
                        if (affect_position)
                        {
                            weight.localPosition = point;
                        }
                        if (affect_rotation)
                        {
                            weight.localRotation = rotation;
                        }
                    }
                    if (affect_scale)
                    {
                        weight.localScale = SegmentScale;
                    }
                }
                _WeightsDirty = false;
            }
        }