Browse Source

Added brush visualizer to the TerrainEditor.

luveti 8 years ago
parent
commit
1ce189361d
2 changed files with 150 additions and 66 deletions
  1. 78 10
      bin/Data/Scripts/Editor/EditorTerrain.as
  2. 72 56
      bin/Data/Scripts/Editor/EditorView.as

+ 78 - 10
bin/Data/Scripts/Editor/EditorTerrain.as

@@ -12,6 +12,54 @@ class TerrainEditorUpdateChanges {
     Image@ newImage;
     Image@ newImage;
 }
 }
 
 
+class TerrainEditorBrushVisualizer
+{
+    Node@ node;
+    CustomGeometry@ customGeometry;
+    private bool addedToOctree = false;
+
+    void Create()
+    {
+        node = Node();
+        customGeometry = node.CreateComponent("CustomGeometry");
+        customGeometry.numGeometries = 1;
+        customGeometry.material = cache.GetResource("Material", "Materials/VColUnlit.xml");
+        customGeometry.occludee = false;
+        customGeometry.enabled = true;
+    }
+
+    void Hide()
+    {
+        node.enabled = false;
+        addedToOctree = false;
+    }
+
+    void Update(Terrain@ terrainComponent, Vector3 position, float radius)
+    {
+        node.enabled = true;
+        node.position = Vector3(position.x, 0, position.z);
+
+        // Generate the circle
+        customGeometry.BeginGeometry(0, LINE_STRIP);
+        for (uint i = 0; i < 364; i += 4)
+        {
+            float angle = i * M_PI / 180;
+            float x = radius * Cos(angle / 0.0174532925);
+            float z = radius * Sin(angle / 0.0174532925);
+            float y = terrainComponent.GetHeight(Vector3(position.x + x, 0, position.z + z));
+            customGeometry.DefineVertex(Vector3(x, y + 0.25, z));
+            customGeometry.DefineColor(Color(0, 1, 0));
+        }
+        customGeometry.Commit();
+
+        if (editorScene.octree !is null && addedToOctree == false)
+        {
+            editorScene.octree.AddManualDrawable(customGeometry);
+            addedToOctree = true;
+        }
+    }
+}
+
 class TerrainEditor
 class TerrainEditor
 {
 {
     private bool dirty = true;
     private bool dirty = true;
@@ -27,6 +75,7 @@ class TerrainEditor
     private Slider@ brushSizeSlider;
     private Slider@ brushSizeSlider;
     private Slider@ brushOpacitySlider;
     private Slider@ brushOpacitySlider;
     private Slider@ brushHeightSlider;
     private Slider@ brushHeightSlider;
+    private TerrainEditorBrushVisualizer brushVisualizer;
 
 
     private Array<Terrain@> terrainsEdited;
     private Array<Terrain@> terrainsEdited;
 
 
@@ -78,6 +127,8 @@ class TerrainEditor
 
 
         LoadBrushes();
         LoadBrushes();
         Show();
         Show();
+
+        brushVisualizer.Create();
     }
     }
 
 
     // Hide the window
     // Hide the window
@@ -86,6 +137,21 @@ class TerrainEditor
         window.visible = false;
         window.visible = false;
     }
     }
 
 
+    void HideBrushVisualizer()
+    {
+        brushVisualizer.Hide();
+    }
+
+    void UpdateBrushVisualizer(Terrain@ terrainComponent, Vector3 position)
+    {
+        if (scaledSelectedBrushImage is null)
+        {
+            brushVisualizer.Hide();
+            return;
+        }
+        brushVisualizer.Update(terrainComponent, position, scaledSelectedBrushImage.width / 2);
+    }
+
     // Save all the terrains we have edited
     // Save all the terrains we have edited
     void Save()
     void Save()
     {
     {
@@ -169,35 +235,39 @@ class TerrainEditor
     }
     }
 
 
     // This gets called when we want to do something to a terrain
     // This gets called when we want to do something to a terrain
