guiDecalEditorCtrl.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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. #ifndef TORQUE_TGB_ONLY
  23. #include "guiDecalEditorCtrl.h"
  24. #include "platform/platform.h"
  25. #include "console/consoleTypes.h"
  26. #include "scene/sceneManager.h"
  27. #include "collision/collision.h"
  28. #include "math/util/frustum.h"
  29. #include "gfx/gfxPrimitiveBuffer.h"
  30. #include "gfx/gfxTextureHandle.h"
  31. #include "gfx/gfxTransformSaver.h"
  32. #include "gfx/primBuilder.h"
  33. #include "gfx/gfxDrawUtil.h"
  34. #include "gui/core/guiCanvas.h"
  35. #include "gui/buttons/guiButtonCtrl.h"
  36. #include "gui/worldEditor/gizmo.h"
  37. #include "T3D/decal/decalManager.h"
  38. #include "T3D/decal/decalInstance.h"
  39. #include "gui/worldEditor/undoActions.h"
  40. IMPLEMENT_CONOBJECT(GuiDecalEditorCtrl);
  41. ConsoleDocClass( GuiDecalEditorCtrl,
  42. "@brief The base class for the Decal Editor tool\n\n"
  43. "Editor use only.\n\n"
  44. "@internal"
  45. );
  46. bool GuiDecalEditorCtrl::smRenderDecalPixelSize = false;
  47. GuiDecalEditorCtrl::GuiDecalEditorCtrl()
  48. {
  49. mSELDecal = NULL;
  50. mHLDecal = NULL;
  51. mCurrentDecalData = NULL;
  52. mMode = "AddDecalMode";
  53. mPerformedDragCopy = false;
  54. }
  55. GuiDecalEditorCtrl::~GuiDecalEditorCtrl()
  56. {
  57. // nothing to do
  58. }
  59. bool GuiDecalEditorCtrl::onAdd()
  60. {
  61. if( !Parent::onAdd() )
  62. return false;
  63. return true;
  64. }
  65. void GuiDecalEditorCtrl::initPersistFields()
  66. {
  67. addField( "currentDecalData", TYPEID< DecalData >(), Offset( mCurrentDecalData, GuiDecalEditorCtrl ) );
  68. Parent::initPersistFields();
  69. }
  70. void GuiDecalEditorCtrl::consoleInit()
  71. {
  72. Con::addVariable( "$DecalEditor::renderPixelSize", TypeBool, &smRenderDecalPixelSize,
  73. "Set true to render the pixel size as on overlay on the selected decal instance. "
  74. "This is the value used to fade distant decals and is intended to help the user adjust "
  75. "the values of DecalData::pixelSizeStartFade and pixelSizeEndFade.\n\n"
  76. "@internal" );
  77. Parent::consoleInit();
  78. }
  79. void GuiDecalEditorCtrl::onEditorDisable()
  80. {
  81. // Tools are not deleted/recreated between missions, but decals instances
  82. // ARE. So we must release any references.
  83. mSELDecal = NULL;
  84. mHLDecal = NULL;
  85. }
  86. bool GuiDecalEditorCtrl::onWake()
  87. {
  88. if ( !Parent::onWake() )
  89. return false;
  90. return true;
  91. }
  92. void GuiDecalEditorCtrl::onSleep()
  93. {
  94. Parent::onSleep();
  95. }
  96. void GuiDecalEditorCtrl::get3DCursor( GuiCursor *&cursor,
  97. bool &visible,
  98. const Gui3DMouseEvent &event_ )
  99. {
  100. cursor = NULL;
  101. visible = false;
  102. GuiCanvas *root = getRoot();
  103. if ( !root )
  104. return;
  105. S32 currCursor = PlatformCursorController::curArrow;
  106. if ( root->mCursorChanged == currCursor )
  107. return;
  108. PlatformWindow *window = root->getPlatformWindow();
  109. PlatformCursorController *controller = window->getCursorController();
  110. // We've already changed the cursor,
  111. // so set it back before we change it again.
  112. if( root->mCursorChanged != -1)
  113. controller->popCursor();
  114. // Now change the cursor shape
  115. controller->pushCursor(currCursor);
  116. root->mCursorChanged = currCursor;
  117. }
  118. void GuiDecalEditorCtrl::on3DMouseDown(const Gui3DMouseEvent & event)
  119. {
  120. mPerformedDragCopy = false;
  121. if ( !isFirstResponder() )
  122. setFirstResponder();
  123. bool dblClick = ( event.mouseClickCount > 1 );
  124. // Gather selected decal information
  125. RayInfo ri;
  126. bool hit = getRayInfo( event, &ri );
  127. Point3F start = event.pos;
  128. Point3F end = start + event.vec * 3000.0f; // use visible distance here??
  129. DecalInstance *pDecal = gDecalManager->raycast( start, end );
  130. if( mMode.compare("AddDecalMode") != 0 )
  131. {
  132. if ( mSELDecal )
  133. {
  134. // If our click hit the gizmo we are done.
  135. if ( mGizmo->getSelection() != Gizmo::None )
  136. {
  137. mGizmo->on3DMouseDown( event );
  138. char returnBuffer[256];
  139. dSprintf(returnBuffer, sizeof(returnBuffer), "%f %f %f %f %f %f %f",
  140. mSELDecal->mPosition.x, mSELDecal->mPosition.y, mSELDecal->mPosition.z,
  141. mSELDecal->mTangent.x, mSELDecal->mTangent.y, mSELDecal->mTangent.z,
  142. mSELDecal->mSize);
  143. Con::executef( this, "prepGizmoTransform", Con::getIntArg(mSELDecal->mId), returnBuffer );
  144. return;
  145. }
  146. }
  147. if ( mHLDecal && pDecal == mHLDecal )
  148. {
  149. mHLDecal = NULL;
  150. selectDecal( pDecal );
  151. if ( isMethod( "onSelectInstance" ) )
  152. {
  153. char idBuf[512];
  154. dSprintf(idBuf, 512, "%i", pDecal->mId);
  155. Con::executef( this, "onSelectInstance", String(idBuf).c_str(), pDecal->mDataBlock->lookupName.c_str() );
  156. }
  157. return;
  158. }
  159. else if ( hit && !pDecal)
  160. {
  161. if ( dblClick )
  162. setMode( String("AddDecalMode"), true );
  163. return;
  164. }
  165. }
  166. else
  167. {
  168. // If we accidently hit a decal, then bail(probably an accident). If the use hits the decal twice,
  169. // then boot them into selection mode and select the decal.
  170. if ( mHLDecal && pDecal == mHLDecal )
  171. {
  172. if ( dblClick )
  173. {
  174. mHLDecal = NULL;
  175. selectDecal( pDecal );
  176. if ( isMethod( "onSelectInstance" ) )
  177. {
  178. char idBuf[512];
  179. dSprintf(idBuf, 512, "%i", pDecal->mId);
  180. Con::executef( this, "onSelectInstance", String(idBuf).c_str(), pDecal->mDataBlock->lookupName.c_str() );
  181. }
  182. setMode( String("SelectDecalMode"), true );
  183. }
  184. return;
  185. }
  186. if ( hit && mCurrentDecalData ) // Create a new decal...
  187. {
  188. U8 flags = PermanentDecal | SaveDecal;
  189. DecalInstance *decalInst = gDecalManager->addDecal( ri.point, ri.normal, 0.0f, mCurrentDecalData, 1.0f, -1, flags );
  190. if ( decalInst )
  191. {
  192. // Give the decal an id
  193. decalInst->mId = gDecalManager->mDecalInstanceVec.size();
  194. gDecalManager->mDecalInstanceVec.push_back(decalInst);
  195. selectDecal( decalInst );
  196. // Grab the mission editor undo manager.
  197. UndoManager *undoMan = NULL;
  198. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  199. {
  200. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  201. return;
  202. }
  203. // Create the UndoAction.
  204. DICreateUndoAction *action = new DICreateUndoAction("Create Decal");
  205. action->addDecal( *decalInst );
  206. action->mEditor = this;
  207. // Submit it.
  208. undoMan->addAction( action );
  209. if ( isMethod( "onCreateInstance" ) )
  210. {
  211. char buffer[512];
  212. dSprintf(buffer, 512, "%i", decalInst->mId);
  213. Con::executef( this, "onCreateInstance", buffer, decalInst->mDataBlock->lookupName.c_str());
  214. }
  215. }
  216. return;
  217. }
  218. }
  219. if ( !mSELDecal )
  220. return;
  221. }
  222. void GuiDecalEditorCtrl::on3DRightMouseDown(const Gui3DMouseEvent & event)
  223. {
  224. //mIsPanning = true;
  225. //mGizmo->on3DRightMouseDown( event );
  226. }
  227. void GuiDecalEditorCtrl::on3DRightMouseUp(const Gui3DMouseEvent & event)
  228. {
  229. //mIsPanning = false;
  230. // mGizmo->on3DRightMouseUp( event );
  231. }
  232. void GuiDecalEditorCtrl::on3DMouseUp(const Gui3DMouseEvent & event)
  233. {
  234. if ( mSELDecal )
  235. {
  236. if ( mGizmo->isDirty() )
  237. {
  238. char returnBuffer[256];
  239. dSprintf(returnBuffer, sizeof(returnBuffer), "%f %f %f %f %f %f %f",
  240. mSELDecal->mPosition.x, mSELDecal->mPosition.y, mSELDecal->mPosition.z,
  241. mSELDecal->mTangent.x, mSELDecal->mTangent.y, mSELDecal->mTangent.z,
  242. mSELDecal->mSize);
  243. Con::executef( this, "completeGizmoTransform", Con::getIntArg(mSELDecal->mId), returnBuffer );
  244. mGizmo->markClean();
  245. }
  246. mGizmo->on3DMouseUp( event );
  247. }
  248. }
  249. void GuiDecalEditorCtrl::on3DMouseMove(const Gui3DMouseEvent & event)
  250. {
  251. if ( mSELDecal )
  252. mGizmo->on3DMouseMove( event );
  253. RayInfo ri;
  254. if ( !getRayInfo( event, &ri ) )
  255. return;
  256. Point3F start = event.pos;
  257. Point3F end = start + event.vec * 3000.0f; // use visible distance here??
  258. DecalInstance *pDecal = gDecalManager->raycast( start, end );
  259. if ( pDecal && pDecal != mSELDecal )
  260. mHLDecal = pDecal;
  261. else if ( !pDecal )
  262. mHLDecal = NULL;
  263. }
  264. void GuiDecalEditorCtrl::on3DMouseDragged(const Gui3DMouseEvent & event)
  265. {
  266. if ( !mSELDecal )
  267. return;
  268. // Doing a drag copy of the decal?
  269. if ( event.modifier & SI_SHIFT && !mPerformedDragCopy )
  270. {
  271. mPerformedDragCopy = true;
  272. DecalInstance *newDecal = gDecalManager->addDecal( mSELDecal->mPosition,
  273. mSELDecal->mNormal,
  274. 0.0f,
  275. mSELDecal->mDataBlock,
  276. 1.0f,
  277. -1,
  278. PermanentDecal | SaveDecal );
  279. newDecal->mTangent = mSELDecal->mTangent;
  280. newDecal->mSize = mSELDecal->mSize;
  281. newDecal->mTextureRectIdx = mSELDecal->mTextureRectIdx;
  282. // TODO: This is crazy... we should move this sort of tracking
  283. // inside of the decal manager... IdDecal flag maybe or just a
  284. // byproduct of PermanentDecal?
  285. //
  286. newDecal->mId = gDecalManager->mDecalInstanceVec.size();
  287. gDecalManager->mDecalInstanceVec.push_back( newDecal );
  288. selectDecal( newDecal );
  289. // Grab the mission editor undo manager.
  290. UndoManager *undoMan = NULL;
  291. if ( Sim::findObject( "EUndoManager", undoMan ) )
  292. {
  293. // Create the UndoAction.
  294. DICreateUndoAction *action = new DICreateUndoAction("Create Decal");
  295. action->addDecal( *mSELDecal );
  296. action->mEditor = this;
  297. undoMan->addAction( action );
  298. if ( isMethod( "onCreateInstance" ) )
  299. {
  300. char buffer[512];
  301. dSprintf( buffer, 512, "%i", mSELDecal->mId );
  302. Con::executef( this, "onCreateInstance", buffer, mSELDecal->mDataBlock->lookupName.c_str());
  303. }
  304. }
  305. }
  306. // Update the Gizmo.
  307. if (mGizmo->getSelection() != Gizmo::None)
  308. {
  309. mGizmo->on3DMouseDragged( event );
  310. // Pull out the Gizmo transform
  311. // and position.
  312. const MatrixF &gizmoMat = mGizmo->getTransform();
  313. const Point3F &gizmoPos = gizmoMat.getPosition();
  314. // Get the new projection vector.
  315. VectorF upVec, rightVec;
  316. gizmoMat.getColumn( 0, &rightVec );
  317. gizmoMat.getColumn( 2, &upVec );
  318. const Point3F &scale = mGizmo->getScale();
  319. // Assign the appropriate changed value back to the decal.
  320. if ( mGizmo->getMode() == ScaleMode )
  321. {
  322. // Save old size.
  323. const F32 oldSize = mSELDecal->mSize;
  324. // Set new size.
  325. mSELDecal->mSize = ( scale.x + scale.y ) * 0.5f;
  326. // See if the decal properly clips/projects at this size. If not,
  327. // stick to the old size.
  328. mSELEdgeVerts.clear();
  329. if ( !gDecalManager->clipDecal( mSELDecal, &mSELEdgeVerts ) )
  330. mSELDecal->mSize = oldSize;
  331. }
  332. else if ( mGizmo->getMode() == MoveMode )
  333. mSELDecal->mPosition = gizmoPos;
  334. else if ( mGizmo->getMode() == RotateMode )
  335. {
  336. mSELDecal->mNormal = upVec;
  337. mSELDecal->mTangent = rightVec;
  338. }
  339. gDecalManager->notifyDecalModified( mSELDecal );
  340. Con::executef( this, "syncNodeDetails" );
  341. }
  342. }
  343. void GuiDecalEditorCtrl::on3DMouseEnter(const Gui3DMouseEvent & event)
  344. {
  345. // nothing to do
  346. }
  347. void GuiDecalEditorCtrl::on3DMouseLeave(const Gui3DMouseEvent & event)
  348. {
  349. // nothing to do
  350. }
  351. void GuiDecalEditorCtrl::updateGuiInfo()
  352. {
  353. // nothing to do
  354. }
  355. void GuiDecalEditorCtrl::onRender( Point2I offset, const RectI &updateRect )
  356. {
  357. Parent::onRender( offset, updateRect );
  358. }
  359. void GuiDecalEditorCtrl::renderGui( Point2I offset, const RectI &updateRect )
  360. {
  361. Parent::renderGui( offset, updateRect );
  362. PROFILE_SCOPE( GuiDecalEditorCtrl_renderGui );
  363. // Show the pixelSize of the selected decal as a text overlay.
  364. if ( smRenderDecalPixelSize && mSELDecal != NULL )
  365. {
  366. const F32 pixelSize = mSELDecal->calcPixelSize( mSaveViewport.extent.y, mLastCameraQuery.cameraMatrix.getPosition(), mSaveWorldToScreenScale.y );
  367. // Find position onscreen to render the text.
  368. Point3F screenPos;
  369. bool onScreen = project( mSELDecal->mPosition, &screenPos );
  370. if ( onScreen )
  371. {
  372. // It is extremely annoying to require the GuiProfile to have a font
  373. // or to create one within the decal editor for only this single use,
  374. // so we instead rely on the fact that we already have a Gizmo, that
  375. // all Gizmo's have a GizmoProfile, and that GizmoProfile has a font.
  376. GFont *font = mGizmo->getProfile()->font;
  377. // Might as well use some colors defined in GizmoProfile too instead
  378. // of just hardcoding it here.
  379. const ColorI bgColor = mGizmo->getProfile()->inActiveColor;
  380. const ColorI textColor = mGizmo->getProfile()->activeColor;
  381. // Note: This mostly mirrors the way WorldEditor renders popupText for
  382. // the gizmo during a drag operation, consider unifying this into a utility method.
  383. char buf[256];
  384. dSprintf( buf, 256, "%0.3f", pixelSize );
  385. const U32 width = font->getStrWidth((const UTF8 *)buf);;
  386. const Point2I posi( (U32)screenPos.x, (U32)screenPos.y + 12 );
  387. const Point2I minPt(posi.x - width / 2 - 2, posi.y - 1);
  388. const Point2I maxPt(posi.x + width / 2 + 2, posi.y + font->getHeight() + 1);
  389. GFXDrawUtil *drawer = GFX->getDrawUtil();
  390. drawer->drawRectFill( minPt, maxPt, bgColor );
  391. GFX->getDrawUtil()->setBitmapModulation( textColor );
  392. GFX->getDrawUtil()->drawText( mProfile->mFont, Point2I( posi.x - width / 2, posi.y ), buf );
  393. }
  394. }
  395. }
  396. void GuiDecalEditorCtrl::renderScene(const RectI & updateRect)
  397. {
  398. PROFILE_SCOPE( GuiDecalEditorCtrl_renderScene );
  399. GFXTransformSaver saver;
  400. RectI bounds = getBounds();
  401. ColorI hlColor(0,255,0,255);
  402. ColorI regColor(255,0,0,255);
  403. ColorI selColor(0,0,255,255);
  404. ColorI color;
  405. GFXDrawUtil *drawUtil = GFX->getDrawUtil();
  406. GFXStateBlockDesc desc;
  407. desc.setBlend( true );
  408. desc.setZReadWrite( true, false );
  409. // Draw 3D stuff here.
  410. if ( mSELDecal )
  411. {
  412. mGizmo->renderGizmo( mLastCameraQuery.cameraMatrix, mLastCameraQuery.fov );
  413. mSELEdgeVerts.clear();
  414. if ( gDecalManager->clipDecal( mSELDecal, &mSELEdgeVerts ) )
  415. _renderDecalEdge( mSELEdgeVerts, ColorI( 255, 255, 255, 255 ) );
  416. const F32 &decalSize = mSELDecal->mSize;
  417. Point3F boxSize( decalSize, decalSize, decalSize );
  418. MatrixF worldMat( true );
  419. mSELDecal->getWorldMatrix( &worldMat, true );
  420. drawUtil->drawObjectBox( desc, boxSize, mSELDecal->mPosition, worldMat, ColorI( 255, 255, 255, 255 ) );
  421. }
  422. if ( mHLDecal )
  423. {
  424. mHLEdgeVerts.clear();
  425. if ( gDecalManager->clipDecal( mHLDecal, &mHLEdgeVerts ) )
  426. _renderDecalEdge( mHLEdgeVerts, ColorI( 255, 255, 255, 255 ) );
  427. const F32 &decalSize = mHLDecal->mSize;
  428. Point3F boxSize( decalSize, decalSize, decalSize );
  429. MatrixF worldMat( true );
  430. mHLDecal->getWorldMatrix( &worldMat, true );
  431. drawUtil->drawObjectBox( desc, boxSize, mHLDecal->mPosition, worldMat, ColorI( 255, 255, 255, 255 ) );
  432. }
  433. }
  434. void GuiDecalEditorCtrl::forceRedraw( DecalInstance * decalInstance )
  435. {
  436. // This should be redundant because the decal is already reclipped
  437. // on each frame. Also it is not possible execute rendering code like
  438. // this in response to UI events from script.
  439. /*
  440. if ( !decalInstance )
  441. return;
  442. GFXDrawUtil *drawUtil = GFX->getDrawUtil();
  443. GFXStateBlockDesc desc;
  444. desc.setBlend( true );
  445. desc.setZReadWrite( true, false );
  446. Vector<Point3F> verts;
  447. verts.clear();
  448. if ( gDecalManager->clipDecal( decalInstance, &verts ) )
  449. if ( gDecalManager->clipDecal( decalInstance, &verts ) )
  450. _renderDecalEdge( verts, ColorI( 255, 255, 255, 255 ) );
  451. const F32 &decalSize = decalInstance->mSize;
  452. Point3F boxSize( decalSize, decalSize, decalSize );
  453. MatrixF worldMat( true );
  454. decalInstance->getWorldMatrix( &worldMat, true );
  455. drawUtil->drawObjectBox( desc, boxSize, decalInstance->mPosition, worldMat, ColorI( 255, 255, 255, 255 ) );
  456. */
  457. }
  458. void GuiDecalEditorCtrl::_renderDecalEdge( const Vector<Point3F> &verts, const ColorI &color )
  459. {
  460. U32 vertCount = verts.size();
  461. GFXTransformSaver saver;
  462. PrimBuild::color( color );
  463. Point3F endPt( 0, 0, 0 );
  464. for ( U32 i = 0; i < vertCount; i++ )
  465. {
  466. const Point3F &vert = verts[i];
  467. if ( i + 1 < vertCount )
  468. endPt = verts[i + 1];
  469. else
  470. break;
  471. PrimBuild::begin( GFXLineList, 2 );
  472. PrimBuild::vertex3f( vert.x, vert.y, vert.z );
  473. PrimBuild::vertex3f( endPt.x, endPt.y, endPt.z );
  474. PrimBuild::end();
  475. }
  476. }
  477. bool GuiDecalEditorCtrl::getRayInfo( const Gui3DMouseEvent & event, RayInfo *rInfo )
  478. {
  479. Point3F startPnt = event.pos;
  480. Point3F endPnt = event.pos + event.vec * 3000.0f;
  481. bool hit;
  482. hit = gServerContainer.castRayRendered( startPnt, endPnt, STATIC_COLLISION_TYPEMASK, rInfo );
  483. return hit;
  484. }
  485. void GuiDecalEditorCtrl::selectDecal( DecalInstance *decalInst )
  486. {
  487. // If id is zero or invalid we set the selected decal to null
  488. // which is correct.
  489. mSELDecal = decalInst;
  490. if ( decalInst )
  491. setGizmoFocus( decalInst );
  492. }
  493. void GuiDecalEditorCtrl::deleteSelectedDecal()
  494. {
  495. if ( !mSELDecal )
  496. return;
  497. // Grab the mission editor undo manager.
  498. UndoManager *undoMan = NULL;
  499. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  500. {
  501. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  502. return;
  503. }
  504. // Create the UndoAction.
  505. DIDeleteUndoAction *action = new DIDeleteUndoAction("Delete Decal");
  506. action->deleteDecal( *mSELDecal );
  507. action->mEditor = this;
  508. // Submit it.
  509. undoMan->addAction( action );
  510. if ( isMethod( "onDeleteInstance" ) )
  511. {
  512. char buffer[512];
  513. dSprintf(buffer, 512, "%i", mSELDecal->mId);
  514. Con::executef( this, "onDeleteInstance", String(buffer).c_str(), mSELDecal->mDataBlock->lookupName.c_str() );
  515. }
  516. gDecalManager->removeDecal( mSELDecal );
  517. mSELDecal = NULL;
  518. }
  519. void GuiDecalEditorCtrl::deleteDecalDatablock( String lookupName )
  520. {
  521. DecalData * datablock = dynamic_cast<DecalData*> ( Sim::findObject(lookupName.c_str()) );
  522. if( !datablock )
  523. return;
  524. // Grab the mission editor undo manager.
  525. UndoManager *undoMan = NULL;
  526. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  527. {
  528. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  529. return;
  530. }
  531. // Create the UndoAction.
  532. DBDeleteUndoAction *action = new DBDeleteUndoAction("Delete Decal Datablock");
  533. action->mEditor = this;
  534. action->mDatablockId = datablock->getId();
  535. Vector<DecalInstance*> mDecalQueue;
  536. Vector<DecalInstance *>::iterator iter;
  537. mDecalQueue.clear();
  538. const Vector<DecalSphere*> &grid = gDecalManager->getDecalDataFile()->getSphereList();
  539. for ( U32 i = 0; i < grid.size(); i++ )
  540. {
  541. const DecalSphere *decalSphere = grid[i];
  542. mDecalQueue.merge( decalSphere->mItems );
  543. }
  544. for ( iter = mDecalQueue.begin();iter != mDecalQueue.end();iter++ )
  545. {
  546. if( !(*iter) )
  547. continue;
  548. if( (*iter)->mDataBlock->lookupName.compare( lookupName ) == 0 )
  549. {
  550. if( (*iter)->mId != -1 )
  551. {
  552. //make sure to call onDeleteInstance as well
  553. if ( isMethod( "onDeleteInstance" ) )
  554. {
  555. char buffer[512];
  556. dSprintf(buffer, 512, "%i", (*iter)->mId);
  557. Con::executef( this, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  558. }
  559. action->deleteDecal( *(*iter) );
  560. if( mSELDecal == (*iter) )
  561. mSELDecal = NULL;
  562. if( mHLDecal == (*iter) )
  563. mHLDecal = NULL;
  564. }
  565. gDecalManager->removeDecal( (*iter) );
  566. }
  567. }
  568. undoMan->addAction( action );
  569. mCurrentDecalData = NULL;
  570. }
  571. void GuiDecalEditorCtrl::retargetDecalDatablock( String dbFrom, String dbTo )
  572. {
  573. DecalData * ptrFrom = dynamic_cast<DecalData*> ( Sim::findObject(dbFrom.c_str()) );
  574. DecalData * ptrTo = dynamic_cast<DecalData*> ( Sim::findObject(dbTo.c_str()) );
  575. if( !ptrFrom || !ptrTo )
  576. return;
  577. // Grab the mission editor undo manager.
  578. UndoManager *undoMan = NULL;
  579. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  580. {
  581. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  582. return;
  583. }
  584. // Create the UndoAction.
  585. DBRetargetUndoAction *action = new DBRetargetUndoAction("Retarget Decal Datablock");
  586. action->mEditor = this;
  587. action->mDBFromId = ptrFrom->getId();
  588. action->mDBToId = ptrTo->getId();
  589. Vector<DecalInstance*> mDecalQueue;
  590. Vector<DecalInstance *>::iterator iter;
  591. mDecalQueue.clear();
  592. const Vector<DecalSphere*> &grid = gDecalManager->getDecalDataFile()->getSphereList();
  593. for ( U32 i = 0; i < grid.size(); i++ )
  594. {
  595. const DecalSphere *decalSphere = grid[i];
  596. mDecalQueue.merge( decalSphere->mItems );
  597. }
  598. for ( iter = mDecalQueue.begin();iter != mDecalQueue.end();iter++ )
  599. {
  600. if( !(*iter) )
  601. continue;
  602. if( (*iter)->mDataBlock->lookupName.compare( dbFrom ) == 0 )
  603. {
  604. if( (*iter)->mId != -1 )
  605. {
  606. action->retargetDecal((*iter));
  607. (*iter)->mDataBlock = ptrTo;
  608. forceRedraw((*iter));
  609. }
  610. }
  611. }
  612. undoMan->addAction( action );
  613. }
  614. void GuiDecalEditorCtrl::setMode( String mode, bool sourceShortcut = false )
  615. {
  616. if( mode.compare("SelectDecalMode") == 0)
  617. mGizmo->getProfile()->mode = NoneMode;
  618. else if( mode.compare("AddDecalMode") == 0)
  619. mGizmo->getProfile()->mode = NoneMode;
  620. else if( mode.compare("MoveDecalMode") == 0)
  621. mGizmo->getProfile()->mode = MoveMode;
  622. else if( mode.compare("RotateDecalMode") == 0)
  623. mGizmo->getProfile()->mode = RotateMode;
  624. else if( mode.compare("ScaleDecalMode") == 0)
  625. mGizmo->getProfile()->mode = ScaleMode;
  626. mMode = mode;
  627. if( sourceShortcut )
  628. Con::executef( this, "paletteSync", mMode );
  629. }
  630. ConsoleMethod( GuiDecalEditorCtrl, deleteSelectedDecal, void, 2, 2, "deleteSelectedDecal()" )
  631. {
  632. object->deleteSelectedDecal();
  633. }
  634. ConsoleMethod( GuiDecalEditorCtrl, deleteDecalDatablock, void, 3, 3, "deleteSelectedDecalDatablock( String datablock )" )
  635. {
  636. String lookupName( argv[2] );
  637. if( lookupName == String::EmptyString )
  638. return;
  639. object->deleteDecalDatablock( lookupName );
  640. }
  641. ConsoleMethod( GuiDecalEditorCtrl, setMode, void, 3, 3, "setMode( String mode )()" )
  642. {
  643. String newMode = ( argv[2] );
  644. object->setMode( newMode );
  645. }
  646. ConsoleMethod( GuiDecalEditorCtrl, getMode, const char*, 2, 2, "getMode()" )
  647. {
  648. return object->mMode;
  649. }
  650. ConsoleMethod( GuiDecalEditorCtrl, getDecalCount, S32, 2, 2, "getDecalCount()" )
  651. {
  652. return gDecalManager->mDecalInstanceVec.size();
  653. }
  654. ConsoleMethod( GuiDecalEditorCtrl, getDecalTransform, const char*, 3, 3, "getDecalTransform()" )
  655. {
  656. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  657. if( decalInstance == NULL )
  658. return "";
  659. static const U32 bufSize = 256;
  660. char* returnBuffer = Con::getReturnBuffer(bufSize);
  661. returnBuffer[0] = 0;
  662. if ( decalInstance )
  663. {
  664. dSprintf(returnBuffer, bufSize, "%f %f %f %f %f %f %f",
  665. decalInstance->mPosition.x, decalInstance->mPosition.y, decalInstance->mPosition.z,
  666. decalInstance->mTangent.x, decalInstance->mTangent.y, decalInstance->mTangent.z,
  667. decalInstance->mSize);
  668. }
  669. return returnBuffer;
  670. }
  671. ConsoleMethod( GuiDecalEditorCtrl, getDecalLookupName, const char*, 3, 3, "getDecalLookupName( S32 )()" )
  672. {
  673. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  674. if( decalInstance == NULL )
  675. return "invalid";
  676. return decalInstance->mDataBlock->lookupName;
  677. }
  678. ConsoleMethod( GuiDecalEditorCtrl, selectDecal, void, 3, 3, "selectDecal( S32 )()" )
  679. {
  680. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  681. if( decalInstance == NULL )
  682. return;
  683. object->selectDecal( decalInstance );
  684. }
  685. ConsoleMethod( GuiDecalEditorCtrl, editDecalDetails, void, 4, 4, "editDecalDetails( S32 )()" )
  686. {
  687. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[ dAtoi(argv[2]) ];
  688. if( decalInstance == NULL )
  689. return;
  690. Point3F pos;
  691. Point3F tan;
  692. F32 size;
  693. S32 count = dSscanf( argv[3], "%f %f %f %f %f %f %f",
  694. &pos.x, &pos.y, &pos.z, &tan.x, &tan.y, &tan.z, &size);
  695. if ( (count != 7) )
  696. {
  697. Con::printf("Failed to parse decal information \"px py pz tx ty tz s\" from '%s'", argv[3]);
  698. return;
  699. }
  700. decalInstance->mPosition = pos;
  701. decalInstance->mTangent = tan;
  702. decalInstance->mSize = size;
  703. if ( decalInstance == object->mSELDecal )
  704. object->setGizmoFocus( decalInstance );
  705. object->forceRedraw( decalInstance );
  706. gDecalManager->notifyDecalModified( decalInstance );
  707. }
  708. ConsoleMethod( GuiDecalEditorCtrl, getSelectionCount, S32, 2, 2, "" )
  709. {
  710. if ( object->mSELDecal != NULL )
  711. return 1;
  712. return 0;
  713. }
  714. ConsoleMethod( GuiDecalEditorCtrl, retargetDecalDatablock, void, 4, 4, "" )
  715. {
  716. if( dStrcmp( argv[2], "" ) != 0 && dStrcmp( argv[3], "" ) != 0 )
  717. object->retargetDecalDatablock( argv[2], argv[3] );
  718. }
  719. void GuiDecalEditorCtrl::setGizmoFocus( DecalInstance * decalInstance )
  720. {
  721. const F32 &size = decalInstance->mSize;
  722. MatrixF worldMat( true );
  723. decalInstance->getWorldMatrix( &worldMat, true );
  724. worldMat.setPosition( Point3F( 0, 0, 0 ) );
  725. mGizmo->set( worldMat, decalInstance->mPosition, Point3F( size, size, size ) );
  726. }
  727. //Decal Instance Create Undo Actions
  728. IMPLEMENT_CONOBJECT( DICreateUndoAction );
  729. ConsoleDocClass( DICreateUndoAction,
  730. "@brief Decal Instance Create Undo Actions\n\n"
  731. "Not intended for game development, for editors or internal use only.\n\n "
  732. "@internal");
  733. DICreateUndoAction::DICreateUndoAction( const UTF8* actionName )
  734. : UndoAction( actionName )
  735. {
  736. }
  737. DICreateUndoAction::~DICreateUndoAction()
  738. {
  739. }
  740. void DICreateUndoAction::initPersistFields()
  741. {
  742. Parent::initPersistFields();
  743. }
  744. void DICreateUndoAction::addDecal( DecalInstance decal )
  745. {
  746. mDecalInstance = decal;
  747. mDatablockId = decal.mDataBlock->getId();
  748. }
  749. void DICreateUndoAction::undo()
  750. {
  751. Vector<DecalInstance *>::iterator iter;
  752. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  753. {
  754. if( !(*iter) )
  755. continue;
  756. if( (*iter)->mId != mDecalInstance.mId )
  757. continue;
  758. if ( mEditor->isMethod( "onDeleteInstance" ) )
  759. {
  760. char buffer[512];
  761. dSprintf(buffer, 512, "%i", (*iter)->mId);
  762. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  763. }
  764. // Decal manager handles clearing the vector if the decal contains a valid id
  765. if( mEditor->mSELDecal == (*iter) )
  766. mEditor->mSELDecal = NULL;
  767. if( mEditor->mHLDecal == (*iter) )
  768. mEditor->mHLDecal = NULL;
  769. gDecalManager->removeDecal( (*iter) );
  770. break;
  771. }
  772. }
  773. void DICreateUndoAction::redo()
  774. {
  775. //Reinstate the valid datablock pointer
  776. mDecalInstance.mDataBlock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  777. DecalInstance * decal = gDecalManager->addDecal( mDecalInstance.mPosition,
  778. mDecalInstance.mNormal,
  779. mDecalInstance.mTangent,
  780. mDecalInstance.mDataBlock,
  781. ( mDecalInstance.mSize / mDecalInstance.mDataBlock->size ),
  782. mDecalInstance.mTextureRectIdx,
  783. mDecalInstance.mFlags );
  784. decal->mId = mDecalInstance.mId;
  785. // Override the rectIdx regardless of random decision in addDecal
  786. decal->mTextureRectIdx = mDecalInstance.mTextureRectIdx;
  787. // We take care of filling in the vector space that was once there
  788. gDecalManager->mDecalInstanceVec[decal->mId] = decal;
  789. if ( mEditor->isMethod( "onCreateInstance" ) )
  790. {
  791. char buffer[512];
  792. dSprintf(buffer, 512, "%i", decal->mId);
  793. Con::executef( mEditor, "onCreateInstance", buffer, decal->mDataBlock->lookupName.c_str());
  794. }
  795. mEditor->selectDecal( decal );
  796. }
  797. //Decal Instance Delete Undo Actions
  798. IMPLEMENT_CONOBJECT( DIDeleteUndoAction );
  799. ConsoleDocClass( DIDeleteUndoAction,
  800. "@brief Decal Instance Delete Undo Actions\n\n"
  801. "Not intended for game development, for editors or internal use only.\n\n "
  802. "@internal");
  803. DIDeleteUndoAction::DIDeleteUndoAction( const UTF8 *actionName )
  804. : UndoAction( actionName )
  805. {
  806. }
  807. DIDeleteUndoAction::~DIDeleteUndoAction()
  808. {
  809. }
  810. void DIDeleteUndoAction::initPersistFields()
  811. {
  812. Parent::initPersistFields();
  813. }
  814. void DIDeleteUndoAction::deleteDecal( DecalInstance decal )
  815. {
  816. mDecalInstance = decal;
  817. mDatablockId = decal.mDataBlock->getId();
  818. }
  819. void DIDeleteUndoAction::undo()
  820. {
  821. //Reinstate the valid datablock pointer
  822. mDecalInstance.mDataBlock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  823. DecalInstance * decal = gDecalManager->addDecal( mDecalInstance.mPosition,
  824. mDecalInstance.mNormal,
  825. mDecalInstance.mTangent,
  826. mDecalInstance.mDataBlock,
  827. ( mDecalInstance.mSize / mDecalInstance.mDataBlock->size ),
  828. mDecalInstance.mTextureRectIdx,
  829. mDecalInstance.mFlags );
  830. decal->mId = mDecalInstance.mId;
  831. // Override the rectIdx regardless of random decision in addDecal
  832. decal->mTextureRectIdx = mDecalInstance.mTextureRectIdx;
  833. // We take care of filling in the vector space that was once there
  834. gDecalManager->mDecalInstanceVec[decal->mId] = decal;
  835. if ( mEditor->isMethod( "onCreateInstance" ) )
  836. {
  837. char buffer[512];
  838. dSprintf(buffer, 512, "%i", decal->mId);
  839. Con::executef( mEditor, "onCreateInstance", buffer, decal->mDataBlock->lookupName.c_str());
  840. }
  841. mEditor->selectDecal( decal );
  842. }
  843. void DIDeleteUndoAction::redo()
  844. {
  845. Vector<DecalInstance *>::iterator iter;
  846. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  847. {
  848. if( !(*iter) )
  849. continue;
  850. if( (*iter)->mId != mDecalInstance.mId )
  851. continue;
  852. if ( mEditor->isMethod( "onDeleteInstance" ) )
  853. {
  854. char buffer[512];
  855. dSprintf(buffer, 512, "%i", (*iter)->mId);
  856. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  857. }
  858. // Decal manager handles clearing the vector if the decal contains a valid id
  859. if( mEditor->mSELDecal == (*iter) )
  860. mEditor->mSELDecal = NULL;
  861. if( mEditor->mHLDecal == (*iter) )
  862. mEditor->mHLDecal = NULL;
  863. gDecalManager->removeDecal( (*iter) );
  864. break;
  865. }
  866. }
  867. //Decal Datablock Delete Undo Actions
  868. IMPLEMENT_CONOBJECT( DBDeleteUndoAction );
  869. ConsoleDocClass( DBDeleteUndoAction,
  870. "@brief Decal Datablock Delete Undo Actions\n\n"
  871. "Not intended for game development, for editors or internal use only.\n\n "
  872. "@internal");
  873. DBDeleteUndoAction::DBDeleteUndoAction( const UTF8 *actionName )
  874. : UndoAction( actionName )
  875. {
  876. }
  877. DBDeleteUndoAction::~DBDeleteUndoAction()
  878. {
  879. }
  880. void DBDeleteUndoAction::initPersistFields()
  881. {
  882. Parent::initPersistFields();
  883. }
  884. void DBDeleteUndoAction::deleteDecal( DecalInstance decal )
  885. {
  886. mDecalInstanceVec.increment();
  887. mDecalInstanceVec.last() = decal;
  888. }
  889. void DBDeleteUndoAction::undo()
  890. {
  891. DecalData * datablock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  892. if ( mEditor->isMethod( "undoDeleteDecalDatablock" ) )
  893. Con::executef( mEditor, "undoDeleteDecalDatablock", datablock->lookupName.c_str());
  894. // Create and restore the decal instances
  895. for ( S32 i= mDecalInstanceVec.size()-1; i >= 0; i-- )
  896. {
  897. DecalInstance vecInstance = mDecalInstanceVec[i];
  898. //Reinstate the valid datablock pointer
  899. vecInstance.mDataBlock = datablock;
  900. DecalInstance * decalInstance = gDecalManager->addDecal( vecInstance.mPosition,
  901. vecInstance.mNormal,
  902. vecInstance.mTangent,
  903. vecInstance.mDataBlock,
  904. ( vecInstance.mSize / vecInstance.mDataBlock->size ),
  905. vecInstance.mTextureRectIdx,
  906. vecInstance.mFlags );
  907. decalInstance->mId = vecInstance.mId;
  908. // Override the rectIdx regardless of random decision in addDecal
  909. decalInstance->mTextureRectIdx = vecInstance.mTextureRectIdx;
  910. // We take care of filling in the vector space that was once there
  911. gDecalManager->mDecalInstanceVec[decalInstance->mId] = decalInstance;
  912. if ( mEditor->isMethod( "onCreateInstance" ) )
  913. {
  914. char buffer[512];
  915. dSprintf(buffer, 512, "%i", decalInstance->mId);
  916. Con::executef( mEditor, "onCreateInstance", buffer, decalInstance->mDataBlock->lookupName.c_str());
  917. }
  918. }
  919. }
  920. void DBDeleteUndoAction::redo()
  921. {
  922. for ( S32 i=0; i < mDecalInstanceVec.size(); i++ )
  923. {
  924. DecalInstance vecInstance = mDecalInstanceVec[i];
  925. Vector<DecalInstance *>::iterator iter;
  926. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  927. {
  928. DecalInstance * decalInstance = (*iter);
  929. if( !decalInstance )
  930. continue;
  931. if( decalInstance->mId != vecInstance.mId )
  932. continue;
  933. if ( mEditor->isMethod( "onDeleteInstance" ) )
  934. {
  935. char buffer[512];
  936. dSprintf(buffer, 512, "%i", decalInstance->mId);
  937. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), decalInstance->mDataBlock->lookupName.c_str() );
  938. }
  939. // Decal manager handles clearing the vector if the decal contains a valid id
  940. if( mEditor->mSELDecal == decalInstance )
  941. mEditor->mSELDecal = NULL;
  942. if( mEditor->mHLDecal == decalInstance )
  943. mEditor->mHLDecal = NULL;
  944. gDecalManager->removeDecal( decalInstance );
  945. break;
  946. }
  947. }
  948. DecalData * datablock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  949. if ( mEditor->isMethod( "redoDeleteDecalDatablock" ) )
  950. Con::executef( mEditor, "redoDeleteDecalDatablock", datablock->lookupName.c_str());
  951. }
  952. //------------------------------
  953. //Decal Datablock Retarget Undo Actions
  954. IMPLEMENT_CONOBJECT( DBRetargetUndoAction );
  955. ConsoleDocClass( DBRetargetUndoAction,
  956. "@brief Decal Datablock Retarget Undo Actions\n\n"
  957. "Not intended for game development, for editors or internal use only.\n\n "
  958. "@internal");
  959. DBRetargetUndoAction::DBRetargetUndoAction( const UTF8 *actionName )
  960. : UndoAction( actionName )
  961. {
  962. }
  963. DBRetargetUndoAction::~DBRetargetUndoAction()
  964. {
  965. }
  966. void DBRetargetUndoAction::initPersistFields()
  967. {
  968. Parent::initPersistFields();
  969. }
  970. void DBRetargetUndoAction::retargetDecal( DecalInstance* decal )
  971. {
  972. mDecalInstanceVec.increment();
  973. mDecalInstanceVec.last() = decal;
  974. }
  975. void DBRetargetUndoAction::undo()
  976. {
  977. DecalData * ptrFrom = dynamic_cast<DecalData*> ( Sim::findObject(mDBFromId) );
  978. if( !ptrFrom )
  979. return;
  980. Vector<DecalInstance *>::iterator iter;
  981. for(iter = mDecalInstanceVec.begin();iter != mDecalInstanceVec.end();iter++)
  982. {
  983. (*iter)->mDataBlock = ptrFrom;
  984. mEditor->forceRedraw((*iter));
  985. }
  986. if ( mEditor->isMethod( "rebuildInstanceTree" ) )
  987. Con::executef( mEditor, "rebuildInstanceTree" );
  988. }
  989. void DBRetargetUndoAction::redo()
  990. {
  991. DecalData * ptrTo = dynamic_cast<DecalData*> ( Sim::findObject(mDBToId) );
  992. if( !ptrTo )
  993. return;
  994. Vector<DecalInstance *>::iterator iter;
  995. for(iter = mDecalInstanceVec.begin();iter != mDecalInstanceVec.end();iter++)
  996. {
  997. (*iter)->mDataBlock = ptrTo;
  998. mEditor->forceRedraw((*iter));
  999. }
  1000. if ( mEditor->isMethod( "rebuildInstanceTree" ) )
  1001. Con::executef( mEditor, "rebuildInstanceTree" );
  1002. }
  1003. #endif