private static void DrawLODRange(LODInfo currentLOD, float previousLODPercentage, bool isSelected) { Color backgroundColor = GUI.backgroundColor; string text = string.Format("{0}\n{1:0}%", currentLOD.LODName, previousLODPercentage * 100f); if (isSelected) { Rect rangePosition = currentLOD.m_RangePosition; rangePosition.width -= 6f; rangePosition.height -= 6f; rangePosition.center += new Vector2(3f, 3f); Styles.m_LODSliderRangeSelected.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false); GUI.backgroundColor = kLODColors[currentLOD.LODLevel]; if (rangePosition.width > 0f) { Styles.m_LODSliderRange.Draw(rangePosition, GUIContent.none, false, false, false, false); } Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, text, false, false, false, false); } else { GUI.backgroundColor = kLODColors[currentLOD.LODLevel]; GUI.backgroundColor = (Color)(GUI.backgroundColor * 0.6f); Styles.m_LODSliderRange.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false); Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, text, false, false, false, false); } GUI.backgroundColor = backgroundColor; }
public TerrainChunk(Vector2 coord, int size, LODInfo[] detailLevels, Transform parent, Material material) { this.detailLevels = detailLevels; position = coord * size; bounds = new Bounds(position, Vector2.one * size); Vector3 positionV3 = new Vector3(position.x, 0, position.y); meshObject = new GameObject("Terrain Chunk"); meshRenderer = meshObject.AddComponent<MeshRenderer>(); meshFilter = meshObject.AddComponent<MeshFilter>(); meshRenderer.material = material; meshObject.transform.position = positionV3; meshObject.transform.parent = parent; SetVisible(false); lodMeshes = new LODMesh[detailLevels.Length]; for(int i=0;i<lodMeshes.Length;i++) { lodMeshes[i] = new LODMesh(detailLevels[i].lod); } terrainGenerator.RequestTerrainData(OnTerrainDataReceived); }
private static void DrawLODRange(LODInfo currentLOD, float previousLODPercentage, bool isSelected) { var tempColor = GUI.backgroundColor; var startPercentageString = string.Format("{0}\n{1:0}%", currentLOD.LODName, previousLODPercentage * 100); if (isSelected) { var foreground = currentLOD.m_RangePosition; foreground.width -= kSelectedLODRangePadding * 2; foreground.height -= kSelectedLODRangePadding * 2; foreground.center += new Vector2(kSelectedLODRangePadding, kSelectedLODRangePadding); Styles.m_LODSliderRangeSelected.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false); GUI.backgroundColor = kLODColors[currentLOD.LODLevel]; if (foreground.width > 0) { Styles.m_LODSliderRange.Draw(foreground, GUIContent.none, false, false, false, false); } Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, startPercentageString, false, false, false, false); } else { GUI.backgroundColor = kLODColors[currentLOD.LODLevel]; GUI.backgroundColor *= 0.6f; Styles.m_LODSliderRange.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false); Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, startPercentageString, false, false, false, false); } GUI.backgroundColor = tempColor; }
protected override void RequestLodMeshData(LODMesh lodMesh, LODInfo lodInfo) { lodMesh.RequestMeshData( () => MeshGenerator.GenerateMeshData( waterData.size + 1, lodInfo), OnLodMeshReady); }
private void RecaluclateLODLevels() { LODInfo[] levels = new LODInfo[_lodFactors.Count]; for (int i = 0; i < _lodFactors.Count; i++) { levels[i] = new LODInfo(_lodFactors[i], LodCurve.Evaluate((i + 1f) / _lodFactors.Count) * MaxViewDistance); } LodLevels = levels; }
protected override void RequestLodMeshData(LODMesh lodMesh, LODInfo lodInfo) { lodMesh.RequestMeshData( () => VoxelMeshGenerator.GenerateVoxelMeshData( terrainData.size, terrainData.cellSize, lodInfo, heightLevelMapData), OnLodMeshReady); }
protected override void OnValidate() { base.OnValidate(); if (detailLevels != null && detailLevels.Length > numSupportedLODs) { var array = new LODInfo[numSupportedLODs]; Array.Copy(detailLevels, 0, array, 0, numSupportedLODs); detailLevels = array; } }
public static TerrainMeshData GenerateMeshData(int size, LODInfo lodInfo, float[,] heightMap = null, float heightScale = 0, AnimationCurve heightCurve = null) { int lodStep = lodInfo.LodStep; int lodSize = lodInfo.LodSize(size); int triangleVertexCounter = 0; float halfSize = (lodSize - 1) / 2f; TerrainMeshData data = new TerrainMeshData(lodSize); AnimationCurve copyHeightCurve = null; if (heightCurve != null) { copyHeightCurve = new AnimationCurve(heightCurve.keys); } for (int z = 0; z < lodSize; z++) { for (int x = 0; x < lodSize; x++) { int vertexIndex = z * lodSize + x; float height = 0; if (heightMap != null) { float heightSample = heightMap[x * lodStep, z *lodStep]; height = heightSample * heightScale; if (copyHeightCurve != null) { height *= copyHeightCurve.Evaluate(heightSample); } } data.vertices[vertexIndex] = new Vector3((x - halfSize) * lodStep, height, (z - halfSize) * lodStep); data.uvs[vertexIndex] = new Vector2(x / (float)lodSize, z / (float)lodSize); if ((x < lodSize - 1) && (z < lodSize - 1)) { int triangleIndex = triangleVertexCounter * 6; data.triangles[triangleIndex] = vertexIndex; data.triangles[triangleIndex + 1] = vertexIndex + lodSize; data.triangles[triangleIndex + 2] = vertexIndex + lodSize + 1; data.triangles[triangleIndex + 3] = vertexIndex + lodSize + 1; data.triangles[triangleIndex + 4] = vertexIndex + 1; data.triangles[triangleIndex + 5] = vertexIndex; triangleVertexCounter++; } } } return(data); }
public static void DrawLODSlider(Rect area, IList <LODInfo> lods, int selectedLevel) { Styles.m_LODSliderBG.Draw(area, GUIContent.none, false, false, false, false); for (int i = 0; i < lods.Count; i++) { LODInfo currentLOD = lods[i]; DrawLODRange(currentLOD, (i != 0) ? lods[i - 1].RawScreenPercent : 1f, i == selectedLevel); DrawLODButton(currentLOD); } DrawCulledRange(area, (lods.Count <= 0) ? 1f : lods[lods.Count - 1].RawScreenPercent); }
protected override void RequestLodMeshData(LODMesh lodMesh, LODInfo lodInfo) { lodMesh.RequestMeshData( () => MeshGenerator.GenerateMeshData( terrainData.size + 1, lodInfo, heightMapData, terrainData.heightScale, terrainData.heightCurve), OnLodMeshReady); }
public static List <LODInfo> CreateLODInfos(int numLODs, Rect area, Func <int, string> nameGen, Func <int, float> heightGen) { var lods = new List <LODInfo>(); for (int i = 0; i < numLODs; ++i) { var lodInfo = new LODInfo(i, nameGen(i), heightGen(i)); lodInfo.m_ButtonPosition = CalcLODButton(area, lodInfo.ScreenPercent); var previousPercentage = i == 0 ? 1.0f : lods[i - 1].ScreenPercent; lodInfo.m_RangePosition = CalcLODRange(area, previousPercentage, lodInfo.ScreenPercent); lods.Add(lodInfo); } return(lods); }
public static List <LODInfo> CreateLODInfos(int numLODs, Rect area, Func <int, string> nameGen, Func <int, float> heightGen) { List <LODInfo> list = new List <LODInfo>(); for (int i = 0; i < numLODs; i++) { LODInfo item = new LODInfo(i, nameGen(i), heightGen(i)); item.m_ButtonPosition = CalcLODButton(area, item.ScreenPercent); float startPercent = (i != 0) ? list[i - 1].ScreenPercent : 1f; item.m_RangePosition = CalcLODRange(area, startPercent, item.ScreenPercent); list.Add(item); } return(list); }
public void AddLod() { LODInfo newLodInfo = new LODInfo(world.lodInfo[world.lodInfo.Length - 1]); CreateLodObject(newLodInfo, world.lodInfo.Length); List <LODInfo> newLodInfos = new List <LODInfo>(); newLodInfos.AddRange(world.lodInfo); newLodInfos.Add(newLodInfo); world.lodInfo = newLodInfos.ToArray(); ResetLodPanel(); world.Reset(); }
public void RemoveLod(LODInfo lodInfo, int index) { List <LODInfo> newLodInfos = new List <LODInfo>(); for (int i = 0; i < world.lodInfo.Length; i++) { if (i != index) { newLodInfos.Add(world.lodInfo[i]); } } world.lodInfo = newLodInfos.ToArray(); ResetLodPanel(); world.Reset(); }
public LodObject CreateLodObject(LODInfo lodInfo, int index) { GameObject lodGameObject = Instantiate(lodLayoutPrefab, lodObjectsPanel); LodObject lodObject = lodGameObject.GetComponent <LodObject>(); lodObject.lodValue.value = lodInfo.Lod; lodObject.lodText.text = lodInfo.Lod.ToString(); lodObject.distance.text = lodInfo.Distance.ToString(); lodObject.colliderToggle.isOn = lodInfo.UseForCollider; lodObject.lodValue.onValueChanged.AddListener(delegate { SetLodValues(lodObject, index); }); lodObject.distance.onEndEdit.AddListener(delegate { SetLodValues(lodObject, index); }); lodObject.colliderToggle.onValueChanged.AddListener(delegate { SetLodValues(lodObject, index); }); lodObject.removeButton.onClick.AddListener(delegate { RemoveLod(lodInfo, index); }); return(lodObject); }
public static VoxelMeshData GenerateVoxelMeshData(int size, int cellSize, LODInfo lodInfo, int[,] heightLevelMap = null) { int lodStep = lodInfo.LodStep; int lodSize = lodInfo.LodSize(size); int lodCellSize = cellSize * lodInfo.LodStep; float halfSizeScaled = lodCellSize * lodSize / 2; VoxelMeshData data = new VoxelMeshData(); Vector3 centerOffset = new Vector3(-halfSizeScaled, 0, -halfSizeScaled); for (int z = 0; z < lodSize; z++) { for (int x = 0; x < lodSize; x++) { data.AddVoxel(x, z, lodStep, lodSize, lodCellSize, heightLevelMap, centerOffset); } } //data.AddVoxel(x, z, size, cellSize, heightLevelMap, centerOffset); return(data); }
/// <summary> /// /// </summary> /// <param name="levels"></param> /// <param name="extent">sr=3857</param> /// <returns></returns> public static long CalculateTileCount(int[] levels, ESRI.ArcGIS.Client.Geometry.Envelope extent) { long total = 0; int constTileSize = 256; LODInfo[] LODs = new LODInfo[20]; const double cornerCoordinate = 20037508.3427892; double resolution = cornerCoordinate * 2 / 256; double scale = 591657527.591555; for (int i = 0; i < LODs.Length; i++) { LODs[i] = new LODInfo() { Resolution = resolution, LevelID = i, Scale = scale }; resolution /= 2; scale /= 2; } PBS.Util.Point TileOrigin = new PBS.Util.Point(-cornerCoordinate, cornerCoordinate); foreach (int level in levels) { LODInfo lod = LODs[level]; double oneTileDistance = lod.Resolution * constTileSize; //calculate start tile and end tile int startTileRow = (int)(Math.Abs(TileOrigin.Y - extent.YMax) / oneTileDistance); int startTileCol = (int)(Math.Abs(TileOrigin.X - extent.XMin) / oneTileDistance); int endTileRow = (int)(Math.Abs(TileOrigin.Y - extent.YMin) / oneTileDistance); int endTileCol = (int)(Math.Abs(TileOrigin.X - extent.XMax) / oneTileDistance); //"startR,startC,endR,endC" total += Math.Abs((endTileCol - startTileCol + 1) * (endTileRow - startTileRow + 1)); } return(total); }
private static void DrawLODButton(LODInfo currentLOD) { // Make the lod button areas a horizonal resizer EditorGUIUtility.AddCursorRect(currentLOD.m_ButtonPosition, MouseCursor.ResizeHorizontal); }
public TerrainChunk(Vector2 coord, int size, LODInfo[] detailLevels, Transform parent, Material material) { this.detailLevels = detailLevels; position = coord * size; bounds = new Bounds(position,Vector2.one * size); Vector3 positionV3 = new Vector3(position.x,0,position.y); meshObject = new GameObject("Terrain Chunk"); meshRenderer = meshObject.AddComponent<MeshRenderer>(); meshFilter = meshObject.AddComponent<MeshFilter>(); meshCollider = meshObject.AddComponent<MeshCollider>(); meshRenderer.material = material; meshObject.transform.position = positionV3 * mapGenerator.terrainData.uniformScale; meshObject.transform.parent = parent; meshObject.transform.localScale = Vector3.one * mapGenerator.terrainData.uniformScale; SetVisible(false); lodMeshes = new LODMesh[detailLevels.Length]; for (int i = 0; i < detailLevels.Length; i++) { lodMeshes[i] = new LODMesh(detailLevels[i].lod, UpdateTerrainChunk); if (detailLevels[i].useForCollider) { collisionLODMesh = lodMeshes[i]; } } mapGenerator.RequestMapData(position,OnMapDataReceived); }
public void Deserialize(Stream input) { this.Version = input.ReadValueU32(); if (this.Version < 3 || this.Version > 22) { throw new FormatException(); } List <ResourceKey> keyTable = null; if (this.Version >= 11) { keyTable = new List <ResourceKey>(); long keyTableOffset = input.ReadValueU32(); long originalPosition = input.Position; input.Seek(keyTableOffset, SeekOrigin.Current); var count = input.ReadValueU8(); for (var i = 0; i < count; i++) { keyTable.Add(input.ReadResourceKeyIGT()); } input.Seek(originalPosition, SeekOrigin.Begin); } this.Presets.Clear(); if (this.Version >= 16) { var count = input.ReadValueU32(); for (uint i = 0; i < count; i++) { var text = input.ReadString(input.ReadValueU32() * 2, true, Encoding.Unicode); var index = input.ReadValueU32(); this.Presets.Add(index, text); } } if (this.Version >= 12) { this.Name = input.ReadString(input.ReadValueS32Packed(), true, Encoding.BigEndianUnicode); } if (this.Version >= 18) { this.DisplayIndex = input.ReadValueF32(); } else if (this.Version >= 13) { input.Seek(4, SeekOrigin.Current); // skip } this.Unknown04 = input.ReadValueB8(); this.Unknown05 = input.ReadValueU32(); if (this.Version >= 15) { this.Unknown06 = input.ReadValueU32(); } else { var remap = new uint[] { 0, 1, 2, 4, 8, 8, 8, 8 }; this.Unknown06 = this.Unknown05 < remap.Length ? remap[this.Unknown05] : 16; } if (this.Version >= 9) { this.Unknown06 = input.ReadValueU32(); } else { var a = input.ReadValueU32(); var b = input.ReadValueU32(); this.Unknown06 = a | b; } if (this.Version >= 8) { this.Unknown07 = input.ReadValueU32(); } if (this.Version >= 16) { this.Unknown09 = keyTable[input.ReadValueU8()]; this.Unknown10 = keyTable[input.ReadValueU8()]; } else if (this.Version >= 15) { this.Unknown09 = input.ReadResourceKeyIGT(); this.Unknown10 = input.ReadResourceKeyIGT(); } this.BlendKeys.Deserialize(input, this.Version, keyTable); this.Unknown17 = input.ReadValueU32(); this.VisualProxies.Clear(); if (this.Version >= 6) { var count = input.ReadValueU8(); for (int i = 0; i < count; i++) { if (this.Version >= 11) { this.VisualProxies.Add(keyTable[input.ReadValueU8()]); } else { this.VisualProxies.Add(input.ReadResourceKeyTGI()); } } } this.LODs.Clear(); { var count = input.ReadValueU8(); for (int i = 0; i < count; i++) { var lodInfo = new LODInfo(); lodInfo.Deserialize(input, this.Version); this.LODs.Add(lodInfo); } } this.TextureKeys.Deserialize(input, this.Version, keyTable); this.Unknown24.Clear(); if (this.Version >= 4) { var count = this.Version >= 6 ? input.ReadValueU8() : 7; for (int i = 0; i < count; i++) { if (this.Version >= 11) { this.Unknown24.Add(keyTable[input.ReadValueU8()]); } else { this.Unknown24.Add(input.ReadResourceKeyIGT()); } } } if (this.Version >= 7 && this.Version <= 15) { var count = input.ReadValueU32(); for (uint i = 0; i < count; i++) { var text = input.ReadString(input.ReadValueS32Packed(), true, Encoding.BigEndianUnicode); var index = input.ReadValueU32(); this.Presets.Add(index, text); } } if (this.Version >= 10) { this.ShoeMaterial = input.ReadString(input.ReadValueS32Packed(), true, Encoding.BigEndianUnicode); } if (this.Version >= 22) { this.OutfitMaterial = input.ReadString(input.ReadValueS32Packed(), true, Encoding.BigEndianUnicode); } if (this.Version >= 20) { this.ProfessionTypes = input.ReadValueU64(); } else if (this.Version >= 19) { this.ProfessionTypes = 0; var count = input.ReadValueU32(); for (uint i = 0; i < count; i++) { this.ProfessionTypes |= input.ReadValueU64(); } } }
// Methods public ArcGISTileSchema(string FilePath) { Resolution resolution2; this.url = @"C:\arcgisserver\arcgiscache\GZMap\Layers\conf.xml"; this.url = FilePath; XmlDocument document = new XmlDocument(); document.Load(this.url); XmlNode documentElement = document.DocumentElement; XmlNodeList elementsByTagName = document.GetElementsByTagName("LODInfo"); List<LODInfo> list2 = new List<LODInfo>(); foreach (XmlNode node2 in elementsByTagName) { string innerText = node2["LevelID"].InnerText; string str2 = node2["Scale"].InnerText; string str3 = node2["Resolution"].InnerText; LODInfo item = new LODInfo(); item.LevelID = Convert.ToInt32(innerText); item.Scale = Convert.ToDouble(str2); item.Resolution = Convert.ToDouble(str3); list2.Add(item); } foreach (LODInfo info2 in list2) { resolution2 = new Resolution(); Resolution resolution = resolution2; resolution.Id = info2.LevelID.ToString(); resolution.UnitsPerPixel = info2.Resolution; base.Resolutions.Add(resolution); } base.Height = 0x100; base.Width = 0x100; base.Extent = new Extent(-180.0, -90.0, 180.0, 90.0); XmlNodeList list3 = document.GetElementsByTagName("SpatialReference"); base.OriginX = Convert.ToDouble(list3[0]["XOrigin"].InnerText); base.OriginY = Convert.ToDouble(list3[0]["YOrigin"].InnerText); list3 = document.GetElementsByTagName("TileCols"); base.Width = Convert.ToInt32(list3[0].InnerText); list3 = document.GetElementsByTagName("TileRows"); base.Height = Convert.ToInt32(list3[0].InnerText); base.Axis = AxisDirection.InvertedY; list3 = document.GetElementsByTagName("TileOrigin"); base.OriginX = Convert.ToDouble(list3[0].FirstChild.InnerText); base.OriginY = Convert.ToDouble(list3[0].LastChild.InnerText); base.Name = "ArcGISTileCache"; base.Format = "png"; base.Srs = "UnKnown"; DirectoryInfo info3 = new DirectoryInfo(Path.GetDirectoryName(FilePath) + @"\_alllayers\L00"); BoundingBox box = null; foreach (DirectoryInfo info4 in info3.GetDirectories()) { int row = RowToHex(info4.Name); int level = 0; foreach (FileInfo info5 in info4.GetFiles()) { if (info5.FullName.EndsWith(base.Format)) { BoundingBox box2; int col = ColumnToHex(info5.Name); TileInfo info6 = new TileInfo(); info6.Extent = this.TileToWorld(new TileRange(col, row), level, this); resolution2 = base.Resolutions[level]; info6.Index = new TileIndex(col, row, resolution2.Id); try { box2 = new BoundingBox(info6.Extent.MinX, info6.Extent.MinY, info6.Extent.MaxX, info6.Extent.MaxY); } catch (Exception) { box2 = new BoundingBox(-180.0, -90.0, 180.0, 90.0); } if (box2 != null) { box = (box == null) ? box2 : box.Join(box2); } } } } if (box != null) { base.Extent = new Extent(box.Min.X, box.Min.Y, box.Max.X, box.Max.Y); } }
protected override void DoConvertToMBTiles(string outputPath, string name, string description, string attribution, int[] levels, Geometry geometry, bool doCompact) { Util.Envelope initial; Point pLeftTop; Point pRightBottom; if (geometry is Envelope) { initial = geometry as Envelope; pLeftTop = Utility.GeographicToWebMercator(new Util.Point(initial.XMin, initial.YMax)); pRightBottom = Utility.GeographicToWebMercator(new Util.Point(initial.XMax, initial.YMin)); } else { Polygon temp = geometry as Polygon; pLeftTop = new Util.Point(temp.Extent.XMin, temp.Extent.YMax); pRightBottom = new Util.Point(temp.Extent.XMax, temp.Extent.YMin); Point GPS_pLeftTop = Utility.WebMercatorToGeographic(pLeftTop); Point GPS_pRightBottom = Utility.WebMercatorToGeographic(pRightBottom); initial = new Envelope(GPS_pLeftTop.X, GPS_pRightBottom.Y, GPS_pRightBottom.X, GPS_pLeftTop.Y); } Envelope downloadExtentMercator = new Envelope(pLeftTop.X, pRightBottom.Y, pRightBottom.X, pLeftTop.Y); _outputFile = outputPath; _downloadGeometry = geometry; _convertingStatus.IsInProgress = true; try { CreateMBTilesFileAndWriteMetaData(outputPath, name, description, attribution, initial); if (autoCorrectCoord) { CreateCCMBTilesFile(outputPath, name, description, attribution, initial); } _outputconn = new SQLiteConnection("Data source = " + base._outputFile); _outputconn.Open(); #region calculate startCol/Row and endCol/Row and tiles count of each level _convertingStatus.TotalCount = 0; string[] keyTileInfos = new string[levels.Length]; int[] tilesCountOfLevel = new int[levels.Length]; for (int i = 0; i < levels.Length; i++) { LODInfo lod = TilingScheme.LODs[levels[i]]; double oneTileDistance = lod.Resolution * 256; int level = TilingScheme.LODs[levels[i]].LevelID; int startTileRow = (int)(Math.Abs(TilingScheme.TileOrigin.Y - geometry.Extent.YMax) / oneTileDistance); int startTileCol = (int)(Math.Abs(TilingScheme.TileOrigin.X - geometry.Extent.XMin) / oneTileDistance); int endTileRow = (int)(Math.Abs(TilingScheme.TileOrigin.Y - geometry.Extent.YMin) / oneTileDistance); int endTileCol = (int)(Math.Abs(TilingScheme.TileOrigin.X - geometry.Extent.XMax) / oneTileDistance); keyTileInfos[i] = string.Format("{0},{1},{2},{3}", startTileRow, startTileCol, endTileRow, endTileCol); tilesCountOfLevel[i] = Math.Abs((endTileCol - startTileCol + 1) * (endTileRow - startTileRow + 1)); _convertingStatus.TotalCount += tilesCountOfLevel[i]; } _totalCount = _convertingStatus.TotalCount; _completeCount = _errorCount = 0; _wroteBytes = _wroteCounts = 0; #endregion int arcgisTileCount = 0; for (int i = 0; i < levels.Length; i++) { int level, startR, startC, endR, endC;//startTileRow,startTileCol,... level = TilingScheme.LODs[levels[i]].LevelID; startR = int.Parse(keyTileInfos[i].Split(new char[] { ',' })[0]); startC = int.Parse(keyTileInfos[i].Split(new char[] { ',' })[1]); endR = int.Parse(keyTileInfos[i].Split(new char[] { ',' })[2]); endC = int.Parse(keyTileInfos[i].Split(new char[] { ',' })[3]); _convertingStatus.Level = level; _convertingStatus.LevelTotalCount = tilesCountOfLevel[i]; _convertingStatus.LevelCompleteCount = _convertingStatus.LevelErrorCount = 0; _levelTotalCount = _convertingStatus.LevelTotalCount; _levelCompleteCount = _levelErrorCount = 0; SaveOneLevelTilesToMBTiles(level, startR, startC, endR, endC); if (autoCorrectCoord) { RCRange range = BaiDuMapManager.inst.getArcgisRCRangeFromMercator(downloadExtentMercator, levels[i]); startR = range.MinRow; startC = range.MinCol; endR = range.MaxRow; endC = range.MaxCol; recordScope(level, startR, startC, endR, endC); arcgisTileCount += (endR - startR + 1) * (endC - startC + 1); } if (_convertingStatus.IsCancelled) { _convertingStatus.IsCompletedSuccessfully = false; break; } } IOProxy.getInst().Dispose(); recordCount(arcgisTileCount); if (doCompact) { _convertingStatus.IsDoingCompact = true; _convertingStatus.SizeBeforeCompact = new FileInfo(_outputFile).Length; CompactMBTiles(_outputFile); _convertingStatus.IsDoingCompact = false; _convertingStatus.SizeAfterCompact = new FileInfo(_outputFile).Length; } if (!_convertingStatus.IsCancelled) { _convertingStatus.IsCompletedSuccessfully = true; } } finally { if (_correctOutputconn != null) { _correctOutputconn.Dispose(); } RecoverFailure(); _convertingStatus.IsInProgress = false; _convertingStatus.IsCommittingTransaction = false; _convertingStatus.IsDoingCompact = false; _outputconn.Close(); _outputconn.Dispose(); } }
/// <summary> /// The h 2 parsed model. /// </summary> /// <param name="meta">The meta.</param> /// <remarks></remarks> public void H2ParsedModel(ref Meta meta) { if (meta.MS.Length == 0) { return; } string[] temps = meta.name.Split('\\'); name = temps[temps.Length - 1]; BoundingBox = new BoundingBoxContainer(ref meta); BinaryReader BR = new BinaryReader(meta.MS); BR.BaseStream.Position = 36; int tempc = BR.ReadInt32(); int tempr = BR.ReadInt32() - meta.magic - meta.offset; RawDataMetaChunks = new RawDataMetaChunk[tempc]; for (int x = 0; x < tempc; x++) { RawDataMetaChunks[x] = new RawDataMetaChunk(tempr + (x * 92), x, BoundingBox, ref meta); } Shaders = new ShaderContainer(ref meta); LOD = new LODInfo(ref meta, ref RawDataMetaChunks); int temphlmt = -1; for (int x = 0; x < meta.Map.IndexHeader.metaCount; x++) { if ("hlmt" == meta.Map.MetaInfo.TagType[x] && meta.Map.FileNames.Name[x] == meta.name) { temphlmt = x; break; } } if (temphlmt != -1) { hlmt = new hlmtContainer(temphlmt, meta.Map); PermutationString = hlmt.Permutations.Name; } // ** Length of Distance LOD Display = DisplayedInfo.FindDisplayedPieces(4, this); Frames = new FrameHierarchy(); Frames.GetFramesFromHalo2Model(ref meta); }
protected abstract void RequestLodMeshData(LODMesh lodMesh, LODInfo lodInfo);
private static void DrawLODButton(LODInfo currentLOD) { EditorGUIUtility.AddCursorRect(currentLOD.m_ButtonPosition, MouseCursor.ResizeHorizontal); }
private void SampleGetTileInfo() { string defaultMapName = this._mapservice.GetDefaultMapName(); this._mapservice.GetServerInfo(defaultMapName); MapDescription defaultMapDescription = this._mapinfo.DefaultMapDescription; string virtualCacheDirectory = this._mapservice.GetVirtualCacheDirectory(defaultMapName, -1); int num = 400; int height = 400; EnvelopeN envelopeN = (EnvelopeN)defaultMapDescription.MapArea.Extent; double num2 = Math.Abs(envelopeN.XMax - envelopeN.XMin) / (double)num; Bitmap bitmap = new Bitmap(num, height); Graphics graphics = Graphics.FromImage(bitmap); graphics.FillRectangle(new SolidBrush(System.Drawing.Color.LightGray), 0, 0, num, height); if (this._mapservice.HasSingleFusedMapCache(defaultMapName)) { TileCacheInfo tileCacheInfo = this._mapservice.GetTileCacheInfo(defaultMapName); LODInfo[] lODInfos = tileCacheInfo.LODInfos; double num3 = 0.0; int level = 0; LODInfo[] array = lODInfos; for (int i = 0; i < array.Length; i++) { LODInfo lODInfo = array[i]; double resolution = lODInfo.Resolution; num3 = resolution; level = lODInfo.LevelID; if (num2 >= resolution) { break; } } double xMin = envelopeN.XMin; double yMin = envelopeN.YMin; double xMax = envelopeN.XMax; double yMax = envelopeN.YMax; double x = ((PointN)tileCacheInfo.TileOrigin).X; double y = ((PointN)tileCacheInfo.TileOrigin).Y; double d = (xMin - x) / ((double)tileCacheInfo.TileCols * num3); double d2 = (y - yMax) / ((double)tileCacheInfo.TileRows * num3); double d3 = (xMax - x) / ((double)tileCacheInfo.TileCols * num3); double d4 = (y - yMin) / ((double)tileCacheInfo.TileRows * num3); int num4 = (int)Math.Floor(d); int num5 = (int)Math.Floor(d2); int num6 = (int)Math.Floor(d3); int num7 = (int)Math.Floor(d4); double num8 = x + (double)num4 * ((double)tileCacheInfo.TileCols * num3); double num9 = y - (double)num5 * ((double)tileCacheInfo.TileRows * num3); double num10 = Math.Abs(xMin - num8); double num11 = Math.Abs(yMax - num9); int num12 = (int)(num10 / num3); int num13 = (int)(num11 / num3); TileImageInfo tileImageInfo = this._mapservice.GetTileImageInfo(this._mapservice.GetDefaultMapName()); int num14 = 0; for (int j = num5; j <= num7; j++) { int num15 = 0; for (int k = num4; k <= num6; k++) { byte[] array2 = null; try { array2 = this._mapservice.GetMapTile(defaultMapName, level, j, k, tileImageInfo.CacheTileFormat); string text = "png"; string requestUriString = string.Concat(new string[] { virtualCacheDirectory, "/L", level.ToString().PadLeft(2, '0'), "/R", j.ToString("x").PadLeft(8, '0'), "/C", k.ToString("x").PadLeft(8, '0'), text }); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUriString); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); MemoryStream memoryStream = new MemoryStream(); int num16; while ((num16 = responseStream.ReadByte()) != -1) { memoryStream.WriteByte((byte)num16); } array2 = memoryStream.ToArray(); } catch { } if (array2 != null) { using (MemoryStream memoryStream2 = new MemoryStream(array2, 0, array2.Length)) { memoryStream2.Write(array2, 0, array2.Length); Image image = Image.FromStream(memoryStream2, true); graphics.DrawImage(image, tileCacheInfo.TileCols * num15 - num12, tileCacheInfo.TileRows * num14 - num13, tileCacheInfo.TileCols, tileCacheInfo.TileRows); } } num15++; } num14++; } } string filename = Utility.TemporaryFilePath() + ".bmp"; bitmap.Save(filename, ImageFormat.Bmp); Bitmap bitmap2 = new Bitmap(num, height); Graphics graphics2 = Graphics.FromImage(bitmap2); graphics2.FillRectangle(new SolidBrush(System.Drawing.Color.LightGray), 0, 0, num, height); graphics2.DrawImage(bitmap, 0, 0, num, height); string filename2 = Utility.TemporaryFilePath() + ".bmp"; bitmap2.Save(filename2, ImageFormat.Bmp); }
/// <summary> /// The dispose. /// </summary> /// <remarks></remarks> public void Dispose() { this.BoundingBox = null; this.Display = null; this.hlmt = null; this.LOD = null; this.RawDataMetaChunks = null; for (int i = 0; i < this.Shaders.Shader.Length; i++) { this.Shaders.Shader[i].Bitmaps.Clear(); this.Shaders.Shader[i].BitmapNames.Clear(); } this.Shaders = null; GC.SuppressFinalize(this); }
// Methods public ArcGISTileCompactSchema(string FilePath) { Resolution resolution2; this.url = @"C:\arcgisserver\arcgiscache\GZMap\Layers\conf.xml"; this.url = FilePath; string cdiFile = string.Format(@"{0}\conf.cdi", Path.GetDirectoryName(FilePath)); XmlDocument document = new XmlDocument(); document.Load(this.url); XmlNode documentElement = document.DocumentElement; XmlNodeList elementsByTagName = document.GetElementsByTagName("LODInfo"); List<LODInfo> list2 = new List<LODInfo>(); foreach (XmlNode node2 in elementsByTagName) { string innerText = node2["LevelID"].InnerText; string str2 = node2["Scale"].InnerText; string str3 = node2["Resolution"].InnerText; LODInfo item = new LODInfo(); item.LevelID = Convert.ToInt32(innerText); item.Scale = Convert.ToDouble(str2); item.Resolution = Convert.ToDouble(str3); list2.Add(item); } foreach (LODInfo info2 in list2) { resolution2 = new Resolution(); Resolution resolution = resolution2; resolution.Id = info2.LevelID.ToString(); resolution.UnitsPerPixel = info2.Resolution; base.Resolutions.Add(resolution); } base.Height = 0x100; base.Width = 0x100; base.Extent = new Extent(-180.0, -90.0, 180.0, 90.0); XmlNodeList list3 = document.GetElementsByTagName("SpatialReference"); base.OriginX = Convert.ToDouble(list3[0]["XOrigin"].InnerText); base.OriginY = Convert.ToDouble(list3[0]["YOrigin"].InnerText); list3 = document.GetElementsByTagName("TileCols"); base.Width = Convert.ToInt32(list3[0].InnerText); list3 = document.GetElementsByTagName("TileRows"); base.Height = Convert.ToInt32(list3[0].InnerText); base.Axis = AxisDirection.InvertedY; list3 = document.GetElementsByTagName("TileOrigin"); base.OriginX = Convert.ToDouble(list3[0].FirstChild.InnerText); base.OriginY = Convert.ToDouble(list3[0].LastChild.InnerText); base.Name = "ArcGISTileCache"; base.Format = "png"; base.Srs = "UnKnown"; DirectoryInfo info3 = new DirectoryInfo(Path.GetDirectoryName(FilePath) + @"\_alllayers\L00"); BoundingBox box = null; //foreach (FileInfo infoBundle in info3.GetFiles()) //{ // if (infoBundle.FullName.EndsWith("bundle")) // { // BoundingBox box2; // //int row = RowToHex(infoBundle.Name.Substring(1, 4)); // int row = RowToHex(infoBundle.Name); // int level = 0; // //int col = ColumnToHex(infoBundle.Name.Substring(6, 4)); // int col = ColumnToHex(infoBundle.Name); // TileInfo infoTile = new TileInfo(); // infoTile.Extent = this.TileToWorld(new TileRange(col, row), level, this); // resolution2 = base.Resolutions[level]; // infoTile.Index = new TileIndex(col, row, resolution2.Id); // try // { // box2 = new BoundingBox(infoTile.Extent.MinX, infoTile.Extent.MinY, infoTile.Extent.MaxX, infoTile.Extent.MaxY); // } // catch (Exception) // { // box2 = new BoundingBox(-180,-90,180,90); // } // if (box2!=null) // { // box = (box == null) ? box2 : box.Join(box2); // } // } //} //foreach (DirectoryInfo info4 in info3.GetDirectories()) //{ // int row = RowToHex(info4.Name); // int level = 0; // foreach (FileInfo info5 in info4.GetFiles()) // { // if (info5.FullName.EndsWith(base.Format)) // { // BoundingBox box2; // int col = ColumnToHex(info5.Name); // TileInfo info6 = new TileInfo(); // info6.Extent = this.TileToWorld(new TileRange(col, row), level, this); // resolution2 = base.Resolutions[level]; // info6.Index = new TileIndex(col, row, resolution2.Id); // try // { // box2 = new BoundingBox(info6.Extent.MinX, info6.Extent.MinY, info6.Extent.MaxX, info6.Extent.MaxY); // } // catch (Exception) // { // box2 = new BoundingBox(-180.0, -90.0, 180.0, 90.0); // } // if (box2 != null) // { // box = (box == null) ? box2 : box.Join(box2); // } // } // } //} //if (box != null) //{ // base.Extent = new Extent(box.Min.X, box.Min.Y, box.Max.X, box.Max.Y); //} try { XDocument xDoc = XDocument.Load(cdiFile); var fullExtent = (from a in xDoc.Descendants("EnvelopeN") select new Extent ( a.Element("XMin") == null ? double.NaN : double.Parse(a.Element("XMin").Value), a.Element("YMin") == null ? double.NaN : double.Parse(a.Element("YMin").Value), a.Element("XMax") == null ? double.NaN : double.Parse(a.Element("XMax").Value), a.Element("YMax") == null ? double.NaN : double.Parse(a.Element("YMax").Value) )).First(); //{ SpatialReference = this.SpatialReference }).First(); base.Extent = fullExtent; } catch (Exception ex) { } //if (box != null) //{ // base.Extent = new Extent(box.Min.X, box.Min.Y, box.Max.X, box.Max.Y); //} }