/indra/newview/llpanelvolume.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 882 lines · 676 code · 127 blank · 79 comment · 95 complexity · 8ffa7188675c1bcfce3e3acc0b84d251 MD5 · raw file

  1. /**
  2. * @file llpanelvolume.cpp
  3. * @brief Object editing (position, scale, etc.) in the tools floater
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. // file include
  28. #include "llpanelvolume.h"
  29. // linden library includes
  30. #include "llclickaction.h"
  31. #include "lleconomy.h"
  32. #include "llerror.h"
  33. #include "llfontgl.h"
  34. #include "llflexibleobject.h"
  35. #include "llmaterialtable.h"
  36. #include "llpermissionsflags.h"
  37. #include "llstring.h"
  38. #include "llvolume.h"
  39. #include "m3math.h"
  40. #include "material_codes.h"
  41. // project includes
  42. #include "llbutton.h"
  43. #include "llcheckboxctrl.h"
  44. #include "llcolorswatch.h"
  45. #include "lltexturectrl.h"
  46. #include "llcombobox.h"
  47. //#include "llfirstuse.h"
  48. #include "llfocusmgr.h"
  49. #include "llmanipscale.h"
  50. #include "llpreviewscript.h"
  51. #include "llresmgr.h"
  52. #include "llselectmgr.h"
  53. #include "llspinctrl.h"
  54. #include "lltextbox.h"
  55. #include "lltool.h"
  56. #include "lltoolcomp.h"
  57. #include "lltoolmgr.h"
  58. #include "lltrans.h"
  59. #include "llui.h"
  60. #include "llviewerobject.h"
  61. #include "llviewerregion.h"
  62. #include "llviewerwindow.h"
  63. #include "llvovolume.h"
  64. #include "llworld.h"
  65. #include "pipeline.h"
  66. #include "llviewershadermgr.h"
  67. #include "lldrawpool.h"
  68. #include "lluictrlfactory.h"
  69. // For mesh physics
  70. #include "llagent.h"
  71. #include "llviewercontrol.h"
  72. #include "llmeshrepository.h"
  73. // "Features" Tab
  74. BOOL LLPanelVolume::postBuild()
  75. {
  76. // Flexible Objects Parameters
  77. {
  78. childSetCommitCallback("Flexible1D Checkbox Ctrl",onCommitIsFlexible,this);
  79. childSetCommitCallback("FlexNumSections",onCommitFlexible,this);
  80. getChild<LLUICtrl>("FlexNumSections")->setValidateBeforeCommit(precommitValidate);
  81. childSetCommitCallback("FlexGravity",onCommitFlexible,this);
  82. getChild<LLUICtrl>("FlexGravity")->setValidateBeforeCommit(precommitValidate);
  83. childSetCommitCallback("FlexFriction",onCommitFlexible,this);
  84. getChild<LLUICtrl>("FlexFriction")->setValidateBeforeCommit(precommitValidate);
  85. childSetCommitCallback("FlexWind",onCommitFlexible,this);
  86. getChild<LLUICtrl>("FlexWind")->setValidateBeforeCommit(precommitValidate);
  87. childSetCommitCallback("FlexTension",onCommitFlexible,this);
  88. getChild<LLUICtrl>("FlexTension")->setValidateBeforeCommit(precommitValidate);
  89. childSetCommitCallback("FlexForceX",onCommitFlexible,this);
  90. getChild<LLUICtrl>("FlexForceX")->setValidateBeforeCommit(precommitValidate);
  91. childSetCommitCallback("FlexForceY",onCommitFlexible,this);
  92. getChild<LLUICtrl>("FlexForceY")->setValidateBeforeCommit(precommitValidate);
  93. childSetCommitCallback("FlexForceZ",onCommitFlexible,this);
  94. getChild<LLUICtrl>("FlexForceZ")->setValidateBeforeCommit(precommitValidate);
  95. }
  96. // LIGHT Parameters
  97. {
  98. childSetCommitCallback("Light Checkbox Ctrl",onCommitIsLight,this);
  99. LLColorSwatchCtrl* LightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  100. if(LightColorSwatch){
  101. LightColorSwatch->setOnCancelCallback(boost::bind(&LLPanelVolume::onLightCancelColor, this, _2));
  102. LightColorSwatch->setOnSelectCallback(boost::bind(&LLPanelVolume::onLightSelectColor, this, _2));
  103. childSetCommitCallback("colorswatch",onCommitLight,this);
  104. }
  105. LLTextureCtrl* LightTexPicker = getChild<LLTextureCtrl>("light texture control");
  106. if (LightTexPicker)
  107. {
  108. LightTexPicker->setOnCancelCallback(boost::bind(&LLPanelVolume::onLightCancelTexture, this, _2));
  109. LightTexPicker->setOnSelectCallback(boost::bind(&LLPanelVolume::onLightSelectTexture, this, _2));
  110. childSetCommitCallback("light texture control", onCommitLight, this);
  111. }
  112. childSetCommitCallback("Light Intensity",onCommitLight,this);
  113. getChild<LLUICtrl>("Light Intensity")->setValidateBeforeCommit(precommitValidate);
  114. childSetCommitCallback("Light Radius",onCommitLight,this);
  115. getChild<LLUICtrl>("Light Radius")->setValidateBeforeCommit(precommitValidate);
  116. childSetCommitCallback("Light Falloff",onCommitLight,this);
  117. getChild<LLUICtrl>("Light Falloff")->setValidateBeforeCommit(precommitValidate);
  118. childSetCommitCallback("Light FOV", onCommitLight, this);
  119. getChild<LLUICtrl>("Light FOV")->setValidateBeforeCommit( precommitValidate);
  120. childSetCommitCallback("Light Focus", onCommitLight, this);
  121. getChild<LLUICtrl>("Light Focus")->setValidateBeforeCommit( precommitValidate);
  122. childSetCommitCallback("Light Ambiance", onCommitLight, this);
  123. getChild<LLUICtrl>("Light Ambiance")->setValidateBeforeCommit( precommitValidate);
  124. }
  125. // PHYSICS Parameters
  126. {
  127. // PhysicsShapeType combobox
  128. mComboPhysicsShapeType = getChild<LLComboBox>("Physics Shape Type Combo Ctrl");
  129. mComboPhysicsShapeType->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsShapeType, this, _1, mComboPhysicsShapeType));
  130. // PhysicsGravity
  131. mSpinPhysicsGravity = getChild<LLSpinCtrl>("Physics Gravity");
  132. mSpinPhysicsGravity->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsGravity, this, _1, mSpinPhysicsGravity));
  133. // PhysicsFriction
  134. mSpinPhysicsFriction = getChild<LLSpinCtrl>("Physics Friction");
  135. mSpinPhysicsFriction->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsFriction, this, _1, mSpinPhysicsFriction));
  136. // PhysicsDensity
  137. mSpinPhysicsDensity = getChild<LLSpinCtrl>("Physics Density");
  138. mSpinPhysicsDensity->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsDensity, this, _1, mSpinPhysicsDensity));
  139. // PhysicsRestitution
  140. mSpinPhysicsRestitution = getChild<LLSpinCtrl>("Physics Restitution");
  141. mSpinPhysicsRestitution->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsRestitution, this, _1, mSpinPhysicsRestitution));
  142. }
  143. std::map<std::string, std::string> material_name_map;
  144. material_name_map["Stone"]= LLTrans::getString("Stone");
  145. material_name_map["Metal"]= LLTrans::getString("Metal");
  146. material_name_map["Glass"]= LLTrans::getString("Glass");
  147. material_name_map["Wood"]= LLTrans::getString("Wood");
  148. material_name_map["Flesh"]= LLTrans::getString("Flesh");
  149. material_name_map["Plastic"]= LLTrans::getString("Plastic");
  150. material_name_map["Rubber"]= LLTrans::getString("Rubber");
  151. material_name_map["Light"]= LLTrans::getString("Light");
  152. LLMaterialTable::basic.initTableTransNames(material_name_map);
  153. // material type popup
  154. mComboMaterial = getChild<LLComboBox>("material");
  155. childSetCommitCallback("material",onCommitMaterial,this);
  156. mComboMaterial->removeall();
  157. for (LLMaterialTable::info_list_t::iterator iter = LLMaterialTable::basic.mMaterialInfoList.begin();
  158. iter != LLMaterialTable::basic.mMaterialInfoList.end(); ++iter)
  159. {
  160. LLMaterialInfo* minfop = *iter;
  161. if (minfop->mMCode != LL_MCODE_LIGHT)
  162. {
  163. mComboMaterial->add(minfop->mName);
  164. }
  165. }
  166. mComboMaterialItemCount = mComboMaterial->getItemCount();
  167. // Start with everyone disabled
  168. clearCtrls();
  169. return TRUE;
  170. }
  171. LLPanelVolume::LLPanelVolume()
  172. : LLPanel(),
  173. mComboMaterialItemCount(0)
  174. {
  175. setMouseOpaque(FALSE);
  176. }
  177. LLPanelVolume::~LLPanelVolume()
  178. {
  179. // Children all cleaned up by default view destructor.
  180. }
  181. void LLPanelVolume::getState( )
  182. {
  183. LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject();
  184. LLViewerObject* root_objectp = objectp;
  185. if(!objectp)
  186. {
  187. objectp = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
  188. // *FIX: shouldn't we just keep the child?
  189. if (objectp)
  190. {
  191. LLViewerObject* parentp = objectp->getRootEdit();
  192. if (parentp)
  193. {
  194. root_objectp = parentp;
  195. }
  196. else
  197. {
  198. root_objectp = objectp;
  199. }
  200. }
  201. }
  202. LLVOVolume *volobjp = NULL;
  203. if ( objectp && (objectp->getPCode() == LL_PCODE_VOLUME))
  204. {
  205. volobjp = (LLVOVolume *)objectp;
  206. }
  207. if( !objectp )
  208. {
  209. //forfeit focus
  210. if (gFocusMgr.childHasKeyboardFocus(this))
  211. {
  212. gFocusMgr.setKeyboardFocus(NULL);
  213. }
  214. // Disable all text input fields
  215. clearCtrls();
  216. return;
  217. }
  218. BOOL owners_identical;
  219. LLUUID owner_id;
  220. std::string owner_name;
  221. owners_identical = LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name);
  222. // BUG? Check for all objects being editable?
  223. BOOL editable = root_objectp->permModify();
  224. BOOL single_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME )
  225. && LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1;
  226. // Select Single Message
  227. if (single_volume)
  228. {
  229. getChildView("edit_object")->setVisible(true);
  230. getChildView("edit_object")->setEnabled(true);
  231. getChildView("select_single")->setVisible(false);
  232. }
  233. else
  234. {
  235. getChildView("edit_object")->setVisible(false);
  236. getChildView("select_single")->setVisible(true);
  237. getChildView("select_single")->setEnabled(true);
  238. }
  239. // Light properties
  240. BOOL is_light = volobjp && volobjp->getIsLight();
  241. getChild<LLUICtrl>("Light Checkbox Ctrl")->setValue(is_light);
  242. getChildView("Light Checkbox Ctrl")->setEnabled(editable && single_volume && volobjp);
  243. if (is_light && editable && single_volume)
  244. {
  245. getChildView("label color")->setEnabled(true);
  246. //mLabelColor ->setEnabled( TRUE );
  247. LLColorSwatchCtrl* LightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  248. if(LightColorSwatch)
  249. {
  250. LightColorSwatch->setEnabled( TRUE );
  251. LightColorSwatch->setValid( TRUE );
  252. LightColorSwatch->set(volobjp->getLightBaseColor());
  253. }
  254. LLTextureCtrl* LightTextureCtrl = getChild<LLTextureCtrl>("light texture control");
  255. if (LightTextureCtrl)
  256. {
  257. LightTextureCtrl->setEnabled(TRUE);
  258. LightTextureCtrl->setValid(TRUE);
  259. LightTextureCtrl->setImageAssetID(volobjp->getLightTextureID());
  260. }
  261. getChildView("Light Intensity")->setEnabled(true);
  262. getChildView("Light Radius")->setEnabled(true);
  263. getChildView("Light Falloff")->setEnabled(true);
  264. getChildView("Light FOV")->setEnabled(true);
  265. getChildView("Light Focus")->setEnabled(true);
  266. getChildView("Light Ambiance")->setEnabled(true);
  267. getChild<LLUICtrl>("Light Intensity")->setValue(volobjp->getLightIntensity());
  268. getChild<LLUICtrl>("Light Radius")->setValue(volobjp->getLightRadius());
  269. getChild<LLUICtrl>("Light Falloff")->setValue(volobjp->getLightFalloff());
  270. LLVector3 params = volobjp->getSpotLightParams();
  271. getChild<LLUICtrl>("Light FOV")->setValue(params.mV[0]);
  272. getChild<LLUICtrl>("Light Focus")->setValue(params.mV[1]);
  273. getChild<LLUICtrl>("Light Ambiance")->setValue(params.mV[2]);
  274. mLightSavedColor = volobjp->getLightColor();
  275. }
  276. else
  277. {
  278. getChild<LLSpinCtrl>("Light Intensity", true)->clear();
  279. getChild<LLSpinCtrl>("Light Radius", true)->clear();
  280. getChild<LLSpinCtrl>("Light Falloff", true)->clear();
  281. getChildView("label color")->setEnabled(false);
  282. LLColorSwatchCtrl* LightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  283. if(LightColorSwatch)
  284. {
  285. LightColorSwatch->setEnabled( FALSE );
  286. LightColorSwatch->setValid( FALSE );
  287. }
  288. LLTextureCtrl* LightTextureCtrl = getChild<LLTextureCtrl>("light texture control");
  289. if (LightTextureCtrl)
  290. {
  291. LightTextureCtrl->setEnabled(FALSE);
  292. LightTextureCtrl->setValid(FALSE);
  293. }
  294. getChildView("Light Intensity")->setEnabled(false);
  295. getChildView("Light Radius")->setEnabled(false);
  296. getChildView("Light Falloff")->setEnabled(false);
  297. getChildView("Light FOV")->setEnabled(false);
  298. getChildView("Light Focus")->setEnabled(false);
  299. getChildView("Light Ambiance")->setEnabled(false);
  300. }
  301. // Flexible properties
  302. BOOL is_flexible = volobjp && volobjp->isFlexible();
  303. getChild<LLUICtrl>("Flexible1D Checkbox Ctrl")->setValue(is_flexible);
  304. if (is_flexible || (volobjp && volobjp->canBeFlexible()))
  305. {
  306. getChildView("Flexible1D Checkbox Ctrl")->setEnabled(editable && single_volume && volobjp && !volobjp->isMesh());
  307. }
  308. else
  309. {
  310. getChildView("Flexible1D Checkbox Ctrl")->setEnabled(false);
  311. }
  312. if (is_flexible && editable && single_volume)
  313. {
  314. getChildView("FlexNumSections")->setVisible(true);
  315. getChildView("FlexGravity")->setVisible(true);
  316. getChildView("FlexTension")->setVisible(true);
  317. getChildView("FlexFriction")->setVisible(true);
  318. getChildView("FlexWind")->setVisible(true);
  319. getChildView("FlexForceX")->setVisible(true);
  320. getChildView("FlexForceY")->setVisible(true);
  321. getChildView("FlexForceZ")->setVisible(true);
  322. getChildView("FlexNumSections")->setEnabled(true);
  323. getChildView("FlexGravity")->setEnabled(true);
  324. getChildView("FlexTension")->setEnabled(true);
  325. getChildView("FlexFriction")->setEnabled(true);
  326. getChildView("FlexWind")->setEnabled(true);
  327. getChildView("FlexForceX")->setEnabled(true);
  328. getChildView("FlexForceY")->setEnabled(true);
  329. getChildView("FlexForceZ")->setEnabled(true);
  330. LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getParameterEntry(LLNetworkData::PARAMS_FLEXIBLE);
  331. getChild<LLUICtrl>("FlexNumSections")->setValue((F32)attributes->getSimulateLOD());
  332. getChild<LLUICtrl>("FlexGravity")->setValue(attributes->getGravity());
  333. getChild<LLUICtrl>("FlexTension")->setValue(attributes->getTension());
  334. getChild<LLUICtrl>("FlexFriction")->setValue(attributes->getAirFriction());
  335. getChild<LLUICtrl>("FlexWind")->setValue(attributes->getWindSensitivity());
  336. getChild<LLUICtrl>("FlexForceX")->setValue(attributes->getUserForce().mV[VX]);
  337. getChild<LLUICtrl>("FlexForceY")->setValue(attributes->getUserForce().mV[VY]);
  338. getChild<LLUICtrl>("FlexForceZ")->setValue(attributes->getUserForce().mV[VZ]);
  339. }
  340. else
  341. {
  342. getChild<LLSpinCtrl>("FlexNumSections", true)->clear();
  343. getChild<LLSpinCtrl>("FlexGravity", true)->clear();
  344. getChild<LLSpinCtrl>("FlexTension", true)->clear();
  345. getChild<LLSpinCtrl>("FlexFriction", true)->clear();
  346. getChild<LLSpinCtrl>("FlexWind", true)->clear();
  347. getChild<LLSpinCtrl>("FlexForceX", true)->clear();
  348. getChild<LLSpinCtrl>("FlexForceY", true)->clear();
  349. getChild<LLSpinCtrl>("FlexForceZ", true)->clear();
  350. getChildView("FlexNumSections")->setEnabled(false);
  351. getChildView("FlexGravity")->setEnabled(false);
  352. getChildView("FlexTension")->setEnabled(false);
  353. getChildView("FlexFriction")->setEnabled(false);
  354. getChildView("FlexWind")->setEnabled(false);
  355. getChildView("FlexForceX")->setEnabled(false);
  356. getChildView("FlexForceY")->setEnabled(false);
  357. getChildView("FlexForceZ")->setEnabled(false);
  358. }
  359. // Material properties
  360. // Update material part
  361. // slightly inefficient - materials are unique per object, not per TE
  362. U8 material_code = 0;
  363. struct f : public LLSelectedTEGetFunctor<U8>
  364. {
  365. U8 get(LLViewerObject* object, S32 te)
  366. {
  367. return object->getMaterial();
  368. }
  369. } func;
  370. bool material_same = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, material_code );
  371. std::string LEGACY_FULLBRIGHT_DESC = LLTrans::getString("Fullbright");
  372. if (editable && single_volume && material_same)
  373. {
  374. mComboMaterial->setEnabled( TRUE );
  375. if (material_code == LL_MCODE_LIGHT)
  376. {
  377. if (mComboMaterial->getItemCount() == mComboMaterialItemCount)
  378. {
  379. mComboMaterial->add(LEGACY_FULLBRIGHT_DESC);
  380. }
  381. mComboMaterial->setSimple(LEGACY_FULLBRIGHT_DESC);
  382. }
  383. else
  384. {
  385. if (mComboMaterial->getItemCount() != mComboMaterialItemCount)
  386. {
  387. mComboMaterial->remove(LEGACY_FULLBRIGHT_DESC);
  388. }
  389. mComboMaterial->setSimple(std::string(LLMaterialTable::basic.getName(material_code)));
  390. }
  391. }
  392. else
  393. {
  394. mComboMaterial->setEnabled( FALSE );
  395. }
  396. // Physics properties
  397. mSpinPhysicsGravity->set(objectp->getPhysicsGravity());
  398. mSpinPhysicsGravity->setEnabled(editable);
  399. mSpinPhysicsFriction->set(objectp->getPhysicsFriction());
  400. mSpinPhysicsFriction->setEnabled(editable);
  401. mSpinPhysicsDensity->set(objectp->getPhysicsDensity());
  402. mSpinPhysicsDensity->setEnabled(editable);
  403. mSpinPhysicsRestitution->set(objectp->getPhysicsRestitution());
  404. mSpinPhysicsRestitution->setEnabled(editable);
  405. // update the physics shape combo to include allowed physics shapes
  406. mComboPhysicsShapeType->removeall();
  407. mComboPhysicsShapeType->add(getString("None"), LLSD(1));
  408. BOOL isMesh = FALSE;
  409. LLSculptParams *sculpt_params = (LLSculptParams *)objectp->getParameterEntry(LLNetworkData::PARAMS_SCULPT);
  410. if (sculpt_params)
  411. {
  412. U8 sculpt_type = sculpt_params->getSculptType();
  413. U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
  414. isMesh = (sculpt_stitching == LL_SCULPT_TYPE_MESH);
  415. }
  416. if(isMesh && objectp)
  417. {
  418. const LLVolumeParams &volume_params = objectp->getVolume()->getParams();
  419. LLUUID mesh_id = volume_params.getSculptID();
  420. if(gMeshRepo.hasPhysicsShape(mesh_id))
  421. {
  422. // if a mesh contains an uploaded or decomposed physics mesh,
  423. // allow 'Prim'
  424. mComboPhysicsShapeType->add(getString("Prim"), LLSD(0));
  425. }
  426. }
  427. else
  428. {
  429. // simple prims always allow physics shape prim
  430. mComboPhysicsShapeType->add(getString("Prim"), LLSD(0));
  431. }
  432. mComboPhysicsShapeType->add(getString("Convex Hull"), LLSD(2));
  433. mComboPhysicsShapeType->setValue(LLSD(objectp->getPhysicsShapeType()));
  434. mComboPhysicsShapeType->setEnabled(editable);
  435. mObject = objectp;
  436. mRootObject = root_objectp;
  437. }
  438. // static
  439. bool LLPanelVolume::precommitValidate( const LLSD& data )
  440. {
  441. // TODO: Richard will fill this in later.
  442. return TRUE; // FALSE means that validation failed and new value should not be commited.
  443. }
  444. void LLPanelVolume::refresh()
  445. {
  446. getState();
  447. if (mObject.notNull() && mObject->isDead())
  448. {
  449. mObject = NULL;
  450. }
  451. if (mRootObject.notNull() && mRootObject->isDead())
  452. {
  453. mRootObject = NULL;
  454. }
  455. BOOL visible = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_DEFERRED) > 0 ? TRUE : FALSE;
  456. getChildView("label texture")->setVisible( visible);
  457. getChildView("Light FOV")->setVisible( visible);
  458. getChildView("Light Focus")->setVisible( visible);
  459. getChildView("Light Ambiance")->setVisible( visible);
  460. getChildView("light texture control")->setVisible( visible);
  461. bool enable_mesh = false;
  462. LLSD sim_features;
  463. LLViewerRegion *region = gAgent.getRegion();
  464. if(region)
  465. {
  466. LLSD sim_features;
  467. region->getSimulatorFeatures(sim_features);
  468. enable_mesh = sim_features.has("PhysicsShapeTypes");
  469. }
  470. getChildView("label physicsshapetype")->setVisible(enable_mesh);
  471. getChildView("Physics Shape Type Combo Ctrl")->setVisible(enable_mesh);
  472. getChildView("Physics Gravity")->setVisible(enable_mesh);
  473. getChildView("Physics Friction")->setVisible(enable_mesh);
  474. getChildView("Physics Density")->setVisible(enable_mesh);
  475. getChildView("Physics Restitution")->setVisible(enable_mesh);
  476. /* TODO: add/remove individual physics shape types as per the PhysicsShapeTypes simulator features */
  477. }
  478. void LLPanelVolume::draw()
  479. {
  480. LLPanel::draw();
  481. }
  482. // virtual
  483. void LLPanelVolume::clearCtrls()
  484. {
  485. LLPanel::clearCtrls();
  486. getChildView("select_single")->setEnabled(false);
  487. getChildView("select_single")->setVisible(true);
  488. getChildView("edit_object")->setEnabled(false);
  489. getChildView("edit_object")->setVisible(false);
  490. getChildView("Light Checkbox Ctrl")->setEnabled(false);
  491. getChildView("label color")->setEnabled(false);
  492. getChildView("label color")->setEnabled(false);
  493. LLColorSwatchCtrl* LightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  494. if(LightColorSwatch)
  495. {
  496. LightColorSwatch->setEnabled( FALSE );
  497. LightColorSwatch->setValid( FALSE );
  498. }
  499. LLTextureCtrl* LightTextureCtrl = getChild<LLTextureCtrl>("light texture control");
  500. if(LightTextureCtrl)
  501. {
  502. LightTextureCtrl->setEnabled( FALSE );
  503. LightTextureCtrl->setValid( FALSE );
  504. }
  505. getChildView("Light Intensity")->setEnabled(false);
  506. getChildView("Light Radius")->setEnabled(false);
  507. getChildView("Light Falloff")->setEnabled(false);
  508. getChildView("Flexible1D Checkbox Ctrl")->setEnabled(false);
  509. getChildView("FlexNumSections")->setEnabled(false);
  510. getChildView("FlexGravity")->setEnabled(false);
  511. getChildView("FlexTension")->setEnabled(false);
  512. getChildView("FlexFriction")->setEnabled(false);
  513. getChildView("FlexWind")->setEnabled(false);
  514. getChildView("FlexForceX")->setEnabled(false);
  515. getChildView("FlexForceY")->setEnabled(false);
  516. getChildView("FlexForceZ")->setEnabled(false);
  517. mSpinPhysicsGravity->setEnabled(FALSE);
  518. mSpinPhysicsFriction->setEnabled(FALSE);
  519. mSpinPhysicsDensity->setEnabled(FALSE);
  520. mSpinPhysicsRestitution->setEnabled(FALSE);
  521. mComboMaterial->setEnabled( FALSE );
  522. }
  523. //
  524. // Static functions
  525. //
  526. void LLPanelVolume::sendIsLight()
  527. {
  528. LLViewerObject* objectp = mObject;
  529. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  530. {
  531. return;
  532. }
  533. LLVOVolume *volobjp = (LLVOVolume *)objectp;
  534. BOOL value = getChild<LLUICtrl>("Light Checkbox Ctrl")->getValue();
  535. volobjp->setIsLight(value);
  536. llinfos << "update light sent" << llendl;
  537. }
  538. void LLPanelVolume::sendIsFlexible()
  539. {
  540. LLViewerObject* objectp = mObject;
  541. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  542. {
  543. return;
  544. }
  545. LLVOVolume *volobjp = (LLVOVolume *)objectp;
  546. BOOL is_flexible = getChild<LLUICtrl>("Flexible1D Checkbox Ctrl")->getValue();
  547. //BOOL is_flexible = mCheckFlexible1D->get();
  548. if (is_flexible)
  549. {
  550. //LLFirstUse::useFlexible();
  551. if (objectp->getClickAction() == CLICK_ACTION_SIT)
  552. {
  553. LLSelectMgr::getInstance()->selectionSetClickAction(CLICK_ACTION_NONE);
  554. }
  555. }
  556. if (volobjp->setIsFlexible(is_flexible))
  557. {
  558. mObject->sendShapeUpdate();
  559. LLSelectMgr::getInstance()->selectionUpdatePhantom(volobjp->flagPhantom());
  560. }
  561. llinfos << "update flexible sent" << llendl;
  562. }
  563. void LLPanelVolume::sendPhysicsShapeType(LLUICtrl* ctrl, void* userdata)
  564. {
  565. U8 type = ctrl->getValue().asInteger();
  566. LLSelectMgr::getInstance()->selectionSetPhysicsType(type);
  567. refreshCost();
  568. }
  569. void LLPanelVolume::sendPhysicsGravity(LLUICtrl* ctrl, void* userdata)
  570. {
  571. F32 val = ctrl->getValue().asReal();
  572. LLSelectMgr::getInstance()->selectionSetGravity(val);
  573. }
  574. void LLPanelVolume::sendPhysicsFriction(LLUICtrl* ctrl, void* userdata)
  575. {
  576. F32 val = ctrl->getValue().asReal();
  577. LLSelectMgr::getInstance()->selectionSetFriction(val);
  578. }
  579. void LLPanelVolume::sendPhysicsRestitution(LLUICtrl* ctrl, void* userdata)
  580. {
  581. F32 val = ctrl->getValue().asReal();
  582. LLSelectMgr::getInstance()->selectionSetRestitution(val);
  583. }
  584. void LLPanelVolume::sendPhysicsDensity(LLUICtrl* ctrl, void* userdata)
  585. {
  586. F32 val = ctrl->getValue().asReal();
  587. LLSelectMgr::getInstance()->selectionSetDensity(val);
  588. }
  589. void LLPanelVolume::refreshCost()
  590. {
  591. LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
  592. if (obj)
  593. {
  594. obj->getObjectCost();
  595. }
  596. }
  597. void LLPanelVolume::onLightCancelColor(const LLSD& data)
  598. {
  599. LLColorSwatchCtrl* LightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  600. if(LightColorSwatch)
  601. {
  602. LightColorSwatch->setColor(mLightSavedColor);
  603. }
  604. onLightSelectColor(data);
  605. }
  606. void LLPanelVolume::onLightCancelTexture(const LLSD& data)
  607. {
  608. LLTextureCtrl* LightTextureCtrl = getChild<LLTextureCtrl>("light texture control");
  609. if (LightTextureCtrl)
  610. {
  611. LightTextureCtrl->setImageAssetID(mLightSavedTexture);
  612. }
  613. }
  614. void LLPanelVolume::onLightSelectColor(const LLSD& data)
  615. {
  616. LLViewerObject* objectp = mObject;
  617. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  618. {
  619. return;
  620. }
  621. LLVOVolume *volobjp = (LLVOVolume *)objectp;
  622. LLColorSwatchCtrl* LightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  623. if(LightColorSwatch)
  624. {
  625. LLColor4 clr = LightColorSwatch->get();
  626. LLColor3 clr3( clr );
  627. volobjp->setLightColor(clr3);
  628. mLightSavedColor = clr;
  629. }
  630. }
  631. void LLPanelVolume::onLightSelectTexture(const LLSD& data)
  632. {
  633. if (mObject.isNull() || (mObject->getPCode() != LL_PCODE_VOLUME))
  634. {
  635. return;
  636. }
  637. LLVOVolume *volobjp = (LLVOVolume *) mObject.get();
  638. LLTextureCtrl* LightTextureCtrl = getChild<LLTextureCtrl>("light texture control");
  639. if(LightTextureCtrl)
  640. {
  641. LLUUID id = LightTextureCtrl->getImageAssetID();
  642. volobjp->setLightTextureID(id);
  643. mLightSavedTexture = id;
  644. }
  645. }
  646. // static
  647. void LLPanelVolume::onCommitMaterial( LLUICtrl* ctrl, void* userdata )
  648. {
  649. //LLPanelObject* self = (LLPanelObject*) userdata;
  650. LLComboBox* box = (LLComboBox*) ctrl;
  651. if (box)
  652. {
  653. // apply the currently selected material to the object
  654. const std::string& material_name = box->getSimple();
  655. std::string LEGACY_FULLBRIGHT_DESC = LLTrans::getString("Fullbright");
  656. if (material_name != LEGACY_FULLBRIGHT_DESC)
  657. {
  658. U8 material_code = LLMaterialTable::basic.getMCode(material_name);
  659. LLSelectMgr::getInstance()->selectionSetMaterial(material_code);
  660. }
  661. }
  662. }
  663. // static
  664. void LLPanelVolume::onCommitLight( LLUICtrl* ctrl, void* userdata )
  665. {
  666. LLPanelVolume* self = (LLPanelVolume*) userdata;
  667. LLViewerObject* objectp = self->mObject;
  668. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  669. {
  670. return;
  671. }
  672. LLVOVolume *volobjp = (LLVOVolume *)objectp;
  673. volobjp->setLightIntensity((F32)self->getChild<LLUICtrl>("Light Intensity")->getValue().asReal());
  674. volobjp->setLightRadius((F32)self->getChild<LLUICtrl>("Light Radius")->getValue().asReal());
  675. volobjp->setLightFalloff((F32)self->getChild<LLUICtrl>("Light Falloff")->getValue().asReal());
  676. LLColorSwatchCtrl* LightColorSwatch = self->getChild<LLColorSwatchCtrl>("colorswatch");
  677. if(LightColorSwatch)
  678. {
  679. LLColor4 clr = LightColorSwatch->get();
  680. volobjp->setLightColor(LLColor3(clr));
  681. }
  682. LLTextureCtrl* LightTextureCtrl = self->getChild<LLTextureCtrl>("light texture control");
  683. if(LightTextureCtrl)
  684. {
  685. LLUUID id = LightTextureCtrl->getImageAssetID();
  686. if (id.notNull())
  687. {
  688. if (!volobjp->isLightSpotlight())
  689. { //this commit is making this a spot light, set UI to default params
  690. volobjp->setLightTextureID(id);
  691. LLVector3 spot_params = volobjp->getSpotLightParams();
  692. self->getChild<LLUICtrl>("Light FOV")->setValue(spot_params.mV[0]);
  693. self->getChild<LLUICtrl>("Light Focus")->setValue(spot_params.mV[1]);
  694. self->getChild<LLUICtrl>("Light Ambiance")->setValue(spot_params.mV[2]);
  695. }
  696. else
  697. { //modifying existing params
  698. LLVector3 spot_params;
  699. spot_params.mV[0] = (F32) self->getChild<LLUICtrl>("Light FOV")->getValue().asReal();
  700. spot_params.mV[1] = (F32) self->getChild<LLUICtrl>("Light Focus")->getValue().asReal();
  701. spot_params.mV[2] = (F32) self->getChild<LLUICtrl>("Light Ambiance")->getValue().asReal();
  702. volobjp->setSpotLightParams(spot_params);
  703. }
  704. }
  705. else if (volobjp->isLightSpotlight())
  706. { //no longer a spot light
  707. volobjp->setLightTextureID(id);
  708. //self->getChildView("Light FOV")->setEnabled(FALSE);
  709. //self->getChildView("Light Focus")->setEnabled(FALSE);
  710. //self->getChildView("Light Ambiance")->setEnabled(FALSE);
  711. }
  712. }
  713. }
  714. // static
  715. void LLPanelVolume::onCommitIsLight( LLUICtrl* ctrl, void* userdata )
  716. {
  717. LLPanelVolume* self = (LLPanelVolume*) userdata;
  718. self->sendIsLight();
  719. }
  720. //----------------------------------------------------------------------------
  721. // static
  722. void LLPanelVolume::onCommitFlexible( LLUICtrl* ctrl, void* userdata )
  723. {
  724. LLPanelVolume* self = (LLPanelVolume*) userdata;
  725. LLViewerObject* objectp = self->mObject;
  726. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  727. {
  728. return;
  729. }
  730. LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getParameterEntry(LLNetworkData::PARAMS_FLEXIBLE);
  731. if (attributes)
  732. {
  733. LLFlexibleObjectData new_attributes;
  734. new_attributes = *attributes;
  735. new_attributes.setSimulateLOD(self->getChild<LLUICtrl>("FlexNumSections")->getValue().asInteger());//(S32)self->mSpinSections->get());
  736. new_attributes.setGravity((F32)self->getChild<LLUICtrl>("FlexGravity")->getValue().asReal());
  737. new_attributes.setTension((F32)self->getChild<LLUICtrl>("FlexTension")->getValue().asReal());
  738. new_attributes.setAirFriction((F32)self->getChild<LLUICtrl>("FlexFriction")->getValue().asReal());
  739. new_attributes.setWindSensitivity((F32)self->getChild<LLUICtrl>("FlexWind")->getValue().asReal());
  740. F32 fx = (F32)self->getChild<LLUICtrl>("FlexForceX")->getValue().asReal();
  741. F32 fy = (F32)self->getChild<LLUICtrl>("FlexForceY")->getValue().asReal();
  742. F32 fz = (F32)self->getChild<LLUICtrl>("FlexForceZ")->getValue().asReal();
  743. LLVector3 force(fx,fy,fz);
  744. new_attributes.setUserForce(force);
  745. objectp->setParameterEntry(LLNetworkData::PARAMS_FLEXIBLE, new_attributes, true);
  746. }
  747. // Values may fail validation
  748. self->refresh();
  749. }
  750. // static
  751. void LLPanelVolume::onCommitIsFlexible( LLUICtrl* ctrl, void* userdata )
  752. {
  753. LLPanelVolume* self = (LLPanelVolume*) userdata;
  754. self->sendIsFlexible();
  755. }