Exemplo n.º 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 (!Animation.Frame.Component.ToLockList.Contains(this))
            {
                Animation.Frame.Component.ToLockList.Add(this);
            }

            if (this.Params.Input.Count == 1)
            {
                DA.GetData("TimeDomain", ref timeDomain);
            }
            else if (this.Params.Input.Count == 2)
            {
                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.SetData("Lock?", !timeDomain.IncludesParameter(Animation.Frame.Component.RightTime));
        }
Exemplo n.º 2
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)
        {
            List <double> valueList = new List <double>();
            int           height    = 0;
            int           type      = 0;

            DA.GetDataList("Events", valueList);
            DA.GetData("GraphHeight", ref height);
            DA.GetData("BlendType", ref type);

            Frame frameComponent;

            if (!BasicFunction.ConnectToFrame(this, out frameComponent))
            {
                return;
            }
            if (!Frame.Component.ClearComponent.Contains(this))
            {
                Frame.Component.ClearComponent.Add(this);
            }

            if (height < 1)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input GraphHeight must be larger than 0!");
                height = 1;
            }
            GraphHeight = height;

            keyPoints = new Dictionary <int, double>();
            CheckParam();
            AddDict(frameComponent.RightFrame);
            FixDict(type, frameComponent.MaxFrame);

            showValue = keyPoints[frameComponent.RightFrame];
            DA.SetData("Value", showValue);
        }
Exemplo n.º 3
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);
            //     }
            // }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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)
        {
            Frame frameComponent;

            if (!BasicFunction.ConnectToFrame(this, out frameComponent))
            {
                return;
            }

            if (!frameComponent.Play)
            {
                if (GetValue("InPut", @default: false))
                {
                    Message = "InPut";
                }
                else
                {
                    Message = "OutPut";
                }
                return;
            }

            string numberofMaxFrame = "D" + ((int)frameComponent.MaxFrame).ToString().Length.ToString();
            string location         = frameComponent.FilePath + this.NickName + "  " + frameComponent.RightFrame.ToString(numberofMaxFrame) + ".3dm";

            if (GetValue("InPut", @default: false))
            {
                Message = "InPut";

                List <IGH_Goo> list = new List <IGH_Goo>();
                try
                {
                    File3dm val = File3dm.Read(location);
                    if (val == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "File could not be read");
                        return;
                    }
                    foreach (File3dmObject item in (CommonComponentTable <File3dmObject>)(object) val.Objects)
                    {
                        IGH_Goo iGH_Goo = GH_Convert.ToGoo(item.Geometry);
                        if (iGH_Goo != null)
                        {
                            list.Add(iGH_Goo);
                        }
                    }
                    Message += "  " + frameComponent.RightFrame.ToString();
                }
                catch (Exception ex)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error during file reading: " + ex.Message);
                    return;
                }

                DA.SetDataList("Geometry", list);
            }
            else
            {
                Message = "OutPut";

                List <Mesh> meshes = new List <Mesh>();
                DA.GetDataList("Mesh", meshes);

                File3dm file3d = new File3dm();
                foreach (Mesh mesh in meshes)
                {
                    file3d.Objects.AddMesh(mesh);
                }
                file3d.Write(location, 6);

                Message += "  " + frameComponent.RightFrame.ToString();
            }
        }