-    void Work(Terrain@ terrainComponent, Image@ terrainImage, IntVector2 position)
+    void Work(Terrain@ terrainComponent, Vector3 position)
     {
     {
+        // Only work if a brush is selected
+        if (selectedBrushImage is null || scaledSelectedBrushImage is null)
+            return;
+
         SetSceneModified();
         SetSceneModified();
 
 
         // Add that terrain to the terrainsEdited if its not already in there
         // Add that terrain to the terrainsEdited if its not already in there
         if (terrainsEdited.FindByRef(terrainComponent) == -1)
         if (terrainsEdited.FindByRef(terrainComponent) == -1)
             terrainsEdited.Push(terrainComponent);
             terrainsEdited.Push(terrainComponent);
 
 
-        // Only work if a brush is selected
-        if (selectedBrushImage is null || scaledSelectedBrushImage is null)
-            return;
-
         TerrainEditorUpdateChanges@ updateChanges = TerrainEditorUpdateChanges();
         TerrainEditorUpdateChanges@ updateChanges = TerrainEditorUpdateChanges();
 
 
+        IntVector2 pos = terrainComponent.WorldToHeightMap(position);
+
         switch (editMode)
         switch (editMode)
         {
         {
         case TERRAIN_EDITMODE_RAISELOWERHEIGHT:
         case TERRAIN_EDITMODE_RAISELOWERHEIGHT:
-            UpdateTerrainRaiseLower(terrainImage, position, updateChanges);
+            UpdateTerrainRaiseLower(terrainComponent.heightMap, pos, updateChanges);
             break;
             break;
         case TERRAIN_EDITMODE_SETHEIGHT:
         case TERRAIN_EDITMODE_SETHEIGHT:
-            UpdateTerrainSetHeight(terrainImage, position, updateChanges);
+            UpdateTerrainSetHeight(terrainComponent.heightMap, pos, updateChanges);
             break;
             break;
         case TERRAIN_EDITMODE_SMOOTHHEIGHT:
         case TERRAIN_EDITMODE_SMOOTHHEIGHT:
-            UpdateTerrainSmooth(terrainImage, position, updateChanges);
+            UpdateTerrainSmooth(terrainComponent.heightMap, pos, updateChanges);
             break;
             break;
         }
         }
 
 
         terrainComponent.ApplyHeightMap();
         terrainComponent.ApplyHeightMap();
 
 
+        UpdateBrushVisualizer(terrainComponent, position);
+
         ModifyTerrainAction action;
         ModifyTerrainAction action;
         action.Define(terrainComponent, updateChanges.offset, updateChanges.oldImage, updateChanges.newImage);
         action.Define(terrainComponent, updateChanges.offset, updateChanges.oldImage, updateChanges.newImage);
         SaveEditAction(action);
         SaveEditAction(action);
@@ -387,8 +457,6 @@ class TerrainEditor
         if (selectedBrushImage is null)
         if (selectedBrushImage is null)
             return;
             return;
         float size = (brushSizeSlider.value / 25) + 0.5;
         float size = (brushSizeSlider.value / 25) + 0.5;
-        Print(brushSizeSlider.value);
-        Print(size);
         scaledSelectedBrushImage = selectedBrushImage.GetSubimage(IntRect(0, 0, selectedBrushImage.width, selectedBrushImage.height));
         scaledSelectedBrushImage = selectedBrushImage.GetSubimage(IntRect(0, 0, selectedBrushImage.width, selectedBrushImage.height));
         scaledSelectedBrushImage.Resize(int(selectedBrushImage.width * size), int(selectedBrushImage.height * size));
         scaledSelectedBrushImage.Resize(int(selectedBrushImage.width * size), int(selectedBrushImage.height * size));
     }
     }

+ 72 - 56
bin/Data/Scripts/Editor/EditorView.as

@@ -481,7 +481,7 @@ void SetRenderPath(const String&in newRenderPathName)
 
 
     if (materialPreview !is null && materialPreview.viewport !is null)
     if (materialPreview !is null && materialPreview.viewport !is null)
         materialPreview.viewport.renderPath = renderPath;
         materialPreview.viewport.renderPath = renderPath;
-        
+
     if (particleEffectPreview !is null && particleEffectPreview.viewport !is null)
     if (particleEffectPreview !is null && particleEffectPreview.viewport !is null)
         particleEffectPreview.viewport.renderPath = renderPath;
         particleEffectPreview.viewport.renderPath = renderPath;
 }
 }
@@ -515,7 +515,7 @@ void CreateCamera()
     {
     {
         SetViewportMode(viewportMode);
         SetViewportMode(viewportMode);
     }
     }
-    
+
     SetActiveViewport(viewports[0]);
     SetActiveViewport(viewports[0]);
 
 
     // Note: the camera is not inside the scene, so that it is not listed, and does not get deleted
     // Note: the camera is not inside the scene, so that it is not listed, and does not get deleted
