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 "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. mSELDecal->mSize = (scale.x + scale.y) * 0.5f;
  322. else if ( mGizmo->getMode() == MoveMode )
  323. mSELDecal->mPosition = gizmoPos;
  324. else if ( mGizmo->getMode() == RotateMode )
  325. {
  326. mSELDecal->mNormal = upVec;
  327. mSELDecal->mTangent = rightVec;
  328. }
  329. gDecalManager->notifyDecalModified( mSELDecal );
  330. Con::executef( this, "syncNodeDetails" );
  331. }
  332. }
  333. void GuiDecalEditorCtrl::on3DMouseEnter(const Gui3DMouseEvent & event)
  334. {
  335. // nothing to do
  336. }
  337. void GuiDecalEditorCtrl::on3DMouseLeave(const Gui3DMouseEvent & event)
  338. {
  339. // nothing to do
  340. }
  341. void GuiDecalEditorCtrl::updateGuiInfo()
  342. {
  343. // nothing to do
  344. }
  345. void GuiDecalEditorCtrl::onRender( Point2I offset, const RectI &updateRect )
  346. {
  347. Parent::onRender( offset, updateRect );
  348. }
  349. void GuiDecalEditorCtrl::renderGui( Point2I offset, const RectI &updateRect )
  350. {
  351. Parent::renderGui( offset, updateRect );
  352. PROFILE_SCOPE( GuiDecalEditorCtrl_renderGui );
  353. // Show the pixelSize of the selected decal as a text overlay.
  354. if ( smRenderDecalPixelSize && mSELDecal != NULL )
  355. {
  356. const F32 pixelSize = mSELDecal->calcPixelSize( mSaveViewport.extent.y, mLastCameraQuery.cameraMatrix.getPosition(), mSaveWorldToScreenScale.y );
  357. // Find position onscreen to render the text.
  358. Point3F screenPos;
  359. bool onScreen = project( mSELDecal->mPosition, &screenPos );
  360. if ( onScreen )
  361. {
  362. // It is extremely annoying to require the GuiProfile to have a font
  363. // or to create one within the decal editor for only this single use,
  364. // so we instead rely on the fact that we already have a Gizmo, that
  365. // all Gizmo's have a GizmoProfile, and that GizmoProfile has a font.
  366. GFont *font = mGizmo->getProfile()->font;
  367. // Might as well use some colors defined in GizmoProfile too instead
  368. // of just hardcoding it here.
  369. const ColorI bgColor = mGizmo->getProfile()->inActiveColor;
  370. const ColorI textColor = mGizmo->getProfile()->activeColor;
  371. // Note: This mostly mirrors the way WorldEditor renders popupText for
  372. // the gizmo during a drag operation, consider unifying this into a utility method.
  373. char buf[256];
  374. dSprintf( buf, 256, "%0.3f", pixelSize );
  375. const U32 width = font->getStrWidth((const UTF8 *)buf);;
  376. const Point2I posi( (U32)screenPos.x, (U32)screenPos.y + 12 );
  377. const Point2I minPt(posi.x - width / 2 - 2, posi.y - 1);
  378. const Point2I maxPt(posi.x + width / 2 + 2, posi.y + font->getHeight() + 1);
  379. GFXDrawUtil *drawer = GFX->getDrawUtil();
  380. drawer->drawRectFill( minPt, maxPt, bgColor );
  381. GFX->getDrawUtil()->setBitmapModulation( textColor );
  382. GFX->getDrawUtil()->drawText( mProfile->mFont, Point2I( posi.x - width / 2, posi.y ), buf );
  383. }
  384. }
  385. }
  386. void GuiDecalEditorCtrl::renderScene(const RectI & updateRect)
  387. {
  388. PROFILE_SCOPE( GuiDecalEditorCtrl_renderScene );
  389. GFXTransformSaver saver;
  390. RectI bounds = getBounds();
  391. ColorI hlColor(0,255,0,255);
  392. ColorI regColor(255,0,0,255);
  393. ColorI selColor(0,0,255,255);
  394. ColorI color;
  395. GFXDrawUtil *drawUtil = GFX->getDrawUtil();
  396. GFXStateBlockDesc desc;
  397. desc.setBlend( true );
  398. desc.setZReadWrite( true, false );
  399. // Draw 3D stuff here.
  400. if ( mSELDecal )
  401. {
  402. mGizmo->renderGizmo( mLastCameraQuery.cameraMatrix, mLastCameraQuery.fov );
  403. mSELEdgeVerts.clear();
  404. if ( gDecalManager->clipDecal( mSELDecal, &mSELEdgeVerts ) )
  405. _renderDecalEdge( mSELEdgeVerts, ColorI( 255, 255, 255, 255 ) );
  406. const F32 &decalSize = mSELDecal->mSize;
  407. Point3F boxSize( decalSize, decalSize, decalSize );
  408. MatrixF worldMat( true );
  409. mSELDecal->getWorldMatrix( &worldMat, true );
  410. drawUtil->drawObjectBox( desc, boxSize, mSELDecal->mPosition, worldMat, ColorI( 255, 255, 255, 255 ) );
  411. }
  412. if ( mHLDecal )
  413. {
  414. mHLEdgeVerts.clear();
  415. if ( gDecalManager->clipDecal( mHLDecal, &mHLEdgeVerts ) )
  416. _renderDecalEdge( mHLEdgeVerts, ColorI( 255, 255, 255, 255 ) );
  417. const F32 &decalSize = mHLDecal->mSize;
  418. Point3F boxSize( decalSize, decalSize, decalSize );
  419. MatrixF worldMat( true );
  420. mHLDecal->getWorldMatrix( &worldMat, true );
  421. drawUtil->drawObjectBox( desc, boxSize, mHLDecal->mPosition, worldMat, ColorI( 255, 255, 255, 255 ) );
  422. }
  423. }
  424. void GuiDecalEditorCtrl::forceRedraw( DecalInstance * decalInstance )
  425. {
  426. // This should be redundant because the decal is already reclipped
  427. // on each frame. Also it is not possible execute rendering code like
  428. // this in response to UI events from script.
  429. /*
  430. if ( !decalInstance )
  431. return;
  432. GFXDrawUtil *drawUtil = GFX->getDrawUtil();
  433. GFXStateBlockDesc desc;
  434. desc.setBlend( true );
  435. desc.setZReadWrite( true, false );
  436. Vector<Point3F> verts;
  437. verts.clear();
  438. if ( gDecalManager->clipDecal( decalInstance, &verts ) )
  439. if ( gDecalManager->clipDecal( decalInstance, &verts ) )
  440. _renderDecalEdge( verts, ColorI( 255, 255, 255, 255 ) );
  441. const F32 &decalSize = decalInstance->mSize;
  442. Point3F boxSize( decalSize, decalSize, decalSize );
  443. MatrixF worldMat( true );
  444. decalInstance->getWorldMatrix( &worldMat, true );
  445. drawUtil->drawObjectBox( desc, boxSize, decalInstance->mPosition, worldMat, ColorI( 255, 255, 255, 255 ) );
  446. */
  447. }
  448. void GuiDecalEditorCtrl::_renderDecalEdge( const Vector<Point3F> &verts, const ColorI &color )
  449. {
  450. U32 vertCount = verts.size();
  451. GFXTransformSaver saver;
  452. PrimBuild::color( color );
  453. Point3F endPt( 0, 0, 0 );
  454. for ( U32 i = 0; i < vertCount; i++ )
  455. {
  456. const Point3F &vert = verts[i];
  457. if ( i + 1 < vertCount )
  458. endPt = verts[i + 1];
  459. else
  460. break;
  461. PrimBuild::begin( GFXLineList, 2 );
  462. PrimBuild::vertex3f( vert.x, vert.y, vert.z );
  463. PrimBuild::vertex3f( endPt.x, endPt.y, endPt.z );
  464. PrimBuild::end();
  465. }
  466. }
  467. bool GuiDecalEditorCtrl::getRayInfo( const Gui3DMouseEvent & event, RayInfo *rInfo )
  468. {
  469. Point3F startPnt = event.pos;
  470. Point3F endPnt = event.pos + event.vec * 3000.0f;
  471. bool hit;
  472. hit = gServerContainer.castRayRendered( startPnt, endPnt, STATIC_COLLISION_TYPEMASK, rInfo );
  473. return hit;
  474. }
  475. void GuiDecalEditorCtrl::selectDecal( DecalInstance *decalInst )
  476. {
  477. // If id is zero or invalid we set the selected decal to null
  478. // which is correct.
  479. mSELDecal = decalInst;
  480. if ( decalInst )
  481. setGizmoFocus( decalInst );
  482. }
  483. void GuiDecalEditorCtrl::deleteSelectedDecal()
  484. {
  485. if ( !mSELDecal )
  486. return;
  487. // Grab the mission editor undo manager.
  488. UndoManager *undoMan = NULL;
  489. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  490. {
  491. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  492. return;
  493. }
  494. // Create the UndoAction.
  495. DIDeleteUndoAction *action = new DIDeleteUndoAction("Delete Decal");
  496. action->deleteDecal( *mSELDecal );
  497. action->mEditor = this;
  498. // Submit it.
  499. undoMan->addAction( action );
  500. if ( isMethod( "onDeleteInstance" ) )
  501. {
  502. char buffer[512];
  503. dSprintf(buffer, 512, "%i", mSELDecal->mId);
  504. Con::executef( this, "onDeleteInstance", String(buffer).c_str(), mSELDecal->mDataBlock->lookupName.c_str() );
  505. }
  506. gDecalManager->removeDecal( mSELDecal );
  507. mSELDecal = NULL;
  508. }
  509. void GuiDecalEditorCtrl::deleteDecalDatablock( String lookupName )
  510. {
  511. DecalData * datablock = dynamic_cast<DecalData*> ( Sim::findObject(lookupName.c_str()) );
  512. if( !datablock )
  513. return;
  514. // Grab the mission editor undo manager.
  515. UndoManager *undoMan = NULL;
  516. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  517. {
  518. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  519. return;
  520. }
  521. // Create the UndoAction.
  522. DBDeleteUndoAction *action = new DBDeleteUndoAction("Delete Decal Datablock");
  523. action->mEditor = this;
  524. action->mDatablockId = datablock->getId();
  525. Vector<DecalInstance*> mDecalQueue;
  526. Vector<DecalInstance *>::iterator iter;
  527. mDecalQueue.clear();
  528. const Vector<DecalSphere*> &grid = gDecalManager->getDecalDataFile()->getSphereList();
  529. for ( U32 i = 0; i < grid.size(); i++ )
  530. {
  531. const DecalSphere *decalSphere = grid[i];
  532. mDecalQueue.merge( decalSphere->mItems );
  533. }
  534. for ( iter = mDecalQueue.begin();iter != mDecalQueue.end();iter++ )
  535. {
  536. if( !(*iter) )
  537. continue;
  538. if( (*iter)->mDataBlock->lookupName.compare( lookupName ) == 0 )
  539. {
  540. if( (*iter)->mId != -1 )
  541. {
  542. //make sure to call onDeleteInstance as well
  543. if ( isMethod( "onDeleteInstance" ) )
  544. {
  545. char buffer[512];
  546. dSprintf(buffer, 512, "%i", (*iter)->mId);
  547. Con::executef( this, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
  548. }
  549. action->deleteDecal( *(*iter) );
  550. if( mSELDecal == (*iter) )
  551. mSELDecal = NULL;
  552. if( mHLDecal == (*iter) )
  553. mHLDecal = NULL;
  554. }
  555. gDecalManager->removeDecal( (*iter) );
  556. }
  557. }
  558. undoMan->addAction( action );
  559. mCurrentDecalData = NULL;
  560. }
  561. void GuiDecalEditorCtrl::retargetDecalDatablock( String dbFrom, String dbTo )
  562. {
  563. DecalData * ptrFrom = dynamic_cast<DecalData*> ( Sim::findObject(dbFrom.c_str()) );
  564. DecalData * ptrTo = dynamic_cast<DecalData*> ( Sim::findObject(dbTo.c_str()) );
  565. if( !ptrFrom || !ptrTo )
  566. return;
  567. // Grab the mission editor undo manager.
  568. UndoManager *undoMan = NULL;
  569. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  570. {
  571. Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
  572. return;
  573. }
  574. // Create the UndoAction.
  575. DBRetargetUndoAction *action = new DBRetargetUndoAction("Retarget Decal Datablock");
  576. action->mEditor = this;
  577. action->mDBFromId = ptrFrom->getId();
  578. action->mDBToId = ptrTo->getId();
  579. Vector<DecalInstance*> mDecalQueue;
  580. Vector<DecalInstance *>::iterator iter;
  581. mDecalQueue.clear();
  582. const Vector<DecalSphere*> &grid = gDecalManager->getDecalDataFile()->getSphereList();
  583. for ( U32 i = 0; i < grid.size(); i++ )
  584. {
  585. const DecalSphere *decalSphere = grid[i];
  586. mDecalQueue.merge( decalSphere->mItems );
  587. }
  588. for ( iter = mDecalQueue.begin();iter != mDecalQueue.end();iter++ )
  589. {
  590. if( !(*iter) )
  591. continue;
  592. if( (*iter)->mDataBlock->lookupName.compare( dbFrom ) == 0 )
  593. {
  594. if( (*iter)->mId != -1 )
  595. {
  596. action->retargetDecal((*iter));
  597. (*iter)->mDataBlock = ptrTo;
  598. forceRedraw((*iter));
  599. }
  600. }
  601. }
  602. undoMan->addAction( action );
  603. }
  604. void GuiDecalEditorCtrl::setMode( String mode, bool sourceShortcut = false )
  605. {
  606. if( mode.compare("SelectDecalMode") == 0)
  607. mGizmo->getProfile()->mode = NoneMode;
  608. else if( mode.compare("AddDecalMode") == 0)
  609. mGizmo->getProfile()->mode = NoneMode;
  610. else if( mode.compare("MoveDecalMode") == 0)
  611. mGizmo->getProfile()->mode = MoveMode;
  612. else if( mode.compare("RotateDecalMode") == 0)
  613. mGizmo->getProfile()->mode = RotateMode;
  614. else if( mode.compare("ScaleDecalMode") == 0)
  615. mGizmo->getProfile()->mode = ScaleMode;
  616. mMode = mode;
  617. if( sourceShortcut )
  618. Con::executef( this, "paletteSync", mMode );
  619. }
  620. ConsoleMethod( GuiDecalEditorCtrl, deleteSelectedDecal, void, 2, 2, "deleteSelectedDecal()" )
  621. {
  622. object->deleteSelectedDecal();
  623. }
  624. ConsoleMethod( GuiDecalEditorCtrl, deleteDecalDatablock, void, 3, 3, "deleteSelectedDecalDatablock( String datablock )" )
  625. {
  626. String lookupName( argv[2] );
  627. if( lookupName == String::EmptyString )
  628. return;
  629. object->deleteDecalDatablock( lookupName );
  630. }
  631. ConsoleMethod( GuiDecalEditorCtrl, setMode, void, 3, 3, "setMode( String mode )()" )
  632. {
  633. String newMode = ( argv[2] );
  634. object->setMode( newMode );
  635. }
  636. ConsoleMethod( GuiDecalEditorCtrl, getMode, const char*, 2, 2, "getMode()" )
  637. {
  638. return object->mMode;
  639. }
  640. ConsoleMethod( GuiDecalEditorCtrl, getDecalCount, S32, 2, 2, "getDecalCount()" )
  641. {
  642. return gDecalManager->mDecalInstanceVec.size();
  643. }
  644. ConsoleMethod( GuiDecalEditorCtrl, getDecalTransform, const char*, 3, 3, "getDecalTransform()" )
  645. {
  646. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  647. if( decalInstance == NULL )
  648. return "";
  649. char* returnBuffer = Con::getReturnBuffer(256);
  650. returnBuffer[0] = 0;
  651. if ( decalInstance )
  652. {
  653. dSprintf(returnBuffer, 256, "%f %f %f %f %f %f %f",
  654. decalInstance->mPosition.x, decalInstance->mPosition.y, decalInstance->mPosition.z,
  655. decalInstance->mTangent.x, decalInstance->mTangent.y, decalInstance->mTangent.z,
  656. decalInstance->mSize);
  657. }
  658. return returnBuffer;
  659. }
  660. ConsoleMethod( GuiDecalEditorCtrl, getDecalLookupName, const char*, 3, 3, "getDecalLookupName( S32 )()" )
  661. {
  662. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  663. if( decalInstance == NULL )
  664. return "invalid";
  665. return decalInstance->mDataBlock->lookupName;
  666. }
  667. ConsoleMethod( GuiDecalEditorCtrl, selectDecal, void, 3, 3, "selectDecal( S32 )()" )
  668. {
  669. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[dAtoi(argv[2])];
  670. if( decalInstance == NULL )
  671. return;
  672. object->selectDecal( decalInstance );
  673. }
  674. ConsoleMethod( GuiDecalEditorCtrl, editDecalDetails, void, 4, 4, "editDecalDetails( S32 )()" )
  675. {
  676. DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[ dAtoi(argv[2]) ];
  677. if( decalInstance == NULL )
  678. return;
  679. Point3F pos;
  680. Point3F tan;
  681. F32 size;
  682. S32 count = dSscanf( argv[3], "%f %f %f %f %f %f %f",
  683. &pos.x, &pos.y, &pos.z, &tan.x, &tan.y, &tan.z, &size);
  684. if ( (count != 7) )
  685. {
  686. Con::printf("Failed to parse decal information \"px py pz tx ty tz s\" from '%s'", argv[3]);
  687. return;
  688. }
  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. ConsoleMethod( GuiDecalEditorCtrl, getSelectionCount, S32, 2, 2, "" )
  698. {
  699. if ( object->mSELDecal != NULL )
  700. return 1;
  701. return 0;
  702. }
  703. ConsoleMethod( GuiDecalEditorCtrl, retargetDecalDatablock, void, 4, 4, "" )
  704. {
  705. if( dStrcmp( argv[2], "" ) != 0 && dStrcmp( argv[3], "" ) != 0 )
  706. object->retargetDecalDatablock( argv[2], argv[3] );
  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 )
  724. {
  725. }
  726. DICreateUndoAction::~DICreateUndoAction()
  727. {
  728. }
  729. void DICreateUndoAction::initPersistFields()
  730. {
  731. Parent::initPersistFields();
  732. }
  733. void DICreateUndoAction::addDecal( 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 )
  794. {
  795. }
  796. DIDeleteUndoAction::~DIDeleteUndoAction()
  797. {
  798. }
  799. void DIDeleteUndoAction::initPersistFields()
  800. {
  801. Parent::initPersistFields();
  802. }
  803. void DIDeleteUndoAction::deleteDecal( 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 )
  864. {
  865. }
  866. DBDeleteUndoAction::~DBDeleteUndoAction()
  867. {
  868. }
  869. void DBDeleteUndoAction::initPersistFields()
  870. {
  871. Parent::initPersistFields();
  872. }
  873. void DBDeleteUndoAction::deleteDecal( 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 )
  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