Example #1
0
        public async Task <TextureWithSize> RetriveHeightDetailElementAsync(string filename)
        {
            IntVector2 textureSize = new IntVector2(241, 241);
            var        path        = _mainDictionaryPath + filename + _extension;

            Preconditions.Assert(File.Exists(path), $"Cannot retrive heightDetailElement of path {path} as it does not exist");
            {
                var texture = await _commonExecutor.AddAction(() =>
                {
                    var tex = SavingFileManager.LoadPngTextureFromFile(path, textureSize.X, textureSize.Y,
                                                                       TextureFormat.ARGB32, true, true);
                    tex.wrapMode = TextureWrapMode.Clamp;
                    return(tex);
                });

                var transformator = new TerrainTextureFormatTransformator(_commonExecutor);
                var plainTexture  = await transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
                {
                    Texture = texture,
                    Size    = textureSize
                });

                return(new TextureWithSize()
                {
                    Size = textureSize,
                    Texture = plainTexture
                });
            }
        }
Example #2
0
        public void StartX()
        {
            TaskUtils.SetGlobalMultithreading(false);
            MainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600, 3600,
                                                                   TextureFormat.ARGB32, true, false);

            var plain = _transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = MainTexture
            });

            var decoded = _transformator.PlainToEncodedHeightTextureAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = plain.Result
            });

            SavingFileManager.SaveTextureToPngFile(@"C:\inz\cont\n49_e019_1arc_v4.rfloat.png", decoded.Result);
        }
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);

            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);


            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(new CommonExecutorUTProxy());
            var mainTexture = transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            }).Result;


            var gameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
            var material   = new Material(Shader.Find("Custom/Terrain/Ring1"));

            TerrainAndNormalTexture pair = CreateTerrainAndNormalTexture(mainTexture);

            material.SetTexture("_HeightmapTex", pair.HeightTexture);
            material.SetTexture("_NormalmapTex", pair.NormalTexture);

            gameObject.GetComponent <MeshRenderer>().material = material;
            gameObject.name = "Terrain";
            gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);

            var unitySideLength = 10f;
            var realSideLength  = 240 * 24;
            var metersPerUnit   = realSideLength / unitySideLength;

            if (_terrainResolution == TerrainCardinalResolution.MIN_RESOLUTION)
            {
                gameObject.transform.localScale    = new Vector3(10, (6500 / metersPerUnit), 10);
                gameObject.transform.localPosition = new Vector3(0, 0, 0);
            }
            else if (_terrainResolution == TerrainCardinalResolution.MID_RESOLUTION)
            {
                gameObject.transform.localScale    = new Vector3(10, (6500 / metersPerUnit) * 8, 10);
                gameObject.transform.localPosition = new Vector3(0, 0, 0);
            }
            else
            {
                gameObject.transform.localScale    = new Vector3(10, (6500 / metersPerUnit) * 8 * 8, 10);
                gameObject.transform.localPosition = new Vector3(0, -30, 0);
            }
            gameObject.GetComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(240, 240);
        }
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(true);
            _computeShaderExecutorObject = new UnityThreadComputeShaderExecutorObject();
            _commonExecutorUtProxy       = new CommonExecutorUTProxy();
            _utTextureRendererProxy      = new UTTextureRendererProxy(new TextureRendererService(
                                                                          new MultistepTextureRenderer(ContainerGameObject), new TextureRendererServiceConfiguration()
            {
                StepSize = new Vector2(500, 500)
            }));

            var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600,
                                                                           3600,
                                                                           TextureFormat.ARGB32, true, false);


            TerrainTextureFormatTransformator transformator =
                new TerrainTextureFormatTransformator(_commonExecutorUtProxy);

            transformator.EncodedHeightTextureToPlainAsync(new TextureWithSize()
            {
                Size    = new IntVector2(3600, 3600),
                Texture = rgbaMainTexture
            }).ContinueWith(x =>
            {
                var mainTexture = x.Result;
                TerrainDetailGenerator generator = CreateTerrainDetailGenerator(new TextureWithSize()
                {
                    Size    = new IntVector2(3600, 3600),
                    Texture = mainTexture
                });
                TerrainDetailProvider terrainDetailProvider = CreateTerrainDetailProvider(generator);
                var db = FETerrainShapeDbInitialization.CreateTerrainShapeDb(terrainDetailProvider, _commonExecutorUtProxy,
                                                                             new TerrainDetailAlignmentCalculator(240), false, false, false, null);


                MyRectangle queryArea = null;
                if (_terrainResolution == TerrainCardinalResolution.MIN_RESOLUTION)
                {
                    queryArea = new MyRectangle(0, 0, 24 * 240, 24 * 240);
                }
                else if (_terrainResolution == TerrainCardinalResolution.MID_RESOLUTION)
                {
                    queryArea = new MyRectangle(3 * 240, 3 * 240, 3 * 240, 3 * 240);
                }
                else
                {
                    queryArea =
                        new MyRectangle(5 * 0.375f * 240, 5 * 0.375f * 240, 0.375f * 240, 0.375f * 240);
                }


                var outputOfGeneration = db.QueryAsync(new TerrainDescriptionQuery()
                {
                    QueryArea = queryArea,
                    RequestedElementDetails = new List <TerrainDescriptionQueryElementDetail>()
                    {
                        new TerrainDescriptionQueryElementDetail()
                        {
                            Resolution = _terrainResolution.LowerResolution,
                            Type       = TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY
                        },
                        new TerrainDescriptionQueryElementDetail()
                        {
                            Resolution = _terrainResolution,
                            Type       = TerrainDescriptionElementTypeEnum.NORMAL_ARRAY
                        },
                    }
                });

                outputOfGeneration.ContinueWith(c =>
                {
                    GeneratedTerrainElements elem = new GeneratedTerrainElements();
                    elem.HeightElement            = c.Result.GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY);
                    elem.NormalElement            = c.Result.GetElementOfType(TerrainDescriptionElementTypeEnum.NORMAL_ARRAY);
                    _generatedElements.Add(elem);
                }).ContinueWith(q =>
                {
                    Debug.Log("Error: Executing task");
                    Debug.Log("Error descr is " + q.Exception);
                }, TaskContinuationOptions.OnlyOnFaulted
                                );
            });
        }