简单的 3d 场景性能缓慢

Slow performance with simple 3d scene

我正在尝试在 Godot 中创建一个触手。我尝试在 Blender 中制作它,然后放入骨骼,但我无法让它工作,所以我尝试更简单的方法:我有 13 个 CSGMesh(圆柱体网格)来表示触手段,每个段都是触手的其余部分。

tentacle
+-> segment1
    +-> segment2
        +-> segmen...

所以我想做的很简单,在每次更新时,我来回修改线段的 Z 轴旋转。效果确实看起来像触手在挥舞,但我每秒可能得到 1-2 帧。场景中没有其他任何东西,所以我觉得也许我做错了什么,虽然我不知道它是什么。

我做的事情很简单,但是代码很多,所以相关的位在这里:

public class tentacle4 : Spatial
{
    private class SegmentPosition
    {
        // ... I cut out the stuff in here for keeping track of position and rotation speed

        // the actual segment in the scene
        public Spatial Node { get; set; }

        public void RotateZ(float delta)
        { 
            // the bit that actually roates is:
            this.Node.Rotation = new Vector3(0, 0, proposed);
        }
    }

    // No meaningful difference here in performance between
    // this and _PhysicsProcess()
    public override void _Process(float delta)
    {
       foreach (var segment in Segments)
       {
          segment.RotateZ(delta);
       }
    }

}

我可能做错了什么导致它表现如此糟糕?我假设我在错误的时间在管道中进行轮换,尽管我不知道什么时候是正确的。我会提到 Godot 中的预览正常运行得很好,并且当 运行 项目(在 GLES2 或 GLES3 中)时计算机不紧张——既不 CPU (i7-8705) 也不GPU (Vega GL) 似乎很在意。

CSG 节点并不意味着每帧都移动,尤其是在像这样的深层嵌套树中。 CSG 操作非常昂贵,并且仅在 CPU 上执行。仅在实际需要时才使用布尔运算。当您不需要布尔运算时,请改用 MeshInstance。

此外,要使网格变形,您可以查看 writing a vertex shader。与 CSG 或脚本不同,着色器代码在 GPU 上运行,速度更快,尤其是在有大量实例的情况下。