Beispiel #1
0
 public MySparseOctree(int height, MyOctreeNode.FilterFunction nodeFilter, byte defaultContent = 0)
 {
     this.m_treeHeight     = height;
     this.m_treeWidth      = 1 << (height & 0x1f);
     this.m_defaultContent = defaultContent;
     this.m_nodeFilter     = nodeFilter;
 }
Beispiel #2
0
 public unsafe MySparseOctree(int height, MyOctreeNode.FilterFunction nodeFilter, TLeafData defaultContent = default(TLeafData))
 {
     Debug.Assert(height < MyCellCoord.MAX_LOD_COUNT, String.Format("Height must be < {0}", MyCellCoord.MAX_LOD_COUNT));
     m_treeHeight     = height;
     m_treeWidth      = 1 << height;
     m_defaultContent = defaultContent;
     m_nodeFilter     = nodeFilter;
 }
            private static unsafe void UpdateLodDataInternal(int lod, byte[] dataArray, MyOctreeNode.FilterFunction filter)
            {
                int offset = 0;

                for (int i = 0; i < lod - 1; ++i)
                {
                    offset += Volume >> (i + i + i);
                }

                var sx = Size >> lod;
                var sy = sx * sx;
                var sz = sy * sx;

                var psx = Size >> (lod - 1);
                var psy = psx * psx;
                var psz = psy * psx;

                ulong dataBit;

                byte *data = (byte *)&dataBit;

                fixed(byte *fixedDataArray = dataArray)
                {
                    byte *voxel = fixedDataArray + offset;

                    byte *store = voxel + psz;

                    for (int z = 0; z < sz; z += sy)
                    {
                        int z0 = z << 3, z1 = (z << 3) + psy;

                        for (int y = 0; y < sy; y += sx)
                        {
                            int y0 = y << 2, y1 = (y << 2) + psx;
                            for (int x = 0; x < sx; ++x)
                            {
                                // precompute corner indices, moar readable
                                int x0 = x << 1, x1 = (x << 1) + 1;

                                data[0] = voxel[z0 + y0 + x0];
                                data[1] = voxel[z0 + y0 + x1];
                                data[2] = voxel[z0 + y1 + x0];
                                data[3] = voxel[z0 + y1 + x1];
                                data[4] = voxel[z1 + y0 + x0];
                                data[5] = voxel[z1 + y0 + x1];
                                data[6] = voxel[z1 + y1 + x0];
                                data[7] = voxel[z1 + y1 + x1];

                                store[x + y + z] = filter(data);
                            }
                        }
                    }
                }
            }