@@ -663,13 +663,13 @@ void SetViewportMode(uint mode = VIEWPORT_SINGLE)
             oldHierarchyWindowHeight = hierarchyWindow.height;
             oldHierarchyWindowHeight = hierarchyWindow.height;
             oldInspectorWindowPosition = attributeInspectorWindow.position;
             oldInspectorWindowPosition = attributeInspectorWindow.position;
             oldInspectorWindowHeight = attributeInspectorWindow.height;
             oldInspectorWindowHeight = attributeInspectorWindow.height;
-        }    
-    
+        }
+
         // Move and scale hierarchy window to left of screen
         // Move and scale hierarchy window to left of screen
         ShowHierarchyWindow();
         ShowHierarchyWindow();
         hierarchyWindow.position = IntVector2(secondaryToolBar.width,toolBar.height + uiMenuBar.height);
         hierarchyWindow.position = IntVector2(secondaryToolBar.width,toolBar.height + uiMenuBar.height);
         hierarchyWindow.height = viewportArea.height-(toolBar.height + uiMenuBar.height);
         hierarchyWindow.height = viewportArea.height-(toolBar.height + uiMenuBar.height);
-        
+
         // Move and scale inspector window to left of screen
         // Move and scale inspector window to left of screen
         ShowAttributeInspectorWindow();
         ShowAttributeInspectorWindow();
         attributeInspectorWindow.position = IntVector2(viewportArea.width-attributeInspectorWindow.width,toolBar.height + uiMenuBar.height);
         attributeInspectorWindow.position = IntVector2(viewportArea.width-attributeInspectorWindow.width,toolBar.height + uiMenuBar.height);
@@ -712,7 +712,7 @@ void SetViewportMode(uint mode = VIEWPORT_SINGLE)
                 attributeInspectorWindow.position = oldInspectorWindowPosition;
                 attributeInspectorWindow.position = oldInspectorWindowPosition;
                 attributeInspectorWindow.height = oldInspectorWindowHeight;
                 attributeInspectorWindow.height = oldInspectorWindowHeight;
             }
             }
-	    
+
             // Show close button and enable resize/movement of inspector/hierarchy windows
             // Show close button and enable resize/movement of inspector/hierarchy windows
             attributeInspectorWindow.GetChild("CloseButton",true).visible = true;
             attributeInspectorWindow.GetChild("CloseButton",true).visible = true;
             attributeInspectorWindow.resizable = true;
             attributeInspectorWindow.resizable = true;
@@ -723,7 +723,7 @@ void SetViewportMode(uint mode = VIEWPORT_SINGLE)
         }
         }
 
 
         viewportMode = mode;
         viewportMode = mode;
-        
+
         // Always have quad a
         // Always have quad a
         {
         {
             uint viewport = 0;
             uint viewport = 0;
@@ -1263,7 +1263,7 @@ void UpdateStats(float timeStep)
 
 
     // Relayout stats bar
     // Relayout stats bar
     Font@ font = cache.GetResource("Font", "Fonts/Anonymous Pro.ttf");
     Font@ font = cache.GetResource("Font", "Fonts/Anonymous Pro.ttf");
-    
+
     if(viewportMode != VIEWPORT_COMPACT)
     if(viewportMode != VIEWPORT_COMPACT)
     {
     {
 	if (graphics.width >= editorModeText.size.x + renderStatsText.size.x + 45)
 	if (graphics.width >= editorModeText.size.x + renderStatsText.size.x + 45)
@@ -1283,7 +1283,7 @@ void UpdateStats(float timeStep)
     {
     {
         SetupStatsBarText(editorModeText, font, secondaryToolBar.width + hierarchyWindow.width + 10 , 64, HA_LEFT, VA_TOP);
         SetupStatsBarText(editorModeText, font, secondaryToolBar.width + hierarchyWindow.width + 10 , 64, HA_LEFT, VA_TOP);
         SetupStatsBarText(renderStatsText, font, secondaryToolBar.width + hierarchyWindow.width + 10 , 84, HA_LEFT, VA_TOP);
         SetupStatsBarText(renderStatsText, font, secondaryToolBar.width + hierarchyWindow.width + 10 , 84, HA_LEFT, VA_TOP);
-        SetupStatsBarText(modelInfoText, font, secondaryToolBar.width + hierarchyWindow.width + 10, 104, HA_LEFT, VA_TOP);	
+        SetupStatsBarText(modelInfoText, font, secondaryToolBar.width + hierarchyWindow.width + 10, 104, HA_LEFT, VA_TOP);
     }
     }
 }
 }
 
 
@@ -1338,7 +1338,7 @@ void UpdateView(float timeStep)
         ReleaseMouseLock();
         ReleaseMouseLock();
         return;
         return;
     }
     }
