public static int ClassifyLatticKeyAxi(IJL key) { int i = key.i; int j = key.j - 2; int rem_i = i % 6; int rem_j = ((3 * j) - i) % 12; if ((rem_i == 0) && (rem_j == 0)) { return(2); } i = key.i + 3; rem_i = i % 6; if (rem_i == 0) { j = key.j - 1; rem_j = ((3 * j) - i) % 12; if (rem_j == 0) { return(3); } j = key.j + 1; rem_j = ((3 * j) - i) % 12; if (rem_j == 0) { return(4); } } return(-1); }
public static IJL GetVoxelIJL(Vector3 point) { Vector3 trfm_point = InverseTransform(point); int min_i = Mathf.FloorToInt(trfm_point.z); int max_i = Mathf.CeilToInt(trfm_point.z); int min_j = Mathf.FloorToInt(trfm_point.x); int max_j = Mathf.CeilToInt(trfm_point.x); int l = Mathf.FloorToInt(point.y); IJL ijl0 = new IJL(min_i, min_j, l); float d0 = SquaredDistanceXZ(point, VoxelVertex(ijl0)); IJL ijl1 = new IJL(min_i, max_j, l); float d1 = SquaredDistanceXZ(point, VoxelVertex(ijl1)); IJL ijl2 = new IJL(max_i, min_j, l); float d2 = SquaredDistanceXZ(point, VoxelVertex(ijl2)); IJL ijl3 = new IJL(max_i, max_j, l); float d3 = SquaredDistanceXZ(point, VoxelVertex(ijl3)); float min = Mathf.Min(d0, d1, d2, d3); if (d0 <= min) { return(new IJL(min_i, min_j, l)); } else if (d1 <= min) { return(new IJL(min_i, max_j, l)); } else if (d2 <= min) { return(new IJL(max_i, min_j, l)); } else { return(new IJL(max_i, max_j, l)); } }
public static bool IsKeyTopHeavy(IJL key) { IJ key_diff = new IJ(key.i + 2, key.j - 2); int rem_i = key_diff.i % 6; int rem_j = ((3 * key_diff.j) - key_diff.i) % 12; return((rem_i == 0) && (rem_j == 0)); }
public static bool operator !=(IJL a, object obj) { if (!(obj is IJL)) { return(true); } IJL b = (IJL)obj; return((a.i != b.i) || (a.j != b.j) || (a.l != b.l)); }
public override bool Equals(object obj) { if (!(obj is IJL)) { return(false); } IJL other = (IJL)obj; return((i == other.i) && (j == other.j) && (l == other.l)); }
public static bool operator ==(object obj, IJL a) { if (!(obj is IJL)) { return(false); } IJL b = (IJL)obj; return((a.i == b.i) && (a.j == b.j) && (a.l == b.l)); }
public static KeyPacket2 GetLongitudeCornerKeys(IJL edge_key, int axi) { if (axi < 0 || axi > 1) { return(KeyPacket2.empty); } int forward_axi = axi; int backward_axi = Vx.OPPAXI[axi]; return(new KeyPacket2(true, new KeyPacket(0, forward_axi, edge_key + KeyTransform_LongitudeCorner[axi, 0]), new KeyPacket(0, backward_axi, edge_key + KeyTransform_LongitudeCorner[axi, 1]) )); }
public static KeyPacket2 GetLateralCornerKeys(IJL edge_key, int axi) { if (axi < 2 || axi > 7) { return(KeyPacket2.empty); } int d = axi - 2; int forward_axi = Vx.ROTAXI[2, axi]; int backward_axi = Vx.NROTAXI[1, axi]; return(new KeyPacket2(true, new KeyPacket(0, forward_axi, edge_key + KeyTransform_LateralCorner[d, 0]), new KeyPacket(0, backward_axi, edge_key + KeyTransform_LateralCorner[d, 1]) )); }
public static KeyPacket6 GetHexagonCornerKeys(IJL face_key, int axi) { if (axi < 0 || axi > 1) { return(KeyPacket6.empty); } return(new KeyPacket6(true, new KeyPacket(0, 5, face_key + KeyTransform_HexagonCorner[0]), new KeyPacket(0, 6, face_key + KeyTransform_HexagonCorner[1]), new KeyPacket(0, 7, face_key + KeyTransform_HexagonCorner[2]), new KeyPacket(0, 2, face_key + KeyTransform_HexagonCorner[3]), new KeyPacket(0, 3, face_key + KeyTransform_HexagonCorner[4]), new KeyPacket(0, 4, face_key + KeyTransform_HexagonCorner[5]) )); }
private void AddVoxelIJL(IJL ijl) { if (!_sampleset.Add(ijl)) { return; } IJL chunk = Vx.ChunkIJL(ijl, chunk_radius); if (!_chunkmap.ContainsKey(chunk)) { _chunkmap.Add(chunk, new List <IJL>()); _chunklist.Add(chunk); } _chunkmap[chunk].Add(ijl - Vx.ChunkVoxelIJL(chunk, chunk_radius)); }
private void InitializeChunkObject(int index) { if (index < 0 || index >= _chunkobjs.Count || _chunkobjs[index] != null) { return; } IJL chunk = _chunksobj_ijls[index]; _chunkobjs[index] = new GameObject("Chunk " + chunk.ToString()); _chunkobjs[index].transform.localPosition = VMD.VoxelVertex(Vx.ChunkVoxelIJL(chunk, chunk_radius)); _chunkobjs[index].AddComponent <MeshFilter>(); MeshRenderer renderer = _chunkobjs[index].AddComponent <MeshRenderer>(); renderer.sharedMaterial = material; }
private void UpdateChunkMesh(IJL chunk) { if (!_chunkobjmap.ContainsKey(chunk) || !_chunkmap.ContainsKey(chunk)) { return; } _data.Clear(); _data.flat_shaded = flat_shaded; _data.map = voxelstyle; int cnt = Vx.AdjBlockIJL.Length; IJL chunkvoxel = Vx.ChunkVoxelIJL(chunk, chunk_radius); List <IJL> voxels = _chunkmap[chunk]; for (int k = 0; k < voxels.Count; k++) { _data.UpdateVoxelData(voxels[k], new Voxel(1), true); IJL voxelijl = chunkvoxel + voxels[k]; for (int cell_index = 0; cell_index < cnt; cell_index++) { IJL adjvoxel = voxelijl + Vx.AdjBlockIJL[cell_index]; if (Vx.ChunkIJL(adjvoxel, chunk_radius) == chunk) { continue; } if (!_sampleset.Contains(adjvoxel)) { continue; } _data.UpdateVoxelData(voxels[k] + Vx.AdjBlockIJL[cell_index], new Voxel(1), false); } } _data.UpdateDirtyComponents(); _data.GenerateMesh(); MeshFilter filter = _chunkobjmap[chunk].GetComponent <MeshFilter>(); if (filter.mesh == null) { filter.mesh = new Mesh(); } filter.mesh.SetVertices(_data.vertices); filter.mesh.SetNormals(_data.normals); filter.mesh.SetTriangles(_data.triangles, 0); filter.mesh.RecalculateBounds(); filter.mesh.RecalculateTangents(); filter.mesh.UploadMeshData(false); }
public static KeyPacket4 GetRectCornerKeys(IJL face_key, int axi) { if (axi < 2 || axi > 7) { return(KeyPacket4.empty); } int d = axi - 2; int forward_axi = Vx.ROTAXI[2, axi]; int backward_axi = Vx.NROTAXI[1, axi]; return(new KeyPacket4(true, new KeyPacket(-1, forward_axi, face_key + KeyTransform_RectCorner[d, 0]), new KeyPacket(1, forward_axi, face_key + KeyTransform_RectCorner[d, 1]), new KeyPacket(1, backward_axi, face_key + KeyTransform_RectCorner[d, 2]), new KeyPacket(-1, backward_axi, face_key + KeyTransform_RectCorner[d, 3]) )); }
public void GenerateChunks() { Random.InitState(rand_seed); //clear any existing chunk data ClearChunkData(); //add sampled voxel ijl to chunk data AddHeightMapVoxelIJL(); //add custom voxel ijl to chunk data AddCustomVoxels(); //delete chunk objects int index = 0; while (index < _chunkobjs.Count) { IJL ijl = _chunksobj_ijls[index]; if (_chunkmap.ContainsKey(ijl)) { index += 1; } else { Destroy(_chunkobjs[index]); _chunkobjs.RemoveAt(index); _chunksobj_ijls.RemoveAt(index); _chunkobjmap.Remove(ijl); } } //add and update chunk objects for (int k = 0; k < _chunklist.Count; k++) { IJL chunk = _chunklist[k]; if (!_chunkobjmap.ContainsKey(chunk)) { //create new chunk object _chunksobj_ijls.Add(chunk); _chunkobjs.Add(null); InitializeChunkObject(_chunkobjs.Count - 1); _chunkobjmap.Add(chunk, _chunkobjs[_chunkobjs.Count - 1]); } UpdateChunkMesh(chunk); } }
public static Vector3 VoxelVertex(IJL voxel_ijl) { return((voxel_ijl.i * Vx.ZAxis) + (voxel_ijl.j * Vx.XAxis) + (voxel_ijl.l * Vx.YAxis)); }
public static IJL ChunkIJL(IJL voxelijl, int radius) { return(voxelijl / radius); }
public static IJL ChunkVoxelIJL(IJL chunk, int radius) { return(((2 * radius) - 1) * chunk); }
public KeyPacket(int socketlevel, int socketaxi, IJL key) { this.socketlevel = socketlevel; this.socketaxi = socketaxi; this.key = key; }
public static IJL VoxelKeyIJL(IJL voxel_key) { return(new IJL(voxel_key.i / 6, Mathf.FloorToInt((voxel_key.j / 4f) - (voxel_key.i / 12f)), voxel_key.l / 2)); }
public static Vector3 KeyVertex(IJL key) { return((key.i * Vx.Key_ZAxis) + (key.j * Vx.Key_XAxis) + (key.l * Vx.Key_YAxis)); }
static VMD() { AxisKey_VoxelX = new IJL(0, 4, 0); AxisKey_VoxelY = new IJL(0, 0, 2); AxisKey_VoxelZ = new IJL(6, 2, 0); //Corner Voxel Transforms KeyTransform_VoxelCorner = new IJL[, ] { { new IJL(2, 2, 1), new IJL(2, 2, -1) }, { new IJL(-2, 2, 1), new IJL(-2, 2, -1) }, { new IJL(-4, 0, 1), new IJL(-4, 0, -1) }, { new IJL(-2, -2, 1), new IJL(-2, -2, -1) }, { new IJL(2, -2, 1), new IJL(2, -2, -1) }, { new IJL(4, 0, 1), new IJL(4, 0, -1) } }; KeyTransform_CornerVoxel = KeyTransform_VoxelCorner; //Lateral Voxel Transforms KeyTransform_VoxelLateral = new IJL[, ] { { new IJL(0, 2, 1), new IJL(0, 2, -1) }, { new IJL(-3, 1, 1), new IJL(-3, 1, -1) }, { new IJL(-3, -1, 1), new IJL(-3, -1, -1) }, { new IJL(0, -2, 1), new IJL(0, -2, -1) }, { new IJL(3, -1, 1), new IJL(3, -1, -1) }, { new IJL(3, 1, 1), new IJL(3, 1, -1) } }; KeyTransform_LateralVoxel = KeyTransform_VoxelLateral; //Longitude Voxel Transforms KeyTransform_VoxelLongitude = new IJL[] { new IJL(2, 2, 0), new IJL(-2, 2, 0), new IJL(-4, 0, 0), new IJL(-2, -2, 0), new IJL(2, -2, 0), new IJL(4, 0, 0) }; KeyTransform_LongitudeVoxel = KeyTransform_VoxelLongitude; //Rect Voxel Transforms KeyTransform_VoxelRect = new IJL[] { new IJL(0, 2, 0), new IJL(-3, 1, 0), new IJL(-3, -1, 0), new IJL(0, -2, 0), new IJL(3, -1, 0), new IJL(3, 1, 0) }; KeyTransform_RectVoxel = KeyTransform_VoxelRect; //Hexagon Voxel Transforms KeyTransform_VoxelHexagon = new IJL[] { new IJL(0, 0, 1), new IJL(0, 0, -1) }; KeyTransform_HexagonVoxel = KeyTransform_VoxelHexagon; //Corner to Other Components KeyTransform_CornerLateral = new IJL[] { new IJL(1, 1, 0), new IJL(-1, 1, 0), new IJL(-2, 0, 0), new IJL(-1, -1, 0), new IJL(1, -1, 0), new IJL(2, 0, 0) }; KeyTransform_CornerLongitude = new IJL[] { new IJL(0, 0, 1), new IJL(0, 0, -1) }; KeyTransform_CornerRect = new IJL[, ] { { new IJL(1, 1, 1), new IJL(1, 1, -1) }, { new IJL(-1, 1, 1), new IJL(-1, 1, -1) }, { new IJL(-2, 0, 1), new IJL(-2, 0, -1), }, { new IJL(-1, -1, 1), new IJL(-1, -1, -1) }, { new IJL(1, -1, 1), new IJL(1, -1, -1) }, { new IJL(2, 0, 1), new IJL(2, 0, -1) } }; KeyTransform_CornerHexagon = new IJL[] { new IJL(2, 2, 0), new IJL(-2, 2, 0), new IJL(-4, 0, 0), new IJL(-2, -2, 0), new IJL(2, -2, 0), new IJL(4, 0, 0) }; //Lateral Edge to Other Components KeyTransform_LateralCorner = new IJL[, ] { { KeyTransform_CornerLateral[5], KeyTransform_CornerLateral[2] }, { KeyTransform_CornerLateral[0], KeyTransform_CornerLateral[3] }, { KeyTransform_CornerLateral[1], KeyTransform_CornerLateral[4] }, { KeyTransform_CornerLateral[2], KeyTransform_CornerLateral[5], }, { KeyTransform_CornerLateral[3], KeyTransform_CornerLateral[0] }, { KeyTransform_CornerLateral[4], KeyTransform_CornerLateral[1] } }; KeyTransform_LateralRect = new IJL[] { new IJL(0, 0, 1), new IJL(0, 0, -1) }; KeyTransform_LateralHexagon = new IJL[] { new IJL(0, 2, 0), new IJL(-3, 1, 0), new IJL(-3, -1, 0), new IJL(0, -2, 0), new IJL(3, -1, 0), new IJL(3, 1, 0) }; //Longitude Edge to Other Components KeyTransform_LongitudeCorner = new IJL[, ] { { KeyTransform_CornerLongitude[1], KeyTransform_CornerLongitude[0] }, { KeyTransform_CornerLongitude[0], KeyTransform_CornerLongitude[1] } }; KeyTransform_LongitudeRect = new IJL[] { new IJL(1, 1, 0), new IJL(-1, 1, 0), new IJL(-2, 0, 0), new IJL(-1, -1, 0), new IJL(1, -1, 0), new IJL(2, 0, 0) }; //Rect Face to Other Components KeyTransform_RectCorner = new IJL[, ] { { new IJL(2, 0, 1), new IJL(2, 0, -1), new IJL(-2, 0, -1), new IJL(-2, 0, 1) }, { new IJL(1, 1, 1), new IJL(1, 1, -1), new IJL(-1, -1, -1), new IJL(-1, -1, 1) }, { new IJL(-1, 1, 1), new IJL(-1, 1, -1), new IJL(1, -1, -1), new IJL(1, -1, 1) }, { new IJL(-2, 0, 1), new IJL(-2, 0, -1), new IJL(2, 0, -1), new IJL(2, 0, 1) }, { new IJL(-1, -1, 1), new IJL(-1, -1, -1), new IJL(1, 1, -1), new IJL(1, 1, 1) }, { new IJL(1, -1, 1), new IJL(1, -1, -1), new IJL(-1, 1, -1), new IJL(-1, 1, 1) } }; KeyTransform_RectLateral = new IJL[] { KeyTransform_LateralRect[0], KeyTransform_LateralRect[1] }; KeyTransform_RectLongitude = new IJL[, ] { { new IJL(2, 0, 0), new IJL(-2, 0, 0) }, { new IJL(1, 1, 0), new IJL(-1, -1, 0) }, { new IJL(-1, 1, 0), new IJL(1, -1, 0) }, { new IJL(-2, 0, 0), new IJL(2, 0, 0) }, { new IJL(-1, -1, 0), new IJL(1, 1, 0) }, { new IJL(1, -1, 0), new IJL(-1, 1, 0) } }; //Hexagon Face to Other Components KeyTransform_HexagonCorner = new IJL[] { KeyTransform_CornerHexagon[0], KeyTransform_CornerHexagon[1], KeyTransform_CornerHexagon[2], KeyTransform_CornerHexagon[3], KeyTransform_CornerHexagon[4], KeyTransform_CornerHexagon[5] }; KeyTransform_HexagonLateral = new IJL[] { KeyTransform_LateralHexagon[0], KeyTransform_LateralHexagon[1], KeyTransform_LateralHexagon[2], KeyTransform_LateralHexagon[3], KeyTransform_LateralHexagon[4], KeyTransform_LateralHexagon[5] }; }
private static Color?FindSelectedColor(IntPtr hWnd) { // This method assumes there is a bounding rectangle around a color swatch. // The rectangle can be any color, but must be a single color. Since // the rectangle surrounds the swatch, it must have a run of pixels that // is longer than the run of pixels inside the swatch. Since it is // a rectangle, and we are scanning from top to bottom (left to right would also work), // then there must be exactly two runs that tie for longest. If two runs cannot // be found, then there is no bounding rectangle. Bitmap bmp = ConvertToBitmap(hWnd); int w = bmp.Width; int h = bmp.Height; Color bg = bmp.GetPixel(0, 0); IJL ijl = new IJL(); IJL ijl0 = new IJL(); IJL ijl1 = new IJL(); int k = 0; for (int i = 0; i < w; i++) { Color lastColor = Color.Empty; for (int j = 0; j <= h; j++) { Color c = (j == h ? Color.Empty : bmp.GetPixel(i, j)); if (c == lastColor) { ijl.len++; } else { if (ijl.len < h) { if (ijl.len > 1 && bg != lastColor) { if (ijl.len > ijl0.len) { ijl0 = ijl; k = 0; } else if (ijl.len == ijl0.len) { ijl1 = ijl; k++; } } } ijl = new IJL(); ijl.i = i; ijl.j = j; ijl.len = 1; lastColor = c; } } } if (k != 1) { bmp.Dispose(); return(null); } // k == 1 means there are exactly two runs of maximum length int x = ijl0.i + (ijl1.i - ijl0.i) / 2; int y = ijl0.j + ijl0.len / 2; Color c1 = bmp.GetPixel(x, y); bmp.Dispose(); return(c1); }
public static IJL VoxelKey(IJL voxel_ijl) { return((voxel_ijl.j * AxisKey_VoxelX) + (voxel_ijl.i * AxisKey_VoxelZ) + (voxel_ijl.l * AxisKey_VoxelY)); }