Ejemplo n.º 1
0
        private void InterpolateKeys(double animationTime, AnimationLayer layer, ref Quaternion rotation, ref Vector3 translation, ref Vector3 scale, PRSKey prsKey, PRSKey nextPrsKey)
        {
            var nextTime = (nextPrsKey.Time < prsKey.Time
                ? (nextPrsKey.Time + Animation.Duration)
                : nextPrsKey.Time);

            var blend = ( float )(animationTime / nextTime);

            if (prsKey.HasRotation)
            {
                rotation = Quaternion.Slerp(prsKey.Rotation, nextPrsKey.Rotation, blend);
            }

            if (prsKey.HasPosition)
            {
                translation = Vector3.Lerp(prsKey.Position * layer.PositionScale,
                                           nextPrsKey.Position * layer.PositionScale,
                                           blend);
            }

            if (prsKey.HasScale)
            {
                scale = Vector3.Lerp(prsKey.Scale * layer.ScaleScale,
                                     nextPrsKey.Scale * layer.ScaleScale,
                                     blend);
            }
        }
            private readonly void _DrawCap(ICoreScene3D dc, ColorStyle fillColor, LineCapStyle cap, Span <POINT3> corners, bool dir)
            {
                var axis = Direction * (Diameter * 0.5f);

                if (dir)
                {
                    axis = -axis;
                }

                switch (cap)
                {
                case LineCapStyle.Round:
                    for (int i = 0; i < corners.Length; ++i)
                    {
                        var j = (i + 1) % corners.Length;

                        var i0 = corners[i].XYZ;
                        var j0 = corners[j].XYZ;
                        var i1 = VECTOR3.Lerp(Point, i0 + axis, 0.7f);
                        var j1 = VECTOR3.Lerp(Point, j0 + axis, 0.7f);

                        dc.DrawConvexSurface(POINT3.Array(i0, j0, j1, i1), fillColor);
                        dc.DrawConvexSurface(POINT3.Array(Point + axis, i1, j1), fillColor);
                    }
                    break;

                case LineCapStyle.Triangle:
                    for (int i = 0; i < corners.Length; ++i)
                    {
                        var j = (i + 1) % corners.Length;
                        dc.DrawConvexSurface(POINT3.Array(Point + axis, corners[i], corners[j]), fillColor);
                    }
                    break;


                default: dc.DrawConvexSurface(corners, fillColor); break;
                }
            }
Ejemplo n.º 3
0
        private void Update(EvaluationContext context)
        {
            // var countX = CountX.GetValue(context).Clamp(1, 100);
            // var countY = CountY.GetValue(context).Clamp(1, 1);

            var listA = A.GetValue(context);
            var listB = B.GetValue(context);

            if (listA == null || listA.Length == 0 || listB == null || listB.Length == 0)
            {
                return;
            }

            var combination = (Combinations)Combination.GetValue(context);

            //var count = countX * countY;
            if (_points.Length != listA.Length)
            {
                _points = new T3.Core.DataTypes.Point[listA.Length];
            }

            var factor = Factor.GetValue(context);
            var mode   = (Modes)Mode.GetValue(context);

            switch (combination)
            {
            case Combinations.Modulo:
            {
                for (var index = 0; index < listA.Length; index++)
                {
                    var pA = listA[index % listA.Length];
                    var pB = listB[index % listB.Length];

                    ComputeStep(index, pA, pB);
                }
                break;
            }

            case Combinations.Interpolate:
            {
                float bStep = (float)listB.Length / (listA.Length - 0.999f);

                for (var index = 0; index < listA.Length; index++)
                {
                    var pA       = listA[index % listA.Length];
                    var bPointer = bStep * index;
                    var bIndex   = (int)bPointer;
                    var fraction = bPointer - bIndex;
                    try
                    {
                        var pB1 = listB[bIndex < listB.Length - 1 ? bIndex  : listB.Length - 1];
                        var pB2 = listB[bIndex < listB.Length - 2 ? bIndex + 1 : listB.Length - 1];
                        var pB  = new T3.Core.DataTypes.Point()
                        {
                            Position    = Vector3.Lerp(pB1.Position, pB2.Position, fraction),
                            W           = MathUtils.Lerp(pB1.W, pB2.W, fraction),
                            Orientation = Quaternion.Identity,
                        };
                        //pB.Position.W = 1;
                        ComputeStep(index, pA, pB);
                    }
                    catch (Exception)
                    {
                        Log.Error("incorrect index calculation: \nindex: {index}  bIndex {bIndex}  fraction: {fraction}  lengthA:{listA.Length}  lengthB:{listB.Length}");
                    }
                }
                break;
            }
            }

            Result.Value = _points;

            void ComputeStep(int index, T3.Core.DataTypes.Point pA, T3.Core.DataTypes.Point pB)
            {
                switch (mode)
                {
                case Modes.Add:
                    _points[index].Position = pA.Position + pB.Position;
                    break;

                case Modes.Multiply:
                    _points[index].Position = pA.Position * pB.Position;
                    break;

                case Modes.Blend:
                    _points[index].Position = Vector3.Lerp(pA.Position, pB.Position, factor);
                    break;
                }
            }
        }