private void TestReadMortons(int voxelAmount) { //read mortons, decrypt mortons and compare to original file Stream s = File.Open("Assets/VoxelData.bin", FileMode.Open); BinaryReader br = new BinaryReader(s); List <ulong> mortons = new List <ulong>(); ulong morton = 1; for (int i = 0; i < voxelAmount; ++i) { morton = br.ReadUInt64(); mortons.Add(morton); } br.Dispose(); StreamWriter w = new StreamWriter("Assets/DecryptedMortons.txt"); for (int i = 0; i < mortons.Capacity; ++i) { uint x, y, z; Morton.morton3DDecode(mortons[i], out x, out y, out z); w.Write($"{x}, {y}, {z}"); w.Write('\n'); } w.Dispose(); }
public void Start() { //Variables init _Parser = new SvoParser(); _Parser.Init(_GameObjectName); _AllNodePositions = new List <voxelPosition>(); _VoxelFaceFlags = new List <uint>(); _UnitFrustumVectors = new Vector3[4]; //Get all childeren and add mortons to list List <Node> nodes = new List <Node>(); _Parser.GetAllNodes(ref nodes, _Parser.GetRootNode()); foreach (Node n in nodes) { //if (n._morton == 0) continue; uint x, y, z; Morton.morton3DDecode(n._morton, out x, out y, out z); _AllNodePositions.Add(new voxelPosition(x, y, z)); } CullFaces(nodes); //DEBUG(nodes); InitBuffers(); _Parser.Dispose(); }
public void Set(Point3l point, T value) { Contract.Requires(Box.Contains(Bounds, point)); long xz = Morton.Encode(point.X - Bounds.X, point.Z - Bounds.Z); Volume[(point.Y - Bounds.Y) + xz * Bounds.Height] = value; }
// Volume is stored in columns (y is up/down), this makes traversals down columns fast. // After that x and z are in morton order. public T Get(Point3l point) { Contract.Requires(Box.Contains(Bounds, point)); long xz = Morton.Encode(point.X - Bounds.X, point.Z - Bounds.Z); return(Volume[(point.Y - Bounds.Y) + xz * Bounds.Height]); }
private void CreateTree(ulong[] data, uint boundExtent, string objectName) { //Init buffers _Buffers = new List <Node> [_MaxDepth]; for (int i = 0; i < _MaxDepth; ++i) { _Buffers[i] = new List <Node>(); } //_Writer = new StreamWriter(File.Open("Assets/Data/TreeNoNewlines.txt", FileMode.OpenOrCreate, FileAccess.Write)); _BWriter = new BinaryWriter(File.Open($"Assets/Data/{objectName}_Svo.bin", FileMode.OpenOrCreate, FileAccess.Write)); //build tree, ignore certain morton (see VoxelDataCreator::WriteVoxelData()) ulong ignoreMorton = Morton.morton3DEncode(boundExtent, boundExtent, boundExtent); for (int i = 0; i < data.Length; ++i) { //ignore empty morton if (data[i] == ignoreMorton || data[i] == 0) { continue; } //only get the 63-bits data[i] &= 0x7FFFFFFFFFFFFFFF; if (_CurrentMorton != data[i]) { AddEmptyVoxels(data[i] - _CurrentMorton); } Node node = new Node(); //leaf node node._morton = data[i]; _Buffers[_MaxDepth - 1].Add(node); RefineBuffers(_MaxDepth - 1); _CurrentMorton++; } //Finalize tree FinalizeTree(); //write header WriteHeader(objectName); //_Writer.Dispose(); _BWriter.Dispose(); }
private unsafe void DrawNode(int idx, int depth, Vector3 coords) { Node node = nodeData[idx]; var nodeSize = bounds.size / (1 << depth); var center = bounds.min + Vector3.Scale(coords + 0.5f * Vector3.one, nodeSize); Gizmos.DrawWireCube(center, nodeSize); for (int i = 0; i < 8; i++) { int child = node.children[i]; if (child > 0 && child < nodeData.Length) { Vector3 child_coords = Morton.Decode(i); DrawNode(child, depth + 1, 2f * coords + child_coords); } } }
private void EncodeVoxels(VoxelSystem.Voxel_t[] voxels, int boundExtent, out List <ulong> mortons) { //write mortons to temp array ulong m = 0; mortons = new List <ulong>(); foreach (VoxelSystem.Voxel_t v in voxels) { //can only send 21 bits to the encryptor, so make sure the positions aren't exeeding limit if (((uint)v.position.x > 0x1FFFFF) || ((uint)v.position.y > 0x1FFFFF) || ((uint)v.position.z > 0x1FFFFF)) { Debug.LogAssertion("one of the positions is larger than 2097152, try reducing the resolution"); } //ignore defaults if (v.position == new Vector3(boundExtent, boundExtent, boundExtent)) { continue; } //Encode the position m = Morton.morton3DEncode((uint)v.position.x, (uint)v.position.y, (uint)v.position.z); //only use the 63 first bits, the rest is signs and fill indicator m &= 0x7FFFFFFFFFFFFFFF; //ulong idx = m; //set last bit to indicate fill m |= (ulong)1 << 63; //write 64-bits //mortons[idx] = m; mortons.Add(m); } //sort array mortons.Sort(); }
public void EncodeDecode() { Vector3 coords = new Vector3(1, 2, 3); Assert.AreEqual(Morton.Decode(Morton.Encode(coords)), coords); }
private void PrintMorton() { Morton.PrintMorton3DTablesToFile(); Morton.PrintMorton2DTablesToFile(); }