public void SubactiveUpdate(ChunkVector OriginalPosition, bool focedResetCheck = false) { AccurateVector3 oldPos = ParentChunk.GetWorldPositionOfBlock(OriginalPosition); AccurateVector3 newPos = ParentChunk.GetWorldPositionOfBlock(Position); AccurateVector3 offset = new AccurateVector3((decimal)Math.Round((oldPos.x - newPos.x) / 2, 1), (decimal)Math.Round((oldPos.y - newPos.y) / 2, 1), (decimal)Math.Round((oldPos.z - newPos.z) / 2, 1)); AccurateVector3 placePos = new AccurateVector3((decimal)Math.Round((oldPos.x - offset.x), 1), (decimal)Math.Round((oldPos.y - offset.y), 1), (decimal)Math.Round((oldPos.z - offset.z), 1)); Vector3 vPP = new Vector3((float)placePos.x, (float)placePos.y, (float)placePos.z); if (BlockType != 0) { GameObject go = Instantiate(Global.QuadPrefab, vPP, Quaternion.Euler(Vector3.zero)) as GameObject; go.transform.LookAt(newPos.ToVector3()); ParentChunk.MeshBuffer.Add(go.GetComponent<MeshFilter>()); } else { if (focedResetCheck) { RaycastHit hit; Physics.Raycast(new Ray(newPos.ToVector3(), offset.ToVector3()), out hit, 2f, ~(1 >> 9)); if (hit.transform) { Debug.Log("Found object!"); ParentChunk.RemoveFace(ParentChunk.GetComponent<MeshCollider>(), ParentChunk.GetComponent<MeshFilter>(), hit.triangleIndex); } Debug.DrawRay(newPos.ToVector3(), offset.ToVector3(), Color.green, 30f); Debug.DrawRay(newPos.ToVector3(), offset.ToVector3() * 2, Color.blue, 5f); } } }
public void ReChunk(ChunkVector Block) { BlockDatabase[Block].BlockType = 0; BlockDatabase[Block].ActiveUpdate(true); Fuse(MeshBuffer.ToArray(), false); MeshBuffer.Clear(); }
public static ChunkVector ConvertWorldToChunkVector(Vector3 normal, GameObject chunk, Vector3 world) { Vector3 offset = world - chunk.transform.position; Vector3 v = new Vector3((float)Math.Round((offset.x + 0.5f) % 16.5f, 3), (float)Math.Round((offset.y + 0.5f) % 16.5, 3), (float)Math.Round((offset.z + 0.5f) % 16.5, 3)); v -= normal.normalized / 2; ChunkVector c = new ChunkVector((byte)(v.x), (byte)(v.y), (byte)(v.z)); return c; }
public AccurateVector3 GetWorldPositionOfBlock(ChunkVector Position, bool add) { if (add) { return new AccurateVector3((decimal)transform.position.x + Position.x, (decimal)transform.position.y + Position.y, (decimal)transform.position.z + Position.z); } else { return new AccurateVector3((decimal)Position.x, (decimal)Position.y, (decimal)Position.z); } }
public void Bridge(MajorChunkVector majorFromVector, Block fromBlock) { Debug.Log("Self Chunk: " + transform.name); Vector3 difference = new Vector3(ChunkPosition.x - majorFromVector.x, ChunkPosition.y - majorFromVector.y, ChunkPosition.z - majorFromVector.z); ChunkVector pos = new ChunkVector(Math.Abs(difference.x) >= 0.01 ? 15 - fromBlock.Position.x : fromBlock.Position.x, Math.Abs(difference.y) >= 0.01 ? 15 - fromBlock.Position.y : fromBlock.Position.y, Math.Abs(difference.z) >= 0.01 ? 15 - fromBlock.Position.z : fromBlock.Position.z); BlockDatabase[pos.To4096Index].BridgeUpdate(difference, fromBlock); Debug.Log("Bridge update! " + pos.x + "(" + fromBlock.Position.x + "), " + pos.y + "(" + fromBlock.Position.y + "), " + pos.z + "(" + fromBlock.Position.z + ")"); Fuse(MeshBuffer.ToArray(), false); MeshBuffer.Clear(); }