升级obi

This commit is contained in:
2026-01-22 22:08:21 +08:00
parent 120b8cda26
commit 20f14322bc
1067 changed files with 149894 additions and 29583 deletions

View File

@@ -1,118 +1,76 @@
#if (OBI_BURST && OBI_MATHEMATICS && OBI_COLLECTIONS)
using Unity.Mathematics;
public struct GridHash
namespace Obi
{
public readonly static int3[] cellOffsets3D =
public struct GridHash
{
new int3(1,0,0),
new int3(0,1,0),
new int3(1,1,0),
new int3(0,0,1),
new int3(1,0,1),
new int3(0,1,1),
new int3(1,1,1),
new int3(-1,1,0),
new int3(-1,-1,1),
new int3(0,-1,1),
new int3(1,-1,1),
new int3(-1,0,1),
new int3(-1,1,1)
};
public readonly static int3[] cellOffsets =
{
new int3(0, 0, 0),
new int3(-1, 0, 0),
new int3(0, -1, 0),
new int3(0, 0, -1),
new int3(1, 0, 0),
new int3(0, 1, 0),
new int3(0, 0, 1)
};
public readonly static int2[] cell2DOffsets =
{
new int2(0, 0),
new int2(-1, 0),
new int2(0, -1),
new int2(1, 0),
new int2(0, 1),
};
public static int Hash(float3 v, float cellSize)
{
return Hash(Quantize(v, cellSize));
}
public static int3 Quantize(float3 v, float cellSize)
{
return new int3(math.floor(v / cellSize));
}
public static int Hash(float2 v, float cellSize)
{
return Hash(Quantize(v, cellSize));
}
public static int2 Quantize(float2 v, float cellSize)
{
return new int2(math.floor(v / cellSize));
}
public static int Hash(int3 grid)
{
unchecked
public readonly static int3[] cellOffsets3D =
{
// Simple int3 hash based on a pseudo mix of :
// 1) https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
// 2) https://en.wikipedia.org/wiki/Jenkins_hash_function
int hash = grid.x;
hash = (hash * 397) ^ grid.y;
hash = (hash * 397) ^ grid.z;
hash += hash << 3;
hash ^= hash >> 11;
hash += hash << 15;
return hash;
}
}
new int3(1,0,0),
new int3(0,1,0),
new int3(1,1,0),
new int3(0,0,1),
new int3(1,0,1),
new int3(0,1,1),
new int3(1,1,1),
new int3(-1,1,0),
new int3(-1,-1,1),
new int3(0,-1,1),
new int3(1,-1,1),
new int3(-1,0,1),
new int3(-1,1,1)
};
public static int Hash(int2 grid)
{
unchecked
public readonly static int3[] cellOffsets =
{
// Simple int3 hash based on a pseudo mix of :
// 1) https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
// 2) https://en.wikipedia.org/wiki/Jenkins_hash_function
int hash = grid.x;
hash = (hash * 397) ^ grid.y;
hash += hash << 3;
hash ^= hash >> 11;
hash += hash << 15;
return hash;
new int3(0, 0, 0),
new int3(-1, 0, 0),
new int3(0, -1, 0),
new int3(0, 0, -1),
new int3(1, 0, 0),
new int3(0, 1, 0),
new int3(0, 0, 1)
};
public readonly static int2[] cell2DOffsets =
{
new int2(0, 0),
new int2(-1, 0),
new int2(0, -1),
new int2(1, 0),
new int2(0, 1),
};
public static int3 Quantize(float3 v, float cellSize)
{
return new int3(math.floor(v / cellSize));
}
}
public static ulong Hash(ulong hash, ulong key)
{
const ulong m = 0xc6a4a7935bd1e995UL;
const int r = 47;
public static int2 Quantize(float2 v, float cellSize)
{
return new int2(math.floor(v / cellSize));
}
ulong h = hash;
ulong k = key;
public static int Hash(in int4 cellIndex, int maxCells)
{
const int p1 = 73856093;
const int p2 = 19349663;
const int p3 = 83492791;
const int p4 = 10380569;
return math.abs(p1 * cellIndex.x ^ p2 * cellIndex.y ^ p3 * cellIndex.z ^ p4 * cellIndex.w) % maxCells;
}
k *= m;
k ^= k >> r;
k *= m;
public static int Hash(in int3 cellIndex, int maxCells)
{
const int p1 = 73856093;
const int p2 = 19349663;
const int p3 = 83492791;
return ((p1 * cellIndex.x ^ p2 * cellIndex.y ^ p3 * cellIndex.z) & 0x7fffffff) % maxCells;
h ^= k;
h *= m;
h ^= h >> r;
h *= m;
h ^= h >> r;
return h;
/*var index = cellIndex - new int3(-32, -32, -32);
return index.x + index.y * 64 + index.z * 64 * 64;*/
}
}
}
#endif