public MarchingCubeEntity(ICubeNeighbourFinder cubeFinder, int triangulationIndex) { this.cubeFinder = cubeFinder; this.triangulationIndex = triangulationIndex; int size = TriangulationTable.triangulationSizes[triangulationIndex]; triangles = new PathTriangle[size]; }
public Color32 GetColor(PathTriangle t, int steepness) { float invLerp = (steepness - minSteepness) / ((float)maxSteepness - minSteepness); if (invLerp < 0) { invLerp = 0; } else if (invLerp > 1) { invLerp = 1; } return(new Color32(15, 150, 15, (byte)steepness)); }
public List <PathTriangle> GetNeighboursOf(PathTriangle tri) { List <PathTriangle> result = new List <PathTriangle>(); int index = Array.IndexOf(triangles, tri); GetInternNeighbours(result, index); //TODO: check to make structs readonly and other optimations //possibly stop reading first to avoid memcopy OutsideEdgeNeighbourDirection neighbour; List <OutsideEdgeNeighbourDirection> edgeDirs = neighbourData.OutsideNeighbours; int count = edgeDirs.Count; for (int i = 0; i < count; ++i) { neighbour = edgeDirs[i]; if (neighbour.triangleIndex != index) { continue; } Vector3Int newPos = origin + neighbour.offset; MarchingCubeEntity cubeNeighbour; //TODO: store if it is boundary cube else check not necessary if (cubeFinder.IsCubeInBounds(newPos.x, newPos.y, newPos.z)) { cubeNeighbour = cubeFinder.GetEntityAt(newPos); } else { cubeNeighbour = cubeFinder.GetEntityInNeighbourAt(newPos); if (cubeNeighbour == null) { continue; } } OutsideNeighbourConnectionInfo info; if (TriangulationTableStaticData.TryGetNeighbourTriangleIndex( cubeNeighbour.triangulationIndex, neighbour.originalEdgePair.x, neighbour.originalEdgePair.y, out info)) { result.Add(cubeNeighbour.triangles[info.otherTriangleIndex]); } } return(result); }
public void AddTriangle(PathTriangle tri) { triangles[counter] = tri; counter++; }
public int IndexOfTri(PathTriangle tri) { return(Array.IndexOf(triangles, tri)); }
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; IMarchingCubeInteractableChunk 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; IMarchingCubeInteractableChunk 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.GetMouseButtonDown(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; IMarchingCubeInteractableChunk chunk = currentHitObject.GetComponent <IHasInteractableMarchingCubeChunk>()?.GetChunk; if (chunk != null) { chunk.EditPointsAroundRayHit(pointDelta, hit, 8); } } } }
public void BuildPath(PathTriangle from, PathTriangle to) { ps = MarchingCubesPathfinder.FindPath(from, to, PathAccuracy.NotSoGoodAnymore); }