PageRenderTime 24ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloatermodelwizard.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 795 lines | 571 code | 152 blank | 72 comment | 90 complexity | b1204154f5c35b07908b45786cf73eca MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloatermodelwizard.cpp
  3. * @author Leyla Farazha
  4. * @brief Implementation of the LLFloaterModelWizard class.
  5. *
  6. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llbutton.h"
  29. #include "lldrawable.h"
  30. #include "llcheckboxctrl.h"
  31. #include "llcombobox.h"
  32. #include "llfloater.h"
  33. #include "llfloatermodelwizard.h"
  34. #include "llfloatermodelpreview.h"
  35. #include "llfloaterreg.h"
  36. #include "llsliderctrl.h"
  37. #include "lltoolmgr.h"
  38. #include "llviewerwindow.h"
  39. LLFloaterModelWizard* LLFloaterModelWizard::sInstance = NULL;
  40. static const std::string stateNames[]={
  41. "choose_file",
  42. "optimize",
  43. "physics",
  44. "review",
  45. "upload"};
  46. static void swap_controls(LLUICtrl* first_ctrl, LLUICtrl* second_ctrl, bool first_ctr_visible);
  47. LLFloaterModelWizard::LLFloaterModelWizard(const LLSD& key)
  48. : LLFloaterModelUploadBase(key)
  49. ,mRecalculateGeometryBtn(NULL)
  50. ,mRecalculatePhysicsBtn(NULL)
  51. ,mRecalculatingPhysicsBtn(NULL)
  52. ,mCalculateWeightsBtn(NULL)
  53. ,mCalculatingWeightsBtn(NULL)
  54. ,mChooseFilePreviewPanel(NULL)
  55. ,mOptimizePreviewPanel(NULL)
  56. ,mPhysicsPreviewPanel(NULL)
  57. {
  58. mLastEnabledState = CHOOSE_FILE;
  59. sInstance = this;
  60. mCommitCallbackRegistrar.add("Wizard.Choose", boost::bind(&LLFloaterModelWizard::setState, this, CHOOSE_FILE));
  61. mCommitCallbackRegistrar.add("Wizard.Optimize", boost::bind(&LLFloaterModelWizard::setState, this, OPTIMIZE));
  62. mCommitCallbackRegistrar.add("Wizard.Physics", boost::bind(&LLFloaterModelWizard::setState, this, PHYSICS));
  63. mCommitCallbackRegistrar.add("Wizard.Review", boost::bind(&LLFloaterModelWizard::setState, this, REVIEW));
  64. mCommitCallbackRegistrar.add("Wizard.Upload", boost::bind(&LLFloaterModelWizard::setState, this, UPLOAD));
  65. }
  66. LLFloaterModelWizard::~LLFloaterModelWizard()
  67. {
  68. sInstance = NULL;
  69. }
  70. void LLFloaterModelWizard::setState(int state)
  71. {
  72. mState = state;
  73. for(size_t t=0; t<LL_ARRAY_SIZE(stateNames); ++t)
  74. {
  75. LLView *view = getChildView(stateNames[t]+"_panel");
  76. if (view)
  77. {
  78. view->setVisible(state == (int) t ? TRUE : FALSE);
  79. }
  80. }
  81. LLView* current_preview_panel = NULL;
  82. if (state == CHOOSE_FILE)
  83. {
  84. mModelPreview->mViewOption["show_physics"] = false;
  85. current_preview_panel = mChooseFilePreviewPanel;
  86. getChildView("close")->setVisible(false);
  87. getChildView("back")->setVisible(true);
  88. getChildView("back")->setEnabled(false);
  89. getChildView("next")->setVisible(true);
  90. getChildView("upload")->setVisible(false);
  91. getChildView("cancel")->setVisible(true);
  92. mCalculateWeightsBtn->setVisible(false);
  93. mCalculatingWeightsBtn->setVisible(false);
  94. }
  95. if (state == OPTIMIZE)
  96. {
  97. if (mLastEnabledState < state)
  98. {
  99. mModelPreview->genLODs(-1);
  100. }
  101. mModelPreview->mViewOption["show_physics"] = false;
  102. current_preview_panel = mOptimizePreviewPanel;
  103. getChildView("back")->setVisible(true);
  104. getChildView("back")->setEnabled(true);
  105. getChildView("close")->setVisible(false);
  106. getChildView("next")->setVisible(true);
  107. getChildView("upload")->setVisible(false);
  108. getChildView("cancel")->setVisible(true);
  109. mCalculateWeightsBtn->setVisible(false);
  110. mCalculatingWeightsBtn->setVisible(false);
  111. }
  112. if (state == PHYSICS)
  113. {
  114. if (mLastEnabledState < state)
  115. {
  116. mModelPreview->setPhysicsFromLOD(1);
  117. // Trigger the recalculate physics when first entering
  118. // the Physics step.
  119. onClickRecalculatePhysics();
  120. }
  121. mModelPreview->mViewOption["show_physics"] = true;
  122. current_preview_panel = mPhysicsPreviewPanel;
  123. getChildView("next")->setVisible(false);
  124. getChildView("upload")->setVisible(false);
  125. getChildView("close")->setVisible(false);
  126. getChildView("back")->setVisible(true);
  127. getChildView("back")->setEnabled(true);
  128. getChildView("cancel")->setVisible(true);
  129. mCalculateWeightsBtn->setVisible(true);
  130. mCalculatingWeightsBtn->setVisible(false);
  131. }
  132. if (state == REVIEW)
  133. {
  134. mModelPreview->mViewOption["show_physics"] = false;
  135. getChildView("close")->setVisible(false);
  136. getChildView("next")->setVisible(false);
  137. getChildView("back")->setVisible(true);
  138. getChildView("back")->setEnabled(true);
  139. getChildView("upload")->setVisible(true);
  140. getChildView("cancel")->setVisible(true);
  141. mCalculateWeightsBtn->setVisible(false);
  142. mCalculatingWeightsBtn->setVisible(false);
  143. }
  144. if (state == UPLOAD)
  145. {
  146. getChildView("close")->setVisible(true);
  147. getChildView("next")->setVisible(false);
  148. getChildView("back")->setVisible(false);
  149. getChildView("upload")->setVisible(false);
  150. getChildView("cancel")->setVisible(false);
  151. mCalculateWeightsBtn->setVisible(false);
  152. mCalculatingWeightsBtn->setVisible(false);
  153. }
  154. if (current_preview_panel)
  155. {
  156. LLRect rect;
  157. current_preview_panel->localRectToOtherView(current_preview_panel->getLocalRect(), &rect, this);
  158. // Reduce the preview rect by 1 px to fit the borders
  159. rect.stretch(-1);
  160. if (rect != mPreviewRect)
  161. {
  162. mPreviewRect = rect;
  163. mModelPreview->refresh();
  164. }
  165. }
  166. updateButtons();
  167. }
  168. void LLFloaterModelWizard::updateButtons()
  169. {
  170. if (mLastEnabledState < mState)
  171. {
  172. mLastEnabledState = mState;
  173. }
  174. for(size_t i=0; i<LL_ARRAY_SIZE(stateNames); ++i)
  175. {
  176. LLButton *button = getChild<LLButton>(stateNames[i]+"_btn");
  177. if (i == mState)
  178. {
  179. button->setEnabled(TRUE);
  180. button->setToggleState(TRUE);
  181. }
  182. else if (i <= mLastEnabledState)
  183. {
  184. button->setEnabled(TRUE);
  185. button->setToggleState(FALSE);
  186. }
  187. else
  188. {
  189. button->setEnabled(FALSE);
  190. }
  191. }
  192. }
  193. void LLFloaterModelWizard::onClickSwitchToAdvanced()
  194. {
  195. LLFloaterModelPreview* floater_preview = LLFloaterReg::getTypedInstance<LLFloaterModelPreview>("upload_model");
  196. if (!floater_preview)
  197. {
  198. llwarns << "FLoater model preview not found." << llendl;
  199. return;
  200. }
  201. // Open floater model preview
  202. floater_preview->openFloater();
  203. // Close the wizard
  204. closeFloater();
  205. std::string filename = getChild<LLUICtrl>("lod_file")->getValue().asString();
  206. if (!filename.empty())
  207. {
  208. // Re-load the model to the floater model preview if it has been loaded
  209. // into the wizard.
  210. floater_preview->loadModel(3, filename);
  211. }
  212. }
  213. void LLFloaterModelWizard::onClickRecalculateGeometry()
  214. {
  215. S32 val = getChild<LLUICtrl>("accuracy_slider")->getValue().asInteger();
  216. mModelPreview->genLODs(-1, NUM_LOD - val);
  217. mModelPreview->refresh();
  218. }
  219. void LLFloaterModelWizard::onClickRecalculatePhysics()
  220. {
  221. // Hide the "Recalculate physics" button and show the "Recalculating..."
  222. // button instead.
  223. swap_controls(mRecalculatePhysicsBtn, mRecalculatingPhysicsBtn, false);
  224. executePhysicsStage("Decompose");
  225. }
  226. void LLFloaterModelWizard::onClickCalculateUploadFee()
  227. {
  228. swap_controls(mCalculateWeightsBtn, mCalculatingWeightsBtn, false);
  229. mModelPreview->rebuildUploadData();
  230. mUploadModelUrl.clear();
  231. gMeshRepo.uploadModel(mModelPreview->mUploadData, mModelPreview->mPreviewScale,
  232. true, false, false, mUploadModelUrl, false, getWholeModelFeeObserverHandle());
  233. }
  234. void LLFloaterModelWizard::loadModel()
  235. {
  236. mModelPreview->mLoading = TRUE;
  237. (new LLMeshFilePicker(mModelPreview, 3))->getFile();
  238. }
  239. void LLFloaterModelWizard::onClickCancel()
  240. {
  241. closeFloater();
  242. }
  243. void LLFloaterModelWizard::onClickBack()
  244. {
  245. setState(llmax((int) CHOOSE_FILE, mState-1));
  246. }
  247. void LLFloaterModelWizard::onClickNext()
  248. {
  249. setState(llmin((int) UPLOAD, mState+1));
  250. }
  251. bool LLFloaterModelWizard::onEnableNext()
  252. {
  253. return true;
  254. }
  255. bool LLFloaterModelWizard::onEnableBack()
  256. {
  257. return true;
  258. }
  259. //-----------------------------------------------------------------------------
  260. // handleMouseDown()
  261. //-----------------------------------------------------------------------------
  262. BOOL LLFloaterModelWizard::handleMouseDown(S32 x, S32 y, MASK mask)
  263. {
  264. if (mPreviewRect.pointInRect(x, y))
  265. {
  266. bringToFront( x, y );
  267. gFocusMgr.setMouseCapture(this);
  268. gViewerWindow->hideCursor();
  269. mLastMouseX = x;
  270. mLastMouseY = y;
  271. return TRUE;
  272. }
  273. return LLFloater::handleMouseDown(x, y, mask);
  274. }
  275. //-----------------------------------------------------------------------------
  276. // handleMouseUp()
  277. //-----------------------------------------------------------------------------
  278. BOOL LLFloaterModelWizard::handleMouseUp(S32 x, S32 y, MASK mask)
  279. {
  280. gFocusMgr.setMouseCapture(FALSE);
  281. gViewerWindow->showCursor();
  282. return LLFloater::handleMouseUp(x, y, mask);
  283. }
  284. //-----------------------------------------------------------------------------
  285. // handleHover()
  286. //-----------------------------------------------------------------------------
  287. BOOL LLFloaterModelWizard::handleHover (S32 x, S32 y, MASK mask)
  288. {
  289. MASK local_mask = mask & ~MASK_ALT;
  290. if (mModelPreview && hasMouseCapture())
  291. {
  292. if (local_mask == MASK_PAN)
  293. {
  294. // pan here
  295. mModelPreview->pan((F32)(x - mLastMouseX) * -0.005f, (F32)(y - mLastMouseY) * -0.005f);
  296. }
  297. else if (local_mask == MASK_ORBIT)
  298. {
  299. F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
  300. F32 pitch_radians = (F32)(y - mLastMouseY) * 0.02f;
  301. mModelPreview->rotate(yaw_radians, pitch_radians);
  302. }
  303. else
  304. {
  305. F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
  306. F32 zoom_amt = (F32)(y - mLastMouseY) * 0.02f;
  307. mModelPreview->rotate(yaw_radians, 0.f);
  308. mModelPreview->zoom(zoom_amt);
  309. }
  310. mModelPreview->refresh();
  311. LLUI::setMousePositionLocal(this, mLastMouseX, mLastMouseY);
  312. }
  313. if (!mPreviewRect.pointInRect(x, y) || !mModelPreview)
  314. {
  315. return LLFloater::handleHover(x, y, mask);
  316. }
  317. else if (local_mask == MASK_ORBIT)
  318. {
  319. gViewerWindow->setCursor(UI_CURSOR_TOOLCAMERA);
  320. }
  321. else if (local_mask == MASK_PAN)
  322. {
  323. gViewerWindow->setCursor(UI_CURSOR_TOOLPAN);
  324. }
  325. else
  326. {
  327. gViewerWindow->setCursor(UI_CURSOR_TOOLZOOMIN);
  328. }
  329. return TRUE;
  330. }
  331. //-----------------------------------------------------------------------------
  332. // handleScrollWheel()
  333. //-----------------------------------------------------------------------------
  334. BOOL LLFloaterModelWizard::handleScrollWheel(S32 x, S32 y, S32 clicks)
  335. {
  336. if (mPreviewRect.pointInRect(x, y) && mModelPreview)
  337. {
  338. mModelPreview->zoom((F32)clicks * -0.2f);
  339. mModelPreview->refresh();
  340. }
  341. return TRUE;
  342. }
  343. void LLFloaterModelWizard::initDecompControls()
  344. {
  345. LLSD key;
  346. static const LLCDStageData* stage = NULL;
  347. static S32 stage_count = 0;
  348. if (!stage && LLConvexDecomposition::getInstance() != NULL)
  349. {
  350. stage_count = LLConvexDecomposition::getInstance()->getStages(&stage);
  351. }
  352. static const LLCDParam* param = NULL;
  353. static S32 param_count = 0;
  354. if (!param && LLConvexDecomposition::getInstance() != NULL)
  355. {
  356. param_count = LLConvexDecomposition::getInstance()->getParameters(&param);
  357. }
  358. for (S32 j = stage_count-1; j >= 0; --j)
  359. {
  360. gMeshRepo.mDecompThread->mStageID[stage[j].mName] = j;
  361. // protected against stub by stage_count being 0 for stub above
  362. LLConvexDecomposition::getInstance()->registerCallback(j, LLPhysicsDecomp::llcdCallback);
  363. for (S32 i = 0; i < param_count; ++i)
  364. {
  365. if (param[i].mStage != j)
  366. {
  367. continue;
  368. }
  369. std::string name(param[i].mName ? param[i].mName : "");
  370. std::string description(param[i].mDescription ? param[i].mDescription : "");
  371. if (param[i].mType == LLCDParam::LLCD_FLOAT)
  372. {
  373. mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mFloat);
  374. }
  375. else if (param[i].mType == LLCDParam::LLCD_INTEGER)
  376. {
  377. mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mIntOrEnumValue);
  378. }
  379. else if (param[i].mType == LLCDParam::LLCD_BOOLEAN)
  380. {
  381. mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mBool);
  382. }
  383. else if (param[i].mType == LLCDParam::LLCD_ENUM)
  384. {
  385. mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mIntOrEnumValue);
  386. }
  387. }
  388. }
  389. mDecompParams["Simplify Method"] = 0; // set it to retain %
  390. }
  391. /*virtual*/
  392. void LLFloaterModelWizard::onPermissionsReceived(const LLSD& result)
  393. {
  394. std::string upload_status = result["mesh_upload_status"].asString();
  395. // BAP HACK: handle "" for case that MeshUploadFlag cap is broken.
  396. mHasUploadPerm = (("" == upload_status) || ("valid" == upload_status));
  397. getChildView("warning_label")->setVisible(!mHasUploadPerm);
  398. getChildView("warning_text")->setVisible(!mHasUploadPerm);
  399. }
  400. /*virtual*/
  401. void LLFloaterModelWizard::setPermissonsErrorStatus(U32 status, const std::string& reason)
  402. {
  403. llwarns << "LLFloaterModelWizard::setPermissonsErrorStatus(" << status << " : " << reason << ")" << llendl;
  404. }
  405. /*virtual*/
  406. void LLFloaterModelWizard::onModelPhysicsFeeReceived(const LLSD& result, std::string upload_url)
  407. {
  408. swap_controls(mCalculateWeightsBtn, mCalculatingWeightsBtn, true);
  409. // Enable the "Upload" buton if we have calculated the upload fee
  410. // and have the permission to upload.
  411. getChildView("upload")->setEnabled(mHasUploadPerm);
  412. mUploadModelUrl = upload_url;
  413. S32 fee = result["upload_price"].asInteger();
  414. childSetTextArg("review_fee", "[FEE]", llformat("%d", fee));
  415. childSetTextArg("charged_fee", "[FEE]", llformat("%d", fee));
  416. setState(REVIEW);
  417. }
  418. /*virtual*/
  419. void LLFloaterModelWizard::setModelPhysicsFeeErrorStatus(U32 status, const std::string& reason)
  420. {
  421. swap_controls(mCalculateWeightsBtn, mCalculatingWeightsBtn, true);
  422. // Disable the "Review" step if it has been previously enabled.
  423. modelChangedCallback();
  424. llwarns << "LLFloaterModelWizard::setModelPhysicsFeeErrorStatus(" << status << " : " << reason << ")" << llendl;
  425. setState(PHYSICS);
  426. }
  427. /*virtual*/
  428. void LLFloaterModelWizard::onModelUploadSuccess()
  429. {
  430. // success!
  431. setState(UPLOAD);
  432. }
  433. /*virtual*/
  434. void LLFloaterModelWizard::onModelUploadFailure()
  435. {
  436. // Failure. Make the user recalculate fees
  437. setState(PHYSICS);
  438. // Disable the "Review" step if it has been previously enabled.
  439. if (mLastEnabledState > PHYSICS)
  440. {
  441. mLastEnabledState = PHYSICS;
  442. }
  443. updateButtons();
  444. }
  445. //static
  446. void LLFloaterModelWizard::executePhysicsStage(std::string stage_name)
  447. {
  448. if (sInstance)
  449. {
  450. // Invert the slider value so that "performance" end is giving the least detailed physics,
  451. // and the "accuracy" end is giving the most detailed physics
  452. F64 physics_accuracy = 1 - sInstance->getChild<LLSliderCtrl>("physics_slider")->getValue().asReal();
  453. sInstance->mDecompParams["Retain%"] = physics_accuracy;
  454. if (!sInstance->mCurRequest.empty())
  455. {
  456. llinfos << "Decomposition request still pending." << llendl;
  457. return;
  458. }
  459. if (sInstance->mModelPreview)
  460. {
  461. for (S32 i = 0; i < sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS].size(); ++i)
  462. {
  463. LLModel* mdl = sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS][i];
  464. DecompRequest* request = new DecompRequest(stage_name, mdl);
  465. if(request->isValid())
  466. {
  467. sInstance->mCurRequest.insert(request);
  468. gMeshRepo.mDecompThread->submitRequest(request);
  469. }
  470. }
  471. }
  472. }
  473. }
  474. LLFloaterModelWizard::DecompRequest::DecompRequest(const std::string& stage, LLModel* mdl)
  475. {
  476. mStage = stage;
  477. mContinue = 1;
  478. mModel = mdl;
  479. mDecompID = &mdl->mDecompID;
  480. mParams = sInstance->mDecompParams;
  481. //copy out positions and indices
  482. assignData(mdl) ;
  483. }
  484. S32 LLFloaterModelWizard::DecompRequest::statusCallback(const char* status, S32 p1, S32 p2)
  485. {
  486. setStatusMessage(llformat("%s: %d/%d", status, p1, p2));
  487. return mContinue;
  488. }
  489. void LLFloaterModelWizard::DecompRequest::completed()
  490. { //called from the main thread
  491. mModel->setConvexHullDecomposition(mHull);
  492. if (sInstance)
  493. {
  494. if (sInstance->mModelPreview)
  495. {
  496. sInstance->mModelPreview->mDirty = true;
  497. LLFloaterModelWizard::sInstance->mModelPreview->refresh();
  498. }
  499. sInstance->mCurRequest.erase(this);
  500. }
  501. if (mStage == "Decompose")
  502. {
  503. executePhysicsStage("Simplify");
  504. }
  505. else
  506. {
  507. // Decomp request is complete so we can enable the "Recalculate physics" button again.
  508. swap_controls(sInstance->mRecalculatePhysicsBtn, sInstance->mRecalculatingPhysicsBtn, true);
  509. }
  510. }
  511. BOOL LLFloaterModelWizard::postBuild()
  512. {
  513. childSetValue("import_scale", (F32) 0.67335826);
  514. getChild<LLUICtrl>("browse")->setCommitCallback(boost::bind(&LLFloaterModelWizard::loadModel, this));
  515. //getChild<LLUICtrl>("lod_file")->setCommitCallback(boost::bind(&LLFloaterModelWizard::loadModel, this));
  516. getChild<LLUICtrl>("cancel")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickCancel, this));
  517. getChild<LLUICtrl>("close")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickCancel, this));
  518. getChild<LLUICtrl>("back")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickBack, this));
  519. getChild<LLUICtrl>("next")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickNext, this));
  520. getChild<LLUICtrl>("preview_lod_combo")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onPreviewLODCommit, this, _1));
  521. getChild<LLUICtrl>("preview_lod_combo2")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onPreviewLODCommit, this, _1));
  522. getChild<LLUICtrl>("upload")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onUpload, this));
  523. getChild<LLUICtrl>("switch_to_advanced")->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickSwitchToAdvanced, this));
  524. mRecalculateGeometryBtn = getChild<LLButton>("recalculate_geometry_btn");
  525. mRecalculateGeometryBtn->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickRecalculateGeometry, this));
  526. mRecalculatePhysicsBtn = getChild<LLButton>("recalculate_physics_btn");
  527. mRecalculatePhysicsBtn->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickRecalculatePhysics, this));
  528. mRecalculatingPhysicsBtn = getChild<LLButton>("recalculating_physics_btn");
  529. mCalculateWeightsBtn = getChild<LLButton>("calculate");
  530. mCalculateWeightsBtn->setCommitCallback(boost::bind(&LLFloaterModelWizard::onClickCalculateUploadFee, this));
  531. mCalculatingWeightsBtn = getChild<LLButton>("calculating");
  532. mChooseFilePreviewPanel = getChild<LLView>("choose_file_preview_panel");
  533. mOptimizePreviewPanel = getChild<LLView>("optimize_preview_panel");
  534. mPhysicsPreviewPanel = getChild<LLView>("physics_preview_panel");
  535. LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
  536. enable_registrar.add("Next.OnEnable", boost::bind(&LLFloaterModelWizard::onEnableNext, this));
  537. enable_registrar.add("Back.OnEnable", boost::bind(&LLFloaterModelWizard::onEnableBack, this));
  538. mModelPreview = new LLModelPreview(512, 512, this);
  539. mModelPreview->setPreviewTarget(16.f);
  540. mModelPreview->setDetailsCallback(boost::bind(&LLFloaterModelWizard::setDetails, this, _1, _2, _3, _4, _5));
  541. mModelPreview->setModelLoadedCallback(boost::bind(&LLFloaterModelWizard::modelLoadedCallback, this));
  542. mModelPreview->setModelUpdatedCallback(boost::bind(&LLFloaterModelWizard::modelChangedCallback, this));
  543. mModelPreview->mViewOption["show_textures"] = true;
  544. center();
  545. setState(CHOOSE_FILE);
  546. childSetTextArg("import_dimensions", "[X]", LLStringUtil::null);
  547. childSetTextArg("import_dimensions", "[Y]", LLStringUtil::null);
  548. childSetTextArg("import_dimensions", "[Z]", LLStringUtil::null);
  549. initDecompControls();
  550. requestAgentUploadPermissions();
  551. return TRUE;
  552. }
  553. void LLFloaterModelWizard::setDetails(F32 x, F32 y, F32 z, F32 streaming_cost, F32 physics_cost)
  554. {
  555. // iterate through all the panels, setting the dimensions
  556. for(size_t t=0; t<LL_ARRAY_SIZE(stateNames); ++t)
  557. {
  558. LLPanel *panel = getChild<LLPanel>(stateNames[t]+"_panel");
  559. if (panel)
  560. {
  561. panel->childSetText("dimension_x", llformat("%.1f", x));
  562. panel->childSetText("dimension_y", llformat("%.1f", y));
  563. panel->childSetText("dimension_z", llformat("%.1f", z));
  564. }
  565. }
  566. childSetTextArg("review_prim_equiv", "[EQUIV]", llformat("%d", mModelPreview->mResourceCost));
  567. }
  568. void LLFloaterModelWizard::modelLoadedCallback()
  569. {
  570. mLastEnabledState = CHOOSE_FILE;
  571. updateButtons();
  572. }
  573. void LLFloaterModelWizard::modelChangedCallback()
  574. {
  575. // Don't allow to proceed to the "Review" step if the model has changed
  576. // but the new upload fee hasn't been calculated yet.
  577. if (mLastEnabledState > PHYSICS)
  578. {
  579. mLastEnabledState = PHYSICS;
  580. }
  581. getChildView("upload")->setEnabled(false);
  582. updateButtons();
  583. }
  584. void LLFloaterModelWizard::onUpload()
  585. {
  586. mModelPreview->rebuildUploadData();
  587. gMeshRepo.uploadModel(mModelPreview->mUploadData, mModelPreview->mPreviewScale,
  588. true, false, false, mUploadModelUrl, true,
  589. LLHandle<LLWholeModelFeeObserver>(), getWholeModelUploadObserverHandle());
  590. }
  591. void LLFloaterModelWizard::onPreviewLODCommit(LLUICtrl* ctrl)
  592. {
  593. if (!mModelPreview)
  594. {
  595. return;
  596. }
  597. S32 which_mode = 0;
  598. LLComboBox* combo = (LLComboBox*) ctrl;
  599. which_mode = (NUM_LOD-1)-combo->getFirstSelectedIndex(); // combo box list of lods is in reverse order
  600. mModelPreview->setPreviewLOD(which_mode);
  601. }
  602. void LLFloaterModelWizard::refresh()
  603. {
  604. if (mState == CHOOSE_FILE)
  605. {
  606. bool model_loaded = false;
  607. if (mModelPreview && mModelPreview->getLoadState() == LLModelLoader::DONE)
  608. {
  609. model_loaded = true;
  610. }
  611. getChildView("next")->setEnabled(model_loaded);
  612. }
  613. }
  614. void LLFloaterModelWizard::draw()
  615. {
  616. refresh();
  617. LLFloater::draw();
  618. if (mModelPreview && mState < REVIEW)
  619. {
  620. mModelPreview->update();
  621. gGL.color3f(1.f, 1.f, 1.f);
  622. gGL.getTexUnit(0)->bind(mModelPreview);
  623. gGL.begin( LLRender::QUADS );
  624. {
  625. gGL.texCoord2f(0.f, 1.f);
  626. gGL.vertex2i(mPreviewRect.mLeft, mPreviewRect.mTop);
  627. gGL.texCoord2f(0.f, 0.f);
  628. gGL.vertex2i(mPreviewRect.mLeft, mPreviewRect.mBottom);
  629. gGL.texCoord2f(1.f, 0.f);
  630. gGL.vertex2i(mPreviewRect.mRight, mPreviewRect.mBottom);
  631. gGL.texCoord2f(1.f, 1.f);
  632. gGL.vertex2i(mPreviewRect.mRight, mPreviewRect.mTop);
  633. }
  634. gGL.end();
  635. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  636. }
  637. }
  638. // static
  639. void swap_controls(LLUICtrl* first_ctrl, LLUICtrl* second_ctrl, bool first_ctr_visible)
  640. {
  641. first_ctrl->setVisible(first_ctr_visible);
  642. second_ctrl->setVisible(!first_ctr_visible);
  643. }