llfloateranimpreview.cpp 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. /**
  2. * @file llfloateranimpreview.cpp
  3. * @brief LLFloaterAnimPreview class implementation
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2009, Linden Research, Inc.
  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 "llfloateranimpreview.h"
  34. #include "llanimationstates.h"
  35. #include "llbbox.h"
  36. #include "llbboxlocal.h"
  37. #include "llbutton.h"
  38. #include "llbvhloader.h"
  39. #include "lldatapacker.h"
  40. #include "lldir.h"
  41. #include "llfilesystem.h"
  42. #include "llkeyframemotion.h"
  43. #include "llnotifications.h"
  44. #include "llrender.h"
  45. #include "llresizehandle.h" // For RESIZE_HANDLE_WIDTH
  46. #include "lluictrlfactory.h"
  47. #include "llagent.h"
  48. #include "lldrawable.h"
  49. #include "lldrawpoolavatar.h"
  50. #include "llface.h"
  51. #include "llfloaterperms.h"
  52. #include "llpipeline.h"
  53. #include "lltoolmgr.h" // For MASK_* constants
  54. #include "llviewerassetupload.h" // For upload_new_resource()
  55. #include "llviewercamera.h"
  56. #include "llviewercontrol.h"
  57. #include "llviewerobjectlist.h"
  58. #include "llviewershadermgr.h"
  59. #include "llviewerwindow.h"
  60. #include "llvoavatarself.h"
  61. constexpr S32 PREVIEW_BORDER_WIDTH = 2;
  62. constexpr S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) +
  63. PREVIEW_BORDER_WIDTH;
  64. constexpr S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
  65. constexpr S32 PREF_BUTTON_HEIGHT = 16;
  66. constexpr S32 PREVIEW_TEXTURE_HEIGHT = 300;
  67. constexpr F32 PREVIEW_CAMERA_DISTANCE = 4.f;
  68. constexpr F32 MIN_CAMERA_ZOOM = 0.5f;
  69. constexpr F32 MAX_CAMERA_ZOOM = 10.f;
  70. constexpr F32 BASE_ANIM_TIME_OFFSET = 5.f;
  71. static std::string STATUS[] =
  72. {
  73. "E_ST_OK",
  74. "E_ST_EOF",
  75. "E_ST_NO_CONSTRAINT",
  76. "E_ST_NO_FILE",
  77. "E_ST_NO_HIER",
  78. "E_ST_NO_JOINT",
  79. "E_ST_NO_NAME",
  80. "E_ST_NO_OFFSET",
  81. "E_ST_NO_CHANNELS",
  82. "E_ST_NO_ROTATION",
  83. "E_ST_NO_AXIS",
  84. "E_ST_NO_MOTION",
  85. "E_ST_NO_FRAMES",
  86. "E_ST_NO_FRAME_TIME",
  87. "E_ST_NO_POS",
  88. "E_ST_NO_ROT",
  89. "E_ST_NO_XLT_FILE",
  90. "E_ST_NO_XLT_HEADER",
  91. "E_ST_NO_XLT_NAME",
  92. "E_ST_NO_XLT_IGNORE",
  93. "E_ST_NO_XLT_RELATIVE",
  94. "E_ST_NO_XLT_OUTNAME",
  95. "E_ST_NO_XLT_MATRIX",
  96. "E_ST_NO_XLT_MERGECHILD",
  97. "E_ST_NO_XLT_MERGEPARENT",
  98. "E_ST_NO_XLT_PRIORITY",
  99. "E_ST_NO_XLT_LOOP",
  100. "E_ST_NO_XLT_EASEIN",
  101. "E_ST_NO_XLT_EASEOUT",
  102. "E_ST_NO_XLT_HAND",
  103. "E_ST_NO_XLT_EMOTE",
  104. "E_ST_BAD_ROOT"
  105. };
  106. //-----------------------------------------------------------------------------
  107. // LLFloaterAnimPreview()
  108. //-----------------------------------------------------------------------------
  109. LLFloaterAnimPreview::LLFloaterAnimPreview(const std::string& filename)
  110. : HBFloaterUploadAsset(filename, LLInventoryType::IT_ANIMATION),
  111. mAnimPreview(NULL),
  112. mInWorld(false),
  113. mBadAnimation(false)
  114. {
  115. mLastMouseX = 0;
  116. mLastMouseY = 0;
  117. mIDList["Standing"] = ANIM_AGENT_STAND;
  118. mIDList["Walking"] = ANIM_AGENT_FEMALE_WALK;
  119. mIDList["Sitting"] = ANIM_AGENT_SIT_FEMALE;
  120. mIDList["Flying"] = ANIM_AGENT_HOVER;
  121. mIDList["[None]"] = LLUUID::null;
  122. mIDList["Aaaaah"] = ANIM_AGENT_EXPRESS_OPEN_MOUTH;
  123. mIDList["Afraid"] = ANIM_AGENT_EXPRESS_AFRAID;
  124. mIDList["Angry"] = ANIM_AGENT_EXPRESS_ANGER;
  125. mIDList["Big Smile"] = ANIM_AGENT_EXPRESS_TOOTHSMILE;
  126. mIDList["Bored"] = ANIM_AGENT_EXPRESS_BORED;
  127. mIDList["Cry"] = ANIM_AGENT_EXPRESS_CRY;
  128. mIDList["Disdain"] = ANIM_AGENT_EXPRESS_DISDAIN;
  129. mIDList["Embarrassed"] = ANIM_AGENT_EXPRESS_EMBARRASSED;
  130. mIDList["Frown"] = ANIM_AGENT_EXPRESS_FROWN;
  131. mIDList["Kiss"] = ANIM_AGENT_EXPRESS_KISS;
  132. mIDList["Laugh"] = ANIM_AGENT_EXPRESS_LAUGH;
  133. mIDList["Plllppt"] = ANIM_AGENT_EXPRESS_TONGUE_OUT;
  134. mIDList["Repulsed"] = ANIM_AGENT_EXPRESS_REPULSED;
  135. mIDList["Sad"] = ANIM_AGENT_EXPRESS_SAD;
  136. mIDList["Shrug"] = ANIM_AGENT_EXPRESS_SHRUG;
  137. mIDList["Smile"] = ANIM_AGENT_EXPRESS_SMILE;
  138. mIDList["Surprise"] = ANIM_AGENT_EXPRESS_SURPRISE;
  139. mIDList["Wink"] = ANIM_AGENT_EXPRESS_WINK;
  140. mIDList["Worry"] = ANIM_AGENT_EXPRESS_WORRY;
  141. mPlayImage = LLUI::getUIImage("button_anim_play.tga");
  142. mPlaySelectedImage = LLUI::getUIImage("button_anim_play_selected.tga");
  143. mPauseImage = LLUI::getUIImage("button_anim_pause.tga");
  144. mPauseSelectedImage = LLUI::getUIImage("button_anim_pause_selected.tga");
  145. LLUICtrlFactory::getInstance()->buildFloater(this,
  146. "floater_animation_preview.xml");
  147. }
  148. //virtual
  149. LLFloaterAnimPreview::~LLFloaterAnimPreview()
  150. {
  151. if (mInWorld && isAgentAvatarValid())
  152. {
  153. if (mMotionID.notNull())
  154. {
  155. gAgentAvatarp->stopMotion(mMotionID, true);
  156. gAgentAvatarp->removeMotion(mMotionID);
  157. }
  158. gAgentAvatarp->deactivateAllMotions();
  159. gAgentAvatarp->startMotion(ANIM_AGENT_STAND, BASE_ANIM_TIME_OFFSET);
  160. gAgentAvatarp->startDefaultMotions();
  161. }
  162. mAnimPreview = NULL;
  163. setEnabled(false);
  164. }
  165. //virtual
  166. bool LLFloaterAnimPreview::postBuild()
  167. {
  168. LLRect r;
  169. LLBVHLoader* loaderp = NULL;
  170. if (!HBFloaterUploadAsset::postBuild())
  171. {
  172. return false;
  173. }
  174. mInWorld = isAgentAvatarValid() &&
  175. gSavedSettings.getBool("PreviewAnimInWorld");
  176. childSetCommitCallback("name_form", onCommitName, this);
  177. setDefaultBtn();
  178. if (mInWorld)
  179. {
  180. r = getRect();
  181. translate(0, 230);
  182. reshape(r.getWidth(), r.getHeight() - 230);
  183. childSetValue("bad_animation_text", getString("in_world"));
  184. childShow("bad_animation_text");
  185. }
  186. else
  187. {
  188. childHide("bad_animation_text");
  189. }
  190. mPreviewRect.set(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT,
  191. getRect().getWidth() - PREVIEW_HPAD,
  192. PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
  193. mPreviewImageRect.set(0.f, 1.f, 1.f, 0.f);
  194. S32 y = mPreviewRect.mTop + gBtnHeight;
  195. S32 btn_left = PREVIEW_HPAD;
  196. r.set(btn_left, y, btn_left + 32, y - gBtnHeight);
  197. mPlayButton = getChild<LLButton>("play_btn");
  198. mPlayButton->setClickedCallback(onBtnPlay);
  199. mPlayButton->setCallbackUserData(this);
  200. mPlayButton->setImageUnselected(mPlayImage);
  201. mPlayButton->setImageSelected(mPlaySelectedImage);
  202. mPlayButton->setDisabledImages(LLStringUtil::null, LLStringUtil::null);
  203. mPlayButton->setScaleImage(true);
  204. mStopButton = getChild<LLButton>("stop_btn");
  205. mStopButton->setClickedCallback(onBtnStop);
  206. mStopButton->setCallbackUserData(this);
  207. mStopButton->setImages("button_anim_stop.tga",
  208. "button_anim_stop_selected.tga");
  209. mStopButton->setDisabledImages(LLStringUtil::null, LLStringUtil::null);
  210. mStopButton->setScaleImage(true);
  211. r.set(r.mRight + PREVIEW_HPAD, y, getRect().getWidth() - PREVIEW_HPAD,
  212. y - gBtnHeight);
  213. if (!mInWorld)
  214. {
  215. mAnimPreview = new LLPreviewAnimation(256, 256);
  216. }
  217. std::string exten = gDirUtil.getExtension(mFilename);
  218. if (exten == "bvh")
  219. {
  220. // Loading a bvh file
  221. S64 file_size = 0;
  222. LLFile infile(mFilenameAndPath, "rb", &file_size);
  223. if (infile)
  224. {
  225. char* file_buffer = new char[file_size + 1];
  226. if (infile.read((U8*)file_buffer, file_size) == file_size)
  227. {
  228. file_buffer[file_size] = '\0';
  229. ELoadStatus load_status = E_ST_OK;
  230. S32 line_number = 0;
  231. llinfos << "Loading BVH file " << mFilename << llendl;
  232. std::map<std::string, std::string> joint_alias_map =
  233. getJointAliases();
  234. loaderp = new LLBVHLoader(file_buffer, load_status,
  235. line_number, joint_alias_map);
  236. if (load_status == E_ST_NO_XLT_FILE)
  237. {
  238. llwarns << "NOTE: No translation table found." << llendl;
  239. }
  240. else if (load_status != E_ST_OK)
  241. {
  242. llwarns << "ERROR: [line: " << line_number << "] "
  243. << getString(STATUS[load_status]) << llendl;
  244. }
  245. }
  246. delete[] file_buffer;
  247. }
  248. else
  249. {
  250. llwarns << "Cannot open BVH file: " << mFilename << llendl;
  251. }
  252. }
  253. F32 max_anim_duration =
  254. llclamp(gSavedSettings.getF32("AnimationsMaxDuration"), 30.f,
  255. ABSOLUTE_MAX_ANIM_DURATION);
  256. if (loaderp && loaderp->isInitialized() &&
  257. loaderp->getDuration() <= max_anim_duration)
  258. {
  259. // Generate an unique Id for this motion
  260. mTransactionID.generate();
  261. mMotionID = mTransactionID.makeAssetID(gAgent.getSecureSessionID());
  262. // Motion will be returned, but it will be in a load-pending state, as
  263. // this is a new motion this motion will not request an asset transfer
  264. // until next update, so we have a chance to load the keyframe data
  265. // locally
  266. LLKeyframeMotion* motionp =
  267. mInWorld ?
  268. (LLKeyframeMotion*)gAgentAvatarp->createMotion(mMotionID) :
  269. (LLKeyframeMotion*)mAnimPreview->getDummyAvatar()->createMotion(mMotionID);
  270. // Create data buffer for keyframe initialization
  271. S32 buffer_size = loaderp->getOutputSize();
  272. U8* buffer = new U8[buffer_size];
  273. LLDataPackerBinaryBuffer dp(buffer, buffer_size);
  274. // Pass animation data through memory buffer
  275. llinfos << "Serializing loader..." << llendl;
  276. loaderp->serialize(dp);
  277. dp.reset();
  278. llinfos << "De-serializing motions..." << llendl;
  279. bool success = motionp && motionp->deserialize(dp, mMotionID, false);
  280. llinfos << "Done." << llendl;
  281. delete[] buffer;
  282. if (success)
  283. {
  284. setAnimCallbacks();
  285. if (!mInWorld)
  286. {
  287. const LLBBoxLocal& pelvis_bbox = motionp->getPelvisBBox();
  288. LLVector3 temp = pelvis_bbox.getCenter();
  289. #if 0 // only consider XY ?
  290. temp.mV[VZ] = 0.f;
  291. #endif
  292. F32 pelvis_offset = temp.length();
  293. temp = pelvis_bbox.getExtent();
  294. #if 0
  295. temp.mV[VZ] = 0.f;
  296. #endif
  297. F32 pelvis_max_displacement =
  298. pelvis_offset + 0.5f * temp.length() + 1.f;
  299. F32 camera_zoom =
  300. gViewerCamera.getDefaultFOV() * 0.5f /
  301. tanf(pelvis_max_displacement / PREVIEW_CAMERA_DISTANCE);
  302. mAnimPreview->setZoom(camera_zoom);
  303. }
  304. motionp->setName(childGetValue("name_form").asString());
  305. if (!mInWorld)
  306. {
  307. mAnimPreview->getDummyAvatar()->startMotion(mMotionID);
  308. }
  309. childSetMinValue("playback_slider", 0.0);
  310. childSetMaxValue("playback_slider", 1.0);
  311. childSetValue("loop_check", LLSD(motionp->getLoop()));
  312. childSetValue("loop_in_point",
  313. LLSD(motionp->getLoopIn() /
  314. motionp->getDuration() * 100.f));
  315. childSetValue("loop_out_point",
  316. LLSD(motionp->getLoopOut() /
  317. motionp->getDuration() * 100.f));
  318. childSetMaxValue("priority",
  319. (F32)llclamp(gSavedSettings.getU32("AnimationsMaxPriority"),
  320. 4U, 5U));
  321. childSetValue("priority", LLSD((F32)motionp->getPriority()));
  322. childSetValue("hand_pose_combo",
  323. LLHandMotion::getHandPoseName(motionp->getHandPose()));
  324. childSetValue("ease_in_time", LLSD(motionp->getEaseInDuration()));
  325. childSetValue("ease_out_time", LLSD(motionp->getEaseOutDuration()));
  326. setEnabled(true);
  327. std::string seconds_string;
  328. seconds_string = llformat(" - %.2f seconds", motionp->getDuration());
  329. setTitle(mFilename + std::string(seconds_string));
  330. }
  331. else
  332. {
  333. mAnimPreview = NULL;
  334. mMotionID.setNull();
  335. childSetValue("bad_animation_text",
  336. getString("failed_to_initialize"));
  337. }
  338. }
  339. else
  340. {
  341. if (loaderp)
  342. {
  343. if (loaderp->getDuration() > max_anim_duration)
  344. {
  345. LLUIString out_str = getString("anim_too_long");
  346. out_str.setArg("[LENGTH]",
  347. llformat("%.1f", loaderp->getDuration()));
  348. out_str.setArg("[MAX_LENGTH]",
  349. llformat("%.1f", max_anim_duration));
  350. childSetValue("bad_animation_text", out_str.getString());
  351. }
  352. else
  353. {
  354. LLUIString out_str = getString("failed_file_read");
  355. // *TODO:Translate
  356. out_str.setArg("[STATUS]",
  357. getString(STATUS[loaderp->getStatus()]));
  358. childSetValue("bad_animation_text", out_str.getString());
  359. mBadAnimation = true;
  360. mUploadButton->setEnabled(false);
  361. }
  362. }
  363. //setEnabled(false);
  364. mMotionID.setNull();
  365. mAnimPreview = NULL;
  366. }
  367. refresh();
  368. delete loaderp;
  369. return true;
  370. }
  371. void LLFloaterAnimPreview::setAnimCallbacks()
  372. {
  373. childSetCommitCallback("playback_slider", onSliderMove, this);
  374. childSetCommitCallback("preview_base_anim", onCommitBaseAnim, this);
  375. childSetValue("preview_base_anim", "Standing");
  376. childSetCommitCallback("priority", onCommitPriority, this);
  377. childSetCommitCallback("loop_check", onCommitLoop, this);
  378. childSetCommitCallback("loop_in_point", onCommitLoopIn, this);
  379. childSetValidate("loop_in_point", validateLoopIn);
  380. childSetCommitCallback("loop_out_point", onCommitLoopOut, this);
  381. childSetValidate("loop_out_point", validateLoopOut);
  382. childSetCommitCallback("hand_pose_combo", onCommitHandPose, this);
  383. childSetCommitCallback("emote_combo", onCommitEmote, this);
  384. childSetValue("emote_combo", "[None]");
  385. childSetCommitCallback("ease_in_time", onCommitEaseIn, this);
  386. childSetValidate("ease_in_time", validateEaseIn);
  387. childSetCommitCallback("ease_out_time", onCommitEaseOut, this);
  388. childSetValidate("ease_out_time", validateEaseOut);
  389. }
  390. //virtual
  391. void LLFloaterAnimPreview::draw()
  392. {
  393. refresh();
  394. LLFloater::draw();
  395. if (!mInWorld && mAnimPreview && mMotionID.notNull())
  396. {
  397. gGL.color3f(1.f, 1.f, 1.f);
  398. LLTexUnit* unit0 = gGL.getTexUnit(0);
  399. unit0->bind(mAnimPreview);
  400. gGL.begin(LLRender::TRIANGLES);
  401. {
  402. S32 right = getRect().getWidth() - PREVIEW_HPAD;
  403. gGL.texCoord2f(0.f, 1.f);
  404. gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT);
  405. gGL.texCoord2f(0.f, 0.f);
  406. gGL.vertex2i(PREVIEW_HPAD,
  407. PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
  408. gGL.texCoord2f(1.f, 0.f);
  409. gGL.vertex2i(right,
  410. PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
  411. gGL.texCoord2f(0.f, 1.f);
  412. gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT);
  413. gGL.texCoord2f(1.f, 0.f);
  414. gGL.vertex2i(right,
  415. PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
  416. gGL.texCoord2f(1.f, 1.f);
  417. gGL.vertex2i(right, PREVIEW_TEXTURE_HEIGHT);
  418. }
  419. gGL.end();
  420. unit0->unbind(LLTexUnit::TT_TEXTURE);
  421. }
  422. }
  423. //virtual
  424. void LLFloaterAnimPreview::refresh()
  425. {
  426. if (mBadAnimation ||
  427. (!mAnimPreview && !(mInWorld && isAgentAvatarValid())))
  428. {
  429. childShow("bad_animation_text");
  430. mPlayButton->setEnabled(false);
  431. mStopButton->setEnabled(false);
  432. mUploadButton->setEnabled(false);
  433. }
  434. else
  435. {
  436. if (!mInWorld)
  437. {
  438. childHide("bad_animation_text");
  439. }
  440. mPlayButton->setEnabled(true);
  441. LLVOAvatar* avatarp = getAvatar();
  442. if (!avatarp)
  443. {
  444. return;
  445. }
  446. if (avatarp->isMotionActive(mMotionID))
  447. {
  448. mStopButton->setEnabled(true);
  449. if (avatarp->areAnimationsPaused())
  450. {
  451. mPlayButton->setImageUnselected(mPlayImage);
  452. mPlayButton->setImageSelected(mPlaySelectedImage);
  453. }
  454. else
  455. {
  456. LLKeyframeMotion* motionp = getMotion();
  457. if (motionp)
  458. {
  459. F32 fraction_complete = motionp->getLastUpdateTime() /
  460. motionp->getDuration();
  461. childSetValue("playback_slider", fraction_complete);
  462. }
  463. mPlayButton->setImageUnselected(mPauseImage);
  464. mPlayButton->setImageSelected(mPauseSelectedImage);
  465. }
  466. }
  467. else
  468. {
  469. mPauseRequest = avatarp->requestPause();
  470. mPlayButton->setImageUnselected(mPlayImage);
  471. mPlayButton->setImageSelected(mPlaySelectedImage);
  472. mStopButton->setEnabled(true); // stop also resets, leave enabled.
  473. }
  474. mUploadButton->setEnabled(true);
  475. }
  476. }
  477. //virtual
  478. bool LLFloaterAnimPreview::handleMouseDown(S32 x, S32 y, MASK mask)
  479. {
  480. if (!mInWorld && mPreviewRect.pointInRect(x, y))
  481. {
  482. bringToFront(x, y);
  483. gFocusMgr.setMouseCapture(this);
  484. gViewerWindowp->hideCursor();
  485. mLastMouseX = x;
  486. mLastMouseY = y;
  487. return true;
  488. }
  489. return LLFloater::handleMouseDown(x, y, mask);
  490. }
  491. //virtual
  492. bool LLFloaterAnimPreview::handleMouseUp(S32 x, S32 y, MASK mask)
  493. {
  494. if (!mInWorld)
  495. {
  496. gFocusMgr.setMouseCapture(NULL);
  497. gViewerWindowp->showCursor();
  498. }
  499. return LLFloater::handleMouseUp(x, y, mask);
  500. }
  501. //virtual
  502. bool LLFloaterAnimPreview::handleHover(S32 x, S32 y, MASK mask)
  503. {
  504. if (mInWorld)
  505. {
  506. return true;
  507. }
  508. MASK local_mask = mask & ~MASK_ALT;
  509. if (mAnimPreview && hasMouseCapture())
  510. {
  511. if (local_mask == MASK_PAN)
  512. {
  513. // pan here
  514. mAnimPreview->pan((F32)(x - mLastMouseX) * -0.005f,
  515. (F32)(y - mLastMouseY) * -0.005f);
  516. }
  517. else if (local_mask == MASK_ORBIT)
  518. {
  519. F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
  520. F32 pitch_radians = (F32)(y - mLastMouseY) * 0.02f;
  521. mAnimPreview->rotate(yaw_radians, pitch_radians);
  522. }
  523. else
  524. {
  525. F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
  526. F32 zoom_amt = (F32)(y - mLastMouseY) * 0.02f;
  527. mAnimPreview->rotate(yaw_radians, 0.f);
  528. mAnimPreview->zoom(zoom_amt);
  529. }
  530. LLUI::setCursorPositionLocal(this, mLastMouseX, mLastMouseY);
  531. }
  532. if (!mPreviewRect.pointInRect(x, y) || !mAnimPreview)
  533. {
  534. return LLFloater::handleHover(x, y, mask);
  535. }
  536. else if (local_mask == MASK_ORBIT)
  537. {
  538. gViewerWindowp->setCursor(UI_CURSOR_TOOLCAMERA);
  539. }
  540. else if (local_mask == MASK_PAN)
  541. {
  542. gViewerWindowp->setCursor(UI_CURSOR_TOOLPAN);
  543. }
  544. else
  545. {
  546. gViewerWindowp->setCursor(UI_CURSOR_TOOLZOOMIN);
  547. }
  548. return true;
  549. }
  550. //virtual
  551. bool LLFloaterAnimPreview::handleScrollWheel(S32 x, S32 y, S32 clicks)
  552. {
  553. if (!mInWorld)
  554. {
  555. mAnimPreview->zoom((F32)clicks * -0.2f);
  556. }
  557. return true;
  558. }
  559. //virtual
  560. void LLFloaterAnimPreview::onMouseCaptureLost()
  561. {
  562. if (!mInWorld)
  563. {
  564. gViewerWindowp->showCursor();
  565. }
  566. }
  567. std::map <std::string, std::string> LLFloaterAnimPreview::getJointAliases()
  568. {
  569. LLPointer<LLVOAvatar> av = mInWorld ? (LLVOAvatar*)gAgentAvatarp
  570. : mAnimPreview->getDummyAvatar();
  571. return av->getJointAliases();
  572. }
  573. LLKeyframeMotion* LLFloaterAnimPreview::getMotion()
  574. {
  575. LLMotion* motionp = NULL;
  576. LLVOAvatar* avatarp = getAvatar();
  577. if (avatarp)
  578. {
  579. motionp = avatarp->findMotion(mMotionID);
  580. }
  581. return motionp ? motionp->asKeyframeMotion() : NULL;
  582. }
  583. void LLFloaterAnimPreview::resetMotion()
  584. {
  585. LLVOAvatar* avatarp = getAvatar();
  586. if (!avatarp)
  587. {
  588. return;
  589. }
  590. bool paused = avatarp->areAnimationsPaused();
  591. LLKeyframeMotion* motionp = getMotion();
  592. if (motionp)
  593. {
  594. // Set emotion
  595. std::string emote = childGetValue("emote_combo").asString();
  596. motionp->setEmote(mIDList[emote]);
  597. }
  598. LLUUID base_id = mIDList[childGetValue("preview_base_anim").asString()];
  599. avatarp->deactivateAllMotions();
  600. avatarp->startMotion(base_id, BASE_ANIM_TIME_OFFSET);
  601. avatarp->startMotion(mMotionID, 0.0f);
  602. childSetValue("playback_slider", 0.0f);
  603. // Set pose
  604. std::string handpose = childGetValue("hand_pose_combo").asString();
  605. avatarp->startMotion(ANIM_AGENT_HAND_MOTION, 0.f);
  606. if (motionp)
  607. {
  608. motionp->setHandPose(LLHandMotion::getHandPose(handpose));
  609. }
  610. if (paused)
  611. {
  612. mPauseRequest = avatarp->requestPause();
  613. }
  614. else
  615. {
  616. mPauseRequest = NULL;
  617. }
  618. }
  619. LLVOAvatar* LLFloaterAnimPreview::getAvatar()
  620. {
  621. LLVOAvatar* avatarp = NULL;
  622. if (mInWorld)
  623. {
  624. if (isAgentAvatarValid())
  625. {
  626. avatarp = gAgentAvatarp.get();
  627. }
  628. }
  629. else if (mAnimPreview)
  630. {
  631. avatarp = mAnimPreview->getDummyAvatar();
  632. }
  633. return avatarp;
  634. }
  635. //virtual
  636. void LLFloaterAnimPreview::uploadAsset()
  637. {
  638. if (!getEnabled()) return;
  639. LLKeyframeMotion* motionp = getMotion();
  640. if (!motionp)
  641. {
  642. return;
  643. }
  644. // Make sure the animation is stopped since we sill destroy the motion once
  645. // uploaded
  646. LLVOAvatar* avatarp = getAvatar();
  647. avatarp->stopMotion(mMotionID, true);
  648. S32 file_size = motionp->getFileSize();
  649. U8* buffer = new U8[file_size];
  650. LLDataPackerBinaryBuffer dp(buffer, file_size);
  651. if (motionp->serialize(dp))
  652. {
  653. LLFileSystem file(motionp->getID(), LLFileSystem::APPEND);
  654. S32 size = dp.getCurrentSize();
  655. if (file.write((U8*)buffer, size))
  656. {
  657. LLResourceUploadInfo::ptr_t
  658. info(new LLResourceUploadInfo(mTransactionID,
  659. LLAssetType::AT_ANIMATION,
  660. mNameEditor->getText(),
  661. mDescEditor->getText(), 0,
  662. LLFolderType::FT_ANIMATION,
  663. LLInventoryType::IT_ANIMATION,
  664. LLFloaterPerms::getNextOwnerPerms(),
  665. LLFloaterPerms::getGroupPerms(),
  666. LLFloaterPerms::getEveryonePerms(),
  667. mCost));
  668. upload_new_resource(info);
  669. }
  670. else
  671. {
  672. gNotifications.add("WriteAnimationFail");
  673. }
  674. }
  675. delete[] buffer;
  676. // Clear out cache for motion data
  677. avatarp->removeMotion(mMotionID);
  678. if (mInWorld)
  679. {
  680. avatarp->deactivateAllMotions();
  681. }
  682. LLKeyframeDataCache::removeKeyframeData(mMotionID);
  683. }
  684. //static
  685. void LLFloaterAnimPreview::onBtnPlay(void* userdata)
  686. {
  687. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  688. if (!self || !self->getEnabled())
  689. {
  690. return;
  691. }
  692. if (self->mMotionID.notNull())
  693. {
  694. LLVOAvatar* avatarp = self->getAvatar();
  695. if (avatarp)
  696. {
  697. if (!avatarp->isMotionActive(self->mMotionID))
  698. {
  699. self->resetMotion();
  700. self->mPauseRequest = NULL;
  701. }
  702. else
  703. {
  704. if (avatarp->areAnimationsPaused())
  705. {
  706. self->mPauseRequest = NULL;
  707. }
  708. else
  709. {
  710. self->mPauseRequest = avatarp->requestPause();
  711. }
  712. }
  713. }
  714. }
  715. }
  716. //static
  717. void LLFloaterAnimPreview::onBtnStop(void* userdata)
  718. {
  719. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  720. if (!self || !self->getEnabled())
  721. {
  722. return;
  723. }
  724. if (self->mMotionID.notNull())
  725. {
  726. LLVOAvatar* avatarp = self->getAvatar();
  727. if (avatarp)
  728. {
  729. #if 0
  730. self->resetMotion();
  731. self->mPauseRequest = avatarp->requestPause();
  732. #else
  733. F32 loop_in = self->childGetValue("loop_in_point").asReal();
  734. F32 playback = self->childGetValue("playback_slider").asReal();
  735. bool stop_now = !self->childGetValue("loop_check").asBoolean() ||
  736. loop_in > playback * 100.f;
  737. avatarp->stopMotion(self->mMotionID, stop_now);
  738. #endif
  739. }
  740. }
  741. }
  742. //static
  743. void LLFloaterAnimPreview::onSliderMove(LLUICtrl* ctrl, void* userdata)
  744. {
  745. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  746. if (!self || !self->getEnabled())
  747. {
  748. return;
  749. }
  750. LLVOAvatar* avatarp = self->getAvatar();
  751. if (!avatarp)
  752. {
  753. return;
  754. }
  755. LLUUID base_id =
  756. self->mIDList[self->childGetValue("preview_base_anim").asString()];
  757. LLMotion* motionp = avatarp->findMotion(self->mMotionID);
  758. if (!motionp)
  759. {
  760. return;
  761. }
  762. F32 duration = motionp->getDuration();// + motionp->getEaseOutDuration();
  763. F32 delta_time = duration *
  764. (F32)self->childGetValue("playback_slider").asReal();
  765. avatarp->deactivateAllMotions();
  766. avatarp->startMotion(base_id, delta_time + BASE_ANIM_TIME_OFFSET);
  767. avatarp->startMotion(self->mMotionID, delta_time);
  768. self->mPauseRequest = avatarp->requestPause();
  769. self->refresh();
  770. }
  771. //static
  772. void LLFloaterAnimPreview::onCommitBaseAnim(LLUICtrl*, void* userdata)
  773. {
  774. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  775. if (!self || !self->getEnabled())
  776. {
  777. return;
  778. }
  779. LLVOAvatar* avatarp = self->getAvatar();
  780. if (!avatarp)
  781. {
  782. return;
  783. }
  784. bool paused = avatarp->areAnimationsPaused();
  785. // stop all other possible base motions
  786. avatarp->stopMotion(ANIM_AGENT_STAND, true);
  787. avatarp->stopMotion(ANIM_AGENT_WALK, true);
  788. avatarp->stopMotion(ANIM_AGENT_SIT, true);
  789. avatarp->stopMotion(ANIM_AGENT_HOVER, true);
  790. self->resetMotion();
  791. if (!paused)
  792. {
  793. self->mPauseRequest = NULL;
  794. }
  795. }
  796. //static
  797. void LLFloaterAnimPreview::onCommitLoop(LLUICtrl*, void* userdata)
  798. {
  799. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  800. if (!self || !self->getEnabled())
  801. {
  802. return;
  803. }
  804. LLKeyframeMotion* motionp = self->getMotion();
  805. if (motionp)
  806. {
  807. motionp->setLoop(self->childGetValue("loop_check").asBoolean());
  808. motionp->setLoopIn((F32)self->childGetValue("loop_in_point").asReal() *
  809. 0.01f * motionp->getDuration());
  810. motionp->setLoopOut((F32)self->childGetValue("loop_out_point").asReal() *
  811. 0.01f * motionp->getDuration());
  812. }
  813. }
  814. //static
  815. void LLFloaterAnimPreview::onCommitLoopIn(LLUICtrl* ctrlp, void* userdata)
  816. {
  817. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  818. if (!self || !ctrlp || !self->getEnabled())
  819. {
  820. return;
  821. }
  822. LLKeyframeMotion* motionp = self->getMotion();
  823. if (motionp)
  824. {
  825. motionp->setLoopIn((F32)self->childGetValue("loop_in_point").asReal() *
  826. 0.01f);
  827. self->resetMotion();
  828. self->childSetValue("loop_check", LLSD(true));
  829. onCommitLoop(ctrlp, userdata);
  830. }
  831. }
  832. //static
  833. void LLFloaterAnimPreview::onCommitLoopOut(LLUICtrl* ctrlp, void* userdata)
  834. {
  835. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  836. if (!self || !ctrlp || !self->getEnabled())
  837. {
  838. return;
  839. }
  840. LLKeyframeMotion* motionp = self->getMotion();
  841. if (motionp)
  842. {
  843. motionp->setLoopOut((F32)self->childGetValue("loop_out_point").asReal() *
  844. 0.01f * motionp->getDuration());
  845. self->resetMotion();
  846. self->childSetValue("loop_check", LLSD(true));
  847. onCommitLoop(ctrlp, userdata);
  848. }
  849. }
  850. //static
  851. void LLFloaterAnimPreview::onCommitName(LLUICtrl*, void* userdata)
  852. {
  853. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  854. if (!self || !self->getEnabled())
  855. {
  856. return;
  857. }
  858. LLKeyframeMotion* motionp = self->getMotion();
  859. if (motionp)
  860. {
  861. motionp->setName(self->childGetValue("name_form").asString());
  862. }
  863. }
  864. //static
  865. void LLFloaterAnimPreview::onCommitHandPose(LLUICtrl*, void* userdata)
  866. {
  867. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  868. if (self && self->getEnabled())
  869. {
  870. self->resetMotion(); // Sets hand pose
  871. }
  872. }
  873. //static
  874. void LLFloaterAnimPreview::onCommitEmote(LLUICtrl*, void* userdata)
  875. {
  876. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  877. if (self && self->getEnabled())
  878. {
  879. self->resetMotion(); // Sets emote
  880. }
  881. }
  882. //static
  883. void LLFloaterAnimPreview::onCommitPriority(LLUICtrl*, void* userdata)
  884. {
  885. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  886. if (!self || !self->getEnabled())
  887. {
  888. return;
  889. }
  890. LLKeyframeMotion* motionp = self->getMotion();
  891. if (motionp)
  892. {
  893. motionp->setPriority(llfloor((F32)self->childGetValue("priority").asReal()));
  894. }
  895. }
  896. //static
  897. void LLFloaterAnimPreview::onCommitEaseIn(LLUICtrl*, void* userdata)
  898. {
  899. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  900. if (!self || !self->getEnabled())
  901. {
  902. return;
  903. }
  904. LLKeyframeMotion* motionp = self->getMotion();
  905. if (motionp)
  906. {
  907. motionp->setEaseIn((F32)self->childGetValue("ease_in_time").asReal());
  908. }
  909. self->resetMotion();
  910. }
  911. //static
  912. void LLFloaterAnimPreview::onCommitEaseOut(LLUICtrl*, void* userdata)
  913. {
  914. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  915. if (!self || !self->getEnabled())
  916. {
  917. return;
  918. }
  919. LLKeyframeMotion* motionp = self->getMotion();
  920. if (motionp)
  921. {
  922. motionp->setEaseOut((F32)self->childGetValue("ease_out_time").asReal());
  923. }
  924. self->resetMotion();
  925. }
  926. //static
  927. bool LLFloaterAnimPreview::validateEaseIn(LLUICtrl*, void* userdata)
  928. {
  929. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  930. if (!self || !self->getEnabled())
  931. {
  932. return false;
  933. }
  934. LLKeyframeMotion* motionp = self->getMotion();
  935. if (!motionp)
  936. {
  937. return false;
  938. }
  939. if (!motionp->getLoop())
  940. {
  941. F32 new_ease_in = llclamp((F32)self->childGetValue("ease_in_time").asReal(),
  942. 0.f,
  943. motionp->getDuration() -
  944. motionp->getEaseOutDuration());
  945. self->childSetValue("ease_in_time", LLSD(new_ease_in));
  946. }
  947. return true;
  948. }
  949. //static
  950. bool LLFloaterAnimPreview::validateEaseOut(LLUICtrl*, void* userdata)
  951. {
  952. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  953. if (!self || !self->getEnabled())
  954. {
  955. return false;
  956. }
  957. LLKeyframeMotion* motionp = self->getMotion();
  958. if (!motionp)
  959. {
  960. return false;
  961. }
  962. if (!motionp->getLoop())
  963. {
  964. F32 new_ease_out = llclamp((F32)self->childGetValue("ease_out_time").asReal(),
  965. 0.f,
  966. motionp->getDuration() -
  967. motionp->getEaseInDuration());
  968. self->childSetValue("ease_out_time", LLSD(new_ease_out));
  969. }
  970. return true;
  971. }
  972. //static
  973. bool LLFloaterAnimPreview::validateLoopIn(LLUICtrl*, void* userdata)
  974. {
  975. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  976. if (!self || !self->getEnabled())
  977. {
  978. return false;
  979. }
  980. F32 loop_in_val = (F32)self->childGetValue("loop_in_point").asReal();
  981. F32 loop_out_val = (F32)self->childGetValue("loop_out_point").asReal();
  982. if (loop_in_val < 0.f)
  983. {
  984. loop_in_val = 0.f;
  985. }
  986. else if (loop_in_val > 100.f)
  987. {
  988. loop_in_val = 100.f;
  989. }
  990. else if (loop_in_val > loop_out_val)
  991. {
  992. loop_in_val = loop_out_val;
  993. }
  994. self->childSetValue("loop_in_point", LLSD(loop_in_val));
  995. return true;
  996. }
  997. //static
  998. bool LLFloaterAnimPreview::validateLoopOut(LLUICtrl*, void* userdata)
  999. {
  1000. LLFloaterAnimPreview* self = (LLFloaterAnimPreview*)userdata;
  1001. if (!self || !self->getEnabled())
  1002. {
  1003. return false;
  1004. }
  1005. F32 loop_out_val =(F32)self->childGetValue("loop_out_point").asReal();
  1006. F32 loop_in_val = (F32)self->childGetValue("loop_in_point").asReal();
  1007. if (loop_out_val < 0.f)
  1008. {
  1009. loop_out_val = 0.f;
  1010. }
  1011. else if (loop_out_val > 100.f)
  1012. {
  1013. loop_out_val = 100.f;
  1014. }
  1015. else if (loop_out_val < loop_in_val)
  1016. {
  1017. loop_out_val = loop_in_val;
  1018. }
  1019. self->childSetValue("loop_out_point", LLSD(loop_out_val));
  1020. return true;
  1021. }
  1022. //-----------------------------------------------------------------------------
  1023. // LLPreviewAnimation
  1024. //-----------------------------------------------------------------------------
  1025. LLPreviewAnimation::LLPreviewAnimation(S32 width, S32 height)
  1026. : LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, false)
  1027. {
  1028. mCameraDistance = PREVIEW_CAMERA_DISTANCE;
  1029. mCameraYaw = 0.f;
  1030. mCameraPitch = 0.f;
  1031. mCameraZoom = 1.f;
  1032. mDummyAvatar =
  1033. (LLVOAvatar*)gObjectList.createObjectViewer(LL_PCODE_LEGACY_AVATAR,
  1034. gAgent.getRegion(),
  1035. LLViewerObject::CO_FLAG_UI_AVATAR);
  1036. if (!mDummyAvatar)
  1037. {
  1038. llwarns << "Cannot create a dummy avatar !" << llendl;
  1039. return;
  1040. }
  1041. mDummyAvatar->createDrawable();
  1042. mDummyAvatar->mSpecialRenderMode = 1;
  1043. mDummyAvatar->startMotion(ANIM_AGENT_STAND, BASE_ANIM_TIME_OFFSET);
  1044. mDummyAvatar->hideHair();
  1045. mDummyAvatar->hideSkirt();
  1046. // Give a default texture to the avatar body parts. HB
  1047. U32 texname = LLViewerFetchedTexture::sDefaultImagep->getTexName();
  1048. LLAvatarJoint* rootp = mDummyAvatar->mRoot;
  1049. LLViewerJointMesh* meshp =
  1050. dynamic_cast<LLViewerJointMesh*>(rootp->findJoint("mHairMesh0"));
  1051. meshp->setTestTexture(texname);
  1052. meshp = dynamic_cast<LLViewerJointMesh*>(rootp->findJoint("mHeadMesh0"));
  1053. meshp->setTestTexture(texname);
  1054. meshp =
  1055. dynamic_cast<LLViewerJointMesh*>(rootp->findJoint("mUpperBodyMesh0"));
  1056. meshp->setTestTexture(texname);
  1057. meshp =
  1058. dynamic_cast<LLViewerJointMesh*>(rootp->findJoint("mLowerBodyMesh0"));
  1059. meshp->setTestTexture(texname);
  1060. // Stop extraneous animations
  1061. mDummyAvatar->stopMotion(ANIM_AGENT_HEAD_ROT, true);
  1062. mDummyAvatar->stopMotion(ANIM_AGENT_EYE, true);
  1063. mDummyAvatar->stopMotion(ANIM_AGENT_BODY_NOISE, true);
  1064. mDummyAvatar->stopMotion(ANIM_AGENT_BREATHE_ROT, true);
  1065. #if LL_PUPPETRY
  1066. mDummyAvatar->stopMotion(ANIM_AGENT_PUPPET_MOTION, true);
  1067. #endif
  1068. mDummyAvatar->stopMotion(ANIM_AGENT_PHYSICS_MOTION, true);
  1069. }
  1070. LLPreviewAnimation::~LLPreviewAnimation()
  1071. {
  1072. if (mDummyAvatar)
  1073. {
  1074. mDummyAvatar->markDead();
  1075. }
  1076. }
  1077. //virtual
  1078. S8 LLPreviewAnimation::getType() const
  1079. {
  1080. return LLViewerDynamicTexture::LL_PREVIEW_ANIMATION;
  1081. }
  1082. bool LLPreviewAnimation::render()
  1083. {
  1084. LLVOAvatar* avatarp = mDummyAvatar.get();
  1085. if (!avatarp || avatarp->mDrawable.isNull())
  1086. {
  1087. return true;
  1088. }
  1089. gGL.pushUIMatrix();
  1090. gGL.loadUIIdentity();
  1091. gGL.matrixMode(LLRender::MM_PROJECTION);
  1092. gGL.pushMatrix();
  1093. gGL.loadIdentity();
  1094. gGL.ortho(0.f, mFullWidth, 0.f, mFullHeight, -1.f, 1.f);
  1095. gGL.matrixMode(LLRender::MM_MODELVIEW);
  1096. gGL.pushMatrix();
  1097. gGL.loadIdentity();
  1098. LLGLSUIDefault def;
  1099. gUIProgram.bind();
  1100. gGL.color4f(0.15f, 0.2f, 0.3f, 1.f);
  1101. gl_rect_2d_simple(mFullWidth, mFullHeight);
  1102. gGL.color4f(1.f, 1.f, 1.f, 1.f);
  1103. gGL.matrixMode(LLRender::MM_PROJECTION);
  1104. gGL.popMatrix();
  1105. gGL.matrixMode(LLRender::MM_MODELVIEW);
  1106. gGL.popMatrix();
  1107. gGL.flush();
  1108. LLVector3 target_pos = avatarp->mRoot->getWorldPosition();
  1109. LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) *
  1110. LLQuaternion(mCameraYaw, LLVector3::z_axis);
  1111. LLQuaternion av_rot = avatarp->mRoot->getWorldRotation() * camera_rot;
  1112. gViewerCamera.setOriginAndLookAt(target_pos +
  1113. ((LLVector3(mCameraDistance, 0.f, 0.f) +
  1114. mCameraOffset) * av_rot), // Camera
  1115. LLVector3::z_axis, // Up
  1116. // point of interest
  1117. target_pos + mCameraOffset * av_rot);
  1118. gViewerCamera.setAspect((F32)mFullWidth / (F32)mFullHeight);
  1119. gViewerCamera.setViewNoBroadcast(gViewerCamera.getDefaultFOV() /
  1120. mCameraZoom);
  1121. gViewerCamera.setPerspective(false, mOrigin.mX, mOrigin.mY, mFullWidth,
  1122. mFullHeight, false);
  1123. avatarp->updateLOD();
  1124. avatarp->dirtyMesh();
  1125. LLVertexBuffer::unbind();
  1126. // Do not let environment settings influence our scene lighting.
  1127. HBPreviewLighting preview_light;
  1128. LLDisableOcclusionCulling no_occlusion;
  1129. LLGLDepthTest gls_depth(GL_TRUE);
  1130. // Make sure alpha=0 shows avatar material color
  1131. LLGLDisable no_blend(GL_BLEND);
  1132. LLFace* facep = avatarp->mDrawable->getFace(0);
  1133. if (facep) // Paranoia
  1134. {
  1135. LLDrawPoolAvatar* poolp = (LLDrawPoolAvatar*)facep->getPool();
  1136. if (poolp) // More paranoia !
  1137. {
  1138. // Render only our dummy avatar
  1139. poolp->renderAvatars(avatarp);
  1140. }
  1141. }
  1142. gGL.popUIMatrix();
  1143. return true;
  1144. }
  1145. void LLPreviewAnimation::rotate(F32 yaw_radians, F32 pitch_radians)
  1146. {
  1147. mCameraYaw = mCameraYaw + yaw_radians;
  1148. mCameraPitch = llclamp(mCameraPitch + pitch_radians, F_PI_BY_TWO * -0.8f,
  1149. F_PI_BY_TWO * 0.8f);
  1150. }
  1151. void LLPreviewAnimation::zoom(F32 zoom_delta)
  1152. {
  1153. setZoom(mCameraZoom + zoom_delta);
  1154. }
  1155. void LLPreviewAnimation::setZoom(F32 zoom_amt)
  1156. {
  1157. mCameraZoom = llclamp(zoom_amt, MIN_CAMERA_ZOOM, MAX_CAMERA_ZOOM);
  1158. }
  1159. void LLPreviewAnimation::pan(F32 right, F32 up)
  1160. {
  1161. mCameraOffset.mV[VY] = llclamp(mCameraOffset.mV[VY] + right * mCameraDistance / mCameraZoom,
  1162. -1.f, 1.f);
  1163. mCameraOffset.mV[VZ] = llclamp(mCameraOffset.mV[VZ] + up * mCameraDistance / mCameraZoom,
  1164. -1.f, 1.f);
  1165. }