1- package com .ss .editor .ui . component . editing . terrain . control ;
1+ package com .ss .editor .control . painting . terrain ;
22
33import static com .ss .editor .util .EditingUtils .calculateHeight ;
44import static com .ss .editor .util .EditingUtils .isContains ;
99import com .jme3 .scene .Geometry ;
1010import com .jme3 .scene .Node ;
1111import com .jme3 .terrain .Terrain ;
12+ import com .ss .editor .annotation .FromAnyThread ;
13+ import com .ss .editor .annotation .JmeThread ;
1214import com .ss .editor .control .painting .PaintingInput ;
1315import com .ss .editor .ui .component .editing .terrain .TerrainEditingComponent ;
1416import com .ss .editor .util .LocalObjects ;
2426 */
2527public class RaiseLowerTerrainToolControl extends ChangeHeightTerrainToolControl {
2628
27- /**
28- * Instantiates a new Raise lower terrain tool control.
29- *
30- * @param component the component
31- */
3229 public RaiseLowerTerrainToolControl (@ NotNull final TerrainEditingComponent component ) {
3330 super (component );
3431 }
3532
36- @ NotNull
3733 @ Override
38- protected ColorRGBA getBrushColor () {
34+ @ FromAnyThread
35+ protected @ NotNull ColorRGBA getBrushColor () {
3936 return ColorRGBA .Green ;
4037 }
4138
4239 @ Override
43- public void startPainting (@ NotNull final PaintingInput paintingInput , @ NotNull final Vector3f contactPoint ) {
44- super .startPainting (paintingInput , contactPoint );
40+ @ JmeThread
41+ public void startPainting (@ NotNull final PaintingInput input , @ NotNull final Vector3f contactPoint ) {
42+ super .startPainting (input , contactPoint );
4543
46- switch (paintingInput ) {
44+ switch (input ) {
4745 case MOUSE_PRIMARY :
4846 case MOUSE_SECONDARY : {
4947 startChange ();
50- modifyHeight (paintingInput , contactPoint );
48+ modifyHeight (input , contactPoint );
5149 }
5250 }
5351 }
@@ -83,12 +81,12 @@ public void finishPainting(@NotNull final Vector3f contactPoint) {
8381 /**
8482 * Modify height of terrain points.
8583 *
86- * @param paintingInput the type of input.
84+ * @param input the type of input.
8785 * @param contactPoint the contact point.
8886 */
89- private void modifyHeight (@ NotNull final PaintingInput paintingInput , @ NotNull final Vector3f contactPoint ) {
87+ private void modifyHeight (@ NotNull final PaintingInput input , @ NotNull final Vector3f contactPoint ) {
9088
91- final LocalObjects local = LocalObjects . get ();
89+ final LocalObjects local = getLocalObjects ();
9290 final Node terrainNode = (Node ) notNull (getPaintedModel ());
9391
9492 final Vector3f worldTranslation = terrainNode .getWorldTranslation ();
@@ -101,7 +99,7 @@ private void modifyHeight(@NotNull final PaintingInput paintingInput, @NotNull f
10199 final Geometry brush = getBrush ();
102100
103101 final float brushSize = getBrushSize ();
104- final float brushPower = paintingInput == PaintingInput .MOUSE_PRIMARY ? getBrushPower () : getBrushPower () * -1F ;
102+ final float brushPower = input == PaintingInput .MOUSE_PRIMARY ? getBrushPower () : getBrushPower () * -1F ;
105103
106104 final int radiusStepsX = (int ) (brushSize / localScale .getX ());
107105 final int radiusStepsZ = (int ) (brushSize / localScale .getY ());
@@ -126,7 +124,12 @@ private void modifyHeight(@NotNull final PaintingInput paintingInput, @NotNull f
126124
127125 terrainLoc .set (locX , locZ );
128126
129- final float currentHeight = terrain .getHeightmapHeight (terrainLoc ) * localScale .getY ();
127+ final float heightmapHeight = terrain .getHeightmapHeight (terrainLoc );
128+ if (Float .isNaN (heightmapHeight )) {
129+ continue ;
130+ }
131+
132+ final float currentHeight = heightmapHeight * localScale .getY ();
130133 // adjust height based on radius of the tool
131134 final float newHeight = calculateHeight (brushSize , brushPower , effectPoint .getX (), effectPoint .getY ());
132135
0 commit comments