guiDecalEditorCtrl.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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 "console/engineAPI.h"
  27. #include "scene/sceneManager.h"
  28. #include "collision/collision.h"
  29. #include "math/util/frustum.h"
  30. #include "gfx/gfxPrimitiveBuffer.h"
  31. #include "gfx/gfxTextureHandle.h"
  32. #include "gfx/gfxTransformSaver.h"
  33. #include "gfx/primBuilder.h"
  34. #include "gfx/gfxDrawUtil.h"
  35. #include "gui/core/guiCanvas.h"
  36. #include "gui/buttons/guiButtonCtrl.h"
  37. #include "gui/worldEditor/gizmo.h"
  38. #include "T3D/decal/decalManager.h"
  39. #include "T3D/decal/decalInstance.h"
  40. #include "gui/worldEditor/undoActions.h"
  41. IMPLEMENT_CONOBJECT(GuiDecalEditorCtrl);
  42. ConsoleDocClass( GuiDecalEditorCtrl,
  43. "@brief The base class for the Decal Editor tool\n\n"
  44. "Editor use only.\n\n"
  45. "@internal"
  46. );
  47. bool GuiDecalEditorCtrl::smRenderDecalPixelSize = false;
  48. GuiDecalEditorCtrl::GuiDecalEditorCtrl()
  49. {
  50. mSELDecal = NULL;
  51. mHLDecal = NULL;
  52. mCurrentDecalData = NULL;
  53. mMode = "AddDecalMode";
  54. mPerformedDragCopy = false;
  55. }
  56. GuiDecalEditorCtrl::~GuiDecalEditorCtrl()
  57. {
  58. // nothing to do
  59. }
  60. bool GuiDecalEditorCtrl::onAdd()
  61. {
  62. if( !Parent::onAdd() )
  63. return false;
  64. return true;
  65. }
  66. void GuiDecalEditorCtrl::initPersistFields()
  67. {
  68. addField( "currentDecalData", TYPEID< DecalData >(), Offset( mCurrentDecalData, GuiDecalEditorCtrl ) );
  69. Parent::initPersistFields();
  70. }
  71. void GuiDecalEditorCtrl::consoleInit()
  72. {
  73. Con::addVariable( "$DecalEditor::renderPixelSize", TypeBool, &smRenderDecalPixelSize,
  74. "Set true to render the pixel size as on overlay on the selected decal instance. "
  75. "This is the value used to fade distant decals and is intended to help the user adjust "
  76. "the values of DecalData::pixelSizeStartFade and pixelSizeEndFade.\n\n"
  77. "@internal" );
  78. Parent::consoleInit();
  79. }
  80. void GuiDecalEditorCtrl::onEditorDisable()
  81. {
  82. // Tools are not deleted/recreated between missions, but decals instances
  83. // ARE. So we must release any references.
  84. mSELDecal = NULL;
  85. mHLDecal = NULL;
  86. }
  87. bool GuiDecalEditorCtrl::onWake()
  88. {
  89. if ( !Parent::onWake() )
  90. return false;
  91. return true;
  92. }
  93. void GuiDecalEditorCtrl::onSleep()
  94. {
  95. Parent::onSleep();
  96. }
  97. void GuiDecalEditorCtrl::get3DCursor( GuiCursor *&cursor,
  98. bool &visible,
  99. const Gui3DMouseEvent &event_ )
  100. {
  101. cursor = NULL;
  102. visible = false;
  103. GuiCanvas *root = getRoot();
  104. if ( !root )
  105. return;
  106. S32 currCursor = PlatformCursorController::curArrow;
  107. if ( root->mCursorChanged == currCursor )
  108. return;
  109. PlatformWindow *window = root->getPlatformWindow();
  110. PlatformCursorController *controller = window->getCursorController();
  111. // We've already changed the cursor,
  112. // so set it back before we change it again.
  113. if( root->mCursorChanged != -1)
  114. controller->popCursor();
  115. // Now change the cursor shape
  116. controller->pushCursor(currCursor);
  117. root->mCursorChanged = currCursor;
  118. }
  119. void GuiDecalEditorCtrl::on3DMouseDown(const Gui3DMouseEvent & event)
  120. {
  121. mPerformedDragCopy = false;
  122. if ( !isFirstResponder() )
  123. setFirstResponder();
  124. bool dblClick = ( event.mouseClickCount > 1 );
  125. // Gather selected decal information
  126. RayInfo ri;
  127. bool hit = getRayInfo( event, &ri );
  128. Point3F start = event.pos;
  129. Point3F end = start + event.vec * 3000.0f; // use visible distance here??
  130. DecalInstance *pDecal = gDecalManager->raycast( start, end );
  131. if( mMode.compare("AddDecalMode") != 0 )
  132. {
  133. if ( mSELDecal )
  134. {
  135. // If our click hit the gizmo we are done.
  136. if ( mGizmo->getSelection() != Gizmo::None )
  137. {
  138. mGizmo->on3DMouseDown( event );
  139. char returnBuffer[256];
  140. dSprintf(returnBuffer, sizeof(returnBuffer), "%f %f %f %f %f %f %f",
  141. mSELDecal->mPosition.x, mSELDecal->mPosition.y, mSELDecal->mPosition.z,
  142. mSELDecal->mTangent.x, mSELDecal->mTangent.y, mSELDecal->mTangent.z,
  143. mSELDecal->mSize);
  144. Con::executef( this, "prepGizmoTransform", Con::getIntArg(mSELDecal->mId), returnBuffer );
  145. return;
  146. }
  147. }
  148. if ( mHLDecal && pDecal == mHLDecal )
  149. {
  150. mHLDecal = NULL;
  151. selectDecal( pDecal );
  152. if ( isMethod( "onSelectInstance" ) )
  153. {
  154. char idBuf[512];
  155. dSprintf(idBuf, 512, "%i", pDecal->mId);
  156. Con::executef( this, "onSelectInstance", String(idBuf).c_str(), pDecal->mDataBlock->lookupName.c_str() );
  157. }
  158. return;
  159. }
  160. else if ( hit && !pDecal)
  161. {
  162. if ( dblClick )
  163. setMode( String("AddDecalMode"), true );
  164. return;
  165. }
  166. }
  167. else
  168. {
  169. // If we accidently hit a decal, then bail(probably an accident). If the use hits the decal twice,
  170. // then boot them into selection mode and select the decal.
  171. if ( mHLDecal && pDecal == mHLDecal )
  172. {
  173. if ( dblClick )
  174. {
  175. mHLDecal = NULL;
  176. selectDecal( pDecal );
  177. if ( isMethod( "onSelectInstance" ) )
  178. {
  179. char idBuf[512];
  180. dSprintf(idBuf, 512, "%i", pDecal->mId);
  181. Con::executef( this, "onSelectInstance", String(idBuf).c_str(), pDecal->mDataBlock->lookupName.c_str() );
  182. }
  183. setMode( String("SelectDecalMode"), true );
  184. }
  185. return;
  186. }
  187. if ( hit && mCurrentDecalData ) // Create a new decal...
  188. {
  189. U8 flags = PermanentDecal | SaveDecal;
  190. DecalInstance *decalInst = gDecalManager->addDecal( ri.point, ri.normal, 0.0f, mCurrentDecalData, 1.0f, -1, flags );
  191. if ( decalInst )
  192. {
  193. // Give the decal an id
  194. decalInst->mId = gDecalManager->mDecalInstanceVec.size();
  195. gDecalManager->mDecalInstanceVec.push_back(decalInst);
  196. selectDecal( decalInst );
  197. // Grab the mission editor undo manager.
  198. UndoManager *undoMan = NULL;
  199. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  200. {
  201. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  202. return;
  203. }
  204. // Create the UndoAction.
  205. DICreateUndoAction *action = new DICreateUndoAction("Create Decal");
  206. action->addDecal( *decalInst );
  207. action->mEditor = this;
  208. // Submit it.
  209. undoMan->addAction( action );
  210. if ( isMethod( "onCreateInstance" ) )
  211. {
  212. char buffer[512];
  213. dSprintf(buffer, 512, "%i", decalInst->mId);
  214. Con::executef( this, "onCreateInstance", buffer, decalInst->mDataBlock->lookupName.c_str());
  215. }
  216. }
  217. return;
  218. }
  219. }
  220. if ( !mSELDecal )
  221. return;
  222. }
  223. void GuiDecalEditorCtrl::on3DRightMouseDown(const Gui3DMouseEvent & event)
  224. {
  225. //mIsPanning = true;
  226. //mGizmo->on3DRightMouseDown( event );
  227. }
  228. void GuiDecalEditorCtrl::on3DRightMouseUp(const Gui3DMouseEvent & event)
  229. {
  230. //mIsPanning = false;
  231. // mGizmo->on3DRightMouseUp( event );
  232. }
  233. void GuiDecalEditorCtrl::on3DMouseUp(const Gui3DMouseEvent & event)
  234. {
  235. if ( mSELDecal )
  236. {
  237. if ( mGizmo->isDirty() )
  238. {
  239. char returnBuffer[256];
  240. dSprintf(returnBuffer, sizeof(returnBuffer), "%f %f %f %f %f %f %f",
  241. mSELDecal->mPosition.x, mSELDecal->mPosition.y, mSELDecal->mPosition.z,
  242. mSELDecal->mTangent.x, mSELDecal->mTangent.y, mSELDecal->mTangent.z,
  243. mSELDecal->mSize);
  244. Con::executef( this, "completeGizmoTransform", Con::getIntArg(mSELDecal->mId), returnBuffer );
  245. mGizmo->markClean();
  246. }
  247. mGizmo->on3DMouseUp( event );
  248. }
  249. }
  250. void GuiDecalEditorCtrl::on3DMouseMove(const Gui3DMouseEvent & event)
  251. {
  252. if ( mSELDecal )
  253. mGizmo->on3DMouseMove( event );
  254. RayInfo ri;
  255. if ( !getRayInfo( event, &ri ) )
  256. return;
  257. Point3F start = event.pos;
  258. Point3F end = start + event.vec * 3000.0f; // use visible distance here??
  259. DecalInstance *pDecal = gDecalManager->raycast( start, end );
  260. if ( pDecal && pDecal != mSELDecal )
  261. mHLDecal = pDecal;
  262. else if ( !pDecal )
  263. mHLDecal = NULL;
  264. }
  265. void GuiDecalEditorCtrl::on3DMouseDragged(const Gui3DMouseEvent & event)
  266. {
  267. if ( !mSELDecal )
  268. return;
  269. // Doing a drag copy of the decal?
  270. if ( event.modifier & SI_SHIFT && !mPerformedDragCopy )
  271. {
  272. mPerformedDragCopy = true;
  273. DecalInstance *newDecal = gDecalManager->addDecal( mSELDecal->mPosition,
  274. mSELDecal->mNormal,
  275. 0.0f,
  276. mSELDecal->mDataBlock,
  277. 1.0f,
  278. -1,
  279. PermanentDecal | SaveDecal );
  280. newDecal->mTangent = mSELDecal->mTangent;
  281. newDecal->mSize = mSELDecal->mSize;
  282. newDecal->mTextureRectIdx = mSELDecal->mTextureRectIdx;
  283. // TODO: This is crazy... we should move this sort of tracking
  284. // inside of the decal manager... IdDecal flag maybe or just a
  285. // byproduct of PermanentDecal?
  286. //
  287. newDecal->mId = gDecalManager->mDecalInstanceVec.size();
  288. gDecalManager->mDecalInstanceVec.push_back( newDecal );
  289. selectDecal( newDecal );
  290. // Grab the mission editor undo manager.
  291. UndoManager *undoMan = NULL;
  292. if ( Sim::findObject( "EUndoManager", undoMan ) )
  293. {
  294. // Create the UndoAction.
  295. DICreateUndoAction *action = new DICreateUndoAction("Create Decal");
  296. action->addDecal( *mSELDecal );
  297. action->mEditor = this;
  298. undoMan->addAction( action );
  299. if ( isMethod( "onCreateInstance" ) )
  300. {
  301. char buffer[512];
  302. dSprintf( buffer, 512, "%i", mSELDecal->mId );
  303. Con::executef( this, "onCreateInstance", buffer, mSELDecal->mDataBlock->lookupName.c_str());
  304. }
  305. }
  306. }
  307. // Update the Gizmo.
  308. if (mGizmo->getSelection() != Gizmo::None)
  309. {
  310. mGizmo->on3DMouseDragged( event );
  311. // Pull out the Gizmo transform
  312. // and position.
  313. const MatrixF &gizmoMat = mGizmo->getTransform();
  314. const Point3F &gizmoPos = gizmoMat.getPosition();
  315. // Get the new projection vector.
  316. VectorF upVec, rightVec;
  317. gizmoMat.getColumn( 0, &rightVec );
  318. gizmoMat.getColumn( 2, &upVec );
  319. const Point3F &scale = mGizmo->getScale();
  320. // Assign the appropriate changed value back to the decal.
  321. if ( mGizmo->getMode() == ScaleMode )
  322. {
  323. // Save old size.
  324. const F32 oldSize = mSELDecal->mSize;
  325. // Set new size.
  326. mSELDecal->mSize = ( scale.x + scale.y ) * 0.5f;
  327. // See if the decal properly clips/projects at this size. If not,
  328. // stick to the old size.
  329. mSELEdgeVerts.clear();
  330. if ( !gDecalManager->clipDecal( mSELDecal, &mSELEdgeVerts ) )
  331. mSELDecal->mSize = oldSize;
  332. }
  333. else if ( mGizmo->getMode() == MoveMode )
  334. mSELDecal->mPosition = gizmoPos;
  335. else if ( mGizmo->getMode() == RotateMode )
  336. {
  337. mSELDecal->mNormal = upVec;
  338. mSELDecal->mTangent = rightVec;
  339. }
  340. gDecalManager->notifyDecalModified( mSELDecal );
  341. Con::executef( this, "syncNodeDetails" );
  342. }
  343. }
  344. void GuiDecalEditorCtrl::on3DMouseEnter(const Gui3DMouseEvent & event)
  345. {
  346. // nothing to do
  347. }
  348. void GuiDecalEditorCtrl::on3DMouseLeave(const Gui3DMouseEvent & event)
  349. {
  350. // nothing to do
  351. }
  352. void GuiDecalEditorCtrl::updateGuiInfo()
  353. {
  354. // nothing to do
  355. }
  356. void GuiDecalEditorCtrl::onRender( Point2I offset, const RectI &updateRect )
  357. {
  358. Parent::onRender( offset, updateRect );
  359. }
  360. void GuiDecalEditorCtrl::renderGui( Point2I offset, const RectI &updateRect )
  361. {
  362. Parent::renderGui( offset, updateRect );
  363. PROFILE_SCOPE( GuiDecalEditorCtrl_renderGui );
  364. // Show the pixelSize of the selected decal as a text overlay.
  365. if ( smRenderDecalPixelSize && mSELDecal != NULL )
  366. {
  367. const F32 pixelSize = mSELDecal->calcPixelSize( mSaveViewport.extent.y, mLastCameraQuery.cameraMatrix.getPosition(), mSaveWorldToScreenScale.y );
  368. // Find position onscreen to render the text.
  369. Point3F screenPos;
  370. bool onScreen = project( mSELDecal->mPosition, &screenPos );
  371. if ( onScreen )
  372. {
  373. // It is extremely annoying to require the GuiProfile to have a font
  374. // or to create one within the decal editor for only this single use,
  375. // so we instead rely on the fact that we already have a Gizmo, that
  376. // all Gizmo's have a GizmoProfile, and that GizmoProfile has a font.
  377. GFont *font = mGizmo->getProfile()->font;
  378. // Might as well use some colors defined in GizmoProfile too instead
  379. // of just hardcoding it here.
  380. const ColorI bgColor = mGizmo->getProfile()->inActiveColor;
  381. const ColorI textColor = mGizmo->getProfile()->activeColor;
  382. // Note: This mostly mirrors the way WorldEditor renders popupText for
  383. // the gizmo during a drag operation, consider unifying this into a utility method.
  384. char buf[256];
  385. dSprintf( buf, 256, "%0.3f", pixelSize );
  386. const U32 width = font->getStrWidth((const UTF8 *)buf);;
  387. const Point2I posi( (U32)screenPos.x, (U32)screenPos.y + 12 );
  388. const Point2I minPt(posi.x - width / 2 - 2, posi.y - 1);
  389. const Point2I maxPt(posi.x + width / 2 + 2, posi.y + font->getHeight() + 1);
  390. GFXDrawUtil *drawer = GFX->getDrawUtil();
  391. drawer->drawRectFill( minPt, maxPt, bgColor );
  392. GFX->getDrawUtil()->setBitmapModulation( textColor );
  393. GFX->getDrawUtil()->drawText( mProfile->mFont, Point2I( posi.x - width / 2, posi.y ), buf );
  394. }
  395. }
  396. }
  397. void GuiDecalEditorCtrl::renderScene(const RectI & updateRect)
  398. {
  399. PROFILE_SCOPE( GuiDecalEditorCtrl_renderScene );
  400. GFXTransformSaver saver;
  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. DefineEngineMethod( GuiDecalEditorCtrl, deleteSelectedDecal, void, (), , "deleteSelectedDecal()" )
  631. {
  632. object->deleteSelectedDecal();
  633. }
  634. DefineEngineMethod( GuiDecalEditorCtrl, deleteDecalDatablock, void, ( const char * datablock ), , "deleteSelectedDecalDatablock( String datablock )" )
  635. {
  636. String lookupName( datablock );
  637. if( lookupName == String::EmptyString )
  638. return;
  639. object->deleteDecalDatablock( lookupName );
  640. }
  641. DefineEngineMethod( GuiDecalEditorCtrl, setMode, void, ( String newMode ), , "setMode( String mode )()" )
  642. {
  643. object->setMode( newMode );
  644. }
  645. DefineEngineMethod( GuiDecalEditorCtrl, getMode, const char*, (), , "getMode()" )
  646. {
  647. return object->mMode;
  648. }
  649. DefineEngineMethod( GuiDecalEditorCtrl, getDecalCount, S32, (), , "getDecalCount()" )
  650. {
  651. return gDecalManager->mDecalInstanceVec.size();
  652. }
  653. DefineEngineMethod( GuiDecalEditorCtrl, getDecalTransform, const char*, ( U32 id ), , "getDecalTransform()" )
  654. {
  655. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[id];
  656. if( decalInstance == NULL )
  657. return "";
  658. static const U32 bufSize = 256;
  659. char* returnBuffer = Con::getReturnBuffer(bufSize);
  660. returnBuffer[0] = 0;
  661. if ( decalInstance )
  662. {
  663. dSprintf(returnBuffer, bufSize, "%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. DefineEngineMethod( GuiDecalEditorCtrl, getDecalLookupName, const char*, ( U32 id ), , "getDecalLookupName( S32 )()" )
  671. {
  672. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[id];
  673. if( decalInstance == NULL )
  674. return "invalid";
  675. return decalInstance->mDataBlock->lookupName;
  676. }
  677. DefineEngineMethod( GuiDecalEditorCtrl, selectDecal, void, ( U32 id ), , "selectDecal( S32 )()" )
  678. {
  679. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[id];
  680. if( decalInstance == NULL )
  681. return;
  682. object->selectDecal( decalInstance );
  683. }
  684. DefineEngineMethod( GuiDecalEditorCtrl, editDecalDetails, void, ( U32 id, Point3F pos, Point3F tan,F32 size ), , "editDecalDetails( S32 )()" )
  685. {
  686. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[id];
  687. if( decalInstance == NULL )
  688. return;
  689. decalInstance->mPosition = pos;
  690. decalInstance->mTangent = tan;
  691. decalInstance->mSize = size;
  692. if ( decalInstance == object->mSELDecal )
  693. object->setGizmoFocus( decalInstance );
  694. object->forceRedraw( decalInstance );
  695. gDecalManager->notifyDecalModified( decalInstance );
  696. }
  697. DefineEngineMethod( GuiDecalEditorCtrl, getSelectionCount, S32, (), , "" )
  698. {
  699. if ( object->mSELDecal != NULL )
  700. return 1;
  701. return 0;
  702. }
  703. DefineEngineMethod( GuiDecalEditorCtrl, retargetDecalDatablock, void, ( const char * dbFrom, const char * dbTo ), , "" )
  704. {
  705. if( String::compare( dbFrom, "" ) != 0 && String::compare( dbTo, "" ) != 0 )
  706. object->retargetDecalDatablock( dbFrom, dbTo );
  707. }
  708. void GuiDecalEditorCtrl::setGizmoFocus( DecalInstance * decalInstance )
  709. {
  710. const F32 &size = decalInstance->mSize;
  711. MatrixF worldMat( true );
  712. decalInstance->getWorldMatrix( &worldMat, true );
  713. worldMat.setPosition( Point3F( 0, 0, 0 ) );
  714. mGizmo->set( worldMat, decalInstance->mPosition, Point3F( size, size, size ) );
  715. }
  716. //Decal Instance Create Undo Actions
  717. IMPLEMENT_CONOBJECT( DICreateUndoAction );
  718. ConsoleDocClass( DICreateUndoAction,
  719. "@brief Decal Instance Create Undo Actions\n\n"
  720. "Not intended for game development, for editors or internal use only.\n\n "
  721. "@internal");
  722. DICreateUndoAction::DICreateUndoAction( const UTF8* actionName )
  723. : UndoAction( actionName ), mEditor(0), mDatablockId(0)
  724. {
  725. }
  726. DICreateUndoAction::~DICreateUndoAction()
  727. {
  728. }
  729. void DICreateUndoAction::initPersistFields()
  730. {
  731. Parent::initPersistFields();
  732. }
  733. void DICreateUndoAction::addDecal(const DecalInstance& decal)
  734. {
  735. mDecalInstance = decal;
  736. mDatablockId = decal.mDataBlock->getId();
  737. }
  738. void DICreateUndoAction::undo()
  739. {
  740. Vector<DecalInstance *>::iterator iter;
  741. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  742. {
  743. if( !(*iter) )
  744. continue;
  745. if( (*iter)->mId != mDecalInstance.mId )
  746. continue;
  747. if ( mEditor->isMethod( "onDeleteInstance" ) )
  748. {
  749. char buffer[512];
  750. dSprintf(buffer, 512, "%i", (*iter)->mId);
  751. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  752. }
  753. // Decal manager handles clearing the vector if the decal contains a valid id
  754. if( mEditor->mSELDecal == (*iter) )
  755. mEditor->mSELDecal = NULL;
  756. if( mEditor->mHLDecal == (*iter) )
  757. mEditor->mHLDecal = NULL;
  758. gDecalManager->removeDecal( (*iter) );
  759. break;
  760. }
  761. }
  762. void DICreateUndoAction::redo()
  763. {
  764. //Reinstate the valid datablock pointer
  765. mDecalInstance.mDataBlock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  766. DecalInstance * decal = gDecalManager->addDecal( mDecalInstance.mPosition,
  767. mDecalInstance.mNormal,
  768. mDecalInstance.mTangent,
  769. mDecalInstance.mDataBlock,
  770. ( mDecalInstance.mSize / mDecalInstance.mDataBlock->size ),
  771. mDecalInstance.mTextureRectIdx,
  772. mDecalInstance.mFlags );
  773. decal->mId = mDecalInstance.mId;
  774. // Override the rectIdx regardless of random decision in addDecal
  775. decal->mTextureRectIdx = mDecalInstance.mTextureRectIdx;
  776. // We take care of filling in the vector space that was once there
  777. gDecalManager->mDecalInstanceVec[decal->mId] = decal;
  778. if ( mEditor->isMethod( "onCreateInstance" ) )
  779. {
  780. char buffer[512];
  781. dSprintf(buffer, 512, "%i", decal->mId);
  782. Con::executef( mEditor, "onCreateInstance", buffer, decal->mDataBlock->lookupName.c_str());
  783. }
  784. mEditor->selectDecal( decal );
  785. }
  786. //Decal Instance Delete Undo Actions
  787. IMPLEMENT_CONOBJECT( DIDeleteUndoAction );
  788. ConsoleDocClass( DIDeleteUndoAction,
  789. "@brief Decal Instance Delete Undo Actions\n\n"
  790. "Not intended for game development, for editors or internal use only.\n\n "
  791. "@internal");
  792. DIDeleteUndoAction::DIDeleteUndoAction( const UTF8 *actionName )
  793. : UndoAction( actionName ), mEditor(0), mDatablockId(0)
  794. {
  795. }
  796. DIDeleteUndoAction::~DIDeleteUndoAction()
  797. {
  798. }
  799. void DIDeleteUndoAction::initPersistFields()
  800. {
  801. Parent::initPersistFields();
  802. }
  803. void DIDeleteUndoAction::deleteDecal(const DecalInstance& decal)
  804. {
  805. mDecalInstance = decal;
  806. mDatablockId = decal.mDataBlock->getId();
  807. }
  808. void DIDeleteUndoAction::undo()
  809. {
  810. //Reinstate the valid datablock pointer
  811. mDecalInstance.mDataBlock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  812. DecalInstance * decal = gDecalManager->addDecal( mDecalInstance.mPosition,
  813. mDecalInstance.mNormal,
  814. mDecalInstance.mTangent,
  815. mDecalInstance.mDataBlock,
  816. ( mDecalInstance.mSize / mDecalInstance.mDataBlock->size ),
  817. mDecalInstance.mTextureRectIdx,
  818. mDecalInstance.mFlags );
  819. decal->mId = mDecalInstance.mId;
  820. // Override the rectIdx regardless of random decision in addDecal
  821. decal->mTextureRectIdx = mDecalInstance.mTextureRectIdx;
  822. // We take care of filling in the vector space that was once there
  823. gDecalManager->mDecalInstanceVec[decal->mId] = decal;
  824. if ( mEditor->isMethod( "onCreateInstance" ) )
  825. {
  826. char buffer[512];
  827. dSprintf(buffer, 512, "%i", decal->mId);
  828. Con::executef( mEditor, "onCreateInstance", buffer, decal->mDataBlock->lookupName.c_str());
  829. }
  830. mEditor->selectDecal( decal );
  831. }
  832. void DIDeleteUndoAction::redo()
  833. {
  834. Vector<DecalInstance *>::iterator iter;
  835. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  836. {
  837. if( !(*iter) )
  838. continue;
  839. if( (*iter)->mId != mDecalInstance.mId )
  840. continue;
  841. if ( mEditor->isMethod( "onDeleteInstance" ) )
  842. {
  843. char buffer[512];
  844. dSprintf(buffer, 512, "%i", (*iter)->mId);
  845. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  846. }
  847. // Decal manager handles clearing the vector if the decal contains a valid id
  848. if( mEditor->mSELDecal == (*iter) )
  849. mEditor->mSELDecal = NULL;
  850. if( mEditor->mHLDecal == (*iter) )
  851. mEditor->mHLDecal = NULL;
  852. gDecalManager->removeDecal( (*iter) );
  853. break;
  854. }
  855. }
  856. //Decal Datablock Delete Undo Actions
  857. IMPLEMENT_CONOBJECT( DBDeleteUndoAction );
  858. ConsoleDocClass( DBDeleteUndoAction,
  859. "@brief Decal Datablock Delete Undo Actions\n\n"
  860. "Not intended for game development, for editors or internal use only.\n\n "
  861. "@internal");
  862. DBDeleteUndoAction::DBDeleteUndoAction( const UTF8 *actionName )
  863. : UndoAction( actionName ), mEditor(0), mDatablockId(0)
  864. {
  865. }
  866. DBDeleteUndoAction::~DBDeleteUndoAction()
  867. {
  868. }
  869. void DBDeleteUndoAction::initPersistFields()
  870. {
  871. Parent::initPersistFields();
  872. }
  873. void DBDeleteUndoAction::deleteDecal(const DecalInstance& decal)
  874. {
  875. mDecalInstanceVec.increment();
  876. mDecalInstanceVec.last() = decal;
  877. }
  878. void DBDeleteUndoAction::undo()
  879. {
  880. DecalData * datablock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  881. if ( mEditor->isMethod( "undoDeleteDecalDatablock" ) )
  882. Con::executef( mEditor, "undoDeleteDecalDatablock", datablock->lookupName.c_str());
  883. // Create and restore the decal instances
  884. for ( S32 i= mDecalInstanceVec.size()-1; i >= 0; i-- )
  885. {
  886. DecalInstance vecInstance = mDecalInstanceVec[i];
  887. //Reinstate the valid datablock pointer
  888. vecInstance.mDataBlock = datablock;
  889. DecalInstance * decalInstance = gDecalManager->addDecal( vecInstance.mPosition,
  890. vecInstance.mNormal,
  891. vecInstance.mTangent,
  892. vecInstance.mDataBlock,
  893. ( vecInstance.mSize / vecInstance.mDataBlock->size ),
  894. vecInstance.mTextureRectIdx,
  895. vecInstance.mFlags );
  896. decalInstance->mId = vecInstance.mId;
  897. // Override the rectIdx regardless of random decision in addDecal
  898. decalInstance->mTextureRectIdx = vecInstance.mTextureRectIdx;
  899. // We take care of filling in the vector space that was once there
  900. gDecalManager->mDecalInstanceVec[decalInstance->mId] = decalInstance;
  901. if ( mEditor->isMethod( "onCreateInstance" ) )
  902. {
  903. char buffer[512];
  904. dSprintf(buffer, 512, "%i", decalInstance->mId);
  905. Con::executef( mEditor, "onCreateInstance", buffer, decalInstance->mDataBlock->lookupName.c_str());
  906. }
  907. }
  908. }
  909. void DBDeleteUndoAction::redo()
  910. {
  911. for ( S32 i=0; i < mDecalInstanceVec.size(); i++ )
  912. {
  913. DecalInstance vecInstance = mDecalInstanceVec[i];
  914. Vector<DecalInstance *>::iterator iter;
  915. for(iter = gDecalManager->mDecalInstanceVec.begin();iter != gDecalManager->mDecalInstanceVec.end();iter++)
  916. {
  917. DecalInstance * decalInstance = (*iter);
  918. if( !decalInstance )
  919. continue;
  920. if( decalInstance->mId != vecInstance.mId )
  921. continue;
  922. if ( mEditor->isMethod( "onDeleteInstance" ) )
  923. {
  924. char buffer[512];
  925. dSprintf(buffer, 512, "%i", decalInstance->mId);
  926. Con::executef( mEditor, "onDeleteInstance", String(buffer).c_str(), decalInstance->mDataBlock->lookupName.c_str() );
  927. }
  928. // Decal manager handles clearing the vector if the decal contains a valid id
  929. if( mEditor->mSELDecal == decalInstance )
  930. mEditor->mSELDecal = NULL;
  931. if( mEditor->mHLDecal == decalInstance )
  932. mEditor->mHLDecal = NULL;
  933. gDecalManager->removeDecal( decalInstance );
  934. break;
  935. }
  936. }
  937. DecalData * datablock = dynamic_cast<DecalData *>( Sim::findObject( mDatablockId ) );
  938. if ( mEditor->isMethod( "redoDeleteDecalDatablock" ) )
  939. Con::executef( mEditor, "redoDeleteDecalDatablock", datablock->lookupName.c_str());
  940. }
  941. //------------------------------
  942. //Decal Datablock Retarget Undo Actions
  943. IMPLEMENT_CONOBJECT( DBRetargetUndoAction );
  944. ConsoleDocClass( DBRetargetUndoAction,
  945. "@brief Decal Datablock Retarget Undo Actions\n\n"
  946. "Not intended for game development, for editors or internal use only.\n\n "
  947. "@internal");
  948. DBRetargetUndoAction::DBRetargetUndoAction( const UTF8 *actionName )
  949. : UndoAction( actionName ), mEditor(0), mDBFromId(0), mDBToId(0)
  950. {
  951. }
  952. DBRetargetUndoAction::~DBRetargetUndoAction()
  953. {
  954. }
  955. void DBRetargetUndoAction::initPersistFields()
  956. {
  957. Parent::initPersistFields();
  958. }
  959. void DBRetargetUndoAction::retargetDecal( DecalInstance* decal )
  960. {
  961. mDecalInstanceVec.increment();
  962. mDecalInstanceVec.last() = decal;
  963. }
  964. void DBRetargetUndoAction::undo()
  965. {
  966. DecalData * ptrFrom = dynamic_cast<DecalData*> ( Sim::findObject(mDBFromId) );
  967. if( !ptrFrom )
  968. return;
  969. Vector<DecalInstance *>::iterator iter;
  970. for(iter = mDecalInstanceVec.begin();iter != mDecalInstanceVec.end();iter++)
  971. {
  972. (*iter)->mDataBlock = ptrFrom;
  973. mEditor->forceRedraw((*iter));
  974. }
  975. if ( mEditor->isMethod( "rebuildInstanceTree" ) )
  976. Con::executef( mEditor, "rebuildInstanceTree" );
  977. }
  978. void DBRetargetUndoAction::redo()
  979. {
  980. DecalData * ptrTo = dynamic_cast<DecalData*> ( Sim::findObject(mDBToId) );
  981. if( !ptrTo )
  982. return;
  983. Vector<DecalInstance *>::iterator iter;
  984. for(iter = mDecalInstanceVec.begin();iter != mDecalInstanceVec.end();iter++)
  985. {
  986. (*iter)->mDataBlock = ptrTo;
  987. mEditor->forceRedraw((*iter));
  988. }
  989. if ( mEditor->isMethod( "rebuildInstanceTree" ) )
  990. Con::executef( mEditor, "rebuildInstanceTree" );
  991. }
  992. #endif