private void TerrainImporter_Activate(object sender, EventArgs e) { if (NWN2NetDisplayManager.Instance.Scenes.Count > 0) { TerrainImporterSettings importerSettings = new TerrainImporterSettings(); importerSettings.ShowDialog(); if (importerSettings.isCanceled()) { return; } float texturePressure = Convert.ToSingle(importerSettings.texturePressure.Value) / 100f; float textureInnerRadius = Convert.ToSingle(importerSettings.textureInnerRadius.Value); float textureOuterRadius = Convert.ToSingle(importerSettings.textureOuterRadius.Value); TerrainImporterProgress importerProgress = new TerrainImporterProgress(); importerProgress.Show(); List<NWN2AreaViewer> allAreaViewers = NWN2ToolsetMainForm.App.GetAllAreaViewers(); NWN2AreaViewer nwN2AreaViewer = allAreaViewers[allAreaViewers.IndexOf((NWN2AreaViewer)NWN2ToolsetMainForm.App.GetActiveViewer())]; NWN2TerrainEditorForm terrainEditor = NWN2ToolsetMainForm.App.TerrainEditor; BoundingBox3 boundsOfArea = nwN2AreaViewer.Area.GetBoundsOfArea(); SynchronousNetDisplayManager netDisplayManager = NWN2NetDisplayManager.Instance; float coordinateIncrement = 1.666667f; float outerRight = boundsOfArea.Right + 160f + coordinateIncrement; float outerTop = boundsOfArea.Top + 160f + coordinateIncrement; int heightMapUpperLeftX = Convert.ToInt32(importerSettings.upperLeftX.Value); int heightMapUpperLeftY = Convert.ToInt32(importerSettings.upperLeftY.Value); float areaToHeigtmapXdifference = (Convert.ToSingle(importerSettings.lowerRightX.Value - heightMapUpperLeftX) - 1f) / outerRight; float areaToHeightmapYdifference = (Convert.ToSingle(importerSettings.lowerRightY.Value - heightMapUpperLeftY) - 1f) / outerTop; float heightDiff = Convert.ToSingle(importerSettings.maximumHeight.Value - importerSettings.minimumHeight.Value); float minHeight = Convert.ToSingle(importerSettings.minimumHeight.Value); importerProgress.Maximum = Convert.ToInt32(Math.Round(outerRight * outerTop)); float areaX = 0.0f; while (areaX < outerRight) { float areaY = 0.0f; while (areaY < outerTop) { int areaOffsetX = Convert.ToInt32(Math.Round(areaToHeigtmapXdifference * areaX)); int areaOffsetY = Convert.ToInt32(Math.Round(areaToHeightmapYdifference * areaY)); int x = areaOffsetX + heightMapUpperLeftX; int y = areaOffsetY + heightMapUpperLeftY; float z = getHeightValue(importerSettings, heightDiff, minHeight, x, y); Vector3 vector3 = new Vector3(areaX, areaY, 0.0f); string texture = terrainEditor.TerrainBrushTexture; string textureName = ""; bool paintTerrain = false; if (importerSettings.paintTerrainCheckbox.Checked) { paintTerrain = true; textureName = (string)importerSettings.fullAttributeTable[((AmfAttributeMap)importerSettings.attributeMap).GetPixel(x, y)]; } //work all the area manipulation netDisplayManager.BeginSynchronizedOperation(); manipulateTerrain(importerSettings, paintTerrain, texturePressure, textureInnerRadius, textureOuterRadius, nwN2AreaViewer, terrainEditor, netDisplayManager, z, ref vector3, ref texture, textureName); handleWaterMap(importerSettings, nwN2AreaViewer, terrainEditor, netDisplayManager, x, y, z, ref vector3, texture); handleAttributeMap(importerSettings, nwN2AreaViewer, terrainEditor, netDisplayManager, outerRight, outerTop, x, y, areaX, areaY, z, ref vector3, texture, ref textureName); netDisplayManager.EndSynchronizedOperation(); updateProgress(importerProgress, outerTop, areaX, areaY); areaY += coordinateIncrement; } areaX += coordinateIncrement; } importerProgress.Dispose(); importerSettings.Dispose(); } else { MessageBox.Show("You must have an area open to use this tool.", "No Area", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }