Wie navigieren Sie mit Morton Code Octree?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie navigieren Sie mit Morton Code Octree?

Post by Anonymous »

Ich verwende Octree in meinem Spiel und benutze Morton Code (Z-Ordnung), um darauf zu navigieren. heraus, warum. Bitte helfen Sie: < /p>

Morton Support Arrays Init, MortonMapping ist für die Rückkehr von echtem lokalem IDX bis zu Z-Orts lokaler IDX und umgekehrt < /li>
< /ol>
static Utils()
{
thresholds[0] = Consts.Lod0Range;
for (int i = 1; i
1a. Bits Helfer -Funktion < /p>
verteilen private static uint SpreadBits(uint x, int offset)
{
uint result = 0;
for (int i = 0; i < 8; i++)
{
result (7 - i)) & 1)

Morton Codierung < /li>
< /ol>
public static ulong MortonEncode(Vector3Int vector)
{
if (vector.x < 0 || vector.y < 0 || vector.z < 0)
throw new System.Exception("Negative morton");
ulong answer =
morton256[0][(vector.x >> 16) & 0xFF] |
morton256[1][(vector.y >> 16) & 0xFF] |
morton256[2][(vector.z >> 16) & 0xFF];
answer = answer > 8) & 0xFF] |
morton256[1][(vector.y >> 8) & 0xFF] |
morton256[2][(vector.z >> 8) & 0xFF];
answer = answer

Holen Sie sich den lokalen untergeordneten Index aus Morton Code für eine spezifische Octree -Ebene < /li>
< /ol>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int MortonIndexForLevel(int level, ulong mortonIndex)
{
return (int)(mortonIndex >> (level * 3)) & 0b111;
}
< /code>

Holen Sie sich die lokale Kinderposition von Morton Code (relativ zum Elternteil) - Dies wird bei der Zeichnung verwendet, die ich nicht wie ich einbeziehe, wie ich nicht einbezieht Ich bin mir sicher, dass das Problem im Einfügungsmechanismus liegt [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3Int FlatIndexToVector(int realIdx)
{
return new Vector3Int((realIdx & 4) >> 2, (realIdx & 2) >> 1, realIdx & 1);
}
< /code>

Rekursive Insertion < /li>
< /ol>
//coords are relative to world 0,0,0 measured in smallest possible node size
public void Insert(byte lod, Vector3Int coords, NativeArray data)
{
EnsureSpace(coords);
Chunk chunk = !data.IsCreated ? null : new Chunk(data);
ulong idx = Utils.MortonEncode(coords - beginCorner); //Substract beginCorner of octree in order to localize coords

//Debug section, no logic here
Vector3 center = FromGlobalCoords(coords) + Vector3.one * (1

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post