forestBrushTool.cpp 19 KB

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