public static TerrainDetailGenerator CreateTerrainDetailGenerator( Texture mainTexture, UTTextureRendererProxy utTextureRendererProxy, CommonExecutorUTProxy commonExecutorUtProxy, UnityThreadComputeShaderExecutorObject computeShaderExecutorObject, ComputeShaderContainerGameObject containerGameObject) { var featureAppliers = TerrainDetailProviderDebugUtils.CreateFeatureAppliers(utTextureRendererProxy, containerGameObject, commonExecutorUtProxy, computeShaderExecutorObject); TerrainDetailGeneratorConfiguration generatorConfiguration = new TerrainDetailGeneratorConfiguration() { TerrainDetailImageSideDisjointResolution = 240 }; TextureWithCoords fullFundationData = new TextureWithCoords(new TextureWithSize() { Texture = mainTexture, Size = new IntVector2(mainTexture.width, mainTexture.height) }, new MyRectangle(0, 0, 3601 * 24, 3601 * 24)); TerrainDetailGenerator generator = new TerrainDetailGenerator(generatorConfiguration, utTextureRendererProxy, fullFundationData, featureAppliers, commonExecutorUtProxy); return(generator); }
public static TerrainDetailProvider CreateTerrainDetailProvider(TerrainDetailGenerator generator, TerrainDetailCornerMerger cornerMerger = null) { var provider = new TerrainDetailProvider(generator, cornerMerger, new TerrainDetailAlignmentCalculator(240)); return(provider); }
public void Start() { var heightmapTextureSize = new IntVector2(3600, 3600); var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(_filePathsConfiguration.HeightmapFilePath, heightmapTextureSize.X, heightmapTextureSize.Y, TextureFormat.ARGB32, true, false); TerrainTextureFormatTransformator transformator = new TerrainTextureFormatTransformator(_gameInitializationFields.Retrive <CommonExecutorUTProxy>()); var globalHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize() { Size = heightmapTextureSize, Texture = rgbaMainTexture }); if (true) { _gameInitializationFields.SetField(new TerrainDetailAlignmentCalculator(240)); TerrainDetailGenerator terrainDetailGenerator = CreateTerrainDetailGenerator( globalHeightTexture, _gameInitializationFields.Retrive <UTTextureRendererProxy>(), _gameInitializationFields.Retrive <CommonExecutorUTProxy>(), _gameInitializationFields.Retrive <UnityThreadComputeShaderExecutorObject>(), _gameInitializationFields.Retrive <ComputeShaderContainerGameObject>()); var commonExecutorUtProxy = _gameInitializationFields.Retrive <CommonExecutorUTProxy>(); TerrainDetailProvider terrainDetailProvider = CreateTerrainDetailProvider(terrainDetailGenerator, commonExecutorUtProxy); var terrainDetailFileManager = new TerrainDetailFileManager(_configuration.TerrainDetailCachePath, commonExecutorUtProxy); var terrainShapeDb = CreateTerrainShapeDb(terrainDetailProvider , commonExecutorUtProxy , _gameInitializationFields.Retrive <TerrainDetailAlignmentCalculator>() , _configuration.TerrainShapeDbConfiguration.MergeTerrainDetail , _configuration.TerrainShapeDbConfiguration.UseTextureSavingToDisk , _configuration.TerrainShapeDbConfiguration.UseTextureLoadingFromDisk, terrainDetailFileManager); TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(terrainShapeDb); var baseTerrainDetailProvider = BaseTerrainDetailProvider.CreateFrom(terrainShapeDb); _gameInitializationFields.SetField(baseTerrainDetailProvider); terrainDetailGenerator.SetBaseTerrainDetailProvider(baseTerrainDetailProvider); _ultraUpdatableContainer.AddOtherThreadProxy(terrainShapeDbProxy); _gameInitializationFields.SetField(terrainShapeDbProxy); } else { ITerrainShapeDb terrainShapeDbProxy = new DebugSlopedTerrainShapeDb( _gameInitializationFields.Retrive <UTTextureRendererProxy>() ); terrainShapeDbProxy = new RecordingTerrainShapeDb(terrainShapeDbProxy); _gameInitializationFields.SetField((RecordingTerrainShapeDb)terrainShapeDbProxy); } }
private TerrainDetailGenerator CreateTerrainDetailGenerator( Texture mainTexture, UTTextureRendererProxy utTextureRendererProxy, CommonExecutorUTProxy commonExecutorUtProxy, UnityThreadComputeShaderExecutorObject computeShaderExecutorObject, ComputeShaderContainerGameObject containerGameObject) { var featureAppliers = new List <RankedTerrainFeatureApplier>(); if (_configuration.EngraveTerrainFeatures) { featureAppliers.AddRange(FinalTerrainFeatureAppliers.CreateFeatureAppliers( utTextureRendererProxy, containerGameObject, commonExecutorUtProxy, computeShaderExecutorObject )); } if (_configuration.EngraveRoadsInTerrain) { featureAppliers.Add(FinalTerrainFeatureAppliers.CreateRoadEngravingApplier(CreateRoadEngravingFeatureApplier())); } TerrainDetailGeneratorConfiguration generatorConfiguration = _configuration.TerrainDetailGeneratorConfiguration; TextureWithCoords fullFundationData = new TextureWithCoords(new TextureWithSize() { Texture = mainTexture, Size = new IntVector2(mainTexture.width, mainTexture.height) }, new MyRectangle(0, 0, 3601 * 24, 3601 * 24)); TerrainDetailGenerator generator = new TerrainDetailGenerator(generatorConfiguration, utTextureRendererProxy, fullFundationData, featureAppliers, commonExecutorUtProxy); return(generator); }
private TerrainDetailProvider CreateTerrainDetailProvider(TerrainDetailGenerator generator, CommonExecutorUTProxy commonExecutorUtProxy) { var cornerMerger = new TerrainDetailCornerMerger( new LateAssignFactory <BaseTerrainDetailProvider>(() => _gameInitializationFields.Retrive <BaseTerrainDetailProvider>()), _gameInitializationFields.Retrive <TerrainDetailAlignmentCalculator>(), _gameInitializationFields.Retrive <UTTextureRendererProxy>(), _gameInitializationFields.Retrive <TextureConcieverUTProxy>(), commonExecutorUtProxy, _configuration.TerrainMergerConfiguration); var provider = new TerrainDetailProvider(generator, cornerMerger, _gameInitializationFields.Retrive <TerrainDetailAlignmentCalculator>()); return(provider); }
private TerrainDetailProvider CreateTerrainDetailProvider(List <RankedTerrainFeatureApplier> featureAppliers, TextureWithSize globalHeightTexture) { TerrainDetailGeneratorConfiguration generatorConfiguration = new TerrainDetailGeneratorConfiguration() { TerrainDetailImageSideDisjointResolution = 240 }; TextureWithCoords fullFundationData = new TextureWithCoords(sizedTexture: globalHeightTexture, coords: new MyRectangle(0, 0, 3601 * 24, 3601 * 24)); TerrainDetailGenerator generator = new TerrainDetailGenerator(generatorConfiguration, _utTextureRendererProxy, fullFundationData, featureAppliers, _commonExecutor); TerrainDetailProvider provider = new TerrainDetailProvider(generator, null, new TerrainDetailAlignmentCalculator(240)); return(provider); }
private TerrainDetailProvider CreateTerrainDetailProvider(List <RankedTerrainFeatureApplier> featureAppliers, Texture mainTexture) { TerrainDetailGeneratorConfiguration generatorConfiguration = new TerrainDetailGeneratorConfiguration() { TerrainDetailImageSideDisjointResolution = 240 }; TextureWithCoords fullFundationData = new TextureWithCoords(new TextureWithSize() { Texture = mainTexture, Size = new IntVector2(mainTexture.width, mainTexture.height) }, new MyRectangle(0, 0, 3601 * 24, 3601 * 24)); TerrainDetailGenerator generator = new TerrainDetailGenerator(generatorConfiguration, _utTextureRendererProxy, fullFundationData, featureAppliers, new CommonExecutorUTProxy()); TerrainDetailProvider provider = new TerrainDetailProvider(generator, null, new TerrainDetailAlignmentCalculator(240)); generator.SetBaseTerrainDetailProvider(BaseTerrainDetailProvider.CreateFrom(provider)); return(provider); }
// Use this for initialization void Start() { _updatableContainer = new UpdatableContainer(); TaskUtils.SetGlobalMultithreading(false); _ring1Tree = new Ring1Tree(); ////////////////// var rgbaMainTexture = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\n49_e019_1arc_v3.png", 3600, 3600, TextureFormat.ARGB32, true, false); CommonExecutorUTProxy commonExecutorUtProxy = new CommonExecutorUTProxy(); //todo _updatableContainer.AddUpdatableElement(commonExecutorUtProxy); TerrainTextureFormatTransformator transformator = new TerrainTextureFormatTransformator(commonExecutorUtProxy); var globalHeightTexture = transformator.EncodedHeightTextureToPlain(new TextureWithSize() { Size = new IntVector2(3600, 3600), Texture = rgbaMainTexture }); /// /// VISIBILITY TEXTURE var visibilityTextureSideLength = 16; var visibilityTexture = new Texture2D(visibilityTextureSideLength, visibilityTextureSideLength, TextureFormat.RFloat, false); visibilityTexture.filterMode = FilterMode.Point; var visibilityTextureProcessorProxy = new Ring1VisibilityTextureProcessorUTProxy(new Ring1VisibilityTextureProcessor(visibilityTexture)); _updatableContainer.AddUpdatableElement(visibilityTextureProcessorProxy); var visibilityTextureChangeGrabber = new Ring1VisibilityTextureChangeGrabber(); var terrainParentGameObject = new GameObject("TerrainParent"); var unityCoordsCalculator = new UnityCoordsCalculator(new Vector2(24 * 240 * 2, 24 * 240 * 2)); var orderGrabber = new Ring1PaintingOrderGrabber(); var painterProxy = new RingTerrainPainterUTProxy(new RingTerrainPainter()); _updatableContainer.AddUpdatableElement(painterProxy); painterProxy.Update(); var mainRespondingProxy = new Ring1NodeEventMainRespondingProxy(new Ring1NodeEventMainResponder()); _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair() { Proxy = mainRespondingProxy, EveryPostAction = () => { var delta = visibilityTextureChangeGrabber.RetriveVisibilityChanges(); if (delta.AnyChange) { var visibilityTextureChagnes = visibilityTextureChangeGrabber.RetriveVisibilityChanges(); visibilityTextureProcessorProxy.AddOrder(visibilityTextureChagnes); } if (orderGrabber.IsAnyOrder) { painterProxy.AddOrder(orderGrabber.RetriveOrderAndClear()); } } }); UTTextureRendererProxy textureRendererProxy = new UTTextureRendererProxy(new TextureRendererService( new MultistepTextureRenderer(ContainerGameObject), new TextureRendererServiceConfiguration() { StepSize = new Vector2(500, 500) })); _updatableContainer.AddUpdatableElement(textureRendererProxy); UnityThreadComputeShaderExecutorObject computeShaderExecutorObject = new UnityThreadComputeShaderExecutorObject(); _updatableContainer.AddUpdatableElement(computeShaderExecutorObject); _updatableContainer.AddUpdatableElement(commonExecutorUtProxy); TerrainDetailGenerator terrainDetailGenerator = CreateTerrainDetailGenerator( globalHeightTexture, textureRendererProxy, commonExecutorUtProxy, computeShaderExecutorObject, ContainerGameObject); TerrainDetailProvider terrainDetailProvider = CreateTerrainDetailProvider(terrainDetailGenerator); var terrainShapeDb = FETerrainShapeDbInitialization.CreateTerrainShapeDb(terrainDetailProvider, commonExecutorUtProxy , new TerrainDetailAlignmentCalculator(240), false, false, false, null); TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(terrainShapeDb); terrainDetailGenerator.SetBaseTerrainDetailProvider(BaseTerrainDetailProvider.CreateFrom(terrainShapeDb)); _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair() { Proxy = terrainShapeDbProxy }); var meshGeneratorProxy = new MeshGeneratorUTProxy(new MeshGeneratorService()); _updatableContainer.AddUpdatableElement(meshGeneratorProxy); _stainTerrainResourceCreatorUtProxy = new StainTerrainResourceCreatorUTProxy(new StainTerrainResourceCreator()); _updatableContainer.AddUpdatableElement(_stainTerrainResourceCreatorUtProxy); var stainTerrainServiceProxy = new StainTerrainServiceProxy( new StainTerrainService( new ComputationStainTerrainResourceGenerator( new StainTerrainResourceComposer( _stainTerrainResourceCreatorUtProxy ), new StainTerrainArrayMelder(), new DummyStainTerrainArrayFromBiomesGenerator( new DebugBiomeContainerGenerator().GenerateBiomesContainer( new BiomesContainerConfiguration()), new StainTerrainArrayFromBiomesGeneratorConfiguration() )), new MyRectangle(0, 0, 24 * 240 * 2, 24 * 240 * 2))); _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair() { Proxy = stainTerrainServiceProxy }); var gRing1NodeTerrainCreator = new GRing1NodeTerrainCreator( orderGrabber, terrainParentGameObject, meshGeneratorProxy, terrainShapeDbProxy, stainTerrainServiceProxy, unityCoordsCalculator, null, null, new GRingGroundShapeProviderConfiguration(), new GRingTerrainMeshProviderConfiguration()); var gRing2NodeTerrainCreator = new GRing2NodeTerrainCreator( orderGrabber, terrainParentGameObject, meshGeneratorProxy, terrainShapeDbProxy, unityCoordsCalculator, new GRing2PatchesCreatorProxy(CreateRing2PatchesCreator()), null, null, new GRingGroundShapeProviderConfiguration(), new GRingTerrainMeshProviderConfiguration()); UTRing2PlateStamperProxy stamperProxy = new UTRing2PlateStamperProxy( new Ring2PlateStamper(new Ring2PlateStamperConfiguration() { PlateStampPixelsPerUnit = new Dictionary <int, float>() }, ContainerGameObject)); _updatableContainer.AddUpdatableElement(stamperProxy); Ring2PatchStamplingOverseerFinalizer patchStamper = new Ring2PatchStamplingOverseerFinalizer(stamperProxy, textureRendererProxy, commonExecutorUtProxy); var gStampedRing2NodeTerrainCreator = new GStampedRing2NodeTerrainCreator( orderGrabber, terrainParentGameObject, meshGeneratorProxy, terrainShapeDbProxy, unityCoordsCalculator, new GRing2PatchesCreatorProxy(CreateRing2PatchesCreator()), patchStamper, null, null, new GRingGroundShapeProviderConfiguration(), new GRingTerrainMeshProviderConfiguration()); var subCreator = new SupremeGRingNodeTerrainCreator(new List <NewListenersCreatorWithLimitation>() { //new NewListenersCreatorWithMaximumLod() //{ // Creator = gRing1NodeTerrainCreator, // MaximumLod = new FlatLod(6) //}, new NewListenersCreatorWithLimitation() { Creator = new GVoidNodeTerrainCreator(), MaximumLod = new FlatLod(6) }, //new NewListenersCreatorWithMaximumLod() //{ // Creator = gRing2NodeTerrainCreator, // MaximumLod = new FlatLod(8) //} new NewListenersCreatorWithLimitation() { Creator = gStampedRing2NodeTerrainCreator, MaximumLod = new FlatLod(9) } }); var eventCollector = new Ring1NodeEventCollector( new DynamicFlatLodGRingNodeTerrainCreator(subCreator, new FlatLodCalculator(unityCoordsCalculator))); _ring1TreeProxy = new Ring1TreeProxy(_ring1Tree); _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair() { Proxy = _ring1TreeProxy, EveryPostAction = () => { if (eventCollector.Any) { mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear()); } } }); var baseQuadSideLength = 90f; StartThreading(_otherThreadActionPairs); _ring1TreeProxy.CreateHeightmap(new Ring1Tree.RootNodeCreationParameters() { UnityCoordsCalculator = unityCoordsCalculator, NodeListener = eventCollector, PrecisionDistances = new Dictionary <float, int> { //{4f * 50f/3f, 9}, //{4f * 50f/2f, 8}, { CalculatePrecisionDistance(baseQuadSideLength, 2, 1), 7 }, { 6.5f * 50f, 6 }, { 20 * 50f, 5 }, { 40 * 50f, 4 }, { 50 * 50f, 3 }, { 100 * 50f, 2 }, { 200 * 50f, 1 } }, InitialCameraPosition = Vector3.zero, }); }