-    
+
     // Check for camara fly mode
     // Check for camara fly mode
     if (hotKeyMode == HOTKEYS_MODE_BLENDER)
     if (hotKeyMode == HOTKEYS_MODE_BLENDER)
     {
     {
@@ -1352,10 +1352,10 @@ void UpdateView(float timeStep)
     float speedMultiplier = 1.0;
     float speedMultiplier = 1.0;
     if (input.keyDown[KEY_LSHIFT])
     if (input.keyDown[KEY_LSHIFT])
         speedMultiplier = cameraShiftSpeedMultiplier;
         speedMultiplier = cameraShiftSpeedMultiplier;
-    
+
     if (!input.keyDown[KEY_LCTRL] && !input.keyDown[KEY_LALT])
     if (!input.keyDown[KEY_LCTRL] && !input.keyDown[KEY_LALT])
     {
     {
-        if (hotKeyMode == HOTKEYS_MODE_STANDARD || (hotKeyMode == HOTKEYS_MODE_BLENDER && cameraFlyMode && !input.keyDown[KEY_LSHIFT])) 
+        if (hotKeyMode == HOTKEYS_MODE_STANDARD || (hotKeyMode == HOTKEYS_MODE_BLENDER && cameraFlyMode && !input.keyDown[KEY_LSHIFT]))
         {
         {
             if (input.keyDown[KEY_W] || input.keyDown[KEY_UP])
             if (input.keyDown[KEY_W] || input.keyDown[KEY_UP])
             {
             {
@@ -1387,9 +1387,9 @@ void UpdateView(float timeStep)
                 cameraNode.Translate(Vector3(0, -cameraBaseSpeed, 0) * timeStep * speedMultiplier, TS_WORLD);
                 cameraNode.Translate(Vector3(0, -cameraBaseSpeed, 0) * timeStep * speedMultiplier, TS_WORLD);
                 FadeUI();
                 FadeUI();
             }
             }
-        } 
+        }
     }
     }
-    
+
     if (input.mouseMoveWheel != 0 && ui.GetElementAt(ui.cursor.position) is null)
     if (input.mouseMoveWheel != 0 && ui.GetElementAt(ui.cursor.position) is null)
     {
     {
         if (hotKeyMode == HOTKEYS_MODE_STANDARD)
         if (hotKeyMode == HOTKEYS_MODE_STANDARD)
@@ -1405,10 +1405,10 @@ void UpdateView(float timeStep)
                 camera.zoom = Clamp(zoom, .1, 30);
                 camera.zoom = Clamp(zoom, .1, 30);
             }
             }
         }
         }
-        else if (hotKeyMode == HOTKEYS_MODE_BLENDER) 
+        else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
         {
         {
             if (mouseWheelCameraPosition && !camera.orthographic)
             if (mouseWheelCameraPosition && !camera.orthographic)
-            {   
+            {
                 if (input.keyDown[KEY_LSHIFT])
                 if (input.keyDown[KEY_LSHIFT])
                     cameraNode.Translate(Vector3(0, -cameraBaseSpeed, 0) * -input.mouseMoveWheel*20* timeStep * speedMultiplier);
                     cameraNode.Translate(Vector3(0, -cameraBaseSpeed, 0) * -input.mouseMoveWheel*20* timeStep * speedMultiplier);
                 else if (input.keyDown[KEY_LCTRL])
                 else if (input.keyDown[KEY_LCTRL])
@@ -1423,7 +1423,7 @@ void UpdateView(float timeStep)
                 }
                 }
             }
             }
             else
             else
