/// <summary> /// Adds another point for the octree. /// </summary> /// <param name="point">The point to add.</param> public void AddPoint(Common.Point point) { _pointCounter++; if (_pointCounter % COMPUTE_EVERY != 0 && COMPUTE_EVERY != 1) { return; } _octree.Add(point.Position, OctreeNodeStates.Occupied); }
public static Octree<Volume> Generate( int width, int depth ) { Octree<Volume> octree = new Octree<Volume>(new Volume(new Vector3(0,0,0), new Vector3(width, 64, depth), new Color()), Volume.AddHandler, Volume.RemoveHandler, Volume.SearchHandler, Volume.SetRootHandler, Volume.RemoveAllHandler); List<Vector3> coords = new List<Vector3>(); int hills = rand.Next(10); int height = 0; for (int i = 0; i < hills; i++) { coords.Add( new Vector3( rand.Next(width), 0, rand.Next(depth))); } System.Drawing.Color c = System.Drawing.Color.LawnGreen; int r, g, b; for (int i = 0; i < width; i++) { for (int j = 0; j < depth; j++) { octree.Add( new Volume( new Vector3(i, 0, j), new Vector3(1, 1, 1), new Color(c.R, c.G, c.B)) ); } } foreach (Vector3 coord in coords) { for (int x = -10; x < 10; x++) { for (int z = -10; z < 10; z++) { c = System.Drawing.Color.LawnGreen; r = (int)(0.1f * (float)height * (int)c.R); g = (int)c.G; b = (int)(0.1f * (float)height * (int)c.B); if (r > 255) r = 255; if (g > 255) g = 255; if (b > 255) b = 255; height = Math.Min(20 - Math.Abs(z), 20 - Math.Abs(x)); c = System.Drawing.Color.FromArgb(r, g, b); octree.Add( new Volume( new Vector3(coord.X + x, height, coord.Z + z), new Vector3(1, 1, 1), new Color(c.R, c.G, c.B)) ); } } } return octree; }
/// <inheritdoc /> public Color GetDominantColor(ReadOnlySpan <byte> imageBytes) { var colorTree = new Octree(); using var img = SixLabors.ImageSharp.Image.Load(imageBytes); for (var x = 0; x < img.Width; x++) { for (var y = 0; y < img.Height; y++) { var pixel = img[x, y]; // Don't include transparent pixels. if (pixel.A > 127) { var color = System.Drawing.Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B); colorTree.Add(color); } } } for (var i = 0; i < 7; i++) { colorTree.Reduce(); } var mostCommonPaletteColor = colorTree.GetPalette().OrderByDescending(x => x.Weight * x.Color.GetSaturation()).FirstOrDefault().Color; // TODO Investigate why we cannot cast here anymore (return (Color)mostCommonPaletteColor;) return(new Color((uint)mostCommonPaletteColor.ToArgb() << 8 >> 8)); }
IEnumerator CreateChunk() { Task GenerationTask; Vector3[] TempPositions = new Vector3[ChunksToGenerate.Count]; ChunksToGenerate.CopyTo(TempPositions, 0); ChunksToGenerate.Clear(); foreach (Vector3 pos in TempPositions) { if (chunks.Get(pos) == null) { generator = new WorldGeneration(); WorldPos TempPos = new WorldPos((int)pos.x * Chunk.ChunkSize, (int)pos.y * Chunk.ChunkSize, (int)pos.z * Chunk.ChunkSize); yield return(Ninja.JumpToUnity); GameObject TempChunkObject = Instantiate(chunkPrefab) as GameObject; TempChunkObject.transform.SetParent(this.transform); TempChunkObject.name = TempPos.ToString(); Chunk TempChunkScript = TempChunkObject.GetComponent <Chunk>(); yield return(Ninja.JumpBack); TempChunkScript.world = this; TempChunkScript.ChunkPosition = TempPos; this.StartCoroutineAsync(GenerateChunk(TempChunkScript), out GenerationTask); yield return(StartCoroutine(GenerationTask.Wait())); generator.FetchChunk(out TempChunkScript); chunks.Add(TempChunkScript, TempPos.ToVector3()); } } }
private void SpawnAndAdd() { var prefab = prefabs[Random.Range(0, prefabs.Count)]; tree.Add( Instantiate(prefab, Random.insideUnitSphere * radius, Quaternion.identity, transform) .GetComponent <ILeaf <Vector3> >() ); }
protected override IEnumerable <V> GenerateVertices() { var cnt = 0; var reduced = new V[_geometry.Vertices.Length]; foreach (var vert in _geometry.Vertices) { if (_octree.Add(vert, cnt)) { reduced [cnt++] = vert; } } return(_minSmoothAngle == 0f ? reduced.Take(cnt) : Smoothen(reduced, cnt)); }
void Start() { octree = new Octree <GameObject> (size, transform.position, minNodeSize, maxObjectsPerNode); gizmosGenerator = new GizmosGenerator <GameObject> (octree); int halfSize = size / 2; gameObjects = new Dictionary <Vector3, GameObject> (); Vector3[] cubePositions = new Vector3[] { new Vector3(6, 7, 6), new Vector3(6, 6, 5), new Vector3(6, 6, 6), new Vector3(6, 6, 7), new Vector3(6, 5, 6), new Vector3(6, 4, 6), new Vector3(6, 2, 6), new Vector3(6, 2, 2), new Vector3(6, -6, 5), new Vector3(-4, 2, -3), }; for (int i = 0; i < cubePositions.Length; i++) { GameObject cube = CreateCube(cubePositions[i]); octree.Add(cube.transform.position, cube); gameObjects.Add(cubePositions[i], cube); } // // for (int i = 0; i < 5; i++) { // Vector3 randPosition = new Vector3 (Random.Range (5, 7), Random.Range (0, 7), Random.Range (5, 7)); // // if (gameObjects.ContainsKey(randPosition)) { // continue; // } // // GameObject cube = CreateCube (randPosition); // octree.Add (cube.transform.position, cube); // // gameObjects.Add (randPosition, cube); // } print("done"); }
public void Initialize() { _octree = Octree <VegetationType> .Create(rootBounds); _results = new List <Octree <VegetationType> .Data>(100); for (int i = 0, n = dataBounds.Count; i < n; ++i) { if (!_octree.Add(new Octree <VegetationType> .Data { bounds = dataBounds[i], value = dataTypes[i] })) { Debug.LogWarningFormat("Failed to map vegetation {0}/{1}", i, n); } } }
/// <summary> /// Identifies a dominant color from the provided image. /// </summary> /// <param name="image">The image for which the dominant color is to be retrieved.</param> /// <returns>A dominant color in the provided image.</returns> public static Color GetDominantColor(Image image) { if (image.Stream is null) { return(new Color(253, 95, 0)); } var imageBytes = new byte[image.Stream.Length].AsSpan(); image.Stream.Seek(0, SeekOrigin.Begin); image.Stream.Read(imageBytes); var colorTree = new Octree(); using (var img = SixLabors.ImageSharp.Image.Load(imageBytes)) { for (var x = 0; x < img.Width; x++) { for (var y = 0; y < img.Height; y++) { var pixel = img[x, y]; // Don't include transparent pixels. if (pixel.A > 127) { var color = System.Drawing.Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B); colorTree.Add(color); } } } } for (var i = 0; i < 7; i++) { colorTree.Reduce(); } var mostCommonPaletteColor = colorTree.GetPalette().OrderByDescending(x => x.Weight * x.Color.GetSaturation()).FirstOrDefault().Color; return((Color)mostCommonPaletteColor); }
internal static uint AddNewNormal(IList <Vector3> target, Vector3 normal, Octree <MeshSpatialInfo> mergeTree) { target.Add(normal); uint index = (uint)target.Count - 1; if (mergeTree != null) { OctreeResult <MeshSpatialInfo> info; if (mergeTree.GetAt(normal, out info)) { info.Entry.Normal = index; } else { mergeTree.Add(new MeshSpatialInfo(null, index), normal); } } return(index); }
internal static uint AddNewVertex(IList <Vector3> target, Vector3 vertex, Octree <MeshSpatialInfo> mergeTree) { target.Add(vertex); uint index = (uint)target.Count - 1; if (mergeTree != null) { OctreeResult <MeshSpatialInfo> info; if (mergeTree.GetAt(vertex, out info)) { info.Entry.Vertex = index; } else { mergeTree.Add(new MeshSpatialInfo(index), vertex); } } return(index); }
protected override unsafe void ProcessPixel(byte *r, byte *g, byte *b, int yPos, int xPos) { var color = new ColorQuantization.Color() { R = *r, G = *g, B = *b }; if (buildOctree) { octree.Add(color); } if (quantize) { int idx = octree.GetPaletteIndex(color); *r = palette[idx].R; *g = palette[idx].G; *b = palette[idx].B; } }
protected void AddToOctree(Model model) { _octree.Add(model); }