Answers:
树状排列听起来对我来说是一个胜利。只需对层次结构进行深度优先遍历并填写数组即可;在递归中倒退时,您可以使用对子项的绝对索引或仅对我的增量来更新父项,而子项也可以使用任何一种方式存储父项索引。实际上,如果使用相对偏移量,则无需携带根地址。我想结构可能看起来像
struct Transform
{
   Matrix m; // whatever you like
   int parent;   // index or offset, you choose!
   int sibling;
   int firstchild;
};
...因此,由于您无法(轻松地)拥有可变大小的结构,因此您还需要节点也知道如何到达同级。尽管我猜想如果您使用字节偏移量而不是转换偏移量,则每个转换可能具有可变数量的子代:
struct Transform
{
   Matrix m; // whatever you like
   int parent;  // negative byte offest
   int numchildren;
   int child[0]; // can't remember if you put a 0 there or leave it empty;
                 // but it's an array of positive byte offsets
};
...那么您只需要确保将正确的连续变换放在正确的位置即可。
这是使用嵌入式子“指针”构建完全独立的树的方法。
int BuildTransforms(Entity* e, OutputStream& os, int parentLocation)
{
    int currentLocation = os.Tell();
    os.Write(e->localMatrix);
    os.Write(parentLocation);
    int numChildren = e->GetNumChildren();
    os.Write(numChildren);
    int childArray = os.Tell();
    os.Skip(numChildren * sizeof(int));
    os.AlignAsNecessary();  // if you need to align transforms
    childLocation = os.Tell();
    for (int i = 0; i < numChildren; ++i) {
        os.Seek(childArray + (i * sizeof(int)));
        os.Write(childLocation);
        os.Seek(childLocation);
        childLocation = BuildTransforms(e->GetChild(i), os, currentLocation);
    }
    return os.Tell();
}
void BuildTransforms(Entity* root)
{
    OutputStream os;
    BuildTransforms(root, os, -1, 0);
}
(如果要存储相对位置,只需- currentLocation在两个“位置”中添加内容即可。)