forestBrushTool.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "forest/editor/forestBrushTool.h"
  24. #include "forest/forest.h"
  25. #include "forest/editor/forestUndo.h"
  26. #include "forest/editor/forestBrushElement.h"
  27. #include "forest/editor/forestEditorCtrl.h"
  28. #include "gui/worldEditor/editTSCtrl.h"
  29. #include "console/consoleTypes.h"
  30. #include "console/engineAPI.h"
  31. #include "core/util/tVector.h"
  32. #include "gfx/gfxDrawUtil.h"
  33. #include "gui/core/guiCanvas.h"
  34. #include "gfx/primBuilder.h"
  35. #include "gui/controls/guiTreeViewCtrl.h"
  36. #include "core/strings/stringUnit.h"
  37. #include "math/mRandomDeck.h"
  38. #include "math/mRandomSet.h"
  39. #include "scene/sceneContainer.h"
  40. #include "console/typeValidators.h"
  41. bool ForestBrushTool::protectedSetSize( void *object, const char *index, const char *data )
  42. {
  43. ForestBrushTool *tool = static_cast<ForestBrushTool*>( object );
  44. F32 val = dAtof(data);
  45. tool->setSize( val );
  46. return false;
  47. }
  48. bool ForestBrushTool::protectedSetPressure( void *object, const char *index, const char *data )
  49. {
  50. ForestBrushTool *tool = static_cast<ForestBrushTool*>( object );
  51. F32 val = dAtof(data);
  52. tool->setPressure( val );
  53. return false;
  54. }
  55. bool ForestBrushTool::protectedSetHardness( void *object, const char *index, const char *data )
  56. {
  57. ForestBrushTool *tool = static_cast<ForestBrushTool*>( object );
  58. F32 val = dAtof(data);
  59. tool->setHardness( val );
  60. return false;
  61. }
  62. ImplementEnumType( ForestBrushMode,
  63. "Active brush mode type.\n"
  64. "@internal\n\n")
  65. { ForestBrushTool::Paint, "Paint", "Creates Items based on the Elements you have selected.\n" },
  66. { ForestBrushTool::Erase, "Erase", "Erases Items of any Mesh type.\n" },
  67. { ForestBrushTool::EraseSelected, "EraseSelected", "Erases items of a specific type.\n" },
  68. EndImplementEnumType;
  69. ForestBrushTool::ForestBrushTool()
  70. : mRandom( Platform::getRealMilliseconds() + 1 ),
  71. mSize( 5.0f ),
  72. mPressure( 0.1f ),
  73. mHardness( 1.0f ),
  74. mMode( Paint ),
  75. mColor( ColorI::WHITE ),
  76. mBrushDown( false ),
  77. mDrawBrush( false ),
  78. mStrokeEvent( 0 ),
  79. mCurrAction( NULL )
  80. {
  81. }
  82. ForestBrushTool::~ForestBrushTool()
  83. {
  84. }
  85. IMPLEMENT_CONOBJECT( ForestBrushTool );
  86. ConsoleDocClass( ForestBrushTool,
  87. "@brief Defines the brush properties when painting trees in Forest Editor\n\n"
  88. "Editor use only.\n\n"
  89. "@internal"
  90. );
  91. FRangeValidator fBrushRange(0.0f, 150.0f);
  92. void ForestBrushTool::initPersistFields()
  93. {
  94. docsURL;
  95. addGroup( "ForestBrushTool" );
  96. addField( "mode", TYPEID< BrushMode >(), Offset( mMode, ForestBrushTool) );
  97. addProtectedFieldV( "size", TypeRangedF32, Offset( mSize, ForestBrushTool ),
  98. &protectedSetSize, &defaultProtectedGetFn, &fBrushRange, "Brush Size" );
  99. addProtectedFieldV( "pressure", TypeRangedF32, Offset( mPressure, ForestBrushTool ),
  100. &protectedSetPressure, &defaultProtectedGetFn, &CommonValidators::NormalizedFloat, "Brush Pressure" );
  101. addProtectedFieldV( "hardness", TypeRangedF32, Offset( mHardness, ForestBrushTool ),
  102. &protectedSetHardness, &defaultProtectedGetFn, &CommonValidators::NormalizedFloat, "Brush Hardness" );
  103. endGroup( "ForestBrushTool" );
  104. Parent::initPersistFields();
  105. }
  106. bool ForestBrushTool::onAdd()
  107. {
  108. if ( !Parent::onAdd() )
  109. return false;
  110. return true;
  111. }
  112. void ForestBrushTool::onRemove()
  113. {
  114. Parent::onRemove();
  115. }
  116. void ForestBrushTool::on3DMouseDown( const Gui3DMouseEvent &evt )
  117. {
  118. Con::executef( this, "onMouseDown" );
  119. if ( !_updateBrushPoint( evt ) || !mForest )
  120. return;
  121. mBrushDown = true;
  122. mEditor->getRoot()->showCursor( false );
  123. _collectElements();
  124. _onStroke();
  125. return;
  126. }
  127. void ForestBrushTool::on3DMouseUp( const Gui3DMouseEvent &evt )
  128. {
  129. _updateBrushPoint( evt );
  130. Sim::cancelEvent( mStrokeEvent );
  131. mBrushDown = false;
  132. mEditor->getRoot()->showCursor( true );
  133. if ( mCurrAction )
  134. {
  135. _submitUndo( mCurrAction );
  136. mCurrAction = NULL;
  137. }
  138. //mElements.clear();
  139. }
  140. void ForestBrushTool::on3DMouseMove( const Gui3DMouseEvent &evt )
  141. {
  142. _updateBrushPoint( evt );
  143. }
  144. void ForestBrushTool::on3DMouseDragged( const Gui3DMouseEvent &evt )
  145. {
  146. _updateBrushPoint( evt );
  147. if ( mBrushDown && !Sim::isEventPending( mStrokeEvent ) )
  148. mStrokeEvent = Sim::postEvent( this, new ForestBrushToolEvent(), Sim::getCurrentTime() + 250 );
  149. }
  150. bool ForestBrushTool::onMouseWheel( const GuiEvent &evt )
  151. {
  152. if ( evt.modifier & SI_PRIMARY_CTRL )
  153. setPressure( mPressure + evt.fval * ( 0.05f / 120.0f ) );
  154. else if ( evt.modifier & SI_SHIFT )
  155. setHardness( mHardness + evt.fval * ( 0.05f / 120.0f ) );
  156. else
  157. setSize( mSize + evt.fval * ( 1.0f / 120.0f ) );
  158. return true;
  159. }
  160. void ForestBrushTool::onRender3D( )
  161. {
  162. }
  163. void ForestBrushTool::onRender2D()
  164. {
  165. if ( !mDrawBrush )
  166. return;
  167. if ( !mEditor->getRoot()->isCursorON() && !mBrushDown )
  168. return;
  169. RayInfo ri;
  170. Point3F start( 0, 0, mLastBrushPoint.z + mSize );
  171. Point3F end( 0, 0, mLastBrushPoint.z - mSize );
  172. Vector<Point3F> pointList;
  173. const U32 steps = 32;
  174. if ( mForest )
  175. mForest->disableCollision();
  176. for ( S32 i = 0; i < steps; i++ )
  177. {
  178. F32 radians = (F32)i / (F32)(steps-1) * M_2PI_F;
  179. VectorF vec(0,1,0);
  180. MathUtils::vectorRotateZAxis( vec, radians );
  181. end.x = start.x = mLastBrushPoint.x + vec.x * mSize;
  182. end.y = start.y = mLastBrushPoint.y + vec.y * mSize;
  183. bool hit = gServerContainer.castRay( start, end, TerrainObjectType | StaticShapeObjectType, &ri );
  184. if ( hit )
  185. pointList.push_back( ri.point );
  186. }
  187. if ( mForest )
  188. mForest->enableCollision();
  189. if ( pointList.empty() )
  190. return;
  191. ColorI brushColor( ColorI::WHITE );
  192. if ( mMode == Paint )
  193. brushColor = ColorI::BLUE;
  194. else if ( mMode == Erase )
  195. brushColor = ColorI::RED;
  196. else if ( mMode == EraseSelected )
  197. brushColor.set( 150, 0, 0 );
  198. if ( mMode == Paint || mMode == EraseSelected )
  199. {
  200. if ( mElements.empty() )
  201. {
  202. brushColor.set( 140, 140, 140 );
  203. }
  204. }
  205. mEditor->drawLineList( pointList, brushColor, 1.5f );
  206. }
  207. void ForestBrushTool::onActivated( const Gui3DMouseEvent &lastEvent )
  208. {
  209. _updateBrushPoint( lastEvent );
  210. Con::executef( this, "onActivated" );
  211. }
  212. void ForestBrushTool::onDeactivated()
  213. {
  214. Con::executef( this, "onDeactivated" );
  215. }
  216. bool ForestBrushTool::updateGuiInfo()
  217. {
  218. GuiTextCtrl *statusbar;
  219. Sim::findObject( "EWorldEditorStatusBarInfo", statusbar );
  220. GuiTextCtrl *selectionBar;
  221. Sim::findObject( "EWorldEditorStatusBarSelection", selectionBar );
  222. String text;
  223. if ( mMode == Paint )
  224. text = "Forest Editor ( Paint Tool ) - This brush creates Items based on the Elements you have selected.";
  225. else if ( mMode == Erase )
  226. text = "Forest Editor ( Erase Tool ) - This brush erases Items of any Mesh type.";
  227. else if ( mMode == EraseSelected )
  228. text = "Forest Editor ( Erase Selected ) - This brush erases Items based on the Elements you have selected.";
  229. if ( statusbar )
  230. statusbar->setText( text );
  231. if ( mMode == Paint || mMode == EraseSelected )
  232. text = String::ToString( "%i elements selected", mElements.size() );
  233. else
  234. text = "";
  235. if ( selectionBar )
  236. selectionBar->setText( text );
  237. return true;
  238. }
  239. void ForestBrushTool::setSize( F32 val )
  240. {
  241. mSize = mClampF( val, 0.0f, 150.0f );
  242. Con::executef( this, "syncBrushToolbar" );
  243. }
  244. void ForestBrushTool::setPressure( F32 val )
  245. {
  246. mPressure = mClampF( val, 0.0f, 1.0f );
  247. Con::executef( this, "syncBrushToolbar" );
  248. }
  249. void ForestBrushTool::setHardness( F32 val )
  250. {
  251. mHardness = mClampF( val, 0.0f, 1.0f );
  252. Con::executef( this, "syncBrushToolbar" );
  253. }
  254. void ForestBrushTool::_onStroke()
  255. {
  256. if ( !mForest || !mBrushDown )
  257. return;
  258. _action( mLastBrushPoint );
  259. }
  260. void ForestBrushTool::_action( const Point3F &point )
  261. {
  262. if ( mMode == Paint )
  263. _paint( point );
  264. else if ( mMode == Erase || mMode == EraseSelected )
  265. _erase( point );
  266. }
  267. inline F32 mCircleArea( F32 radius )
  268. {
  269. return radius * radius * M_PI_F;
  270. }
  271. void ForestBrushTool::_paint( const Point3F &point )
  272. {
  273. AssertFatal( mForest, "ForestBrushTool::_paint() - Can't paint without a Forest!" );
  274. if ( mElements.empty() )
  275. return;
  276. // Iterators, pointers, and temporaries.
  277. ForestBrushElement *pElement;
  278. ForestItemData *pData;
  279. F32 radius, area;
  280. // How much area do we have to fill with trees ( within the brush ).
  281. F32 fillArea = mCircleArea( mSize );
  282. // Scale that down by pressure, this is how much area we want to fill.
  283. fillArea *= mPressure;
  284. // Create an MRandomSet we can get items we are painting out of with
  285. // the desired distribution.
  286. // Also grab the smallest and largest radius elements while we are looping.
  287. ForestBrushElement *smallestElement, *largestElement;
  288. smallestElement = largestElement = mElements[0];
  289. MRandomSet<ForestBrushElement*> randElementSet(&mRandom);
  290. for ( S32 i = 0; i < mElements.size(); i++ )
  291. {
  292. pElement = mElements[i];
  293. if ( pElement->mData->mRadius > largestElement->mData->mRadius )
  294. largestElement = pElement;
  295. if ( pElement->mData->mRadius < smallestElement->mData->mRadius )
  296. smallestElement = pElement;
  297. randElementSet.add( pElement, pElement->mProbability );
  298. }
  299. // Pull elements from the random set until we would theoretically fill
  300. // the desired area.
  301. F32 areaLeft = fillArea;
  302. F32 scaleFactor, sink, randRot, worldCoordZ, slope;
  303. Point2F worldCoords;
  304. Point3F normalVector, right;
  305. Point2F temp;
  306. const S32 MaxTries = 5;
  307. while ( areaLeft > 0.0f )
  308. {
  309. pElement = randElementSet.get();
  310. pData = pElement->mData;
  311. scaleFactor = mLerp( pElement->mScaleMin, pElement->mScaleMax, mClampF( mPow( mRandom.randF(), pElement->mScaleExponent ), 0.0f, 1.0f ) );
  312. radius = getMax( pData->mRadius * scaleFactor, 0.1f );
  313. area = mCircleArea( radius );
  314. areaLeft -= area * 5.0f; // fudge value
  315. // No room left we are done.
  316. //if ( areaLeft < 0.0f )
  317. // break;
  318. // We have area left to fill...
  319. const F32 rotRange = mDegToRad( pElement->mRotationRange );
  320. // Get a random sink value.
  321. sink = mRandom.randF( pElement->mSinkMin, pElement->mSinkMax ) * scaleFactor;
  322. // Get a random rotation.
  323. randRot = mRandom.randF( 0.0f, rotRange );
  324. // Look for a place within the brush area to place this item.
  325. // We may have to try several times or give and go onto the next.
  326. S32 i = 0;
  327. for ( ; i < MaxTries; i++ )
  328. {
  329. // Pick some randoms for placement.
  330. worldCoords = MathUtils::randomPointInCircle( mSize ) + point.asPoint2F();
  331. // Look for the ground at this position.
  332. if ( !getGroundAt( Point3F( worldCoords.x, worldCoords.y , point.z ),
  333. &worldCoordZ,
  334. &normalVector ) )
  335. {
  336. continue;
  337. }
  338. // Does this pass our slope and elevation limits.
  339. right.set( normalVector.x, normalVector.y, 0 );
  340. right.normalizeSafe();
  341. slope = mRadToDeg( mDot( right, normalVector ) );
  342. if ( worldCoordZ < pElement->mElevationMin ||
  343. worldCoordZ > pElement->mElevationMax ||
  344. slope < pElement->mSlopeMin ||
  345. slope > pElement->mSlopeMax )
  346. {
  347. continue;
  348. }
  349. // Are we up against another tree?
  350. if ( mForest->getData()->getItems( worldCoords, radius, NULL ) > 0 )
  351. continue;
  352. // If the trunk radius is set then we need to sink
  353. // the tree into the ground a bit to hide the bottom.
  354. if ( pElement->mSinkRadius > 0.0f )
  355. {
  356. // Items that are not aligned to the ground surface
  357. // get sunken down to hide the bottom of their trunks.
  358. // sunk down a bit to hide their bottoms on slopes.
  359. normalVector.z = 0;
  360. normalVector.normalizeSafe();
  361. normalVector *= sink;
  362. temp = worldCoords + normalVector.asPoint2F();
  363. getGroundAt( Point3F( temp.x, temp.y, point.z ),
  364. &worldCoordZ,
  365. NULL );
  366. }
  367. worldCoordZ -= sink;
  368. // Create a new undo action if this is a new stroke.
  369. ForestCreateUndoAction *action = dynamic_cast<ForestCreateUndoAction*>( mCurrAction );
  370. if ( !action )
  371. {
  372. action = new ForestCreateUndoAction( mForest->getData(), mEditor );
  373. mCurrAction = action;
  374. }
  375. //Con::printf( "worldCoords = %g, %g, %g", worldCoords.x, worldCoords.y, worldCoordZ );
  376. // Let the action manage adding it to the forest.
  377. action->addItem( pData,
  378. Point3F( worldCoords.x, worldCoords.y, worldCoordZ ),
  379. randRot,
  380. scaleFactor );
  381. break;
  382. }
  383. }
  384. }
  385. void ForestBrushTool::_erase( const Point3F &point )
  386. {
  387. AssertFatal( mForest, "ForestBrushTool::_erase() - Can't erase without a Forest!" );
  388. // First grab all the forest items around the point.
  389. ForestItemVector trees;
  390. if ( mForest->getData()->getItems( point.asPoint2F(), mSize, &trees ) == 0 )
  391. return;
  392. if ( mMode == EraseSelected )
  393. {
  394. for ( U32 i = 0; i < trees.size(); i++ )
  395. {
  396. const ForestItem &tree = trees[i];
  397. if ( !mDatablocks.contains( tree.getData() ) )
  398. {
  399. trees.erase_fast( i );
  400. i--;
  401. }
  402. }
  403. }
  404. if ( trees.empty() )
  405. return;
  406. // Number of trees to erase depending on pressure.
  407. S32 eraseCount = getMax( (S32)mCeil( (F32)trees.size() * mPressure ), 0 );
  408. // Initialize an MRandomDeck with trees under the brush.
  409. MRandomDeck<ForestItem> deck(&mRandom);
  410. deck.addToPile( trees );
  411. deck.shuffle();
  412. ForestItem currentTree;
  413. // Draw eraseCount number of trees from MRandomDeck, adding them to our erase action.
  414. for ( U32 i = 0; i < eraseCount; i++ )
  415. {
  416. deck.draw(&currentTree);
  417. // Create a new undo action if this is a new stroke.
  418. ForestDeleteUndoAction *action = dynamic_cast<ForestDeleteUndoAction*>( mCurrAction );
  419. if ( !action )
  420. {
  421. action = new ForestDeleteUndoAction( mForest->getData(), mEditor );
  422. mCurrAction = action;
  423. }
  424. action->removeItem( currentTree );
  425. }
  426. }
  427. bool ForestBrushTool::_updateBrushPoint( const Gui3DMouseEvent &event_ )
  428. {
  429. // Do a raycast for terrain... thats the placement center.
  430. const U32 mask = TerrainObjectType | StaticShapeObjectType; // TODO: Make an option!
  431. Point3F start( event_.pos );
  432. Point3F end( event_.pos + ( event_.vec * 10000.0f ) );
  433. if ( mForest )
  434. mForest->disableCollision();
  435. RayInfo rinfo;
  436. mDrawBrush = gServerContainer.castRay( start, end, mask, &rinfo );
  437. if ( mForest )
  438. mForest->enableCollision();
  439. if ( mDrawBrush )
  440. {
  441. mLastBrushPoint = rinfo.point;
  442. mLastBrushNormal = rinfo.normal;
  443. }
  444. return mDrawBrush;
  445. }
  446. bool findSelectedElements( ForestBrushElement *obj )
  447. {
  448. if ( obj->isSelectedRecursive() )
  449. return true;
  450. return false;
  451. }
  452. void ForestBrushTool::_collectElements()
  453. {
  454. mElements.clear();
  455. // Get the selected objects from the tree view.
  456. // These can be a combination of ForestBrush(s) and ForestBrushElement(s).
  457. GuiTreeViewCtrl *brushTree;
  458. if ( !Sim::findObject( "ForestEditBrushTree", brushTree ) )
  459. return;
  460. ConsoleValue cValue = Con::executef( brushTree, "getSelectedObjectList" );
  461. const char* objectIdList = cValue.getString();
  462. // Collect those objects in a vector and mark them as selected.
  463. Vector<SimObject*> objectList;
  464. SimObject *simobj;
  465. S32 wordCount = StringUnit::getUnitCount( objectIdList, " " );
  466. for ( S32 i = 0; i < wordCount; i++ )
  467. {
  468. const char* word = StringUnit::getUnit( objectIdList, i, " " );
  469. if ( Sim::findObject( word, simobj ) )
  470. {
  471. objectList.push_back( simobj );
  472. simobj->setSelected(true);
  473. }
  474. }
  475. // Find all ForestBrushElements that are directly or indirectly selected.
  476. SimSet* brushSet;
  477. if (!Sim::findObject("ForestBrushSet", brushSet))
  478. {
  479. Con::errorf("ForestBrushTool::_collectElements() - could not find ForestBrushSet!");
  480. return;
  481. }
  482. brushSet->findObjectByCallback( findSelectedElements, mElements );
  483. // We just needed to flag these objects as selected for the benefit of our
  484. // findSelectedElements callback, we can now mark them un-selected again.
  485. for ( S32 i = 0; i < objectList.size(); i++ )
  486. objectList[i]->setSelected(false);
  487. // If we are in Paint or EraseSelected mode we filter out elements with
  488. // a non-positive probability.
  489. if ( mMode == Paint || mMode == EraseSelected )
  490. {
  491. for ( S32 i = 0; i < mElements.size(); i++ )
  492. {
  493. if ( mElements[i]->mProbability <= 0.0f )
  494. {
  495. mElements.erase_fast(i);
  496. i--;
  497. }
  498. }
  499. }
  500. // Filter out elements with NULL datablocks and collect all unique datablocks
  501. // in a vector.
  502. mDatablocks.clear();
  503. for ( S32 i = 0; i < mElements.size(); i++ )
  504. {
  505. if ( mElements[i]->mData == NULL )
  506. {
  507. mElements.erase_fast(i);
  508. i--;
  509. continue;
  510. }
  511. mDatablocks.push_back_unique( mElements[i]->mData );
  512. }
  513. }
  514. bool ForestBrushTool::getGroundAt( const Point3F &worldPt, F32 *zValueOut, VectorF *normalOut )
  515. {
  516. const U32 mask = TerrainObjectType | StaticShapeObjectType;
  517. Point3F start( worldPt.x, worldPt.y, worldPt.z + mSize );
  518. Point3F end( worldPt.x, worldPt.y, worldPt.z - mSize );
  519. if ( mForest )
  520. mForest->disableCollision();
  521. // Do a cast ray at this point from the top to
  522. // the bottom of our brush radius.
  523. RayInfo rinfo;
  524. bool hit = gServerContainer.castRay( start, end, mask, &rinfo );
  525. if ( mForest )
  526. mForest->enableCollision();
  527. if ( !hit )
  528. return false;
  529. if (zValueOut)
  530. *zValueOut = rinfo.point.z;
  531. if (normalOut)
  532. *normalOut = rinfo.normal;
  533. return true;
  534. }
  535. DefineEngineMethod( ForestBrushTool, collectElements, void, (), , "" )
  536. {
  537. object->collectElements();
  538. }