methusalah / SplineMesh

A Unity plugin to create curved content in real-time with bézier curves
https://twitter.com/dumas181
MIT License
1.05k stars 104 forks source link

[Question] change set of points and update spline after all are updated #42

Closed LiorBanai closed 2 years ago

LiorBanai commented 3 years ago

HI, I have 4 splines with 10 points each which I'm changing in 400Hz. for each update I'm changing (in Spline.cs):

        public void UpdateNode(int i, Vector3 newPosition)
        {
            if (i < nodes.Count)
            {
                nodes[i].Position = newPosition;
            }
        }

the problem is that after each change rasie event:

       /// <summary>
        /// Node position
        /// </summary>
        public Vector3 Position {
            get { return position; }
            set {
                if (position.Equals(value)) return;
                position.x = value.x;
                position.y = value.y;
                position.z = value.z;
                 Changed?.Invoke(this, EventArgs.Empty);

            }
        }

which cause performance issuses.

is ther ea way to update alll spline points in a batch and only after that recreate/update the presentation/spline itself?

it will reduce redrawing by 10...

methusalah commented 3 years ago

SplineMesh will only update once perf frame, even if the event is raised multiple times in the same frame. In the same way, only the part of the spline that change will be updated, so if the position has not change, no unnecessary computation will occur.

Do you observe a different behavior?

LiorBanai commented 3 years ago

We do see some slowness when spline is enable in standalone mode. I will further investigate it :)

methusalah commented 3 years ago

The performance is massively impacted by the number of vertices to move so you may want to use a less tesselated mesh to get better perf. Another trick that work in some situations, is to avoid moving node at each frame, but for example one per frame. It can quicky drop the calculations by 5 or 10 but will cause artifact and may not suit your needs.