Beispiel #1
0
 public ValuesFromRandomFieldProvider(RandomFieldNature nature,
                                      float seed,
                                      Ring2RandomFieldFigureRepository randomFieldFigureRepository)
 {
     _nature = nature;
     _seed   = seed;
     _randomFieldFigureRepository = randomFieldFigureRepository;
 }
        public async Task <List <float> > GetValuesAsync(RandomFieldNature nature, float seed,
                                                         List <Vector2> queryPositions)
        {
            Dictionary <MyRectangle, IntensityFieldFigure> segmentsDict = null;
            var randomFieldFigureId = new RandomFieldFigureId(nature, seed);

            if (!_figuresDictionary.ContainsKey(randomFieldFigureId))
            {
                segmentsDict = new Dictionary <MyRectangle, IntensityFieldFigure>();
                _figuresDictionary[randomFieldFigureId] = segmentsDict;
            }
            else
            {
                segmentsDict = _figuresDictionary[randomFieldFigureId];
            }

            List <MyRectangle> segmentCoordsList = new List <MyRectangle>(queryPositions.Count);

            for (int i = 0; i < queryPositions.Count; i++)
            {
                segmentCoordsList.Add(CalculateSegment(queryPositions[i]));
            }

            List <MyRectangle> distinctCoords          = segmentCoordsList.Distinct().ToList();
            List <MyRectangle> coordsToCreateFigureFor =
                distinctCoords.Where(c => !segmentsDict.ContainsKey(c)).ToList();

            if (coordsToCreateFigureFor.Any())
            {
                var createdFigures = await TaskUtils.WhenAll(Enumerable.Range(0, coordsToCreateFigureFor.Count).Select(
                                                                 (i) =>
                {
                    var coord = coordsToCreateFigureFor[i];
                    return(_figureGenerator.GenerateRandomFieldFigureAsync(nature, seed, coord));
                }));

                for (int i = 0; i < coordsToCreateFigureFor.Count; i++)
                {
                    var coord = coordsToCreateFigureFor[i];
                    segmentsDict[coord] = createdFigures[i];
                }
            }

            List <float> outList = new List <float>(queryPositions.Count);

            for (int i = 0; i < queryPositions.Count; i++)
            {
                var position      = queryPositions[i];
                var segmentCoords = segmentCoordsList[i];
                IntensityFieldFigure fieldFigure = segmentsDict[segmentCoords];

                var inFigureUv = new Vector2((position.x - segmentCoords.X) / segmentCoords.Width,
                                             (position.y - segmentCoords.Y) / segmentCoords.Height);
                outList.Add(fieldFigure.GetPixelWithUv(inFigureUv));
            }
            return(outList);
        }
Beispiel #3
0
 public Task <IntensityFieldFigure> GenerateRandomFieldFigureAsync(RandomFieldNature nature, float seed,
                                                                   MyRectangle segmentCoords)
 {
     return(BaseUtAddOrder(new RandomFieldFigureGeneratorOrder()
     {
         Nature = nature,
         Seed = seed,
         SegmentCoords = segmentCoords,
     }));
 }
        public IntensityFieldFigure Generate(RandomFieldNature nature, float seed,
                                             MyRectangle segmentCoords) //todo use nature
        {
            UniformsPack uniforms = new UniformsPack();

            uniforms.SetUniform("_Seed", seed);
            uniforms.SetUniform("_Coords",
                                new Vector4(segmentCoords.X, segmentCoords.Y, segmentCoords.Width, segmentCoords.Height));

            Vector2 imageSize = new Vector2(
                (int)Mathf.Round(_configuration.PixelsPerUnit.x * segmentCoords.Width),
                (int)Mathf.Round(_configuration.PixelsPerUnit.y * segmentCoords.Height)
                );

            RenderTextureInfo renderTextureInfo = new RenderTextureInfo(
                (int)imageSize.x,
                (int)imageSize.y,
                RenderTextureFormat.ARGB32
                );

            ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(
                (int)imageSize.x,
                (int)imageSize.y,
                TextureFormat.ARGB32
                );

            Texture2D outTexture = _textureRenderer.RenderTexture(_shaderName, _inputBlankTexture, uniforms,
                                                                  renderTextureInfo, outTextureInfo);

            var toReturn = CopyToRandomFieldFigure(outTexture);

            if (DebugLastGeneratedTexture != null)
            {
                GameObject.Destroy(DebugLastGeneratedTexture);
            }
            DebugLastGeneratedTexture = outTexture;
            //GameObject.Destroy(outTexture);

            return(toReturn);
        }
 public RandomFieldFigureId(RandomFieldNature nature, float seed)
 {
     _nature   = nature;
     this.seed = seed;
 }