-            {   
+            {
                 if (input.keyDown[KEY_LSHIFT])
                 if (input.keyDown[KEY_LSHIFT])
                 {
                 {
                     cameraNode.Translate(Vector3(0, -cameraBaseSpeed, 0) * -input.mouseMoveWheel*20* timeStep * speedMultiplier);
                     cameraNode.Translate(Vector3(0, -cameraBaseSpeed, 0) * -input.mouseMoveWheel*20* timeStep * speedMultiplier);
@@ -1432,14 +1432,14 @@ void UpdateView(float timeStep)
                 {
                 {
                     cameraNode.Translate(Vector3(-cameraBaseSpeed,0, 0) * -input.mouseMoveWheel*20 * timeStep * speedMultiplier);
                     cameraNode.Translate(Vector3(-cameraBaseSpeed,0, 0) * -input.mouseMoveWheel*20 * timeStep * speedMultiplier);
                 }
                 }
-                else 
+                else
                 {
                 {
                     if (input.qualifierDown[QUAL_ALT])
                     if (input.qualifierDown[QUAL_ALT])
                     {
                     {
                         float zoom = camera.zoom + -input.mouseMoveWheel *.1 * speedMultiplier;
                         float zoom = camera.zoom + -input.mouseMoveWheel *.1 * speedMultiplier;
                         camera.zoom = Clamp(zoom, .1, 30);
                         camera.zoom = Clamp(zoom, .1, 30);
                     }
                     }
-                    else 
+                    else
                     {
                     {
                         cameraNode.Translate(Vector3(0, 0, -cameraBaseSpeed) * -input.mouseMoveWheel*20 * timeStep * speedMultiplier);
                         cameraNode.Translate(Vector3(0, 0, -cameraBaseSpeed) * -input.mouseMoveWheel*20 * timeStep * speedMultiplier);
                     }
                     }
@@ -1458,11 +1458,11 @@ void UpdateView(float timeStep)
             cameraNode.worldPosition = centerPoint - q * Vector3(0.0, 0.0,10);
             cameraNode.worldPosition = centerPoint - q * Vector3(0.0, 0.0,10);
         }
         }
     }
     }
-    
+
     // Rotate/orbit/pan camera
     // Rotate/orbit/pan camera
     bool changeCamViewButton = false;
     bool changeCamViewButton = false;
 
 
-    if (hotKeyMode == HOTKEYS_MODE_STANDARD) 
+    if (hotKeyMode == HOTKEYS_MODE_STANDARD)
         changeCamViewButton = input.mouseButtonDown[MOUSEB_RIGHT] || input.mouseButtonDown[MOUSEB_MIDDLE];
         changeCamViewButton = input.mouseButtonDown[MOUSEB_RIGHT] || input.mouseButtonDown[MOUSEB_MIDDLE];
     else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
     else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
     {
     {
@@ -1518,19 +1518,19 @@ void UpdateView(float timeStep)
                         Vector3 d = cameraNode.worldPosition - centerPoint;
                         Vector3 d = cameraNode.worldPosition - centerPoint;
                         cameraNode.worldPosition = centerPoint - q * Vector3(0.0, 0.0, d.length);
                         cameraNode.worldPosition = centerPoint - q * Vector3(0.0, 0.0, d.length);
                         orbiting = true;
                         orbiting = true;
-                    }    
+                    }
                 }
                 }
                 else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
                 else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
                 {
                 {
                     if (input.mouseButtonDown[MOUSEB_MIDDLE])
                     if (input.mouseButtonDown[MOUSEB_MIDDLE])
                     {
                     {
                         Vector3 centerPoint = Vector3(0,0,0);
                         Vector3 centerPoint = Vector3(0,0,0);
-                        
+
                         if ((selectedNodes.length > 0 || selectedComponents.length > 0))
                         if ((selectedNodes.length > 0 || selectedComponents.length > 0))
                             centerPoint = SelectedNodesCenterPoint();
                             centerPoint = SelectedNodesCenterPoint();
                         else
                         else
                             centerPoint = lastSelectedNodesCenterPoint;
                             centerPoint = lastSelectedNodesCenterPoint;
-                            
+
                         Vector3 d = cameraNode.worldPosition - centerPoint;
                         Vector3 d = cameraNode.worldPosition - centerPoint;
                         cameraNode.worldPosition = centerPoint - q * Vector3(0.0, 0.0, d.length);
                         cameraNode.worldPosition = centerPoint - q * Vector3(0.0, 0.0, d.length);
                         orbiting = true;
                         orbiting = true;
@@ -1556,7 +1556,7 @@ void UpdateView(float timeStep)
             if (selectedNodes.length <= 1)
             if (selectedNodes.length <= 1)
             {
             {
                 Drawable@ drawable = lastSelectedDrawable.Get();
                 Drawable@ drawable = lastSelectedDrawable.Get();
-                if (drawable !is null) 
+                if (drawable !is null)
                 {
                 {
                     bb = drawable.boundingBox;
                     bb = drawable.boundingBox;
                     centerPoint = drawable.node.worldPosition;
                     centerPoint = drawable.node.worldPosition;
@@ -1582,7 +1582,7 @@ void UpdateView(float timeStep)
             // ReacquireCameraYawPitch();
             // ReacquireCameraYawPitch();
             viewCloser =  false;
             viewCloser =  false;
         }
         }
-        else 
+        else
             viewCloser =  false;
             viewCloser =  false;
     }
     }
 
 
@@ -1764,7 +1764,7 @@ void HandlePostRenderUpdate()
 
 
         Array<Component@>@ dynNavMeshes = editorScene.GetComponents("DynamicNavigationMesh", true);
         Array<Component@>@ dynNavMeshes = editorScene.GetComponents("DynamicNavigationMesh", true);
         for (uint i = 0; i < dynNavMeshes.length; ++i)
         for (uint i = 0; i < dynNavMeshes.length; ++i)
-            cast<DynamicNavigationMesh>(dynNavMeshes[i]).DrawDebugGeometry(true);        
+            cast<DynamicNavigationMesh>(dynNavMeshes[i]).DrawDebugGeometry(true);
     }
     }
 
 
     if (setViewportCursor | resizingBorder > 0)
     if (setViewportCursor | resizingBorder > 0)
@@ -1798,6 +1798,24 @@ void DrawNodeDebug(Node@ node, DebugRenderer@ debug, bool drawNode = true)
 
 
 void ViewMouseMove()
 void ViewMouseMove()
 {
 {
+    Ray cameraRay = GetActiveViewportCameraRay();
+    Component@ selectedComponent;
+
+    if (pickMode < PICK_RIGIDBODIES && editorScene.octree !is null)
+    {
+        RayQueryResult result = editorScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, camera.farClip,
+            pickModeDrawableFlags[pickMode], 0x7fffffff);
+
+        if (result.drawable !is null && result.drawable.typeName == "TerrainPatch" && result.drawable.node.parent !is null)
+        {
+            Terrain@ terrainComponent = result.drawable.node.parent.GetComponent("Terrain");
+            terrainEditor.UpdateBrushVisualizer(terrainComponent, result.position);
+        }
+        else {
+            terrainEditor.HideBrushVisualizer();
+        }
+    }
+
     // setting mouse position based on mouse position
     // setting mouse position based on mouse position
     if (ui.IsDragging()) { }
     if (ui.IsDragging()) { }
     else if (ui.focusElement !is null || input.mouseButtonDown[MOUSEB_LEFT|MOUSEB_MIDDLE|MOUSEB_RIGHT])
     else if (ui.focusElement !is null || input.mouseButtonDown[MOUSEB_LEFT|MOUSEB_MIDDLE|MOUSEB_RIGHT])
@@ -1907,31 +1925,31 @@ void ViewRaycast(bool mouseClick)
 
 
         RayQueryResult result = editorScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, camera.farClip,
         RayQueryResult result = editorScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, camera.farClip,
             pickModeDrawableFlags[pickMode], 0x7fffffff);
             pickModeDrawableFlags[pickMode], 0x7fffffff);
-        
+
         if (result.drawable !is null)
         if (result.drawable !is null)
-        {            
+        {
             Drawable@ drawable = result.drawable;
             Drawable@ drawable = result.drawable;
-            
+
             // for actual last selected node or component in both modes
             // for actual last selected node or component in both modes
-            if (hotKeyMode == HOTKEYS_MODE_STANDARD) 
+            if (hotKeyMode == HOTKEYS_MODE_STANDARD)
             {
             {
-                if (input.mouseButtonDown[MOUSEB_LEFT]) 
+                if (input.mouseButtonDown[MOUSEB_LEFT])
                 {
                 {
                     lastSelectedNode = drawable.node;
                     lastSelectedNode = drawable.node;
                     lastSelectedDrawable = drawable;
                     lastSelectedDrawable = drawable;
                     lastSelectedComponent = drawable;
                     lastSelectedComponent = drawable;
                 }
                 }
             }
             }
-            else if (hotKeyMode == HOTKEYS_MODE_BLENDER) 
+            else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
             {
             {
-                if (input.mouseButtonDown[MOUSEB_RIGHT]) 
+                if (input.mouseButtonDown[MOUSEB_RIGHT])
                 {
                 {
                     lastSelectedNode = drawable.node;
                     lastSelectedNode = drawable.node;
                     lastSelectedDrawable = drawable;
                     lastSelectedDrawable = drawable;
                     lastSelectedComponent = drawable;
                     lastSelectedComponent = drawable;
                 }
                 }
             }
             }
-             
+
             // If selecting a terrain patch, select the parent terrain instead
             // If selecting a terrain patch, select the parent terrain instead
             if (drawable.typeName != "TerrainPatch")
             if (drawable.typeName != "TerrainPatch")
             {
             {
@@ -1942,21 +1960,19 @@ void ViewRaycast(bool mouseClick)
                     drawable.DrawDebugGeometry(debug, false);
                     drawable.DrawDebugGeometry(debug, false);
                 }
                 }
             }
             }
-			else if (drawable.node.parent !is null){
-				Terrain@ terrainComponent = drawable.node.parent.GetComponent("Terrain");
-				selectedComponent = terrainComponent;
-			
-				if(selectedComponent is terrainComponent && input.mouseButtonDown[MOUSEB_LEFT])
-				{
-					selectedComponent = terrainComponent;
-					IntVector2 pos = terrainComponent.WorldToHeightMap(result.position);
-					terrainEditor.Work(terrainComponent, terrainComponent.heightMap, pos);
-				}
-				else
-				{
-					terrainEditor.targetColorSelected = false;
-				}
-			}
+            else if (drawable.node.parent !is null){
+                Terrain@ terrainComponent = drawable.node.parent.GetComponent("Terrain");
+                selectedComponent = terrainComponent;
+                if (selectedComponent is terrainComponent && input.mouseButtonDown[MOUSEB_LEFT])
+                {
+                    selectedComponent = terrainComponent;
+                    terrainEditor.Work(terrainComponent, result.position);
+                }
+                else
+                {
+                    terrainEditor.targetColorSelected = false;
+                }
+            }
         }
         }
     }
     }
     else
     else
