public void SetInteractableChunk(ReducedMarchingCubesChunk chunk) { if (chunk != null) { GetCubeForwarder().chunk = chunk; } }
protected MarchingCubeMeshDisplayer(ReducedMarchingCubesChunk chunk, GameObject g, Transform t) : this(g, g.AddComponent <MeshFilter>(), g.AddComponent <MeshRenderer>(), new Mesh(), g.AddComponent <MeshCollider>()) { g.transform.SetParent(t, false); if (chunk is ReducedMarchingCubesChunk interactable) { hasCube = g.AddComponent <HasMarchingCube>(); hasCube.chunk = chunk; } }
protected CompressedMarchingCubeChunk GetThreadedChunkObjectAt(Vector3Int position, int lodPower, int chunkSizePower, bool allowOverride) { if (lodPower <= DEFAULT_MIN_CHUNK_LOD_POWER) { ReducedMarchingCubesChunk chunk = new ReducedMarchingCubesChunk(); return(GetChunkObjectAt(chunk, position, lodPower, chunkSizePower, allowOverride)); } else { return(GetChunkObjectAt(new CompressedMarchingCubeChunk(), position, lodPower, chunkSizePower, allowOverride)); } }
public void Store(Vector3Int anchorPos, ReducedMarchingCubesChunk chunk, bool overrideNoise = false) { StoredChunkEdits edits; if (!TryGetGroupItemAt(VectorExtension.ToArray(anchorPos), out edits) || overrideNoise) { edits = new StoredChunkEdits(); StorageTreeRoot r = GetOrCreateGroupAtCoordinate(PositionToGroupCoord(anchorPos)); chunk.StoreChunk(edits); r.SetLeafAtPosition(anchorPos, edits, true); //call all instantiableData from chunk that need to be stored //(everything not depending on triangles only, e.g trees ) } //Remove later if (edits.noise != chunk.Points) { throw new Exception(); } chunk.storageLeaf = edits.leaf; }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) { pointDelta *= -1; } if (Input.GetMouseButtonDown(2)) { //RaycastHit hit; //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Debug.DrawRay(ray.origin, ray.direction * 10, Color.red, 0.1f); //if (Physics.Raycast(ray, out hit, 2000, layer)) //{ // Transform currentHitObject = hit.collider.transform; // ReducedMarchingCubesChunk chunk = currentHitObject.GetComponent<IHasInteractableMarchingCubeChunk>()?.GetChunk; // if (chunk != null) // { // if (clickCount == 0) // { // firstTriIndex = chunk.GetTriangleFromRayHit(hit); // } // else // { // secondTriIndex = chunk.GetTriangleFromRayHit(hit); // BuildPath(firstTriIndex, secondTriIndex); // } // clickCount++; // clickCount = clickCount % 2; // } //} } else if (Input.GetMouseButtonDown(1)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 10, Color.red, 0.1f); if (Physics.Raycast(ray, out hit, 2000, layer)) { Transform currentHitObject = hit.collider.transform; ReducedMarchingCubesChunk chunk = currentHitObject.GetComponent <IHasInteractableMarchingCubeChunk>()?.GetChunk; if (chunk != null) { //MarchingCubeEntity e2 = chunk.GetClosestEntity(hit.point); //PathTriangle tri = chunk.GetTriangleFromRayHit(hit); //ps = tri.Neighbours; //p = tri; // h.DecreaseChunkLod(chunk, chunk.LODPower + 1); // chunk.GetChunkHandler.DecreaseChunkLod(chunk, 1); } } } else if (Input.GetMouseButton/*Down*/ (0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 10, Color.red, 0.1f); if (Physics.Raycast(ray, out hit, 2000, layer)) { Transform currentHitObject = hit.collider.transform; ReducedMarchingCubesChunk chunk = currentHitObject.GetComponent <IHasInteractableMarchingCubeChunk>()?.GetChunk; if (chunk != null) { chunk.EditPointsAroundRayHit(pointDelta, hit, 4); } } } }
public void EditPointsAroundRayHit(float delta, RaycastHit hit, int editDistance) { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); Vector3Int origin = GlobalPosToCubeIndex(hit.point); //var e = GetEntityFromRayHit(hit); int originX = origin.x; int originY = origin.y; int originZ = origin.z; Vector3 globalOrigin = origin + AnchorPos; Vector3 hitDiff = hit.point - globalOrigin; Vector3Int[] neighbourDirs = NeighbourDirections(originX, originY, originZ, editDistance + 1); int length = neighbourDirs.Length; List <Tuple <ReducedMarchingCubesChunk, Vector3Int> > chunks = new List <Tuple <ReducedMarchingCubesChunk, Vector3Int> >(); chunks.Add(Tuple.Create(this, origin)); CompressedMarchingCubeChunk chunk; for (int i = 0; i < length; i++) { Vector3Int offset = ChunkSize * neighbourDirs[i]; Vector3Int newChunkPos = AnchorPos + offset; //TODO: Get empty chunk first, only request actual noise when noise values change //!TODO: When requesting a nonexisting chunk instead of create -> edit request modified noise and only build that if (ChunkHandler.TryGetReadyChunkAt(newChunkPos, out chunk)) { if (chunk is ReducedMarchingCubesChunk threadedChunk) { Vector3Int v3 = origin - offset; chunks.Add(Tuple.Create(threadedChunk, v3)); } else { Debug.LogWarning("Editing of compressed marchingcube chunks is not supported!"); } } else { Vector3Int start; Vector3Int end; GetNoiseEditData(offset, editDistance, origin - offset, out start, out end); chunkHandler.CreateChunkWithNoiseEdit(newChunkPos, hit.point - newChunkPos, start, end, delta, editDistance, out CompressedMarchingCubeChunk a); } } int count = chunks.Count; for (int i = 0; i < count; i++) { Vector3Int v3 = chunks[i].Item2; ReducedMarchingCubesChunk currentChunk = chunks[i].Item1; currentChunk.RebuildAround(hitDiff, editDistance, v3, delta); } watch.Stop(); Debug.Log($"Time to rebuild {count} chunks: {watch.Elapsed.TotalMilliseconds} ms."); }
public MarchingCubeMeshDisplayer(ReducedMarchingCubesChunk chunk, Transform t) : this(chunk, new GameObject(/*$"{chunk.AnchorPos.x},{chunk.AnchorPos.y},{chunk.AnchorPos.z} "*/), t) { }
public MeshData DispatchRebuildAround(ReducedMarchingCubesChunk chunk, Vector3Int clickedIndex, Vector3 startVec, Vector3 endVec, float marchSquare) { return(chunkGPURequest.DispatchAndGetChunkMeshData(chunk, null)); }
public void Store(Vector3Int anchorPos, ReducedMarchingCubesChunk chunk, bool overrideNoise = false) => storageGroup.Store(anchorPos, chunk, overrideNoise);
public MarchingCubeMeshDisplayer GetNextInteractableMeshDisplayer(ReducedMarchingCubesChunk chunk) { return(interactableDisplayerPool.GetItemFromPoolFor(chunk)); }