コード例 #1
0
        // Use this for initialization
        void Start()
        {
            string        bilFilePath    = @"C:\n49_e019_1arc_v3.bil";
            HeightmapFile heightmapFile  = new HeightmapFile();
            const int     filePixelWidth = 3601;
            //heightmapFile.LoadFile(bilFilePath, 3601);
            //heightmapFile.MirrorReflectHeightDataInXAxis();

            MyTotalHeightmap totalHeightmap = new MyTotalHeightmap();

            //const int subTerrainCount = 14;
            int minSubmapWidth = 256; //(int)Math.Floor((double)filePixelWidth/subTerrainCount)-1 ;
            List <SubmapPreparmentOrder> preparmentOrders = new List <SubmapPreparmentOrder>
            {
                newPreparmentOrder(0, 0, 4, 4, minSubmapWidth, 6, 0),
                newPreparmentOrder(0, 4, 4, 6, minSubmapWidth, 7, 0),
                newPreparmentOrder(4, 0, 6, 4, minSubmapWidth, 5, 0),
                newPreparmentOrder(0, 10, 4, 4, minSubmapWidth, 4, 0),

                newPreparmentOrder(4, 4, 2, 2, minSubmapWidth, 2 + 4, 0),
                newPreparmentOrder(4, 6, 2, 2, minSubmapWidth, 2 + 4, 0),

                newPreparmentOrder(4, 8, 2, 2, minSubmapWidth, 2 + 4, 0),
                newPreparmentOrder(6, 4, 2, 2, minSubmapWidth, 2 + 4, 0),
                newPreparmentOrder(6, 8, 2, 2, minSubmapWidth, 3, 0),
                newPreparmentOrder(8, 4, 2, 2, minSubmapWidth, 2 + 4, 0),

                newPreparmentOrder(8, 6, 2, 2, minSubmapWidth, 2 + 4, 0),

                //newPreparmentOrder(8,8,2,2,minSubmapWidth, 2+4, 1), was lithe this
                newPreparmentOrder(8, 8, 1, 1, minSubmapWidth, 3, 0),
                newPreparmentOrder(9, 8, 1, 1, minSubmapWidth, 3, 0),
                newPreparmentOrder(9, 8, 1, 1, minSubmapWidth, 3, 0),
                newPreparmentOrder(9, 9, 1, 1, minSubmapWidth, 0, 1),


                newPreparmentOrder(6, 6, 2, 2, minSubmapWidth, 2 + 4, 0),
                newPreparmentOrder(10, 4, 4, 6, minSubmapWidth, 3 + 2, 0),

                newPreparmentOrder(10, 10, 4, 4, minSubmapWidth, 4 + 1, 0),
                newPreparmentOrder(4, 10, 6, 4, minSubmapWidth, 3 + 4, 0),
                newPreparmentOrder(10, 0, 4, 4, minSubmapWidth, 3 + 4, 0),
            };

            SubmapPreparer submapPreparer = new SubmapPreparer();
            //var submaps = submapPreparer.PrepareSubmaps(heightmapFile.GlobalHeightArray, preparmentOrders);
            //totalHeightmap.LoadHeightmap(submaps.Ring0Submaps);


            Ring1HeightArrayCreator creator = new Ring1HeightArrayCreator();
            //var ring1Array = creator.CreateRing1HeightmapArray(submaps.Ring1Submaps[0].Heightmap);
            //SavingFileManager.SaveToFile("map.dat", ring1Array);
            var ring1Array = SavingFileManager.LoadFromFile("map.dat", 2048, 2048);

            //ring1Array = BasicHeightmapModifier.AddConstant(-0.5f, ring1Array);
            ring1Array = BasicHeightmapModifier.Multiply(1000, ring1Array);

            _ring1Tree = new Ring1Tree();

            var tempHeightmapInfo = new GlobalHeightmapInfo(2000, 1000, 80000, 80000);

            //_ring1Tree.CreateHeightmap(ring1Array, heightmapFile.GlobalHeightmapInfo);
            _ring1Tree.CreateHeightmap_TODO_DELETE(ring1Array);
        }
