protected void CreatePatchData() { // Assumes GridsPerEdge, GridsPerPatchEdge, and PatchesPerEdge have been properly set // TODO -- check for create() called when surface is not empty UInt32 i; UInt32 j; SurfacePatch patch; // Allocate memory PatchList = new SurfacePatch[NumberOfPatches]; for (i = 0; i < NumberOfPatches; i++) { PatchList[i] = new SurfacePatch(); } // One of each for each camera VisiblePatchCount = NumberOfPatches; for (j = 0; j < PatchesPerEdge; j++) { for (i = 0; i < PatchesPerEdge; i++) { patch = GetPatch(i, j); patch.Surface = this; } } for (j = 0; j < PatchesPerEdge; j++) { for (i = 0; i < PatchesPerEdge; i++) { patch = GetPatch(i, j); patch.HasReceivedData = false; patch.SurfaceTextureUpdate = true; UInt32 dataOffset = i * GridsPerPatchEdge + j * GridsPerPatchEdge * GridsPerEdge; patch.SetDataZ(SurfaceZ, dataOffset); patch.SetDataNorm(Norm, dataOffset); // We make each patch point to its neighbours so we can do resolution checking // when butting up different resolutions. Patches that don't have neighbours // somewhere will point to NULL on that side. patch.SetNeighbourPatch(DirectionIndex.East, i < PatchesPerEdge - 1 ? GetPatch(i + 1, j) : null); patch.SetNeighbourPatch(DirectionIndex.North, j < PatchesPerEdge - 1 ? GetPatch(i, j + 1) : null); patch.SetNeighbourPatch(DirectionIndex.West, i > 0 ? GetPatch(i - 1, j) : null); patch.SetNeighbourPatch(DirectionIndex.South, j > 0 ? GetPatch(i, j - 1) : null); patch.SetNeighbourPatch(DirectionIndex.NorthEast, i < PatchesPerEdge - 1 && j < PatchesPerEdge - 1 ? GetPatch(i + 1, j + 1) : null); patch.SetNeighbourPatch(DirectionIndex.NorthWest, i > 0 && j < PatchesPerEdge - 1 ? GetPatch(i - 1, j + 1) : null); patch.SetNeighbourPatch(DirectionIndex.SouthWest, i > 0 && j > 0 ? GetPatch(i - 1, j - 1) : null); patch.SetNeighbourPatch(DirectionIndex.SouthEast, i < PatchesPerEdge - 1 && j > 0 ? GetPatch(i + 1, j - 1) : null); patch.OriginGlobal = new Vector3Double( // NOTE: y and z are swapped compared to Indra because of handedness OriginGlobal.x + i * MetersPerGrid * GridsPerPatchEdge, 0f, OriginGlobal.x + j * MetersPerGrid * GridsPerPatchEdge); // TODO: Is it really correct to use .x here? } } }
public void UpdateNorthEdge() { UInt32 gridsPerPatchEdge = Surface.GridsPerPatchEdge; UInt32 gridsPerEdge = Surface.GridsPerEdge; UInt32 i; UInt32 southSurfaceIndex = gridsPerPatchEdge * gridsPerEdge + DataZStart; UInt32 northSurfaceIndex; float[] northSource = null; if (GetNeighbourPatch(DirectionIndex.North) != null) { northSource = DataZ; northSurfaceIndex = (gridsPerPatchEdge - 1) * gridsPerEdge + DataZStart; } else if ((ConnectedEdge & EdgeType.North) != 0) { SurfacePatch neighbour = GetNeighbourPatch(DirectionIndex.North); northSource = neighbour.DataZ; northSurfaceIndex = 0 + neighbour.DataZStart; } else { return; } // Update patch's north edge ... for (i = 0; i < gridsPerPatchEdge; i++) { DataZ[southSurfaceIndex + i] = northSource[northSurfaceIndex + i]; // update buffer Z } }
public void UpdateEastEdge() { UInt32 gridsPerPatchEdge = Surface.GridsPerPatchEdge; UInt32 gridsPerEdge = Surface.GridsPerEdge; UInt32 j; UInt32 k; UInt32 westSurfaceIndex = gridsPerPatchEdge + DataZStart; UInt32 eastSurfaceIndex; float[] eastSource = DataZ; if (GetNeighbourPatch(DirectionIndex.East) != null) { eastSurfaceIndex = gridsPerPatchEdge - 1 + DataZStart; } else if ((ConnectedEdge & EdgeType.East) != 0) { SurfacePatch neighbour = GetNeighbourPatch(DirectionIndex.East); eastSource = neighbour.DataZ; eastSurfaceIndex = 0 + neighbour.DataZStart; } else { return; } // If patch is on the east edge of its surface, then we update the east // side buffer for (j = 0; j < gridsPerPatchEdge; j++) { k = j * gridsPerEdge; DataZ[westSurfaceIndex + k] = eastSource[eastSurfaceIndex + k]; // update buffer Z } }
/// <summary> /// Decompresses all the patches in the given BitPack and assigns heights and normals to the surface. /// </summary> /// <param name="bitPack"></param> /// <param name="groupHeader"></param> /// <param name="isLargePatch"></param> public void DecompressPatches(BitPack bitPack, GroupHeader groupHeader, bool isLargePatch) { int j; int i; int[] patchData = new int[Patch.LARGE_PATCH_SIZE * Patch.LARGE_PATCH_SIZE]; // Large enough for a maximum sized patch Patch.InitPatchDecompressor(groupHeader.PatchSize); groupHeader.Stride = (UInt16)GridsPerEdge; Patch.SetGroupHeader(groupHeader); while (true) { PatchHeader patchHeader = new PatchHeader(bitPack); //Logger.LogDebug("Surface.DecompressPatches", $"{patchHeader} w={patchHeader.PatchIds >> 5} h={patchHeader.PatchIds & 0x1f} (PatchesPerEdge={PatchesPerEdge})"); if (patchHeader.IsEnd) { break; } i = patchHeader.PatchIds >> 5; j = patchHeader.PatchIds & 0x1f; if ((i >= PatchesPerEdge) || (j >= PatchesPerEdge)) { //Logger.LogWarning("Surface.DecompressPatches", $"Received invalid terrain packet - patch header patch ID incorrect! {i}x{j} DcOffset={patchHeader.DcOffset} Range={patchHeader.Range} QuantWBits={patchHeader.QuantWBits} PatchIds={patchHeader.PatchIds}"); return; } SurfacePatch surfacePatch = PatchList[j * PatchesPerEdge + i]; Patch.Decode(bitPack, groupHeader.PatchSize, (patchHeader.QuantWBits & 0xf) + 2, patchData); Patch.DeCompress(SurfaceZ, surfacePatch.DataZStart, patchData, patchHeader); // Update edges for neighbours. Need to guarantee that this gets done before we generate vertical stats. surfacePatch.UpdateNorthEdge(); surfacePatch.UpdateEastEdge(); if (surfacePatch.GetNeighbourPatch(DirectionIndex.West) != null) { surfacePatch.GetNeighbourPatch(DirectionIndex.West).UpdateEastEdge(); } if (surfacePatch.GetNeighbourPatch(DirectionIndex.SouthWest) != null) { surfacePatch.GetNeighbourPatch(DirectionIndex.SouthWest).UpdateEastEdge(); surfacePatch.GetNeighbourPatch(DirectionIndex.SouthWest).UpdateNorthEdge(); } if (surfacePatch.GetNeighbourPatch(DirectionIndex.South) != null) { surfacePatch.GetNeighbourPatch(DirectionIndex.South).UpdateNorthEdge(); } //// Dirty patch statistics, and flag that the patch has data. surfacePatch.DirtyZ(); surfacePatch.HasReceivedData = true; //break; //TODO: Only do the first patch for testing } }
public SurfacePatchMesh(SurfacePatch bezierPoints, int resolution) { CoreSurfacePatch = bezierPoints; Resolution = resolution; rebuild(); //ZNoise test = new ZNoise(EBiom.Flat); //test.calculatePoints(); //Debug.Log(test.ToString()); }
public void SetNeighbourPatch(DirectionIndex direction, SurfacePatch neighbor) { NeighborPatches[(UInt32)direction] = neighbor; NormalsInvalid[(UInt32)direction] = true; if ((UInt32)direction < 4) { NormalsInvalid[(UInt32)World.DirAdjacent[(UInt32)direction, 0]] = true; NormalsInvalid[(UInt32)World.DirAdjacent[(UInt32)direction, 1]] = true; } }
public void AssignPatches() { SurfacePatches = new SurfacePatch[PatchAmount, PatchAmount]; for (int x = 0; x < PatchAmount; x++) { for (int z = 0; z < PatchAmount; z++) { SurfacePatches[x, z] = new SurfacePatch(); for (int x2 = 0; x2 < 4; x2++) { for (int z2 = 0; z2 < 4; z2++) { SurfacePatches[x, z].BezierPoints[x2, z2] = ChunkNoise.calculatedPoints[(x * 3) + x2, (z * 3) + z2]; } } } } //Debug.Log("Pachtes of Chunk " + Positionkey + " have been assigned!"); }
public void ConnectNeighbour(SurfacePatch neighbour, DirectionIndex direction) { if (neighbour == null) { // TODO: Should I throw an exception? return; } NormalsInvalid[(int)direction] = true; neighbour.NormalsInvalid[(int)World.DirOpposite[(int)direction]] = true; SetNeighbourPatch(direction, neighbour); neighbour.SetNeighbourPatch(World.DirOpposite[(int)direction], this); switch (direction) { case DirectionIndex.East: ConnectedEdge |= EdgeType.East; neighbour.ConnectedEdge |= EdgeType.West; break; case DirectionIndex.North: ConnectedEdge |= EdgeType.North; neighbour.ConnectedEdge |= EdgeType.South; break; case DirectionIndex.West: ConnectedEdge |= EdgeType.West; neighbour.ConnectedEdge |= EdgeType.East; break; case DirectionIndex.South: ConnectedEdge |= EdgeType.South; neighbour.ConnectedEdge |= EdgeType.North; break; } }
public void DecompressDCTPatch() { byte[] volumeData = { 0x08, 0x01, 0x10, 0x4c, 0x8b, 0xfa, 0x6d, 0xa7, 0x41, 0x01, 0x00, 0x07, 0x7e, 0xff, 0xf0, 0x18, 0x38, 0x10, 0x30, 0x08, 0x03, 0x80, 0x82, 0x8a, 0xba, 0xda, 0xa4, 0x41, 0x01, 0x00, 0xe7, 0x3a, 0x45, 0xf0, 0x90, 0xe1, 0x01, 0xc1, 0x03, 0x83, 0x87, 0x06, 0x0e, 0x08, 0x1c, 0x18, 0x38, 0x28, 0x70, 0x30, 0xe0, 0x41, 0xc1, 0x03, 0x82, 0x07, 0x04, 0x0e, 0x06, 0x1c, 0x08, 0x38, 0x18, 0x70, 0x30, 0xe0, 0x61, 0xc0, 0xc3, 0x81, 0x07, 0x01, 0x0e, 0x04, 0x1c, 0x0c, 0x38, 0x18, 0x70, 0x20, 0xe0, 0x41, 0xc0, 0x43, 0x80, 0x87, 0x02, 0x0e, 0x04, 0x1c, 0x08, 0x38, 0x10, 0x70, 0x20, 0xe0, 0x41, 0xc0, 0x43, 0x80, 0x87, 0x01, 0x0e, 0x04, 0x1c, 0x08, 0x38, 0x10, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x83, 0x80, 0x87, 0x01, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x83, 0x80, 0x87, 0x01, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x81, 0xc0, 0x43, 0x80, 0x87, 0x01, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x80, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x85, 0x17, 0x6c, 0xe7, 0x4e, 0x82, 0x02, 0x00, 0x10, 0xff, 0xff, 0xd1, 0x66, 0x92, 0x31, 0x08, 0x20, 0x80, 0x00, 0xce, 0xc6, 0xce, 0x9b, 0x0e, 0x1a, 0x0e, 0x3b, 0x07, 0xd2, 0x07, 0x96, 0x06, 0x1e, 0x06, 0x65, 0x07, 0x2b, 0x07, 0x86, 0x06, 0x52, 0x06, 0x7c, 0x06, 0x05, 0x07, 0x22, 0x06, 0x12, 0x07, 0x18, 0x07, 0x01, 0x06, 0x14, 0x07, 0x38, 0x07, 0x53, 0x07, 0x08, 0x07, 0x19, 0x06, 0x0d, 0x06, 0x31, 0x06, 0x02, 0x07, 0x1b, 0x06, 0x09, 0x06, 0x0d, 0x03, 0x83, 0x03, 0x0b, 0x03, 0x0c, 0x03, 0x89, 0x83, 0x89, 0x83, 0x0b, 0x03, 0x08, 0x01, 0xc4, 0x01, 0xc0, 0xc1, 0x85, 0x81, 0x80, 0x41, 0xc6, 0x41, 0xc2, 0x80, 0xe0, 0xc0, 0xc0, 0x80, 0xc0, 0x60, 0xc0, 0x20, 0xc1, 0xc0, 0xc0, 0x80, 0xe2, 0x80, 0xe1, 0x60, 0xc1, 0x00, 0x70, 0x40, 0x30, 0x18, 0x38, 0x18, 0x38, 0x08, 0x30, 0x88, 0x30, 0x70, 0x38, 0x20, 0x38, 0x08, 0x30, 0x10, 0x38, 0x10, 0x1c, 0x08, 0x0e, 0x04, 0x0e, 0x08, 0x0c, 0x02, 0x0e, 0x0a, 0x0e, 0x1c, 0x0e, 0x04, 0x0c, 0x0a, 0x03, 0x00, 0x81, 0xc0, 0x40, 0xe0, 0x20, 0xe0, 0xa0, 0xc0, 0x60, 0xc0, 0xe0, 0x30, 0x18, 0x18, 0x04, 0x18, 0x04, 0x18, 0x04, 0x0c, 0x02, 0x03, 0x01, 0x81, 0xc0, 0x81, 0x80, 0xc1, 0x80, 0x80, 0xc0, 0x20, 0x70, 0x10, 0x30, 0x08, 0x38, 0x08, 0x18, 0x04, 0x1c, 0x04, 0x07, 0x03, 0x07, 0x02, 0x03, 0x81, 0x00, 0xe0, 0x60, 0xc0, 0x40, 0xc0, 0x20, 0x60, 0x20, 0x60, 0x10, 0x30, 0x10, 0x07, 0x01, 0x03, 0x01, 0x00, 0xc0, 0x40, 0xe0, 0x20, 0xc0, 0x20, 0xe0, 0x20, 0xe0, 0x60, 0x60, 0x10, 0x60, 0x10, 0x60, 0x10, 0x0e, 0x02, 0x06, 0x01, 0x07, 0x01, 0x07, 0x01, 0x07, 0x02, 0x01, 0xc0, 0x80, 0xe0, 0x20, 0xe0, 0x20, 0xe0, 0x20, 0xe0, 0x20, 0xc0, 0x40, 0xc0, 0x40, 0xe0, 0x40, 0x60, 0x20, 0x60, 0x10, 0x70, 0x20, 0x30, 0x08, 0x30, 0x08, 0x0c, 0x02, 0x0c, 0x02, 0x0e, 0x02, 0x06, 0x02, 0x03, 0x00, 0x81, 0xc0, 0x40, 0x38, 0x08, 0x18, 0x04, 0x0e, 0x06, 0x0c, 0x04, 0x03, 0x00, 0x80, 0x30, 0x08, 0x38, 0x08, 0x38, 0x08, 0x30, 0x08, 0x1c, 0x04, 0x03, 0x80, 0x81, 0x80, 0x40, 0xe0, 0x20, 0xe0, 0x20, 0x06, 0x01, 0x05, 0x10, 0x45, 0xfb, 0x08, 0x82, 0x0a, 0x00, 0x4e, 0xec, 0x8f, 0x28, 0x5c, 0xd0, 0xea, 0x27, 0x33, 0xb6, 0x53, 0xe7, 0x4d, 0xf4, 0x75, 0x93, 0x01, 0x18, 0x1c, 0xe7, 0x27, 0x6a, 0x36, 0x01, 0x8d, 0x8c, 0x34, 0x73, 0x73, 0x4c, 0x9c, 0xac, 0xe2, 0x06, 0x0e, 0x30, 0x58, 0xe3, 0xe6, 0x12, 0x31, 0x21, 0x82, 0x0e, 0x06, 0x70, 0xb3, 0x03, 0x9c, 0x20, 0xc6, 0xa7, 0x04, 0x38, 0xf9, 0xc1, 0x0c, 0x0c, 0x60, 0x33, 0x80, 0x9c, 0x1c, 0xe0, 0x66, 0x13, 0x38, 0x11, 0xc0, 0x8c, 0x14, 0x60, 0xa3, 0x82, 0x1c, 0x28, 0xe0, 0x46, 0x11, 0x30, 0x49, 0x82, 0xce, 0x0c, 0x70, 0x53, 0x00, 0x98, 0x04, 0xc0, 0x46, 0x02, 0x38, 0x20, 0xc0, 0x27, 0x02, 0x30, 0x51, 0xc2, 0x0c, 0x16, 0x38, 0x19, 0xc0, 0xce, 0x04, 0x70, 0x83, 0x83, 0x18, 0x28, 0xc0, 0x67, 0x02, 0x38, 0x09, 0xc0, 0x4e, 0x06, 0x07, 0x03, 0x38, 0x21, 0x80, 0x8e, 0x04, 0x70, 0x13, 0x07, 0x1c, 0x38, 0xc0, 0xe7, 0x04, 0x38, 0x10, 0x70, 0x41, 0xc0, 0x8c, 0x06, 0x60, 0x13, 0x04, 0x9c, 0x18, 0xe0, 0x66, 0x03, 0x38, 0x10, 0xe0, 0x21, 0xc0, 0x8e, 0x04, 0x70, 0x13, 0x01, 0x98, 0x04, 0xe0, 0xc6, 0x06, 0x30, 0x39, 0xc1, 0xcc, 0x04, 0x70, 0x33, 0x00, 0x98, 0x08, 0xc0, 0x23, 0x00, 0x9c, 0x0c, 0x70, 0x33, 0x01, 0x1c, 0x04, 0xc1, 0x46, 0x01, 0x38, 0x29, 0x80, 0x46, 0x01, 0x1c, 0x04, 0x18, 0x04, 0xc0, 0x26, 0x02, 0x38, 0x19, 0xc0, 0x4c, 0x10, 0x38, 0x11, 0xc0, 0x43, 0x00, 0x9c, 0x04, 0x70, 0x11, 0x80, 0x43, 0x00, 0x98, 0x14, 0x18, 0x04, 0xc0, 0x27, 0x01, 0x03, 0x80, 0x98, 0x04, 0xc0, 0x41, 0xc0, 0x4e, 0x02, 0x70, 0x31, 0xc0, 0x4e, 0x06, 0x38, 0x19, 0x80, 0x40, 0x60, 0x13, 0x01, 0x07, 0x01, 0x06, 0x02, 0x38, 0x18, 0xe0, 0x23, 0x81, 0x0e, 0x02, 0x30, 0x09, 0xc0, 0x8e, 0x02, 0x38, 0x08, 0x1c, 0x0c, 0xc0, 0x26, 0x01, 0x38, 0x11, 0x80, 0x4e, 0x02, 0x0c, 0x06, 0x60, 0x13, 0x81, 0x14, 0x51, 0xa4, 0x8c, 0x42, 0x08, 0x20, 0x01, 0x43, 0x9a, 0x7f, 0x64, 0x27, 0x4f, 0x3e, 0x32, 0x18, 0xa0, 0xbc, 0x68, 0x78, 0x90, 0xf0, 0x61, 0xc2, 0x43, 0x5c, 0x87, 0x20, 0x0f, 0x10, 0x18, 0xb8, 0x39, 0xd8, 0x64, 0x50, 0xc2, 0xc1, 0x8f, 0x83, 0x91, 0x06, 0x06, 0x0c, 0x38, 0x1c, 0x6c, 0x38, 0x30, 0x61, 0x70, 0xe1, 0x01, 0x89, 0x83, 0x04, 0x86, 0x02, 0x0e, 0x34, 0x1c, 0x18, 0x38, 0xf8, 0x70, 0x40, 0xe1, 0xc1, 0xc0, 0xc3, 0x81, 0x87, 0x01, 0x0c, 0x34, 0x1c, 0x34, 0x38, 0xc0, 0x60, 0xf0, 0xe0, 0xa1, 0x81, 0xc3, 0x86, 0x06, 0x0b, 0x0c, 0x12, 0x18, 0x44, 0x38, 0x28, 0x61, 0x00, 0xe0, 0xe1, 0x82, 0x83, 0x82, 0x86, 0x01, 0x0e, 0x24, 0x18, 0x10, 0x30, 0x68, 0x70, 0x40, 0xe0, 0x21, 0x80, 0x83, 0x82, 0x86, 0x09, 0x0c, 0x12, 0x18, 0x08, 0x30, 0x10, 0x60, 0x30, 0xe0, 0x41, 0xc3, 0x43, 0x81, 0x03, 0x80, 0x86, 0x04, 0x0e, 0x0e, 0x1c, 0x04, 0x38, 0x08, 0x38, 0x58, 0x30, 0x10, 0x30, 0x28, 0x70, 0x50, 0xe0, 0x81, 0x80, 0xc3, 0x81, 0x06, 0x02, 0x0c, 0x08, 0x0e, 0x02, 0x18, 0x08, 0x38, 0x08, 0x30, 0x20, 0x60, 0x10, 0x60, 0x20, 0xe0, 0x21, 0x81, 0xc3, 0x81, 0x06, 0x02, 0x0e, 0x06, 0x18, 0x08, 0x38, 0x08, 0x38, 0x28, 0x30, 0x28, 0x70, 0x10, 0x38, 0x18, 0x60, 0x40, 0xc0, 0xa1, 0x80, 0x81, 0xc0, 0xc3, 0x02, 0x03, 0x00, 0x87, 0x04, 0x0e, 0x06, 0x1c, 0x14, 0x38, 0x08, 0x60, 0x10, 0xc0, 0x21, 0x80, 0xc3, 0x80, 0x80, 0x38, 0x08, 0x70, 0x20, 0xe0, 0xc0, 0xc0, 0x40, 0xc0, 0x20, 0x70, 0x20, 0x60, 0x30, 0x18, 0x04, 0x38, 0x20, 0x70, 0x10, 0x60, 0x10, 0x60, 0x10, 0xe0, 0x41, 0x80, 0xc1, 0x80, 0x83, 0x01, 0x83, 0x80, 0x83, 0x00, 0x83, 0x80, 0x81, 0xc0, 0x83, 0x01, 0x86, 0x01, 0x0c, 0x02, 0x0e, 0x02, 0x06, 0x01, 0x0e, 0x04, 0x18, 0x04, 0x38, 0x08, 0x38, 0x28, 0x60, 0x10, 0x70, 0x10, 0xc0, 0x40, 0x18, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x40, 0x18, 0x04, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x30, 0x10, 0x30, 0x08, 0x30, 0x08, 0x70, 0x10, 0x01, 0x80, 0x41, 0xc0, 0x80, 0x0c, 0x02, 0x14, 0x5d, 0xb3, 0x9d, 0x3a, 0x08, 0x08, 0x00, 0x4b, 0xff, 0xff, 0x30, 0x80, }; float[] heights = // TODO: These are not correct - the data from the C++ test project doesn't take the stride into account { 13.4609261f, 21.4374886f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 21.4286995f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, }; Surface surface = new Surface(SurfaceType.Land, null); surface.Create(256, 16, new Vector3Double(0, 0, 0), 256); BitPack bitPack = new BitPack(volumeData); GroupHeader groupHeader = new GroupHeader(bitPack); Assert.AreEqual(0x108, groupHeader.Stride); Assert.AreEqual(0x10, groupHeader.PatchSize); Assert.AreEqual(LayerType.Land, groupHeader.LayerType); surface.DecompressPatches(bitPack, groupHeader, false); SurfacePatch patch = surface.GetPatch(8, 7); Assert.AreEqual(0x70f0, patch.DataZStart); //for (int i = 0; i < heights.Length; i++) //{ // Assert.AreEqual(heights[i], surface._SurfaceZ[patch.DataZStart + i], $"Height: Incorrect value at position {i}"); //} }
public void DecompressDCTPatch() { byte[] volumeData = { 0x08, 0x01, 0x10, 0x4c, 0x8b, 0xfa, 0x6d, 0xa7, 0x41, 0x01, 0x00, 0x07, 0x7e, 0xff, 0xf0, 0x18, 0x38, 0x10, 0x30, 0x08, 0x03, 0x80, 0x82, 0x8a, 0xba, 0xda, 0xa4, 0x41, 0x01, 0x00, 0xe7, 0x3a, 0x45, 0xf0, 0x90, 0xe1, 0x01, 0xc1, 0x03, 0x83, 0x87, 0x06, 0x0e, 0x08, 0x1c, 0x18, 0x38, 0x28, 0x70, 0x30, 0xe0, 0x41, 0xc1, 0x03, 0x82, 0x07, 0x04, 0x0e, 0x06, 0x1c, 0x08, 0x38, 0x18, 0x70, 0x30, 0xe0, 0x61, 0xc0, 0xc3, 0x81, 0x07, 0x01, 0x0e, 0x04, 0x1c, 0x0c, 0x38, 0x18, 0x70, 0x20, 0xe0, 0x41, 0xc0, 0x43, 0x80, 0x87, 0x02, 0x0e, 0x04, 0x1c, 0x08, 0x38, 0x10, 0x70, 0x20, 0xe0, 0x41, 0xc0, 0x43, 0x80, 0x87, 0x01, 0x0e, 0x04, 0x1c, 0x08, 0x38, 0x10, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x83, 0x80, 0x87, 0x01, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x83, 0x80, 0x87, 0x01, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x81, 0xc0, 0x43, 0x80, 0x87, 0x01, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x80, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x21, 0xc0, 0x43, 0x80, 0x85, 0x17, 0x6c, 0xe7, 0x4e, 0x82, 0x02, 0x00, 0x10, 0xff, 0xff, 0xd1, 0x66, 0x92, 0x31, 0x08, 0x20, 0x80, 0x00, 0xce, 0xc6, 0xce, 0x9b, 0x0e, 0x1a, 0x0e, 0x3b, 0x07, 0xd2, 0x07, 0x96, 0x06, 0x1e, 0x06, 0x65, 0x07, 0x2b, 0x07, 0x86, 0x06, 0x52, 0x06, 0x7c, 0x06, 0x05, 0x07, 0x22, 0x06, 0x12, 0x07, 0x18, 0x07, 0x01, 0x06, 0x14, 0x07, 0x38, 0x07, 0x53, 0x07, 0x08, 0x07, 0x19, 0x06, 0x0d, 0x06, 0x31, 0x06, 0x02, 0x07, 0x1b, 0x06, 0x09, 0x06, 0x0d, 0x03, 0x83, 0x03, 0x0b, 0x03, 0x0c, 0x03, 0x89, 0x83, 0x89, 0x83, 0x0b, 0x03, 0x08, 0x01, 0xc4, 0x01, 0xc0, 0xc1, 0x85, 0x81, 0x80, 0x41, 0xc6, 0x41, 0xc2, 0x80, 0xe0, 0xc0, 0xc0, 0x80, 0xc0, 0x60, 0xc0, 0x20, 0xc1, 0xc0, 0xc0, 0x80, 0xe2, 0x80, 0xe1, 0x60, 0xc1, 0x00, 0x70, 0x40, 0x30, 0x18, 0x38, 0x18, 0x38, 0x08, 0x30, 0x88, 0x30, 0x70, 0x38, 0x20, 0x38, 0x08, 0x30, 0x10, 0x38, 0x10, 0x1c, 0x08, 0x0e, 0x04, 0x0e, 0x08, 0x0c, 0x02, 0x0e, 0x0a, 0x0e, 0x1c, 0x0e, 0x04, 0x0c, 0x0a, 0x03, 0x00, 0x81, 0xc0, 0x40, 0xe0, 0x20, 0xe0, 0xa0, 0xc0, 0x60, 0xc0, 0xe0, 0x30, 0x18, 0x18, 0x04, 0x18, 0x04, 0x18, 0x04, 0x0c, 0x02, 0x03, 0x01, 0x81, 0xc0, 0x81, 0x80, 0xc1, 0x80, 0x80, 0xc0, 0x20, 0x70, 0x10, 0x30, 0x08, 0x38, 0x08, 0x18, 0x04, 0x1c, 0x04, 0x07, 0x03, 0x07, 0x02, 0x03, 0x81, 0x00, 0xe0, 0x60, 0xc0, 0x40, 0xc0, 0x20, 0x60, 0x20, 0x60, 0x10, 0x30, 0x10, 0x07, 0x01, 0x03, 0x01, 0x00, 0xc0, 0x40, 0xe0, 0x20, 0xc0, 0x20, 0xe0, 0x20, 0xe0, 0x60, 0x60, 0x10, 0x60, 0x10, 0x60, 0x10, 0x0e, 0x02, 0x06, 0x01, 0x07, 0x01, 0x07, 0x01, 0x07, 0x02, 0x01, 0xc0, 0x80, 0xe0, 0x20, 0xe0, 0x20, 0xe0, 0x20, 0xe0, 0x20, 0xc0, 0x40, 0xc0, 0x40, 0xe0, 0x40, 0x60, 0x20, 0x60, 0x10, 0x70, 0x20, 0x30, 0x08, 0x30, 0x08, 0x0c, 0x02, 0x0c, 0x02, 0x0e, 0x02, 0x06, 0x02, 0x03, 0x00, 0x81, 0xc0, 0x40, 0x38, 0x08, 0x18, 0x04, 0x0e, 0x06, 0x0c, 0x04, 0x03, 0x00, 0x80, 0x30, 0x08, 0x38, 0x08, 0x38, 0x08, 0x30, 0x08, 0x1c, 0x04, 0x03, 0x80, 0x81, 0x80, 0x40, 0xe0, 0x20, 0xe0, 0x20, 0x06, 0x01, 0x05, 0x10, 0x45, 0xfb, 0x08, 0x82, 0x0a, 0x00, 0x4e, 0xec, 0x8f, 0x28, 0x5c, 0xd0, 0xea, 0x27, 0x33, 0xb6, 0x53, 0xe7, 0x4d, 0xf4, 0x75, 0x93, 0x01, 0x18, 0x1c, 0xe7, 0x27, 0x6a, 0x36, 0x01, 0x8d, 0x8c, 0x34, 0x73, 0x73, 0x4c, 0x9c, 0xac, 0xe2, 0x06, 0x0e, 0x30, 0x58, 0xe3, 0xe6, 0x12, 0x31, 0x21, 0x82, 0x0e, 0x06, 0x70, 0xb3, 0x03, 0x9c, 0x20, 0xc6, 0xa7, 0x04, 0x38, 0xf9, 0xc1, 0x0c, 0x0c, 0x60, 0x33, 0x80, 0x9c, 0x1c, 0xe0, 0x66, 0x13, 0x38, 0x11, 0xc0, 0x8c, 0x14, 0x60, 0xa3, 0x82, 0x1c, 0x28, 0xe0, 0x46, 0x11, 0x30, 0x49, 0x82, 0xce, 0x0c, 0x70, 0x53, 0x00, 0x98, 0x04, 0xc0, 0x46, 0x02, 0x38, 0x20, 0xc0, 0x27, 0x02, 0x30, 0x51, 0xc2, 0x0c, 0x16, 0x38, 0x19, 0xc0, 0xce, 0x04, 0x70, 0x83, 0x83, 0x18, 0x28, 0xc0, 0x67, 0x02, 0x38, 0x09, 0xc0, 0x4e, 0x06, 0x07, 0x03, 0x38, 0x21, 0x80, 0x8e, 0x04, 0x70, 0x13, 0x07, 0x1c, 0x38, 0xc0, 0xe7, 0x04, 0x38, 0x10, 0x70, 0x41, 0xc0, 0x8c, 0x06, 0x60, 0x13, 0x04, 0x9c, 0x18, 0xe0, 0x66, 0x03, 0x38, 0x10, 0xe0, 0x21, 0xc0, 0x8e, 0x04, 0x70, 0x13, 0x01, 0x98, 0x04, 0xe0, 0xc6, 0x06, 0x30, 0x39, 0xc1, 0xcc, 0x04, 0x70, 0x33, 0x00, 0x98, 0x08, 0xc0, 0x23, 0x00, 0x9c, 0x0c, 0x70, 0x33, 0x01, 0x1c, 0x04, 0xc1, 0x46, 0x01, 0x38, 0x29, 0x80, 0x46, 0x01, 0x1c, 0x04, 0x18, 0x04, 0xc0, 0x26, 0x02, 0x38, 0x19, 0xc0, 0x4c, 0x10, 0x38, 0x11, 0xc0, 0x43, 0x00, 0x9c, 0x04, 0x70, 0x11, 0x80, 0x43, 0x00, 0x98, 0x14, 0x18, 0x04, 0xc0, 0x27, 0x01, 0x03, 0x80, 0x98, 0x04, 0xc0, 0x41, 0xc0, 0x4e, 0x02, 0x70, 0x31, 0xc0, 0x4e, 0x06, 0x38, 0x19, 0x80, 0x40, 0x60, 0x13, 0x01, 0x07, 0x01, 0x06, 0x02, 0x38, 0x18, 0xe0, 0x23, 0x81, 0x0e, 0x02, 0x30, 0x09, 0xc0, 0x8e, 0x02, 0x38, 0x08, 0x1c, 0x0c, 0xc0, 0x26, 0x01, 0x38, 0x11, 0x80, 0x4e, 0x02, 0x0c, 0x06, 0x60, 0x13, 0x81, 0x14, 0x51, 0xa4, 0x8c, 0x42, 0x08, 0x20, 0x01, 0x43, 0x9a, 0x7f, 0x64, 0x27, 0x4f, 0x3e, 0x32, 0x18, 0xa0, 0xbc, 0x68, 0x78, 0x90, 0xf0, 0x61, 0xc2, 0x43, 0x5c, 0x87, 0x20, 0x0f, 0x10, 0x18, 0xb8, 0x39, 0xd8, 0x64, 0x50, 0xc2, 0xc1, 0x8f, 0x83, 0x91, 0x06, 0x06, 0x0c, 0x38, 0x1c, 0x6c, 0x38, 0x30, 0x61, 0x70, 0xe1, 0x01, 0x89, 0x83, 0x04, 0x86, 0x02, 0x0e, 0x34, 0x1c, 0x18, 0x38, 0xf8, 0x70, 0x40, 0xe1, 0xc1, 0xc0, 0xc3, 0x81, 0x87, 0x01, 0x0c, 0x34, 0x1c, 0x34, 0x38, 0xc0, 0x60, 0xf0, 0xe0, 0xa1, 0x81, 0xc3, 0x86, 0x06, 0x0b, 0x0c, 0x12, 0x18, 0x44, 0x38, 0x28, 0x61, 0x00, 0xe0, 0xe1, 0x82, 0x83, 0x82, 0x86, 0x01, 0x0e, 0x24, 0x18, 0x10, 0x30, 0x68, 0x70, 0x40, 0xe0, 0x21, 0x80, 0x83, 0x82, 0x86, 0x09, 0x0c, 0x12, 0x18, 0x08, 0x30, 0x10, 0x60, 0x30, 0xe0, 0x41, 0xc3, 0x43, 0x81, 0x03, 0x80, 0x86, 0x04, 0x0e, 0x0e, 0x1c, 0x04, 0x38, 0x08, 0x38, 0x58, 0x30, 0x10, 0x30, 0x28, 0x70, 0x50, 0xe0, 0x81, 0x80, 0xc3, 0x81, 0x06, 0x02, 0x0c, 0x08, 0x0e, 0x02, 0x18, 0x08, 0x38, 0x08, 0x30, 0x20, 0x60, 0x10, 0x60, 0x20, 0xe0, 0x21, 0x81, 0xc3, 0x81, 0x06, 0x02, 0x0e, 0x06, 0x18, 0x08, 0x38, 0x08, 0x38, 0x28, 0x30, 0x28, 0x70, 0x10, 0x38, 0x18, 0x60, 0x40, 0xc0, 0xa1, 0x80, 0x81, 0xc0, 0xc3, 0x02, 0x03, 0x00, 0x87, 0x04, 0x0e, 0x06, 0x1c, 0x14, 0x38, 0x08, 0x60, 0x10, 0xc0, 0x21, 0x80, 0xc3, 0x80, 0x80, 0x38, 0x08, 0x70, 0x20, 0xe0, 0xc0, 0xc0, 0x40, 0xc0, 0x20, 0x70, 0x20, 0x60, 0x30, 0x18, 0x04, 0x38, 0x20, 0x70, 0x10, 0x60, 0x10, 0x60, 0x10, 0xe0, 0x41, 0x80, 0xc1, 0x80, 0x83, 0x01, 0x83, 0x80, 0x83, 0x00, 0x83, 0x80, 0x81, 0xc0, 0x83, 0x01, 0x86, 0x01, 0x0c, 0x02, 0x0e, 0x02, 0x06, 0x01, 0x0e, 0x04, 0x18, 0x04, 0x38, 0x08, 0x38, 0x28, 0x60, 0x10, 0x70, 0x10, 0xc0, 0x40, 0x18, 0x04, 0x38, 0x08, 0x70, 0x10, 0xe0, 0x40, 0x18, 0x04, 0x0e, 0x02, 0x1c, 0x04, 0x38, 0x08, 0x30, 0x10, 0x30, 0x08, 0x30, 0x08, 0x70, 0x10, 0x01, 0x80, 0x41, 0xc0, 0x80, 0x0c, 0x02, 0x14, 0x5d, 0xb3, 0x9d, 0x3a, 0x08, 0x08, 0x00, 0x4b, 0xff, 0xff, 0x30, 0x80, }; float[] heights = { 44.8443375f, 23.8873062f, 16.1412125f, 19.8912125f, 19.7037125f, 18.03965f, 19.7310562f, 19.0709f, 18.6724625f, 19.367775f, 19.0709f, 18.8912125f, 19.1685562f, 19.1763687f, 18.7310562f, 19.3130875f, 22.3755875f, 14.9693375f, 21.8326187f, 17.8755875f, 19.0279312f, 19.5279312f, 18.7193375f, 19.0709f, 19.2935562f, 18.9068375f, 19.0709f, 19.1685562f, 19.0709f, 19.0709f, 19.1919937f, 18.9419937f, 20.2232437f, 17.8951187f, 19.2466812f, 19.930275f, 17.6998062f, 20.3599625f, 18.4068375f, 19.1451187f, 19.2349625f, 18.8912125f, 19.0709f, 19.1763687f, 19.0709f, 19.0709f, 19.1998062f, 18.9341812f, 15.4068375f, 23.430275f, 16.66465f, 19.1724625f, 20.47715f, 17.4107437f, 20.1099625f, 18.9888687f, 18.711525f, 19.3638687f, 19.0709f, 18.8443375f, 19.3130875f, 19.0709f, 18.7974625f, 19.3599625f, 21.9537125f, 15.5044937f, 21.5591812f, 17.9576187f, 19.1373062f, 19.367775f, 18.742775f, 19.1607437f, 19.0709f, 19.0709f, 19.0709f, 19.1919937f, 18.9419937f, 19.0709f, 19.0709f, 19.0709f, 18.72715f, 19.7310562f, 17.9576187f, 20.5318375f, 17.586525f, 20.2193375f, 18.6216812f, 19.0709f, 19.3873062f, 18.8443375f, 19.0709f, 19.0709f, 19.0709f, 18.9263687f, 19.2232437f, 18.9107437f, 17.8013687f, 20.3599625f, 18.8716812f, 18.2544937f, 20.4654312f, 17.8130875f, 19.7544937f, 19.0709f, 18.7310562f, 19.3130875f, 19.0709f, 18.7974625f, 19.2154312f, 19.0709f, 18.9107437f, 19.2388687f, 20.0084f, 18.0084f, 19.66465f, 18.9888687f, 18.8912125f, 19.3638687f, 18.8599625f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.2154312f, 18.9185562f, 19.2310562f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 18.8248062f, 19.5201187f, 18.5826187f, 19.3873062f, 19.0709f, 19.0709f, 19.1998062f, 18.9341812f, 19.0709f, 19.0709f, 19.0709f, 18.9029312f, 19.2466812f, 19.0709f, 18.774025f, 19.3169937f, 19.0709f, 18.9732437f, 19.2818375f, 18.9576187f, 19.0709f, 19.1998062f, 18.9341812f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.1841812f, 18.9498062f, 19.1998062f, 18.9341812f, 19.2154312f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.1607437f, 18.9732437f, 19.1763687f, 19.0709f, 19.0709f, 19.0709f, 18.9341812f, 19.2154312f, 18.9185562f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 18.9576187f, 19.3130875f, 18.6841812f, 19.3443375f, 19.0709f, 19.0709f, 19.2310562f, 18.9029312f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 18.9654312f, 19.1841812f, 19.0709f, 18.9419937f, 19.3443375f, 18.7818375f, 19.2232437f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.1998062f, 18.7974625f, 19.2154312f, 19.0709f, 19.0709f, 19.2388687f, 18.8951187f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.3130875f, 18.9419937f, 19.0709f, 19.3599625f, 18.6138687f, 19.3912125f, 19.0709f, 18.8951187f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, 19.0709f, }; Surface surface = new Surface(SurfaceType.Land, null); surface.Create(256, 16, new Vector3Double(0, 0, 0), 256); BitPack bitPack = new BitPack(volumeData); GroupHeader groupHeader = new GroupHeader(bitPack); Assert.AreEqual(0x108, groupHeader.Stride); Assert.AreEqual(0x10, groupHeader.PatchSize); Assert.AreEqual(LayerType.Land, groupHeader.LayerType); surface.DecompressPatches(bitPack, groupHeader, false); SurfacePatch patch = surface.GetPatch(8, 6); Assert.AreEqual(0x60e0, patch.DataZStart); // y = 96, x = 224 string s = ""; for (int y = 0; y < surface.GridsPerEdge; y++) { for (int x = 0; x < surface.GridsPerEdge; x++) { float height = surface.GetZ(x, y); s += $"{height}, "; } s += "\n"; } File.WriteAllText("surfaceHeightsUNITY.csv", s); //string s = ""; //for (int y = 0; y < groupHeader.PatchSize; y++) //{ // for (int x = 0; x < groupHeader.PatchSize; x++) // { // s += $"{surface._SurfaceZ[patch.DataZStart + y * groupHeader.Stride + x]}, "; // } // s += "\n"; //} //File.WriteAllText("surfacePatchHeights_8_6.csv", s); for (int y = 0; y < groupHeader.PatchSize; y++) { for (int x = 0; x < groupHeader.PatchSize; x++) { Assert.AreEqual(heights[y * groupHeader.PatchSize + x], surface._SurfaceZ[patch.DataZStart + y * groupHeader.Stride + x]); } } //for (int i = 0; i < heights.Length; i++) //{ // Assert.AreEqual(heights[i], surface._SurfaceZ[patch.DataZStart + i], $"Height: Incorrect value at position {i}"); //} }
public void DirtySurfacePatch(SurfacePatch patch) { // Put surface patch on dirty surface patch list DirtyPatchList.Add(patch); }
/// <summary> /// Called when loading the script /// </summary> void Awake() { bezierPoints = new SurfacePatch(); CoreSurfacePatchMesh = new SurfacePatchMesh(bezierPoints, Resolution); }