コード例 #1
0
ファイル: HeightArrayDb.cs プロジェクト: defacto2k15/PwMgr
        public async Task <CoordedPart <MySimpleArray <float> > > GeneratePartAsync(MyRectangle queryArea)
        {
            var heightTexture = (await _terrainShapeDb.Query(new TerrainDescriptionQuery()
            {
                QueryArea = queryArea,
                RequestedElementDetails = new List <TerrainDescriptionQueryElementDetail>()
                {
                    new TerrainDescriptionQueryElementDetail()
                    {
                        Type = TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY,
                        Resolution = _resolution
                    }
                }
            })).GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY);

            var encodedTexture = await _transformator.PlainToEncodedHeightTextureAsync(
                heightTexture.TokenizedElement.DetailElement.Texture);

            var heightArray = HeightmapUtils.EncodedHeightToArray(encodedTexture);

            return(new CoordedPart <MySimpleArray <float> >()
            {
                Coords = queryArea,
                Part = heightArray
            });
        }
コード例 #2
0
        private async Task <UniformsPack> CreateUniformsPack(Ring1Node ring1Node)
        {
            UniformsPack pack = new UniformsPack();


            var terrainOutput = await _terrainShapeDb.Query(new TerrainDescriptionQuery()
            {
                QueryArea = Ring1Node.Ring1Position,
                RequestedElementDetails = new List <TerrainDescriptionQueryElementDetail>()
                {
                    new TerrainDescriptionQueryElementDetail()
                    {
                        //PixelsPerMeter = 10, //todo
                        Resolution = TerrainCardinalResolution.FromRing1NodeLodLevel(Ring1Node.QuadLodLevel),
                        Type       = TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY
                    },
                    new TerrainDescriptionQueryElementDetail()
                    {
                        //PixelsPerMeter = 10, //todo
                        Resolution = TerrainCardinalResolution.FromRing1NodeLodLevel(Ring1Node.QuadLodLevel),
                        Type       = TerrainDescriptionElementTypeEnum.TESSALATION_REQ_ARRAY
                    },
                }
            });

            var uvPosition =
                _coordsCalculator.CalculateUvPosition(Ring1Node.Ring1Position); //_submapTextures.UvPosition;
            var heightmapTexture   = terrainOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY);
            var tessalationTexture =
                terrainOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.TESSALATION_REQ_ARRAY);

            pack.SetUniform("_TerrainTextureUvPositions",
                            new Vector4(uvPosition.X, uvPosition.Y, uvPosition.Width, uvPosition.Height));
            pack.SetTexture("_HeightmapTex", heightmapTexture.TokenizedElement.DetailElement.Texture.Texture);
            pack.SetTexture("_TessalationTex", tessalationTexture.TokenizedElement.DetailElement.Texture.Texture);

            pack.SetTexture("_LodTexture", _visibilityTexture);
            pack.SetUniform("_MaxHeight", 100);
            pack.SetUniform("_LodTextureUvOffset",
                            _coordsCalculator.CalculateTextureUvLodOffset(ring1Node.Ring1Position));
            pack.SetUniform("_BaseTrianglesCount",
                            _coordsCalculator.CalculateGameObjectSize(ring1Node.Ring1Position).X - 1);
            return(pack);
        }