@@ -1980,12 +1996,12 @@ void ViewRaycast(bool mouseClick)
             selectedComponent = body;
             selectedComponent = body;
         }
         }
     }
     }
-    
+
     bool multiselect = false;
     bool multiselect = false;
     bool componentSelectQualifier = false;
     bool componentSelectQualifier = false;
     bool mouseButtonPressRL = false;
     bool mouseButtonPressRL = false;
-    
-    if (hotKeyMode == HOTKEYS_MODE_STANDARD) 
+
+    if (hotKeyMode == HOTKEYS_MODE_STANDARD)
     {
     {
         mouseButtonPressRL = input.mouseButtonPress[MOUSEB_LEFT];
         mouseButtonPressRL = input.mouseButtonPress[MOUSEB_LEFT];
         componentSelectQualifier = input.qualifierDown[QUAL_SHIFT];
         componentSelectQualifier = input.qualifierDown[QUAL_SHIFT];
@@ -1997,7 +2013,7 @@ void ViewRaycast(bool mouseClick)
         componentSelectQualifier = input.qualifierDown[QUAL_CTRL];
         componentSelectQualifier = input.qualifierDown[QUAL_CTRL];
         multiselect = input.qualifierDown[QUAL_SHIFT];
         multiselect = input.qualifierDown[QUAL_SHIFT];
     }
     }
-    
+
     if (mouseClick && mouseButtonPressRL)
     if (mouseClick && mouseButtonPressRL)
     {
     {
         if (selectedComponent !is null)
         if (selectedComponent !is null)
@@ -2142,12 +2158,12 @@ Vector3 SelectedNodesCenterPoint()
             centerPoint += selectedComponents[i].node.worldPosition;
             centerPoint += selectedComponents[i].node.worldPosition;
     }
     }
 
 
-    if (count > 0) 
+    if (count > 0)
     {
     {
         lastSelectedNodesCenterPoint = centerPoint / count;
         lastSelectedNodesCenterPoint = centerPoint / count;
         return centerPoint / count;
         return centerPoint / count;
     }
     }
-    else 
+    else
     {
     {
         lastSelectedNodesCenterPoint = centerPoint;
         lastSelectedNodesCenterPoint = centerPoint;
         return centerPoint;
         return centerPoint;