Wie navigieren Sie mit Morton Code Octree?C#

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

Post by Guest »

Ich verwende Octree in meinem Spiel und benutze Morton Code (Z-Ordnung), um darauf zu navigieren. heraus, warum - Knoten in falschen Positionen eingefügt werden (Screenshots belly). BR /> Hier sind entscheidende Codefragmente. Bitte helfen Sie: < /p>

Morton Support Arrays Init, Mortonmapping dient zur Umkehrung von echten lokalen IDX bis Z- Bestellte lokale IDX und umgekehrt < /li>
< /ol>

Code: Select all

    static Utils()
{
thresholds[0] = Consts.Lod0Range;
for (int i = 1; i 
< /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 = parentCenter.z)
index |= 1;

Debug.Log("Indexes: " + index + ", " + curIdx + "\n" + Convert.ToString(index, 2).PadLeft(3, '0') + "\n" + Convert.ToString(curIdx, 2).PadLeft(3, '0'));

if (lod == value.Lod)
{
parent[index] = value;
return;
}
if (parent[index] == null)
parent[index] = new Node(lod);
InsertRecursive(parent[index], value, idx, parentCorner + Utils.FlatIndexToVector(index) * (1

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post