guiDecalEditorCtrl.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  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", (const char*)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. char* returnBuffer = Con::getReturnBuffer(256);
  660. returnBuffer[0] = 0;
  661. if ( decalInstance )
  662. {
  663. dSprintf(returnBuffer, 256, "%f %f %f %f %f %f %f",
  664. decalInstance->mPosition.x, decalInstance->mPosition.y, decalInstance->mPosition.z,
  665. decalInstance->mTangent.x, decalInstance->mTangent.y, decalInstance->mTangent.z,
  666. decalInstance->mSize);
  667. }
  668. return returnBuffer;
  669. }
  670. ConsoleMethod( GuiDecalEditorCtrl, getDecalLookupName, const char*, 3, 3, "getDecalLookupName( S32 )()" )
  671. {
  672. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  673. if( decalInstance == NULL )
  674. return "invalid";
  675. return decalInstance->mDataBlock->lookupName;
  676. }
  677. ConsoleMethod( GuiDecalEditorCtrl, selectDecal, void, 3, 3, "selectDecal( S32 )()" )
  678. {
  679. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  680. if( decalInstance == NULL )
  681. return;
  682. object->selectDecal( decalInstance );
  683. }
  684. ConsoleMethod( GuiDecalEditorCtrl, editDecalDetails, void, 4, 4, "editDecalDetails( S32 )()" )
  685. {
  686. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[ dAtoi(argv[2]) ];
  687. if( decalInstance == NULL )
  688. return;
  689. Point3F pos;
  690. Point3F tan;
  691. F32 size;
  692. S32 count = dSscanf( argv[3], "%f %f %f %f %f %f %f",
  693. &pos.x, &pos.y, &pos.z, &tan.x, &tan.y, &tan.z, &size);
  694. if ( (count != 7) )
  695. {
  696. Con::printf("Failed to parse decal information \"px py pz tx ty tz s\" from '%s'", argv[3]);
  697. return;
  698. }
  699. decalInstance->mPosition = pos;
  700. decalInstance->mTangent = tan;
  701. decalInstance->mSize = size;
  702. if ( decalInstance == object->mSELDecal )
  703. object->setGizmoFocus( decalInstance );
  704. object->forceRedraw( decalInstance );
  705. gDecalManager->notifyDecalModified( decalInstance );
  706. }
  707. ConsoleMethod( GuiDecalEditorCtrl, getSelectionCount, S32, 2, 2, "" )
  708. {
  709. if ( object->mSELDecal != NULL )
  710. return 1;
  711. return 0;
  712. }
  713. ConsoleMethod( GuiDecalEditorCtrl, retargetDecalDatablock, void, 4, 4, "" )
  714. {
  715. if( dStrcmp( argv[2], "" ) != 0 && dStrcmp( argv[3], "" ) != 0 )
  716. object->retargetDecalDatablock( (const char*)argv[2], (const char*)argv[3] );
  717. }
  718. void GuiDecalEditorCtrl::setGizmoFocus( DecalInstance * decalInstance )
  719. {
  720. const F32 &size = decalInstance->mSize;
  721. MatrixF worldMat( true );
  722. decalInstance->getWorldMatrix( &worldMat, true );
  723. worldMat.setPosition( Point3F( 0, 0, 0 ) );
  724. mGizmo->set( worldMat, decalInstance->mPosition, Point3F( size, size, size ) );
  725. }
  726. //Decal Instance Create Undo Actions
  727. IMPLEMENT_CONOBJECT( DICreateUndoAction );
  728. ConsoleDocClass( DICreateUndoAction,
  729. "@brief Decal Instance Create Undo Actions\n\n"
  730. "Not intended for game development, for editors or internal use only.\n\n "
  731. "@internal");
  732. DICreateUndoAction::DICreateUndoAction( const UTF8* actionName )
  733. : UndoAction( actionName )
  734. {
  735. }
  736. DICreateUndoAction::~DICreateUndoAction()
  737. {
  738. }
  739. void DICreateUndoAction::initPersistFields()
  740. {
  741. Parent::initPersistFields();
  742. }
  743. void DICreateUndoAction::addDecal( DecalInstance decal )
  744. {
  745. mDecalInstance = decal;
  746. mDatablockId = decal.mDataBlock->getId();
  747. }
  748. void DICreateUndoAction::undo()
  749. {
  750. Vector<DecalInstance *>::iterator iter;
  751. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  752. {
  753. if( !(*iter) )
  754. continue;
  755. if( (*iter)->mId != mDecalInstance.mId )
  756. continue;
  757. if ( mEditor->isMethod( "onDeleteInstance" ) )
  758. {
  759. char buffer[512];
  760. dSprintf(buffer, 512, "%i", (*iter)->mId);
  761. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  762. }
  763. // Decal manager handles clearing the vector if the decal contains a valid id
  764. if( mEditor->mSELDecal == (*iter) )
  765. mEditor->mSELDecal = NULL;
  766. if( mEditor->mHLDecal == (*iter) )
  767. mEditor->mHLDecal = NULL;
  768. gDecalManager->removeDecal( (*iter) );
  769. break;
  770. }
  771. }
  772. void DICreateUndoAction::redo()
  773. {
  774. //Reinstate the valid datablock pointer
  775. mDecalInstance.mDataBlock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  776. DecalInstance * decal = gDecalManager->addDecal( mDecalInstance.mPosition,
  777. mDecalInstance.mNormal,
  778. mDecalInstance.mTangent,
  779. mDecalInstance.mDataBlock,
  780. ( mDecalInstance.mSize / mDecalInstance.mDataBlock->size ),
  781. mDecalInstance.mTextureRectIdx,
  782. mDecalInstance.mFlags );
  783. decal->mId = mDecalInstance.mId;
  784. // Override the rectIdx regardless of random decision in addDecal
  785. decal->mTextureRectIdx = mDecalInstance.mTextureRectIdx;
  786. // We take care of filling in the vector space that was once there
  787. gDecalManager->mDecalInstanceVec[decal->mId] = decal;
  788. if ( mEditor->isMethod( "onCreateInstance" ) )
  789. {
  790. char buffer[512];
  791. dSprintf(buffer, 512, "%i", decal->mId);
  792. Con::executef( mEditor, "onCreateInstance", buffer, decal->mDataBlock->lookupName.c_str());
  793. }
  794. mEditor->selectDecal( decal );
  795. }
  796. //Decal Instance Delete Undo Actions
  797. IMPLEMENT_CONOBJECT( DIDeleteUndoAction );
  798. ConsoleDocClass( DIDeleteUndoAction,
  799. "@brief Decal Instance Delete Undo Actions\n\n"
  800. "Not intended for game development, for editors or internal use only.\n\n "
  801. "@internal");
  802. DIDeleteUndoAction::DIDeleteUndoAction( const UTF8 *actionName )
  803. : UndoAction( actionName )
  804. {
  805. }
  806. DIDeleteUndoAction::~DIDeleteUndoAction()
  807. {
  808. }
  809. void DIDeleteUndoAction::initPersistFields()
  810. {
  811. Parent::initPersistFields();
  812. }
  813. void DIDeleteUndoAction::deleteDecal( DecalInstance decal )
  814. {
  815. mDecalInstance = decal;
  816. mDatablockId = decal.mDataBlock->getId();
  817. }
  818. void DIDeleteUndoAction::undo()
  819. {
  820. //Reinstate the valid datablock pointer
  821. mDecalInstance.mDataBlock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  822. DecalInstance * decal = gDecalManager->addDecal( mDecalInstance.mPosition,
  823. mDecalInstance.mNormal,
  824. mDecalInstance.mTangent,
  825. mDecalInstance.mDataBlock,
  826. ( mDecalInstance.mSize / mDecalInstance.mDataBlock->size ),
  827. mDecalInstance.mTextureRectIdx,
  828. mDecalInstance.mFlags );
  829. decal->mId = mDecalInstance.mId;
  830. // Override the rectIdx regardless of random decision in addDecal
  831. decal->mTextureRectIdx = mDecalInstance.mTextureRectIdx;
  832. // We take care of filling in the vector space that was once there
  833. gDecalManager->mDecalInstanceVec[decal->mId] = decal;
  834. if ( mEditor->isMethod( "onCreateInstance" ) )
  835. {
  836. char buffer[512];
  837. dSprintf(buffer, 512, "%i", decal->mId);
  838. Con::executef( mEditor, "onCreateInstance", buffer, decal->mDataBlock->lookupName.c_str());
  839. }
  840. mEditor->selectDecal( decal );
  841. }
  842. void DIDeleteUndoAction::redo()
  843. {
  844. Vector<DecalInstance *>::iterator iter;
  845. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  846. {
  847. if( !(*iter) )
  848. continue;
  849. if( (*iter)->mId != mDecalInstance.mId )
  850. continue;
  851. if ( mEditor->isMethod( "onDeleteInstance" ) )
  852. {
  853. char buffer[512];
  854. dSprintf(buffer, 512, "%i", (*iter)->mId);
  855. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  856. }
  857. // Decal manager handles clearing the vector if the decal contains a valid id
  858. if( mEditor->mSELDecal == (*iter) )
  859. mEditor->mSELDecal = NULL;
  860. if( mEditor->mHLDecal == (*iter) )
  861. mEditor->mHLDecal = NULL;
  862. gDecalManager->removeDecal( (*iter) );
  863. break;
  864. }
  865. }
  866. //Decal Datablock Delete Undo Actions
  867. IMPLEMENT_CONOBJECT( DBDeleteUndoAction );
  868. ConsoleDocClass( DBDeleteUndoAction,
  869. "@brief Decal Datablock Delete Undo Actions\n\n"
  870. "Not intended for game development, for editors or internal use only.\n\n "
  871. "@internal");
  872. DBDeleteUndoAction::DBDeleteUndoAction( const UTF8 *actionName )
  873. : UndoAction( actionName )
  874. {
  875. }
  876. DBDeleteUndoAction::~DBDeleteUndoAction()
  877. {
  878. }
  879. void DBDeleteUndoAction::initPersistFields()
  880. {
  881. Parent::initPersistFields();
  882. }
  883. void DBDeleteUndoAction::deleteDecal( DecalInstance decal )
  884. {
  885. mDecalInstanceVec.increment();
  886. mDecalInstanceVec.last() = decal;
  887. }
  888. void DBDeleteUndoAction::undo()
  889. {
  890. DecalData * datablock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  891. if ( mEditor->isMethod( "undoDeleteDecalDatablock" ) )
  892. Con::executef( mEditor, "undoDeleteDecalDatablock", datablock->lookupName.c_str());
  893. // Create and restore the decal instances
  894. for ( S32 i= mDecalInstanceVec.size()-1; i >= 0; i-- )
  895. {
  896. DecalInstance vecInstance = mDecalInstanceVec[i];
  897. //Reinstate the valid datablock pointer
  898. vecInstance.mDataBlock = datablock;
  899. DecalInstance * decalInstance = gDecalManager->addDecal( vecInstance.mPosition,
  900. vecInstance.mNormal,
  901. vecInstance.mTangent,
  902. vecInstance.mDataBlock,
  903. ( vecInstance.mSize / vecInstance.mDataBlock->size ),
  904. vecInstance.mTextureRectIdx,
  905. vecInstance.mFlags );
  906. decalInstance->mId = vecInstance.mId;
  907. // Override the rectIdx regardless of random decision in addDecal
  908. decalInstance->mTextureRectIdx = vecInstance.mTextureRectIdx;
  909. // We take care of filling in the vector space that was once there
  910. gDecalManager->mDecalInstanceVec[decalInstance->mId] = decalInstance;
  911. if ( mEditor->isMethod( "onCreateInstance" ) )
  912. {
  913. char buffer[512];
  914. dSprintf(buffer, 512, "%i", decalInstance->mId);
  915. Con::executef( mEditor, "onCreateInstance", buffer, decalInstance->mDataBlock->lookupName.c_str());
  916. }
  917. }
  918. }
  919. void DBDeleteUndoAction::redo()
  920. {
  921. for ( S32 i=0; i < mDecalInstanceVec.size(); i++ )
  922. {
  923. DecalInstance vecInstance = mDecalInstanceVec[i];
  924. Vector<DecalInstance *>::iterator iter;
  925. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  926. {
  927. DecalInstance * decalInstance = (*iter);
  928. if( !decalInstance )
  929. continue;
  930. if( decalInstance->mId != vecInstance.mId )
  931. continue;
  932. if ( mEditor->isMethod( "onDeleteInstance" ) )
  933. {
  934. char buffer[512];
  935. dSprintf(buffer, 512, "%i", decalInstance->mId);
  936. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), decalInstance->mDataBlock->lookupName.c_str() );
  937. }
  938. // Decal manager handles clearing the vector if the decal contains a valid id
  939. if( mEditor->mSELDecal == decalInstance )
  940. mEditor->mSELDecal = NULL;
  941. if( mEditor->mHLDecal == decalInstance )
  942. mEditor->mHLDecal = NULL;
  943. gDecalManager->removeDecal( decalInstance );
  944. break;
  945. }
  946. }
  947. DecalData * datablock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  948. if ( mEditor->isMethod( "redoDeleteDecalDatablock" ) )
  949. Con::executef( mEditor, "redoDeleteDecalDatablock", datablock->lookupName.c_str());
  950. }
  951. //------------------------------
  952. //Decal Datablock Retarget Undo Actions
  953. IMPLEMENT_CONOBJECT( DBRetargetUndoAction );
  954. ConsoleDocClass( DBRetargetUndoAction,
  955. "@brief Decal Datablock Retarget Undo Actions\n\n"
  956. "Not intended for game development, for editors or internal use only.\n\n "
  957. "@internal");
  958. DBRetargetUndoAction::DBRetargetUndoAction( const UTF8 *actionName )
  959. : UndoAction( actionName )
  960. {
  961. }
  962. DBRetargetUndoAction::~DBRetargetUndoAction()
  963. {
  964. }
  965. void DBRetargetUndoAction::initPersistFields()
  966. {
  967. Parent::initPersistFields();
  968. }
  969. void DBRetargetUndoAction::retargetDecal( DecalInstance* decal )
  970. {
  971. mDecalInstanceVec.increment();
  972. mDecalInstanceVec.last() = decal;
  973. }
  974. void DBRetargetUndoAction::undo()
  975. {
  976. DecalData * ptrFrom = dynamic_cast<DecalData*> ( Sim::findObject(mDBFromId) );
  977. if( !ptrFrom )
  978. return;
  979. Vector<DecalInstance *>::iterator iter;
  980. for(iter = mDecalInstanceVec.begin();iter != mDecalInstanceVec.end();iter++)
  981. {
  982. (*iter)->mDataBlock = ptrFrom;
  983. mEditor->forceRedraw((*iter));
  984. }
  985. if ( mEditor->isMethod( "rebuildInstanceTree" ) )
  986. Con::executef( mEditor, "rebuildInstanceTree" );
  987. }
  988. void DBRetargetUndoAction::redo()
  989. {
  990. DecalData * ptrTo = dynamic_cast<DecalData*> ( Sim::findObject(mDBToId) );
  991. if( !ptrTo )
  992. return;
  993. Vector<DecalInstance *>::iterator iter;
  994. for(iter = mDecalInstanceVec.begin();iter != mDecalInstanceVec.end();iter++)
  995. {
  996. (*iter)->mDataBlock = ptrTo;
  997. mEditor->forceRedraw((*iter));
  998. }
  999. if ( mEditor->isMethod( "rebuildInstanceTree" ) )
  1000. Con::executef( mEditor, "rebuildInstanceTree" );
  1001. }
  1002. #endif