コード例 #2
0
ファイル: Ring1DebugObject.cs プロジェクト: defacto2k15/PwMgr
        // Use this for initialization
        void Start()
        {
            _updatableContainer = new UpdatableContainer();
            TaskUtils.SetGlobalMultithreading(true);

            int minSubmapWidth = 256; //(int)Math.Floor((double)filePixelWidth/subTerrainCount)-1 ;
            var ring1Array     = SavingFileManager.LoadFromFile("map.dat", 2048, 2048);

            ring1Array = BasicHeightmapModifier.Multiply(1000, ring1Array);
            _ring1Tree = new Ring1Tree();

            //////////////////

            var tessalationRequirementTextureGenerator = new TessalationRequirementTextureGenerator();
            var tessalationReqTexture =
                tessalationRequirementTextureGenerator.GenerateTessalationRequirementTexture(ring1Array, 64);

            var heightmapBundle = SavingFileManager.LoadHeightmapBundlesFromFiles("heightmapBundle", 4, 2048);

            var submapTextures = new Ring1SubmapTextures(heightmapBundle, tessalationReqTexture);

            /// /// 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(256, 256));
            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());
                    }
                }
            });

            var commonExecutor = new CommonExecutorUTProxy();

            _updatableContainer.AddUpdatableElement(commonExecutor);

            TerrainShapeDbProxy terrainShapeDbProxy = new TerrainShapeDbProxy(
                FETerrainShapeDbInitialization.CreateTerrainShapeDb(null /*todo here*/, commonExecutor, new TerrainDetailAlignmentCalculator(240),
                                                                    false, false, false, null));

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy = terrainShapeDbProxy
            });


            var meshGeneratorProxy = new MeshGeneratorUTProxy(new MeshGeneratorService());

            _updatableContainer.AddUpdatableElement(meshGeneratorProxy);

            //var eventCollector = new Ring1NodeEventCollector((node) =>
            //    new Ring1NodeDirectHeightTerrain(
            //        node,
            //        visibilityTextureChangeGrabber,
            //        visibilityTexture,
            //        terrainParentGameObject,
            //        unityCoordsCalculator,
            //        orderGrabber,
            //        terrainShapeDbProxy,
            //        ring1Array,
            //        meshGeneratorProxy));
            var eventCollector = new Ring1NodeEventCollector(new FromLambdaListenersCreator((node) =>
                                                                                            new Ring1ListenerToGRingListener(
                                                                                                new Ring1NodeShaderHeightTerrain(
                                                                                                    node,
                                                                                                    visibilityTextureChangeGrabber,
                                                                                                    visibilityTexture,
                                                                                                    terrainParentGameObject,
                                                                                                    unityCoordsCalculator,
                                                                                                    orderGrabber,
                                                                                                    terrainShapeDbProxy,
                                                                                                    meshGeneratorProxy,
                                                                                                    null)))); //todo if you want this to work

            var ring1Proxy = new Ring1TreeProxy(_ring1Tree);

            _otherThreadActionPairs.Add(new OtherThreadProxyAndActionPair()
            {
                Proxy           = ring1Proxy,
                EveryPostAction =
                    () =>
                {
                    if (eventCollector.Any)
                    {
                        mainRespondingProxy.AddOrder(eventCollector.RetriveOrderAndClear());
                    }
                }
            });

            StartThreading();
            ring1Proxy.CreateHeightmap(
                new Ring1Tree.RootNodeCreationParameters()
            {
                UnityCoordsCalculator = unityCoordsCalculator,
                NodeListener          = eventCollector,
                PrecisionDistances    = Ring1TestDefaults.PrecisionDistances,
                InitialCameraPosition = Vector3.zero,
            });
        }