public SerializedChunk(IntVector3 ChunkPos, MapDisplay.LODBuffers DBuffers, uint[] Voxels, Chunk.MetaData metaData) { this.ChunkPos = ChunkPos; this.Voxels = Voxels; this.DBuffers = DBuffers; this.metaData = metaData; }
void RenderPoints() { IntVector3 size = new IntVector3(_chunkSize); var points = GetPoints(size); //int bits = (int) Mathf.Log( _chunkSize * _chunkSize * _chunkSize, 8); points = points.OrderBy(v => HilbertTables.XYZToHilbertIndex[v.index]).ToList(); // v.v.ToUint3().CoordsToFlatHilbertIndex(bits)).ToList(); var verts = new List <Vertex>(points.Count); for (int i = 0; i < points.Count; i++) { Vertex a = new Vertex() { pos = (Vector3)points[i].v, color = ColorUtil.roygbivMod(i) }; verts.Add(a); } TestHilbertBackToXYZ(points); lsr.Apply(verts.ToArray()); //cr.Apply(verts); var dbuffers = new MapDisplay.LODBuffers(); // GenerateMapBuffers(points); MapDisplay md = Instantiate(displayPrefab); md.transform.SetParent(transform); md.transform.localPosition = transform.localPosition + Vector3.right * 10f; // just nudge right a bit md.initialize(dbuffers); //voxelShader, //ColorUtil.roygbiv, //spriteTex, //dbuffers); }
public static void WriteBuffer(MapDisplay.LODBuffers dbuffers, string path) { for (int i = 0; i < ChunkGenData.LODLevels; ++i) { WriteBuffAtIndex(dbuffers, path, i); } }
public static MapDisplay.LODBuffers ReadBufferAt(string path) { var dbuffers = new MapDisplay.LODBuffers(); for (int i = 0; i < 3; ++i) { dbuffers[i] = CVoxelMapFormat.BufferCountArgs.CreateBuffer(ReadUintsFromFile(FilePathForBuffer(path, i))); } return(dbuffers); }
public MapDisplay.LODBuffers takeDisplayBuffers() { var lodBuffers = new MapDisplay.LODBuffers(); lodBuffers.display = SolidVoxels; lodBuffers.lod2 = SolidVoxelsLOD2; lodBuffers.lod4 = SolidVoxelsLOD4; SolidVoxels = null; SolidVoxelsLOD2 = null; SolidVoxelsLOD4 = null; return(lodBuffers); }
MapDisplay GenerateMapDisplay(IntVector3 chunkPos, MapDisplay.LODBuffers dbuffers) // MapDisplay.DisplayBuffers dbuffers) { GameObject go = (GameObject)Instantiate(displayPrefab); go.transform.SetParent(transform); go.transform.localPosition = transform.localPosition + Vector3.Scale(chunkPos, vGenConfig.ChunkSize); MapDisplay md = go.GetComponent <MapDisplay>(); md.initialize( //geometryShader, //ColorUtil.roygbiv, //voxelTexture, dbuffers, vGenConfig); return(md); }
public static SerializedChunk Read(IntVector3 chunkPos) { if (!File.Exists(GetFileFullPath(chunkPos))) { return(null); } try { MapDisplay.LODBuffers dbuffers = null; Chunk.MetaData metaData = new Chunk.MetaData() { Dirty = true }; metaData = XMLOp.Deserialize <Chunk.MetaData>(GetMetaDataFullPath(chunkPos)); try { dbuffers = SerializedDisplayBuffers.ReadBufferAt(GetDBufferFullPath(chunkPos)); // SerializedDisplayBuffers.Deserialize(GetDBufferFullPath(chunkPos)).ToDisplayBuffers(); } catch (Exception e) { Debug.LogWarning("Excptn while reading dbuffers " + e.ToString()); return(null); } FileStream chunkFile = File.Open(GetFileFullPath(chunkPos), FileMode.Open); using (BinaryReader br = new BinaryReader(chunkFile)) { int pos = 0; int length = (int)br.BaseStream.Length; uint[] voxels = new uint[length / VoxelStorageSize]; while (pos * VoxelStorageSize < length) { voxels[pos++] = br.ReadUInt32(); } return(new SerializedChunk(chunkPos, dbuffers, voxels, metaData)); } } catch (Exception e) { Debug.LogWarning("Excptn while reading: " + e.ToString()); return(null); } }
static void WriteBuffAtIndex(MapDisplay.LODBuffers dbuffers, string path, int index) { WriteUintsToFile(CVoxelMapFormat.BufferCountArgs.GetData <uint>(dbuffers[index]), FilePathForBuffer(path, index)); }
public static void ReadAsync(IntVector3 chunkPos, Action <SerializedChunk> callback) { /* * if (!File.Exists(GetFileFullPath(chunkPos))) * { * Debug.Log("No file at" + chunkPos); * callback(null); * return; * } */ if (!Chunk.MetaData.SavedChunkExists(chunkPos)) { callback(null); return; } GameObject jcbGO = new GameObject(); SerializedDisplayBuffers.DeserJob dsbuffJob = default(SerializedDisplayBuffers.DeserJob); MapDisplay.LODBuffers dbuffers = null; try { Chunk.MetaData metaData = new Chunk.MetaData() { Dirty = true }; metaData = XMLOp.Deserialize <Chunk.MetaData>(GetMetaDataFullPath(chunkPos)); if (metaData.isInvalid) { Debug.Log("invalid meta data at: " + chunkPos); callback(null); return; } dsbuffJob = new SerializedDisplayBuffers.DeserJob(); var all = Allocator.TempJob; dsbuffJob.path = new NativeArray <byte>(StringToBytes.ToBytes(GetDBufferFullPath(chunkPos)), all); dsbuffJob.rLOD0 = new NativeArray <VoxelGeomDataMirror>(metaData.LODBufferLengths[0], all); dsbuffJob.rLOD1 = new NativeArray <VoxelGeomDataMirror>(metaData.LODBufferLengths[1], all); dsbuffJob.rLOD2 = new NativeArray <VoxelGeomDataMirror>(metaData.LODBufferLengths[2], all); var jcb = jcbGO.AddComponent <JobCall>(); jcb.Schedule(dsbuffJob, () => { dbuffers = new MapDisplay.LODBuffers(); dbuffers[0] = CVoxelMapFormat.BufferCountArgs.CreateBuffer(dsbuffJob.rLOD0); dbuffers[1] = CVoxelMapFormat.BufferCountArgs.CreateBuffer(dsbuffJob.rLOD1); dbuffers[2] = CVoxelMapFormat.BufferCountArgs.CreateBuffer(dsbuffJob.rLOD2); dsbuffJob.DisposeNArrays(); uint[] voxelsFakeEmpty = new uint[1]; callback(new SerializedChunk(chunkPos, dbuffers, voxelsFakeEmpty, metaData)); /* * FileStream chunkFile = File.Open(GetFileFullPath(chunkPos), FileMode.Open); * // * // Maybe read the full voxel array later, as needed * // * using (BinaryReader br = new BinaryReader(chunkFile)) * { * int pos = 0; * int length = (int)br.BaseStream.Length; * uint[] voxels = new uint[length / VoxelStorageSize]; * while (pos * VoxelStorageSize < length) * { * voxels[pos++] = br.ReadUInt32(); * } * callback(new SerializedChunk(chunkPos, dbuffers, voxels, metaData)); * } */ GameObject.Destroy(jcbGO); }); } catch (Exception e) { Debug.LogWarning("Excptn while reading: " + e.ToString()); dsbuffJob.DisposeNArrays(); if (dbuffers != null) { dbuffers.release(); } GameObject.Destroy(jcbGO); callback(null); } }