Example #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Animation.Frame frameComponent;
            if (!BasicFunction.ConnectToFrame(this, out frameComponent))
            {
                return;
            }

            if (this.Params.Input.Count == 3)
            {
                DA.GetData("TimeDomain", ref timedomain);
            }
            else if (this.Params.Input.Count == 4)
            {
                Interval startDomain = new Interval();
                Interval endDomain   = new Interval();
                DA.GetData("StartTime", ref startDomain);
                DA.GetData("EndTime", ref endDomain);
                timedomain = new Interval(startDomain.T0, endDomain.T1);
            }
            DA.GetData("ValueDomain", ref valuedomain);


            this.frames = new List <int>();
            List <double> outValue = new List <double>();

            for (int i = 0; i <= frameComponent.MaxFrame; i++)
            {
                if (timedomain.IncludesParameter(frameComponent.KeyTimes[i]))
                {
                    double value = (frameComponent.KeyTimes[i] - timedomain.T0) / timedomain.Length;
                    outValue.Add(value);
                    this.frames.Add(i);
                }
            }


            int type = 0;

            DA.GetData("BlendType", ref type);

            double[] newoutValue = new double[outValue.Count];

            for (int n = 0; n < outValue.Count; n++)
            {
                newoutValue[n] = BasicFunction.RemapByType(outValue[n], type, this);
            }

            for (int i = 0; i < Frame.Component.KeyTimes.Count; i++)
            {
                if (Math.Abs(Frame.Component.KeyTimes[i] - timedomain.T0) < 0.00001)
                {
                    this.StartFrame = i;
                }
                else if (Math.Abs(Frame.Component.KeyTimes[i] - timedomain.T1) < 0.00001)
                {
                    this.EndFrame = i;
                    break;
                }
            }

            DA.SetDataList("Value", newoutValue);

            //if (timedomain.IncludesParameter(frameComponent.RightTime))
            // {
            //     double value = (frameComponent.RightTime - timedomain.T0) / timedomain.Length;
            //     DA.SetData("Value", value);
            //     RightFrame = frameComponent.RightFrame;
            // }
            // else
            // {
            //     if(frameComponent.RightTime < timedomain.T0)
            //     {
            //         for(int n = 0; n < frameComponent.KeyTimes.Count; n++)
            //             if (frameComponent.KeyTimes[n] > timedomain.T0)
            //             {
            //                 RightFrame = n;
            //                 break;
            //             }
            //         DA.SetData("Value", 0);
            //     }
            //     else
            //     {
            //         for (int n = 0; n < frameComponent.KeyTimes.Count; n++)
            //             if (frameComponent.KeyTimes[n] > timedomain.T1)
            //             {
            //                 RightFrame = n-1;
            //                 break;
            //             }
            //         DA.SetData("Value", 1);
            //     }
            // }
        }
Example #2
0
        protected void FixDict(int type, int maxFrame)
        {
            //Dictionary<int, double> stopFrame = new Dictionary<int, double>();
            //bool flag = keyPoints.Keys.Contains(0);
            //for (int frame = 1; frame <= maxFrame + 1; frame++)
            //{
            //    if (flag && keyPoints.Keys.Contains(frame))
            //    {
            //        if (flag) stopFrame[frame - 1] = keyPoints[frame - 1];
            //        else stopFrame[frame] = keyPoints[frame];
            //    }
            //    flag = keyPoints.Keys.Contains(frame);
            //}


            for (int frame = 0; frame <= maxFrame; frame++)
            {
                if (keyPoints.Keys.Contains(frame))
                {
                    continue;
                }

                int leftframe  = eventThing[0].StartFrame;
                int rightframe = eventThing[0].StartFrame;
                for (int i = 0; i < eventThing.Count; i++)
                {
                    try
                    {
                        if (eventThing[i].EndFrame <= frame && eventThing[i + 1].StartFrame >= frame)
                        {
                            leftframe  = eventThing[i].EndFrame;
                            rightframe = eventThing[i + 1].StartFrame;
                            break;
                        }
                    }
                    catch
                    {
                        leftframe  = eventThing[i].EndFrame;
                        rightframe = eventThing[i].EndFrame;
                    }
                }

                //double rightTime = Frame.Component.KeyTimes[frame]
                //int leftframe = 0;
                //for (int minframe = frame; minframe >= 0; minframe--)
                //{
                //    if (stopFrame.Keys.Contains(minframe))
                //    {
                //        leftframe = minframe;
                //        break;
                //    }
                //}

                //int rightframe = maxFrame;
                //for (int maxframe = frame-1; maxframe <= maxFrame; maxframe++)
                //{
                //    if (stopFrame.Keys.Contains(maxframe))
                //    {
                //        rightframe = maxframe;
                //        break;
                //    }
                //}

                double t     = ((double)(frame - leftframe)) / ((double)(rightframe - leftframe));
                double f     = BasicFunction.RemapByType(t, type, this);
                double right = keyPoints[rightframe];
                double left  = keyPoints[leftframe];
                keyPoints[frame] = keyPoints[leftframe] + f * (right - left);
            }
        }