Translate SplinePath

Hi there! Is there an efficient way to translate SplinePath?

At the moment I have to create a new function inside SplinePath for this.

void SplinePath::TranslatePath(const Vector3 &v)
{
for (unsigned i = 0; i < controlPoints_.Size(); ++i)
{
Vector3 pos = controlPoints_[i]->GetWorldPosition() + v;
controlPoints_[i]->SetWorldPosition(pos);
}
}

Why don’t we make controlpoints the child of the node where this component is added to.
This way we just need to move the parent node and everything moves with it.

Also, I have tested translate 50 ControlPoints of the SplinePath and I found that it is very slow to update. In my test I can translate 5000 none spline controlpoint nodes faster than that of 50 ControlPoints in the SplinePath.

regards

As confirmatory nitpicking, I’d rewrite your function as such:

void SplinePath::TranslatePath(const Vector3& delta, TransformSpace space = TS_WORLD)
{
     for (WeakPtr<Node> node: controlPoints_) {

          node->Translate(delta, space);
     }
}
1 Like

Thanks Modanung,
I rarely use foreach. But that’s pretty compact. Do you think there is a performance reduction in that translate function?

I have tested for CATMULL_ROM_FULL_CURVE.

Also, the debug line seems to be edgy if we have lots of nodes. See pic.

image

image

Best regards

How do you create the spheres? Could they by any chance be offset?

Sphere is created by adding control point to SplinePath directly.
After more than 20 nodes. The debug line reduce accuracy. Maybe there is a limited in the number of line segments used in the debug code.

regards

Instead of adding a TranslatePath function. I recommend to expose the control points. Through GetControlPoints()

This way we could translate or do what ever with it without touch core.

Best regards

1 Like

The translation of SplinePath node for non linear spline is quite slow.
See small comparision pictures.

test

test2

Does this hold true when not drawing debug geometry?

Yes, it also slow without debug lines.
I think there maybe some sort internal code that do a deep update every frame when we move the path.
I’m not too sure, as I linked the lib. so I can’t debug into it.

Best regards

Probably SplinePath::OnMarkedDirty cause lags because CalculateLength is quite heavy.

2 Likes

Thanks Eugene!
Is it possible to temporary disable mark dirty and re-enable (call) when we need it?

We could e.g have a flag in that OnMarkedDirty function.

Or is there an existing global flag that I can used?

Thanks

Thanks,
I’ve comment out CalculateLength in OnMarkedDirty.
Make CalculateLength() public and calls it when I translate the SplinePath

void SplinePath::OnMarkedDirty(Node* point)
{

    if (!point)
        return;

    WeakPtr<Node> controlPoint(point);

    for (unsigned i = 0; i < controlPoints_.Size(); ++i)
    {
        if (controlPoints_[i] == controlPoint)
        {
            spline_.SetKnot(point->GetWorldPosition(), i);
            break;
        }
    }

   // CalculateLength();
}

test2

1 Like