llpanelvolume.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  1. /**
  2. * @file llpanelvolume.cpp
  3. * @brief Object editing (position, scale, etc.) in the tools floater
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc, (c)2009-2023 Henri Beauchamp
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpanelvolume.h"
  34. #include "llbutton.h"
  35. #include "llcheckboxctrl.h"
  36. #include "llcombobox.h"
  37. #include "lleconomy.h"
  38. #include "llnotifications.h"
  39. #include "llpermissionsflags.h"
  40. #include "llspinctrl.h"
  41. #include "lltextbox.h"
  42. #include "lltrans.h"
  43. #include "llscrolllistctrl.h"
  44. #include "lluictrlfactory.h"
  45. #include "llvolume.h"
  46. #include "llagent.h"
  47. #include "llcolorswatch.h"
  48. #include "lldrawpool.h"
  49. #include "llflexibleobject.h"
  50. #include "llmanipscale.h"
  51. #include "llmeshrepository.h"
  52. #include "llpipeline.h"
  53. #include "llpreviewscript.h"
  54. #include "llselectmgr.h"
  55. #include "lltexturectrl.h"
  56. #include "lltooldraganddrop.h"
  57. #include "lltool.h"
  58. #include "lltoolcomp.h"
  59. #include "lltoolmgr.h"
  60. #include "llviewermenu.h" // For handle_refresh_probes()
  61. #include "llviewerobject.h"
  62. #include "llviewerregion.h"
  63. #include "llvoavatarself.h"
  64. #include "llvovolume.h"
  65. #include "llworld.h"
  66. constexpr F32 DEFAULT_GRAVITY_MULTIPLIER = 1.f;
  67. constexpr F32 DEFAULT_DENSITY = 1000.f;
  68. ///////////////////////////////////////////////////////////////////////////////
  69. // HBReflectionProbe class
  70. ///////////////////////////////////////////////////////////////////////////////
  71. // Floater for adjusting reflection probe parameters. Using a separate floater
  72. // for this rarely used feature avoids cluttering excessively the already
  73. // crowded "Features" tab, without having to enlarge the Build tools floater to
  74. // fit the new controls. HB
  75. class HBReflectionProbe final : public LLFloater
  76. {
  77. protected:
  78. LOG_CLASS(HBReflectionProbe);
  79. public:
  80. static void show(LLView* ownerp);
  81. static void hide();
  82. static void update();
  83. private:
  84. HBReflectionProbe(LLView* ownerp); // Use show()
  85. ~HBReflectionProbe() override; // Use hide()
  86. bool postBuild() override;
  87. void draw() override;
  88. void refresh() override;
  89. LLVOVolume* getEditedVolume();
  90. void setProbeParams(bool force);
  91. static void onProbeCheck(LLUICtrl*, void* userdata);
  92. static void onCommitProbe(LLUICtrl*, void* userdata);
  93. private:
  94. LLFloater* mParentFloater;
  95. LLCheckBoxCtrl* mProbeCheck;
  96. LLComboBox* mTypeCombo;
  97. LLComboBox* mVolumeCombo;
  98. LLSpinCtrl* mAmbianceSpin;
  99. LLSpinCtrl* mNearClipSpin;
  100. bool mMustClose;
  101. static HBReflectionProbe* sInstance;
  102. };
  103. //static
  104. HBReflectionProbe* HBReflectionProbe::sInstance = NULL;
  105. //static
  106. void HBReflectionProbe::show(LLView* ownerp)
  107. {
  108. if (!sInstance)
  109. {
  110. sInstance = new HBReflectionProbe(ownerp);
  111. }
  112. sInstance->open();
  113. sInstance->setFocus(true);
  114. }
  115. //static
  116. void HBReflectionProbe::hide()
  117. {
  118. if (sInstance)
  119. {
  120. sInstance->close();
  121. }
  122. }
  123. //static
  124. void HBReflectionProbe::update()
  125. {
  126. if (sInstance)
  127. {
  128. sInstance->refresh();
  129. }
  130. }
  131. HBReflectionProbe::HBReflectionProbe(LLView* ownerp)
  132. : mParentFloater(NULL),
  133. mMustClose(false)
  134. {
  135. llassert_always(!sInstance);
  136. sInstance = this;
  137. LLUICtrlFactory* factoryp = LLUICtrlFactory::getInstance();
  138. factoryp->buildFloater(this, "floater_reflection_probe.xml");
  139. // Note: at this point postBuild() has been called and returned.
  140. LLView* parentp = ownerp;
  141. // Search for our owner's parent floater and register as dependent of
  142. // it if found.
  143. while (parentp)
  144. {
  145. LLFloater* floaterp = parentp->asFloater();
  146. if (floaterp)
  147. {
  148. mParentFloater = floaterp;
  149. floaterp->addDependentFloater(this);
  150. break;
  151. }
  152. parentp = parentp->getParent();
  153. }
  154. }
  155. //virtual
  156. HBReflectionProbe::~HBReflectionProbe()
  157. {
  158. sInstance = NULL;
  159. }
  160. //virtual
  161. bool HBReflectionProbe::postBuild()
  162. {
  163. mProbeCheck = getChild<LLCheckBoxCtrl>("probe_check");
  164. mProbeCheck->setCommitCallback(onProbeCheck);
  165. mProbeCheck->setCallbackUserData(this);
  166. mVolumeCombo = getChild<LLComboBox>("volume_combo");
  167. mVolumeCombo->setCommitCallback(onCommitProbe);
  168. mVolumeCombo->setCallbackUserData(this);
  169. mTypeCombo = getChild<LLComboBox>("type_combo");
  170. mTypeCombo->setCommitCallback(onCommitProbe);
  171. mTypeCombo->setCallbackUserData(this);
  172. // These are the two "Mirror" items.
  173. LLScrollListItem* itemp = mTypeCombo->getItemByIndex(2);
  174. if (itemp)
  175. {
  176. itemp->setEnabled(LLPipeline::sRenderMirrors);
  177. }
  178. itemp = mTypeCombo->getItemByIndex(3);
  179. if (itemp)
  180. {
  181. itemp->setEnabled(LLPipeline::sRenderMirrors);
  182. }
  183. mAmbianceSpin = getChild<LLSpinCtrl>("ambiance_ctrl");
  184. mAmbianceSpin->setCommitCallback(onCommitProbe);
  185. mAmbianceSpin->setCallbackUserData(this);
  186. mNearClipSpin = getChild<LLSpinCtrl>("near_clip_ctrl");
  187. mNearClipSpin->setCommitCallback(onCommitProbe);
  188. mNearClipSpin->setCallbackUserData(this);
  189. refresh();
  190. return true;
  191. }
  192. LLVOVolume* HBReflectionProbe::getEditedVolume()
  193. {
  194. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  195. if (selection->getObjectCount() != 1 || !gAgent.hasInventoryMaterial())
  196. {
  197. mMustClose = true;
  198. return NULL;
  199. }
  200. LLViewerObject* objectp = selection->getFirstObject();
  201. LLVOVolume* vovolp = objectp->asVolume();
  202. if (!vovolp || vovolp->getPCode() != LL_PCODE_VOLUME || vovolp->isMesh())
  203. {
  204. mMustClose = true;
  205. return NULL;
  206. }
  207. return vovolp;
  208. }
  209. //virtual
  210. void HBReflectionProbe::draw()
  211. {
  212. if (mMustClose || (mParentFloater && !mParentFloater->getVisible()))
  213. {
  214. close();
  215. return;
  216. }
  217. LLFloater::draw();
  218. }
  219. //virtual
  220. void HBReflectionProbe::refresh()
  221. {
  222. LLVOVolume* volobjp = getEditedVolume();
  223. if (!volobjp)
  224. {
  225. return;
  226. }
  227. bool enabled = volobjp->permModify() && !volobjp->isPermanentEnforced();
  228. mProbeCheck->setEnabled(enabled);
  229. bool is_probe = volobjp->isReflectionProbe();
  230. bool is_dynamic = volobjp->getReflectionProbeIsDynamic();
  231. bool is_mirror = volobjp->getReflectionProbeIsMirror();
  232. mProbeCheck->set(is_probe);
  233. // Other controls enabled when actually a probe
  234. enabled &= is_probe;
  235. mTypeCombo->setEnabled(enabled);
  236. mAmbianceSpin->setEnabled(enabled && !is_mirror);
  237. mNearClipSpin->setEnabled(enabled && !is_mirror);
  238. // For now, mirrors are only working properly with box probes.
  239. mVolumeCombo->setEnabled(enabled && !is_mirror);
  240. if (enabled)
  241. {
  242. // For now, mirrors are only working properly with box probes.
  243. bool is_box = is_mirror || volobjp->getReflectionProbeIsBox();
  244. mVolumeCombo->setValue(is_box ? "Box" : "Sphere");
  245. if (is_dynamic)
  246. {
  247. mTypeCombo->setValue(is_mirror ? "Mirror (dynamic)" : "Dynamic");
  248. }
  249. else
  250. {
  251. mTypeCombo->setValue(is_mirror ? "Mirror (static)" : "Static");
  252. }
  253. mAmbianceSpin->setEnabled(!is_mirror);
  254. mNearClipSpin->setEnabled(!is_mirror);
  255. if (is_mirror)
  256. {
  257. mAmbianceSpin->clear();
  258. mNearClipSpin->clear();
  259. }
  260. else
  261. {
  262. mAmbianceSpin->setValue(volobjp->getReflectionProbeAmbiance());
  263. mNearClipSpin->setValue(volobjp->getReflectionProbeNearClip());
  264. }
  265. }
  266. else
  267. {
  268. mVolumeCombo->clear();
  269. mTypeCombo->clear();
  270. mAmbianceSpin->clear();
  271. mNearClipSpin->clear();
  272. }
  273. }
  274. void HBReflectionProbe::setProbeParams(bool force)
  275. {
  276. LLVOVolume* volobjp = getEditedVolume();
  277. if (!volobjp)
  278. {
  279. return;
  280. }
  281. if (!volobjp->permModify() || volobjp->isPermanentEnforced())
  282. {
  283. return;
  284. }
  285. F32 ambiance = mAmbianceSpin->getValue().asReal();
  286. F32 nearclip = mNearClipSpin->getValue().asReal();
  287. std::string type = mTypeCombo->getValue().asString();
  288. bool is_dynamic = type.find("ynamic") != std::string::npos;
  289. bool is_mirror = type.find("Mirror") != std::string::npos;
  290. bool is_box = mVolumeCombo->getValue().asString() == "Box";
  291. if (is_mirror && !is_box)
  292. {
  293. // For now, mirrors are only working properly with box probes.
  294. is_box = true;
  295. mVolumeCombo->setValue("Box");
  296. }
  297. if (force)
  298. {
  299. // Do not change the shape to a sphere when turning a primitve for the
  300. // first time into a reflection probe and the primitive is already a
  301. // box: the user wanted it that way in the first place, and likely
  302. // sized it appropriately (turning it into a sphere makes us loose any
  303. // non cubic sizes, ruining the user's work).
  304. const LLVolumeParams& volparams = volobjp->getVolume()->getParams();
  305. if (volparams.getPathParams().getCurveType() != LL_PCODE_PATH_CIRCLE)
  306. {
  307. is_box = true;
  308. }
  309. }
  310. volobjp->setReflectionProbeIsDynamic(is_dynamic);
  311. volobjp->setReflectionProbeIsMirror(is_mirror);
  312. if (!is_mirror)
  313. {
  314. volobjp->setReflectionProbeAmbiance(ambiance);
  315. volobjp->setReflectionProbeNearClip(nearclip);
  316. }
  317. if (volobjp->setReflectionProbeIsBox(is_box) || force)
  318. {
  319. if (volobjp->getRootEdit() == (LLViewerObject*)volobjp)
  320. {
  321. gSelectMgr.selectionUpdatePhantom(true);
  322. }
  323. else // This is a child primitive: cannot set it phantom.
  324. {
  325. // Remove its physics hull.
  326. gSelectMgr.selectionSetPhysicsType(1); // 1 = None
  327. // And prevent any accidental interaction for non-PBR viewers.
  328. gSelectMgr.selectionSetClickAction(9); // 9 = Ignore object
  329. }
  330. gSelectMgr.selectionSetGLTFMaterial(LLUUID::null);
  331. gSelectMgr.selectionSetAlphaOnly(0.f);
  332. U8 profile, path;
  333. if (is_box)
  334. {
  335. profile = LL_PCODE_PROFILE_SQUARE;
  336. path = LL_PCODE_PATH_LINE;
  337. }
  338. else
  339. {
  340. profile = LL_PCODE_PROFILE_CIRCLE_HALF;
  341. path = LL_PCODE_PATH_CIRCLE;
  342. F32 scale = volobjp->getScale().mV[0];
  343. volobjp->setScale(LLVector3(scale, scale, scale), false);
  344. constexpr U8 updates = UPD_ROTATION | UPD_POSITION | UPD_SCALE;
  345. gSelectMgr.sendMultipleUpdate(updates);
  346. }
  347. LLVolumeParams params;
  348. params.setType(profile, path);
  349. volobjp->updateVolume(params);
  350. }
  351. handle_refresh_probes(NULL);
  352. refresh();
  353. }
  354. //static
  355. void HBReflectionProbe::onProbeCheck(LLUICtrl*, void* userdata)
  356. {
  357. HBReflectionProbe* self = (HBReflectionProbe*)userdata;
  358. if (!self)
  359. {
  360. return;
  361. }
  362. LLVOVolume* volobjp = self->getEditedVolume();
  363. if (!volobjp)
  364. {
  365. return;
  366. }
  367. bool is_probe = volobjp->isReflectionProbe();
  368. bool set_probe = self->mProbeCheck->get();
  369. volobjp->setIsReflectionProbe(set_probe);
  370. if (!is_probe && set_probe)
  371. {
  372. self->setProbeParams(true); // true = force volume changes to match
  373. }
  374. else
  375. {
  376. self->refresh();
  377. }
  378. }
  379. //static
  380. void HBReflectionProbe::onCommitProbe(LLUICtrl*, void* userdata)
  381. {
  382. HBReflectionProbe* self = (HBReflectionProbe*)userdata;
  383. if (self)
  384. {
  385. self->setProbeParams(false);
  386. }
  387. }
  388. ///////////////////////////////////////////////////////////////////////////////
  389. // LLPanelVolume class
  390. ///////////////////////////////////////////////////////////////////////////////
  391. // "Features" Tab
  392. LLPanelVolume::LLPanelVolume(const std::string& name)
  393. : LLPanel(name),
  394. mIsPhysical(false),
  395. mComboMaterialItemCount(0)
  396. {
  397. setMouseOpaque(false);
  398. }
  399. LLPanelVolume::~LLPanelVolume()
  400. {
  401. HBReflectionProbe::hide();
  402. }
  403. bool LLPanelVolume::postBuild()
  404. {
  405. mLabelSelectSingle = getChild<LLTextBox>("select_single");
  406. mLabelEditObject = getChild<LLTextBox>("edit_object");
  407. // Flexible objects parameters
  408. mCheckFlexiblePath = getChild<LLCheckBoxCtrl>("Flexible1D Checkbox Ctrl");
  409. mCheckFlexiblePath->setCommitCallback(onCommitIsFlexible);
  410. mCheckFlexiblePath->setCallbackUserData(this);
  411. mSpinFlexSections = getChild<LLSpinCtrl>("FlexNumSections");
  412. mSpinFlexSections->setCommitCallback(onCommitFlexible);
  413. mSpinFlexSections->setCallbackUserData(this);
  414. mSpinFlexGravity = getChild<LLSpinCtrl>("FlexGravity");
  415. mSpinFlexGravity->setCommitCallback(onCommitFlexible);
  416. mSpinFlexGravity->setCallbackUserData(this);
  417. mSpinFlexFriction = getChild<LLSpinCtrl>("FlexFriction");
  418. mSpinFlexFriction->setCommitCallback(onCommitFlexible);
  419. mSpinFlexFriction->setCallbackUserData(this);
  420. mSpinFlexWind = getChild<LLSpinCtrl>("FlexWind");
  421. mSpinFlexWind->setCommitCallback(onCommitFlexible);
  422. mSpinFlexWind->setCallbackUserData(this);
  423. mSpinFlexTension = getChild<LLSpinCtrl>("FlexTension");
  424. mSpinFlexTension->setCommitCallback(onCommitFlexible);
  425. mSpinFlexTension->setCallbackUserData(this);
  426. mSpinFlexForceX = getChild<LLSpinCtrl>("FlexForceX");
  427. mSpinFlexForceX->setCommitCallback(onCommitFlexible);
  428. mSpinFlexForceX->setCallbackUserData(this);
  429. mSpinFlexForceY = getChild<LLSpinCtrl>("FlexForceY");
  430. mSpinFlexForceY->setCommitCallback(onCommitFlexible);
  431. mSpinFlexForceY->setCallbackUserData(this);
  432. mSpinFlexForceZ = getChild<LLSpinCtrl>("FlexForceZ");
  433. mSpinFlexForceZ->setCommitCallback(onCommitFlexible);
  434. mSpinFlexForceZ->setCallbackUserData(this);
  435. // Light parameters
  436. mCheckEmitLight = getChild<LLCheckBoxCtrl>("Light Checkbox Ctrl");
  437. mCheckEmitLight->setCommitCallback(onCommitIsLight);
  438. mCheckEmitLight->setCallbackUserData(this);
  439. mSwatchLightColor = getChild<LLColorSwatchCtrl>("colorswatch");
  440. mSwatchLightColor->setOnCancelCallback(onLightCancelColor);
  441. mSwatchLightColor->setOnSelectCallback(onLightSelectColor);
  442. mSwatchLightColor->setCommitCallback(onCommitLight);
  443. mSwatchLightColor->setCallbackUserData(this);
  444. mTextureLight = getChild<LLTextureCtrl>("light texture control");
  445. mTextureLight->setCommitCallback(onCommitLight);
  446. mTextureLight->setCallbackUserData(this);
  447. mTextureLight->setOnCancelCallback(onLightCancelTexture);
  448. mTextureLight->setOnSelectCallback(onLightSelectTexture);
  449. mTextureLight->setDragCallback(onDragTexture);
  450. mSpinLightIntensity = getChild<LLSpinCtrl>("Light Intensity");
  451. mSpinLightIntensity->setCommitCallback(onCommitLight);
  452. mSpinLightIntensity->setCallbackUserData(this);
  453. mSpinLightRadius = getChild<LLSpinCtrl>("Light Radius");
  454. mSpinLightRadius->setCommitCallback(onCommitLight);
  455. mSpinLightRadius->setCallbackUserData(this);
  456. mSpinLightFalloff = getChild<LLSpinCtrl>("Light Falloff");
  457. mSpinLightFalloff->setCommitCallback(onCommitLight);
  458. mSpinLightFalloff->setCallbackUserData(this);
  459. mSpinLightFOV = getChild<LLSpinCtrl>("Light FOV");
  460. mSpinLightFOV->setCommitCallback(onCommitLight);
  461. mSpinLightFOV->setCallbackUserData(this);
  462. mSpinLightFocus = getChild<LLSpinCtrl>("Light Focus");
  463. mSpinLightFocus->setCommitCallback(onCommitLight);
  464. mSpinLightFocus->setCallbackUserData(this);
  465. mSpinLightAmbiance = getChild<LLSpinCtrl>("Light Ambiance");
  466. mSpinLightAmbiance->setCommitCallback(onCommitLight);
  467. mSpinLightAmbiance->setCallbackUserData(this);
  468. // Physics parameters
  469. mLabelPhysicsShape = getChild<LLTextBox>("label physicsshapetype");
  470. // Physical checkbox
  471. mCheckPhysics = getChild<LLCheckBoxCtrl>("Physical Checkbox Ctrl");
  472. mCheckPhysics->setCommitCallback(onCommitPhysics);
  473. mCheckPhysics->setCallbackUserData(this);
  474. mComboPhysicsShape = getChild<LLComboBox>("Physics Shape Type Combo Ctrl");
  475. mComboPhysicsShape->setCommitCallback(sendPhysicsShapeType);
  476. mComboPhysicsShape->setCallbackUserData(this);
  477. mSpinPhysicsGravity = getChild<LLSpinCtrl>("Physics Gravity");
  478. mSpinPhysicsGravity->setCommitCallback(sendPhysicsGravity);
  479. mSpinPhysicsGravity->setCallbackUserData(this);
  480. mSpinPhysicsFriction = getChild<LLSpinCtrl>("Physics Friction");
  481. mSpinPhysicsFriction->setCommitCallback(sendPhysicsFriction);
  482. mSpinPhysicsFriction->setCallbackUserData(this);
  483. mSpinPhysicsDensity = getChild<LLSpinCtrl>("Physics Density");
  484. mSpinPhysicsDensity->setCommitCallback(sendPhysicsDensity);
  485. mSpinPhysicsDensity->setCallbackUserData(this);
  486. mSpinPhysicsRestitution = getChild<LLSpinCtrl>("Physics Restitution");
  487. mSpinPhysicsRestitution->setCommitCallback(sendPhysicsRestitution);
  488. mSpinPhysicsRestitution->setCallbackUserData(this);
  489. mPhysicsNone = getString("None");
  490. mPhysicsPrim = getString("Prim");
  491. mPhysicsHull = getString("Convex Hull");
  492. // Material parameters
  493. mFullBright = LLTrans::getString("Fullbright");
  494. std::map<std::string, std::string> material_name_map;
  495. material_name_map["Stone"]= LLTrans::getString("Stone");
  496. material_name_map["Metal"]= LLTrans::getString("Metal");
  497. material_name_map["Glass"]= LLTrans::getString("Glass");
  498. material_name_map["Wood"]= LLTrans::getString("Wood");
  499. material_name_map["Flesh"]= LLTrans::getString("Flesh");
  500. material_name_map["Plastic"]= LLTrans::getString("Plastic");
  501. material_name_map["Rubber"]= LLTrans::getString("Rubber");
  502. material_name_map["Light"]= LLTrans::getString("Light");
  503. gMaterialTable.initTableTransNames(material_name_map);
  504. mLabelMaterial = getChild<LLTextBox>("label material");
  505. mComboMaterial = getChild<LLComboBox>("material");
  506. childSetCommitCallback("material", onCommitMaterial, this);
  507. mComboMaterial->removeall();
  508. for (LLMaterialTable::info_list_t::const_iterator
  509. iter = gMaterialTable.mMaterialInfoList.begin(),
  510. end = gMaterialTable.mMaterialInfoList.end();
  511. iter != end; ++iter)
  512. {
  513. const LLMaterialInfo& minfo = *iter;
  514. if (minfo.mMCode != LL_MCODE_LIGHT)
  515. {
  516. mComboMaterial->add(minfo.mName);
  517. }
  518. }
  519. mComboMaterialItemCount = mComboMaterial->getItemCount();
  520. // Animated mesh/puppet parameter
  521. mCheckAnimatedMesh = getChild<LLCheckBoxCtrl>("AniMesh Checkbox Ctrl");
  522. mCheckAnimatedMesh->setCommitCallback(onCommitAnimatedMesh);
  523. mCheckAnimatedMesh->setCallbackUserData(this);
  524. // Reflection probe
  525. mReflectionProbe = getChild<LLButton>("reflection_probe");
  526. mReflectionProbe->setClickedCallback(onClickProbe, this);
  527. // Start with everyone disabled
  528. clearCtrls();
  529. return true;
  530. }
  531. void LLPanelVolume::getState()
  532. {
  533. HBReflectionProbe::update();
  534. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  535. LLViewerObject* objectp = selection->getFirstRootObject();
  536. LLViewerObject* root_objectp = objectp;
  537. if (!objectp)
  538. {
  539. objectp = selection->getFirstObject();
  540. // *FIX: should not we just keep the child ?
  541. if (objectp)
  542. {
  543. LLViewerObject* parentp = objectp->getRootEdit();
  544. root_objectp = parentp ? parentp : objectp;
  545. }
  546. }
  547. LLVOVolume* volobjp = NULL;
  548. if (objectp && objectp->getPCode() == LL_PCODE_VOLUME)
  549. {
  550. volobjp = (LLVOVolume*)objectp;
  551. }
  552. LLVOVolume* root_volobjp = NULL;
  553. if (root_objectp && root_objectp->getPCode() == LL_PCODE_VOLUME)
  554. {
  555. root_volobjp = (LLVOVolume*)root_objectp;
  556. }
  557. if (!objectp)
  558. {
  559. // Forfeit focus
  560. if (gFocusMgr.childHasKeyboardFocus(this))
  561. {
  562. gFocusMgr.setKeyboardFocus(NULL);
  563. }
  564. // Disable all text input fields
  565. clearCtrls();
  566. return;
  567. }
  568. LLUUID owner_id;
  569. std::string owner_name;
  570. gSelectMgr.selectGetOwner(owner_id, owner_name);
  571. // BUG ? Check for all objects being editable ?
  572. bool editable = root_objectp->permModify() &&
  573. !root_objectp->isPermanentEnforced();
  574. bool visible_params = (editable || gAgent.isGodlikeWithoutAdminMenuFakery());
  575. bool single_volume = gSelectMgr.selectionAllPCode(LL_PCODE_VOLUME) &&
  576. selection->getObjectCount() == 1;
  577. bool single_root_volume = gSelectMgr.selectionAllPCode(LL_PCODE_VOLUME) &&
  578. gSelectMgr.getSelection()->getRootObjectCount() == 1;
  579. // Select Single Message
  580. if (single_volume)
  581. {
  582. mLabelSelectSingle->setVisible(false);
  583. mLabelEditObject->setVisible(true);
  584. mLabelEditObject->setEnabled(true);
  585. }
  586. else
  587. {
  588. mLabelSelectSingle->setVisible(true);
  589. mLabelSelectSingle->setEnabled(true);
  590. mLabelEditObject->setVisible(false);
  591. }
  592. // Light properties
  593. bool is_light = volobjp && volobjp->getIsLight();
  594. mCheckEmitLight->setValue(is_light);
  595. mCheckEmitLight->setEnabled(editable && single_volume && volobjp);
  596. if (is_light && single_volume && visible_params)
  597. {
  598. mLightSavedColor = volobjp->getLightSRGBBaseColor();
  599. mSwatchLightColor->setEnabled(editable);
  600. mSwatchLightColor->setValid(true);
  601. mSwatchLightColor->set(mLightSavedColor);
  602. mTextureLight->setEnabled(editable);
  603. mTextureLight->setValid(true);
  604. mTextureLight->setImageAssetID(volobjp->getLightTextureID());
  605. LLAggregatePermissions tex_perms;
  606. if (gSelectMgr.selectGetAggregateTexturePermissions(tex_perms))
  607. {
  608. bool can_copy =
  609. tex_perms.getValue(PERM_COPY) == LLAggregatePermissions::AP_EMPTY ||
  610. tex_perms.getValue(PERM_COPY) == LLAggregatePermissions::AP_ALL;
  611. bool can_transfer =
  612. tex_perms.getValue(PERM_TRANSFER) == LLAggregatePermissions::AP_EMPTY ||
  613. tex_perms.getValue(PERM_TRANSFER) == LLAggregatePermissions::AP_ALL;
  614. mTextureLight->setCanApplyImmediately(can_copy && can_transfer);
  615. }
  616. else
  617. {
  618. mTextureLight->setCanApplyImmediately(false);
  619. }
  620. if (objectp && objectp->isAttachment())
  621. {
  622. mTextureLight->setImmediateFilterPermMask(PERM_COPY |
  623. PERM_TRANSFER);
  624. }
  625. else
  626. {
  627. mTextureLight->setImmediateFilterPermMask(PERM_NONE);
  628. }
  629. mSpinLightIntensity->setEnabled(editable);
  630. mSpinLightRadius->setEnabled(true);
  631. mSpinLightFalloff->setEnabled(true);
  632. mSpinLightFOV->setEnabled(editable);
  633. mSpinLightFocus->setEnabled(true);
  634. mSpinLightAmbiance->setEnabled(true);
  635. mSpinLightIntensity->setValue(volobjp->getLightIntensity());
  636. mSpinLightRadius->setValue(volobjp->getLightRadius());
  637. mSpinLightFalloff->setValue(volobjp->getLightFalloff());
  638. LLVector3 params = volobjp->getSpotLightParams();
  639. mSpinLightFOV->setValue(params.mV[0]);
  640. mSpinLightFocus->setValue(params.mV[1]);
  641. mSpinLightAmbiance->setValue(params.mV[2]);
  642. }
  643. else
  644. {
  645. mSpinLightIntensity->clear();
  646. mSpinLightRadius->clear();
  647. mSpinLightFalloff->clear();
  648. mSwatchLightColor->setEnabled(false);
  649. mSwatchLightColor->setValid(false);
  650. mTextureLight->setEnabled(false);
  651. mTextureLight->setValid(false);
  652. mSpinLightIntensity->setEnabled(false);
  653. mSpinLightRadius->setEnabled(false);
  654. mSpinLightFalloff->setEnabled(false);
  655. mSpinLightFOV->setEnabled(false);
  656. mSpinLightFocus->setEnabled(false);
  657. mSpinLightAmbiance->setEnabled(false);
  658. }
  659. // Animated mesh property
  660. bool is_animated_mesh = single_root_volume && root_volobjp &&
  661. root_volobjp->isAnimatedObject();
  662. mCheckAnimatedMesh->setValue(is_animated_mesh);
  663. bool enabled_animated_mesh = false;
  664. if (editable && single_root_volume && root_volobjp &&
  665. root_volobjp == volobjp)
  666. {
  667. enabled_animated_mesh = root_volobjp->canBeAnimatedObject();
  668. if (enabled_animated_mesh && !is_animated_mesh &&
  669. root_volobjp->isAttachment())
  670. {
  671. enabled_animated_mesh =
  672. isAgentAvatarValid() &&
  673. gAgentAvatarp->canAttachMoreAnimatedObjects();
  674. }
  675. }
  676. mCheckAnimatedMesh->setEnabled(enabled_animated_mesh);
  677. // Refresh any bake on mesh texture
  678. if (root_volobjp)
  679. {
  680. root_volobjp->refreshBakeTexture();
  681. LLViewerObject::const_child_list_t& child_list =
  682. root_volobjp->getChildren();
  683. for (LLViewerObject::child_list_t::const_iterator
  684. it = child_list.begin(), end = child_list.end();
  685. it != end; ++it)
  686. {
  687. LLViewerObject* childp = *it;
  688. if (childp)
  689. {
  690. childp->refreshBakeTexture();
  691. }
  692. }
  693. if (isAgentAvatarValid())
  694. {
  695. gAgentAvatarp->updateMeshVisibility();
  696. }
  697. }
  698. // Flexible properties
  699. bool is_flexible = volobjp && volobjp->isFlexible();
  700. mCheckFlexiblePath->setValue(is_flexible);
  701. if (is_flexible || (volobjp && volobjp->canBeFlexible()))
  702. {
  703. mCheckFlexiblePath->setEnabled(editable && single_volume && volobjp &&
  704. !volobjp->isMesh() &&
  705. !objectp->isPermanentEnforced());
  706. }
  707. else
  708. {
  709. mCheckFlexiblePath->setEnabled(false);
  710. }
  711. if (is_flexible && single_volume && visible_params)
  712. {
  713. mSpinFlexSections->setVisible(true);
  714. mSpinFlexGravity->setVisible(true);
  715. mSpinFlexFriction->setVisible(true);
  716. mSpinFlexWind->setVisible(true);
  717. mSpinFlexTension->setVisible(true);
  718. mSpinFlexForceX->setVisible(true);
  719. mSpinFlexForceY->setVisible(true);
  720. mSpinFlexForceZ->setVisible(true);
  721. mSpinFlexSections->setEnabled(editable);
  722. mSpinFlexGravity->setEnabled(editable);
  723. mSpinFlexFriction->setEnabled(editable);
  724. mSpinFlexWind->setEnabled(editable);
  725. mSpinFlexTension->setEnabled(editable);
  726. mSpinFlexForceX->setEnabled(editable);
  727. mSpinFlexForceY->setEnabled(editable);
  728. mSpinFlexForceZ->setEnabled(editable);
  729. const LLFlexibleObjectData* params = objectp->getFlexibleObjectData();
  730. mSpinFlexSections->setValue((F32)params->getSimulateLOD());
  731. mSpinFlexGravity->setValue(params->getGravity());
  732. mSpinFlexFriction->setValue(params->getAirFriction());
  733. mSpinFlexWind->setValue(params->getWindSensitivity());
  734. mSpinFlexTension->setValue(params->getTension());
  735. mSpinFlexForceX->setValue(params->getUserForce().mV[VX]);
  736. mSpinFlexForceY->setValue(params->getUserForce().mV[VY]);
  737. mSpinFlexForceZ->setValue(params->getUserForce().mV[VZ]);
  738. }
  739. else
  740. {
  741. mSpinFlexSections->clear();
  742. mSpinFlexGravity->clear();
  743. mSpinFlexFriction->clear();
  744. mSpinFlexWind->clear();
  745. mSpinFlexTension->clear();
  746. mSpinFlexForceX->clear();
  747. mSpinFlexForceY->clear();
  748. mSpinFlexForceZ->clear();
  749. mSpinFlexSections->setEnabled(false);
  750. mSpinFlexGravity->setEnabled(false);
  751. mSpinFlexFriction->setEnabled(false);
  752. mSpinFlexWind->setEnabled(false);
  753. mSpinFlexTension->setEnabled(false);
  754. mSpinFlexForceX->setEnabled(false);
  755. mSpinFlexForceY->setEnabled(false);
  756. mSpinFlexForceZ->setEnabled(false);
  757. }
  758. // Material properties
  759. // Update material part
  760. // slightly inefficient - materials are unique per object, not per TE
  761. U8 mcode = 0;
  762. struct f : public LLSelectedTEGetFunctor<U8>
  763. {
  764. U8 get(LLViewerObject* object, S32 te)
  765. {
  766. return object->getMaterial();
  767. }
  768. } func;
  769. bool material_same = selection->getSelectedTEValue(&func, mcode);
  770. if (single_volume && material_same && visible_params)
  771. {
  772. mComboMaterial->setEnabled(editable);
  773. mLabelMaterial->setEnabled(editable);
  774. if (mcode == LL_MCODE_LIGHT)
  775. {
  776. if (mComboMaterial->getItemCount() == mComboMaterialItemCount)
  777. {
  778. mComboMaterial->add(mFullBright);
  779. }
  780. mComboMaterial->setSimple(mFullBright);
  781. }
  782. else
  783. {
  784. if (mComboMaterial->getItemCount() != mComboMaterialItemCount)
  785. {
  786. mComboMaterial->remove(mFullBright);
  787. }
  788. // *TODO:Translate
  789. mComboMaterial->setSimple(gMaterialTable.getName(mcode));
  790. }
  791. }
  792. else
  793. {
  794. mComboMaterial->setEnabled(false);
  795. mLabelMaterial->setEnabled(false);
  796. }
  797. // Physics properties
  798. mIsPhysical = root_objectp && root_objectp->flagUsePhysics();
  799. // Physics checkbox
  800. mCheckPhysics->set(mIsPhysical);
  801. bool is_permanent = root_objectp->flagObjectPermanent();
  802. if (is_permanent && mIsPhysical)
  803. {
  804. // *TODO: Pop up a one-time warning with object details
  805. llwarns_sparse << "PATHFINDING BUG: editing a Permanent object that is also Physical !"
  806. << llendl;
  807. }
  808. bool enable_physics = !is_flexible && !is_permanent &&
  809. selection->getRootObjectCount();
  810. mCheckPhysics->setEnabled(enable_physics &&
  811. (editable || gAgent.isGodlike()));
  812. if (mIsPhysical && enable_physics && visible_params)
  813. {
  814. mSpinPhysicsGravity->setValue(objectp->getPhysicsGravity());
  815. mSpinPhysicsGravity->setEnabled(editable);
  816. mSpinPhysicsFriction->setValue(objectp->getPhysicsFriction());
  817. mSpinPhysicsFriction->setEnabled(editable);
  818. mSpinPhysicsDensity->setValue(objectp->getPhysicsDensity());
  819. mSpinPhysicsDensity->setEnabled(editable);
  820. mSpinPhysicsRestitution->setValue(objectp->getPhysicsRestitution());
  821. mSpinPhysicsRestitution->setEnabled(editable);
  822. }
  823. else
  824. {
  825. mSpinPhysicsGravity->clear();
  826. mSpinPhysicsGravity->setEnabled(false);
  827. mSpinPhysicsFriction->clear();
  828. mSpinPhysicsFriction->setEnabled(false);
  829. mSpinPhysicsDensity->clear();
  830. mSpinPhysicsDensity->setEnabled(false);
  831. mSpinPhysicsRestitution->clear();
  832. mSpinPhysicsRestitution->setEnabled(false);
  833. }
  834. // Update the physics shape combo to include allowed physics shapes
  835. mComboPhysicsShape->removeall();
  836. mComboPhysicsShape->add(mPhysicsNone, LLSD(1));
  837. bool is_mesh = false;
  838. if (objectp)
  839. {
  840. const LLSculptParams* sculpt_paramsp = objectp->getSculptParams();
  841. is_mesh = sculpt_paramsp &&
  842. (sculpt_paramsp->getSculptType() &
  843. LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH;
  844. }
  845. if (is_mesh)
  846. {
  847. const LLVolumeParams& volume_params =
  848. objectp->getVolume()->getParams();
  849. const LLUUID& mesh_id = volume_params.getSculptID();
  850. if (gMeshRepo.hasPhysicsShape(mesh_id))
  851. {
  852. // If a mesh contains an uploaded or decomposed physics mesh,
  853. // allow 'Prim'
  854. mComboPhysicsShape->add(mPhysicsPrim, LLSD(0));
  855. }
  856. }
  857. else
  858. {
  859. // Simple prims always allow physics shape prim
  860. mComboPhysicsShape->add(mPhysicsPrim, LLSD(0));
  861. }
  862. mComboPhysicsShape->add(mPhysicsHull, LLSD(2));
  863. mComboPhysicsShape->setValue(LLSD(objectp->getPhysicsShapeType()));
  864. bool enabled = editable && !objectp->isPermanentEnforced() &&
  865. (!root_objectp || !root_objectp->isPermanentEnforced());
  866. mComboPhysicsShape->setEnabled(enabled);
  867. mLabelPhysicsShape->setEnabled(enabled);
  868. mReflectionProbe->setEnabled(single_volume && enabled &&
  869. volobjp && !volobjp->isMesh() &&
  870. gAgent.hasInventoryMaterial());
  871. mObject = objectp;
  872. mRootObject = root_objectp;
  873. }
  874. void LLPanelVolume::refresh()
  875. {
  876. getState();
  877. if (mObject.notNull() && mObject->isDead())
  878. {
  879. mObject = NULL;
  880. }
  881. if (mRootObject.notNull() && mRootObject->isDead())
  882. {
  883. mRootObject = NULL;
  884. }
  885. bool enable_physics = false;
  886. LLSD sim_features;
  887. LLViewerRegion* region = gAgent.getRegion();
  888. if (region)
  889. {
  890. enable_physics = region->physicsShapeTypes();
  891. }
  892. mLabelPhysicsShape->setVisible(enable_physics);
  893. mComboPhysicsShape->setVisible(enable_physics);
  894. mSpinPhysicsGravity->setVisible(enable_physics);
  895. mSpinPhysicsFriction->setVisible(enable_physics);
  896. mSpinPhysicsDensity->setVisible(enable_physics);
  897. mSpinPhysicsRestitution->setVisible(enable_physics);
  898. // *TODO: add/remove individual physics shape types as per the
  899. // PhysicsShapeTypes simulator features
  900. }
  901. // virtual
  902. void LLPanelVolume::clearCtrls()
  903. {
  904. LLPanel::clearCtrls();
  905. mLabelSelectSingle->setEnabled(false);
  906. mLabelSelectSingle->setVisible(true);
  907. mLabelEditObject->setEnabled(false);
  908. mLabelEditObject->setVisible(false);
  909. mCheckEmitLight->setEnabled(false);
  910. mSwatchLightColor->setEnabled(false);
  911. mSwatchLightColor->setValid(false);
  912. mTextureLight->setEnabled(false);
  913. mTextureLight->setValid(false);
  914. mSpinLightIntensity->setEnabled(false);
  915. mSpinLightRadius->setEnabled(false);
  916. mSpinLightFalloff->setEnabled(false);
  917. mSpinLightFOV->setEnabled(false);
  918. mSpinLightFocus->setEnabled(false);
  919. mSpinLightAmbiance->setEnabled(false);
  920. mCheckFlexiblePath->setEnabled(false);
  921. mSpinFlexSections->setEnabled(false);
  922. mSpinFlexGravity->setEnabled(false);
  923. mSpinFlexFriction->setEnabled(false);
  924. mSpinFlexWind->setEnabled(false);
  925. mSpinFlexTension->setEnabled(false);
  926. mSpinFlexForceX->setEnabled(false);
  927. mSpinFlexForceY->setEnabled(false);
  928. mSpinFlexForceZ->setEnabled(false);
  929. mCheckPhysics->set(false);
  930. mSpinPhysicsGravity->setEnabled(false);
  931. mSpinPhysicsFriction->setEnabled(false);
  932. mSpinPhysicsDensity->setEnabled(false);
  933. mSpinPhysicsRestitution->setEnabled(false);
  934. mComboMaterial->setEnabled(false);
  935. mLabelMaterial->setEnabled(false);
  936. mCheckAnimatedMesh->setEnabled(false);
  937. }
  938. //
  939. // Static functions
  940. //
  941. void LLPanelVolume::sendIsLight()
  942. {
  943. LLViewerObject* objectp = mObject;
  944. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  945. {
  946. return;
  947. }
  948. LLVOVolume* volobjp = (LLVOVolume*)objectp;
  949. bool value = mCheckEmitLight->getValue();
  950. volobjp->setIsLight(value);
  951. llinfos << "update light sent" << llendl;
  952. }
  953. void LLPanelVolume::sendIsFlexible()
  954. {
  955. LLViewerObject* objectp = mObject;
  956. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  957. {
  958. return;
  959. }
  960. LLVOVolume* volobjp = (LLVOVolume*)objectp;
  961. bool is_flexible = mCheckFlexiblePath->getValue();
  962. if (is_flexible && objectp->getClickAction() == CLICK_ACTION_SIT)
  963. {
  964. gSelectMgr.selectionSetClickAction(CLICK_ACTION_NONE);
  965. }
  966. if (volobjp->setIsFlexible(is_flexible))
  967. {
  968. mObject->sendShapeUpdate();
  969. gSelectMgr.selectionUpdatePhantom(volobjp->flagPhantom());
  970. }
  971. llinfos << "update flexible sent" << llendl;
  972. }
  973. void LLPanelVolume::sendIsPhysical()
  974. {
  975. bool value = mCheckPhysics->get();
  976. if (mIsPhysical != value)
  977. {
  978. gSelectMgr.selectionUpdatePhysics(value);
  979. mIsPhysical = value;
  980. llinfos << "Update physics sent" << llendl;
  981. }
  982. }
  983. //static
  984. void LLPanelVolume::onCommitPhysics(LLUICtrl* ctrl, void* userdata)
  985. {
  986. LLPanelVolume* self = (LLPanelVolume*)userdata;
  987. if (self)
  988. {
  989. self->sendIsPhysical();
  990. }
  991. }
  992. //static
  993. void LLPanelVolume::sendPhysicsShapeType(LLUICtrl* ctrl, void* userdata)
  994. {
  995. LLPanelVolume* self = (LLPanelVolume*) userdata;
  996. if (!self || !ctrl) return;
  997. U8 type = ctrl->getValue().asInteger();
  998. gSelectMgr.selectionSetPhysicsType(type);
  999. self->refreshCost();
  1000. }
  1001. //static
  1002. void LLPanelVolume::sendPhysicsGravity(LLUICtrl* ctrl, void* userdata)
  1003. {
  1004. F32 val = ctrl->getValue().asReal();
  1005. gSelectMgr.selectionSetGravity(val);
  1006. }
  1007. //static
  1008. void LLPanelVolume::sendPhysicsFriction(LLUICtrl* ctrl, void* userdata)
  1009. {
  1010. F32 val = ctrl->getValue().asReal();
  1011. gSelectMgr.selectionSetFriction(val);
  1012. }
  1013. //static
  1014. void LLPanelVolume::sendPhysicsRestitution(LLUICtrl* ctrl, void* userdata)
  1015. {
  1016. F32 val = ctrl->getValue().asReal();
  1017. gSelectMgr.selectionSetRestitution(val);
  1018. }
  1019. //static
  1020. void LLPanelVolume::sendPhysicsDensity(LLUICtrl* ctrl, void* userdata)
  1021. {
  1022. F32 val = ctrl->getValue().asReal();
  1023. gSelectMgr.selectionSetDensity(val);
  1024. }
  1025. //static
  1026. void LLPanelVolume::refreshCost()
  1027. {
  1028. LLViewerObject* obj = gSelectMgr.getSelection()->getFirstObject();
  1029. if (obj)
  1030. {
  1031. obj->getObjectCost();
  1032. }
  1033. }
  1034. void LLPanelVolume::onLightCancelColor(LLUICtrl* ctrl, void* userdata)
  1035. {
  1036. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1037. if (self)
  1038. {
  1039. self->mSwatchLightColor->setColor(self->mLightSavedColor);
  1040. onLightSelectColor(NULL, userdata);
  1041. }
  1042. }
  1043. void LLPanelVolume::onLightCancelTexture(LLUICtrl* ctrl, void* userdata)
  1044. {
  1045. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1046. if (self)
  1047. {
  1048. self->mTextureLight->setImageAssetID(self->mLightSavedTexture);
  1049. }
  1050. }
  1051. void LLPanelVolume::onLightSelectColor(LLUICtrl* ctrl, void* userdata)
  1052. {
  1053. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1054. if (!self || !self->mObject ||
  1055. self->mObject->getPCode() != LL_PCODE_VOLUME)
  1056. {
  1057. return;
  1058. }
  1059. LLVOVolume* volobjp = (LLVOVolume*)self->mObject.get();
  1060. if (!volobjp) return;
  1061. LLColor4 clr = self->mSwatchLightColor->get();
  1062. LLColor3 clr3(clr);
  1063. volobjp->setLightSRGBColor(clr3);
  1064. self->mLightSavedColor = clr;
  1065. }
  1066. void LLPanelVolume::onLightSelectTexture(LLUICtrl* ctrl, void* userdata)
  1067. {
  1068. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1069. if (!self || !self->mObject ||
  1070. self->mObject->getPCode() != LL_PCODE_VOLUME)
  1071. {
  1072. return;
  1073. }
  1074. LLVOVolume* volobjp = (LLVOVolume*)self->mObject.get();
  1075. if (!volobjp) return;
  1076. LLUUID id = self->mTextureLight->getImageAssetID();
  1077. volobjp->setLightTextureID(id);
  1078. self->mLightSavedTexture = id;
  1079. }
  1080. //static
  1081. bool LLPanelVolume::onDragTexture(LLUICtrl* ctrl, LLInventoryItem* item,
  1082. void* userdata)
  1083. {
  1084. bool accept = true;
  1085. for (LLObjectSelection::root_iterator
  1086. iter = gSelectMgr.getSelection()->root_begin(),
  1087. end = gSelectMgr.getSelection()->root_end();
  1088. iter != end; ++iter)
  1089. {
  1090. LLSelectNode* node = *iter;
  1091. LLViewerObject* obj = node->getObject();
  1092. if (!LLToolDragAndDrop::isInventoryDropAcceptable(obj, item))
  1093. {
  1094. accept = false;
  1095. break;
  1096. }
  1097. }
  1098. return accept;
  1099. }
  1100. //static
  1101. void LLPanelVolume::onCommitMaterial(LLUICtrl* ctrl, void* userdata)
  1102. {
  1103. if (!userdata || !ctrl)
  1104. {
  1105. return;
  1106. }
  1107. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1108. LLComboBox* combop = (LLComboBox*)ctrl;
  1109. const std::string& material_name = combop->getSimple();
  1110. if (material_name == self->mFullBright)
  1111. {
  1112. return;
  1113. }
  1114. // Apply the currently selected material to the object
  1115. U8 mcode = gMaterialTable.getMCode(material_name);
  1116. LLViewerObject* objectp = self->mObject;
  1117. if (objectp)
  1118. {
  1119. objectp->setPhysicsGravity(DEFAULT_GRAVITY_MULTIPLIER);
  1120. objectp->setPhysicsFriction(gMaterialTable.getFriction(mcode));
  1121. // Currently density is always set to 1000 server side regardless of
  1122. // chosen material, actual material density should be used here, if
  1123. // this behavior changes.
  1124. objectp->setPhysicsDensity(DEFAULT_DENSITY);
  1125. objectp->setPhysicsRestitution(gMaterialTable.getRestitution(mcode));
  1126. }
  1127. gSelectMgr.selectionSetMaterial(mcode);
  1128. }
  1129. //static
  1130. void LLPanelVolume::onCommitLight(LLUICtrl* ctrl, void* userdata)
  1131. {
  1132. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1133. if (!self || !self->mObject ||
  1134. self->mObject->getPCode() != LL_PCODE_VOLUME)
  1135. {
  1136. return;
  1137. }
  1138. LLVOVolume* volobjp = (LLVOVolume*)self->mObject.get();
  1139. if (!volobjp) return;
  1140. volobjp->setLightIntensity((F32)self->mSpinLightIntensity->getValue().asReal());
  1141. volobjp->setLightRadius((F32)self->mSpinLightRadius->getValue().asReal());
  1142. volobjp->setLightFalloff((F32)self->mSpinLightFalloff->getValue().asReal());
  1143. LLColor4 clr = self->mSwatchLightColor->get();
  1144. volobjp->setLightSRGBColor(LLColor3(clr));
  1145. LLUUID id = self->mTextureLight->getImageAssetID();
  1146. if (id.notNull())
  1147. {
  1148. if (!volobjp->isLightSpotlight())
  1149. {
  1150. // This commit is making this a spot light; set UI to
  1151. // default params
  1152. volobjp->setLightTextureID(id);
  1153. LLVector3 spot_params = volobjp->getSpotLightParams();
  1154. self->mSpinLightFOV->setValue(spot_params.mV[0]);
  1155. self->mSpinLightFocus->setValue(spot_params.mV[1]);
  1156. self->mSpinLightAmbiance->setValue(spot_params.mV[2]);
  1157. }
  1158. else
  1159. {
  1160. // Modifying existing params
  1161. LLVector3 spot_params;
  1162. spot_params.mV[0] = (F32)self->mSpinLightFOV->getValue().asReal();
  1163. spot_params.mV[1] =
  1164. (F32)self->mSpinLightFocus->getValue().asReal();
  1165. spot_params.mV[2] =
  1166. (F32)self->mSpinLightAmbiance->getValue().asReal();
  1167. volobjp->setSpotLightParams(spot_params);
  1168. }
  1169. }
  1170. else if (volobjp->isLightSpotlight())
  1171. {
  1172. // No longer a spot light
  1173. volobjp->setLightTextureID(id);
  1174. #if 0
  1175. self->mSpinLightFOV->setEnabled(false);
  1176. self->mSpinLightFocus->setEnabled(false);
  1177. self->mSpinLightAmbiance->setEnabled(false);
  1178. #endif
  1179. }
  1180. }
  1181. //static
  1182. void LLPanelVolume::onCommitIsLight(LLUICtrl* ctrl, void* userdata)
  1183. {
  1184. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1185. if (self)
  1186. {
  1187. self->sendIsLight();
  1188. }
  1189. }
  1190. //static
  1191. void LLPanelVolume::onCommitFlexible(LLUICtrl* ctrl, void* userdata)
  1192. {
  1193. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1194. if (!self) return;
  1195. LLViewerObject* objectp = self->mObject;
  1196. if (!objectp || objectp->getPCode() != LL_PCODE_VOLUME)
  1197. {
  1198. return;
  1199. }
  1200. const LLFlexibleObjectData* params = objectp->getFlexibleObjectData();
  1201. if (params)
  1202. {
  1203. LLFlexibleObjectData new_params(*params);
  1204. new_params.setSimulateLOD(self->mSpinFlexSections->getValue().asInteger());
  1205. new_params.setGravity((F32)self->mSpinFlexGravity->getValue().asReal());
  1206. new_params.setAirFriction((F32)self->mSpinFlexFriction->getValue().asReal());
  1207. new_params.setWindSensitivity((F32)self->mSpinFlexWind->getValue().asReal());
  1208. new_params.setTension((F32)self->mSpinFlexTension->getValue().asReal());
  1209. F32 fx = (F32)self->mSpinFlexForceX->getValue().asReal();
  1210. F32 fy = (F32)self->mSpinFlexForceY->getValue().asReal();
  1211. F32 fz = (F32)self->mSpinFlexForceZ->getValue().asReal();
  1212. LLVector3 force(fx, fy, fz);
  1213. new_params.setUserForce(force);
  1214. objectp->setParameterEntry(LLNetworkData::PARAMS_FLEXIBLE, new_params, true);
  1215. }
  1216. // Values may fail validation
  1217. self->refresh();
  1218. }
  1219. bool handleResponseChangeToFlexible(const LLSD& notification,
  1220. const LLSD& response,
  1221. LLPanelVolume* self)
  1222. {
  1223. S32 option = LLNotification::getSelectedOption(notification, response);
  1224. if (self && option == 0)
  1225. {
  1226. self->sendIsFlexible();
  1227. }
  1228. return false;
  1229. }
  1230. //static
  1231. void LLPanelVolume::onCommitIsFlexible(LLUICtrl* ctrl, void* userdata)
  1232. {
  1233. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1234. if (self && self->mObject)
  1235. {
  1236. if (self->mObject->flagObjectPermanent())
  1237. {
  1238. gNotifications.add("ChangeToFlexiblePath", LLSD(), LLSD(),
  1239. boost::bind(handleResponseChangeToFlexible,
  1240. _1, _2, self));
  1241. }
  1242. else
  1243. {
  1244. self->sendIsFlexible();
  1245. }
  1246. }
  1247. }
  1248. //static
  1249. void LLPanelVolume::onCommitAnimatedMesh(LLUICtrl* ctrl, void* userdata)
  1250. {
  1251. LLPanelVolume* self = (LLPanelVolume*)userdata;
  1252. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  1253. if (!self || !check) return;
  1254. LLViewerObject* objectp = self->mObject;
  1255. if (!objectp || objectp->getPCode() != LL_PCODE_VOLUME)
  1256. {
  1257. return;
  1258. }
  1259. LLVOVolume* volobjp = (LLVOVolume*)objectp;
  1260. U32 flags = volobjp->getExtendedMeshFlags();
  1261. U32 new_flags = flags;
  1262. if (check->get())
  1263. {
  1264. new_flags |= LLExtendedMeshParams::ANIMATED_MESH_ENABLED_FLAG;
  1265. }
  1266. else
  1267. {
  1268. new_flags &= ~LLExtendedMeshParams::ANIMATED_MESH_ENABLED_FLAG;
  1269. }
  1270. if (new_flags != flags)
  1271. {
  1272. volobjp->setExtendedMeshFlags(new_flags);
  1273. }
  1274. // Refresh any bake on mesh texture
  1275. volobjp->refreshBakeTexture();
  1276. LLViewerObject::const_child_list_t& child_list = volobjp->getChildren();
  1277. for (LLViewerObject::child_list_t::const_iterator
  1278. it = child_list.begin(), end = child_list.end();
  1279. it != end; ++it)
  1280. {
  1281. LLViewerObject* childp = *it;
  1282. if (childp)
  1283. {
  1284. childp->refreshBakeTexture();
  1285. }
  1286. }
  1287. if (isAgentAvatarValid())
  1288. {
  1289. gAgentAvatarp->updateMeshVisibility();
  1290. }
  1291. }
  1292. //static
  1293. void LLPanelVolume::onClickProbe(void* userdata)
  1294. {
  1295. HBReflectionProbe::show((LLView*)userdata);
  1296. }