示例#1
0
        public TAMSoleImagesPack GenerateTamPack(TAMPackGenerationConfiguration configuration, bool generateDebugPlates, ComputeShaderContainerGameObject shaderContainerGameObject)
        {
            var tones             = configuration.Tones;
            var levels            = configuration.Levels;
            var tonesCount        = tones.Count;
            var levelsCount       = levels.Count;
            var templateGenerator = new TAMTemplateGenerator(
                new PoissonTAMImageDiagramGenerator(
                    new TAMPoissonDiskSampler(),
                    new StrokesGenerator(configuration.StrokesGeneratorConfiguration),
                    configuration.PoissonTamImageDiagramGeneratorConfiguration)
                );

            var template = templateGenerator.Generate(new TAMTemplateSpecification()
            {
                Tones        = tones,
                MipmapLevels = levels
            });

            var margin = configuration.Margin;
            var smallestLevelSoleImageResolution = configuration.SmallestLevelSoleImageResolution;

            var renderer = new TAMDeckRenderer(
                Image.FromFile(configuration.StrokeImagePath),
                Image.FromFile(configuration.BlankImagePath),
                new TAMDeckRendererConfiguration()
            {
                SoleImagesResolutionPerLevel = levels
                                               .Select((level, i) => new { level, i })
                                               .ToDictionary(c => c.level, c => c.i)
                                               .ToDictionary(pair => pair.Key, pair => (smallestLevelSoleImageResolution * Mathf.Pow(2, pair.Value)).ToIntVector()),
                Margin = margin,
                StrokeHeightMultiplierPerLevel = levels
                                                 .Select((level, i) => new { level, i })
                                                 .ToDictionary(c => c.level, c => c.i)
                                                 .ToDictionary(pair => pair.Key, pair => configuration.StrokeHeightMultiplierForZeroLevel / Mathf.Pow(2, pair.Value))
            });
            var deck = renderer.Render(template);

            var wrapper = new TAMMarginsWrapper(new UTTextureRendererProxy(new TextureRendererService(
                                                                               new MultistepTextureRenderer(shaderContainerGameObject),
                                                                               new TextureRendererServiceConfiguration()
            {
                StepSize = configuration.RendererOneStepSize
            })), new TAMMarginsWrapperConfiguration()
            {
                Margin = margin,
            });

            for (int toneIndex = 0; toneIndex < tonesCount; toneIndex++)
            {
                for (int levelIndex = 0; levelIndex < levelsCount; levelIndex++)
                {
                    var image        = deck.Columns[tones[toneIndex]][levels[levelIndex]];
                    var soleTexture  = wrapper.WrapTexture(TAMUtils.ImageToTexture2D(image));
                    var strokesCount = template.Columns[tones[toneIndex]][levels[levelIndex]].Strokes.Count;
                    if (generateDebugPlates)
                    {
                        CreateTexturedPlate(soleTexture, 11f * new Vector2(toneIndex, levelIndex),
                                            "Tone " + toneIndex + " Level " + levelIndex + " Count" + strokesCount);
                    }
                }
            }

            var soleImagesPack = new TAMSoleImagesPack(deck.Columns.ToDictionary(
                                                           c => c.Key,
                                                           c => c.Value.ToDictionary(
                                                               k => k.Key,
                                                               k => wrapper.WrapTexture(TAMUtils.ImageToTexture2D(k.Value)))));

            return(soleImagesPack);
        }
示例#2
0
        public TamIdSoleImagesPack GenerateTamPack(TamIdPackGenerationConfiguration configuration, bool generateDebugPlates, ComputeShaderContainerGameObject shaderContainerGameObject)
        {
            var tones             = configuration.Tones;
            var levels            = configuration.Levels;
            var templateGenerator = new TAMTemplateGenerator(
                new PoissonTAMImageDiagramGenerator(
                    new TAMPoissonDiskSampler(),
                    new StrokesGenerator(configuration.StrokesGeneratorConfiguration),
                    configuration.PoissonTamImageDiagramGeneratorConfiguration)
                );

            var template = templateGenerator.Generate(new TAMTemplateSpecification()
            {
                Tones        = tones,
                MipmapLevels = levels
            });

            var margin = configuration.Margin;
            var smallestLevelSoleImageResolution = configuration.SmallestLevelSoleImageResolution;

            Debug.Log("XXXy: " + configuration.StrokeImagePath);
            var a1 = Image.FromFile(configuration.StrokeImagePath);
            var a2 =
                Image.FromFile(configuration.BlankImagePath);
            var renderer = new TamIdDeckRenderer(
                Image.FromFile(configuration.StrokeImagePath),
                Image.FromFile(configuration.BlankImagePath),
                new TAMDeckRendererConfiguration()
            {
                UseSmoothAlpha = configuration.UseSmoothAlpha,
                UseDithering   = configuration.UseDithering,
                SoleImagesResolutionPerLevel = levels
                                               .Select((level, i) => new { level, i })
                                               .ToDictionary(c => c.level, c => c.i)
                                               .ToDictionary(pair => pair.Key, pair => (smallestLevelSoleImageResolution * Mathf.Pow(2, pair.Value)).ToIntVector()),
                Margin = margin,
                StrokeHeightMultiplierPerLevel = levels
                                                 .Select((level, i) => new { level, i })
                                                 .ToDictionary(c => c.level, c => c.i)
                                                 .ToDictionary(pair => pair.Key, pair => configuration.StrokeHeightMultiplierForZeroLevel / Mathf.Pow(2, pair.Value))
            }, configuration.LayersCount);
            var deck = renderer.Render(template);

            var wrapper = new TAMMarginsWrapper(new UTTextureRendererProxy(new TextureRendererService(
                                                                               new MultistepTextureRenderer(shaderContainerGameObject),
                                                                               new TextureRendererServiceConfiguration()
            {
                StepSize = configuration.RendererOneStepSize
            })), new TAMMarginsWrapperConfiguration()
            {
                Margin = margin,
            });

            var soleImagesPack = new TamIdSoleImagesPack(deck.Columns.ToDictionary(
                                                             c => c.Key,
                                                             c => c.Value.ToDictionary(
                                                                 k => k.Key,
                                                                 k =>
            {
                var x1 = k.Value.Select(r => wrapper.WrapTexture(TAMUtils.ImageToTexture2D(r))).ToList();
                return(x1);
            })));

            deck.DisposeImages();

            return(soleImagesPack);
        }