shadowVolumeBSP.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "lighting/common/shadowVolumeBSP.h"
  24. #include "lighting/lightInfo.h"
  25. #include "math/mPlane.h"
  26. ShadowVolumeBSP::ShadowVolumeBSP() :
  27. mSVRoot(0),
  28. mNodeStore(0),
  29. mPolyStore(0),
  30. mFirstInteriorNode(0)
  31. {
  32. }
  33. ShadowVolumeBSP::~ShadowVolumeBSP()
  34. {
  35. for(U32 i = 0; i < mSurfaces.size(); i++)
  36. delete mSurfaces[i];
  37. }
  38. void ShadowVolumeBSP::insertShadowVolume(SVNode ** root, U32 volume)
  39. {
  40. SVNode * traverse = mShadowVolumes[volume];
  41. // insert 'em
  42. while(traverse)
  43. {
  44. // copy it
  45. *root = createNode();
  46. (*root)->mPlaneIndex = traverse->mPlaneIndex;
  47. (*root)->mSurfaceInfo = traverse->mSurfaceInfo;
  48. (*root)->mShadowVolume = traverse->mShadowVolume;
  49. // do the next
  50. root = &(*root)->mFront;
  51. traverse = traverse->mFront;
  52. }
  53. }
  54. ShadowVolumeBSP::SVNode::Side ShadowVolumeBSP::whichSide(SVPoly * poly, const PlaneF & plane) const
  55. {
  56. bool front = false;
  57. bool back = false;
  58. for(U32 i = 0; i < poly->mWindingCount; i++)
  59. {
  60. switch(plane.whichSide(poly->mWinding[i]))
  61. {
  62. case PlaneF::Front:
  63. if(back)
  64. return(SVNode::Split);
  65. front = true;
  66. break;
  67. case PlaneF::Back:
  68. if(front)
  69. return(SVNode::Split);
  70. back = true;
  71. break;
  72. default:
  73. break;
  74. }
  75. }
  76. AssertFatal(!(front && back), "ShadowVolumeBSP::whichSide - failed to classify poly");
  77. if(!front && !back)
  78. return(SVNode::On);
  79. return(front ? SVNode::Front : SVNode::Back);
  80. }
  81. void ShadowVolumeBSP::splitPoly(SVPoly * poly, const PlaneF & plane, SVPoly ** front, SVPoly ** back)
  82. {
  83. PlaneF::Side sides[SVPoly::MaxWinding];
  84. U32 i;
  85. for(i = 0; i < poly->mWindingCount; i++)
  86. sides[i] = plane.whichSide(poly->mWinding[i]);
  87. // create the polys
  88. (*front) = createPoly();
  89. (*back) = createPoly();
  90. // copy the info
  91. (*front)->mWindingCount = (*back)->mWindingCount = 0;
  92. (*front)->mPlane = (*back)->mPlane = poly->mPlane;
  93. (*front)->mTarget = (*back)->mTarget = poly->mTarget;
  94. (*front)->mSurfaceInfo = (*back)->mSurfaceInfo = poly->mSurfaceInfo;
  95. (*front)->mShadowVolume = (*back)->mShadowVolume = poly->mShadowVolume;
  96. //
  97. for(i = 0; i < poly->mWindingCount; i++)
  98. {
  99. U32 j = (i+1) % poly->mWindingCount;
  100. if(sides[i] == PlaneF::On)
  101. {
  102. (*front)->mWinding[(*front)->mWindingCount++] = poly->mWinding[i];
  103. (*back)->mWinding[(*back)->mWindingCount++] = poly->mWinding[i];
  104. }
  105. else if(sides[i] == PlaneF::Front)
  106. {
  107. (*front)->mWinding[(*front)->mWindingCount++] = poly->mWinding[i];
  108. if(sides[j] == PlaneF::Back)
  109. {
  110. const Point3F & a = poly->mWinding[i];
  111. const Point3F & b = poly->mWinding[j];
  112. F32 t = plane.intersect(a, b);
  113. AssertFatal(t >=0 && t <= 1, "ShadowVolumeBSP::splitPoly - bad plane intersection");
  114. Point3F pos;
  115. pos.interpolate(a, b, t);
  116. //
  117. (*front)->mWinding[(*front)->mWindingCount++] =
  118. (*back)->mWinding[(*back)->mWindingCount++] = pos;
  119. }
  120. }
  121. else if(sides[i] == PlaneF::Back)
  122. {
  123. (*back)->mWinding[(*back)->mWindingCount++] = poly->mWinding[i];
  124. if(sides[j] == PlaneF::Front)
  125. {
  126. const Point3F & a = poly->mWinding[i];
  127. const Point3F & b = poly->mWinding[j];
  128. F32 t = plane.intersect(a, b);
  129. AssertFatal(t >=0 && t <= 1, "ShadowVolumeBSP::splitPoly - bad plane intersection");
  130. Point3F pos;
  131. pos.interpolate(a, b, t);
  132. (*front)->mWinding[(*front)->mWindingCount++] =
  133. (*back)->mWinding[(*back)->mWindingCount++] = pos;
  134. }
  135. }
  136. }
  137. AssertFatal((*front)->mWindingCount && (*back)->mWindingCount, "ShadowVolume::split - invalid split");
  138. }
  139. void ShadowVolumeBSP::addUniqueVolume(SurfaceInfo * surfaceInfo, U32 volume)
  140. {
  141. if(!surfaceInfo)
  142. return;
  143. for(U32 i = 0; i < surfaceInfo->mShadowed.size(); i++)
  144. if(surfaceInfo->mShadowed[i] == volume)
  145. return;
  146. // add it
  147. surfaceInfo->mShadowed.push_back(volume);
  148. }
  149. void ShadowVolumeBSP::insertPoly(SVNode ** root, SVPoly * poly)
  150. {
  151. if(!(*root))
  152. {
  153. insertShadowVolume(root, poly->mShadowVolume);
  154. if(poly->mSurfaceInfo && !mFirstInteriorNode)
  155. mFirstInteriorNode = mShadowVolumes[poly->mShadowVolume];
  156. if(poly->mTarget)
  157. addUniqueVolume(poly->mTarget->mSurfaceInfo, poly->mShadowVolume);
  158. recyclePoly(poly);
  159. return;
  160. }
  161. const PlaneF & plane = getPlane((*root)->mPlaneIndex);
  162. //
  163. switch(whichSide(poly, plane))
  164. {
  165. case SVNode::On:
  166. case SVNode::Front:
  167. insertPolyFront(root, poly);
  168. break;
  169. case SVNode::Back:
  170. insertPolyBack(root, poly);
  171. break;
  172. case SVNode::Split:
  173. {
  174. SVPoly * front;
  175. SVPoly * back;
  176. splitPoly(poly, plane, &front, &back);
  177. recyclePoly(poly);
  178. insertPolyFront(root, front);
  179. insertPolyBack(root, back);
  180. break;
  181. }
  182. }
  183. }
  184. void ShadowVolumeBSP::insertPolyFront(SVNode ** root, SVPoly * poly)
  185. {
  186. // POLY type node?
  187. if(!(*root)->mFront)
  188. {
  189. if(poly->mSurfaceInfo && !mFirstInteriorNode)
  190. mFirstInteriorNode = mShadowVolumes[poly->mShadowVolume];
  191. addUniqueVolume(poly->mSurfaceInfo, (*root)->mShadowVolume);
  192. recyclePoly(poly);
  193. }
  194. else
  195. insertPoly(&(*root)->mFront, poly);
  196. }
  197. void ShadowVolumeBSP::insertPolyBack(SVNode ** root, SVPoly * poly)
  198. {
  199. // list of nodes where an interior has been added
  200. if(poly->mSurfaceInfo && !(*root)->mSurfaceInfo && !(*root)->mBack)
  201. {
  202. if(!mFirstInteriorNode)
  203. mFirstInteriorNode = mShadowVolumes[poly->mShadowVolume];
  204. mParentNodes.push_back(*root);
  205. }
  206. // POLY type node?
  207. if(!(*root)->mFront)
  208. {
  209. poly->mTarget = (*root);
  210. insertPoly(&(*root)->mBack, poly);
  211. }
  212. else
  213. insertPoly(&(*root)->mBack, poly);
  214. }
  215. //------------------------------------------------------------------------------
  216. ShadowVolumeBSP::SVNode * ShadowVolumeBSP::createNode()
  217. {
  218. SVNode * node;
  219. if(mNodeStore)
  220. {
  221. node = mNodeStore;
  222. mNodeStore = mNodeStore->mFront;
  223. }
  224. else
  225. node = mNodeChunker.alloc();
  226. //
  227. node->mFront = node->mBack = 0;
  228. node->mShadowVolume = 0;
  229. node->mSurfaceInfo = 0;
  230. return(node);
  231. }
  232. void ShadowVolumeBSP::recycleNode(SVNode * node)
  233. {
  234. if(!node)
  235. return;
  236. recycleNode(node->mFront);
  237. recycleNode(node->mBack);
  238. //
  239. node->mFront = mNodeStore;
  240. node->mBack = 0;
  241. mNodeStore = node;
  242. }
  243. ShadowVolumeBSP::SVPoly * ShadowVolumeBSP::createPoly()
  244. {
  245. SVPoly * poly;
  246. if(mPolyStore)
  247. {
  248. poly = mPolyStore;
  249. mPolyStore = mPolyStore->mNext;
  250. }
  251. else
  252. poly = mPolyChunker.alloc();
  253. //
  254. poly->mNext = 0;
  255. poly->mTarget = 0;
  256. poly->mSurfaceInfo = 0;
  257. poly->mShadowVolume = 0;
  258. poly->mWindingCount = 0;
  259. for (U32 i = 0; i < SVPoly::MaxWinding; i++)
  260. poly->mWinding[i] = Point3F(0.0f, 0.0f, 0.0f);
  261. return(poly);
  262. }
  263. void ShadowVolumeBSP::recyclePoly(SVPoly * poly)
  264. {
  265. if(!poly)
  266. return;
  267. recyclePoly(poly->mNext);
  268. //
  269. poly->mNext = mPolyStore;
  270. mPolyStore = poly;
  271. }
  272. U32 ShadowVolumeBSP::insertPlane(const PlaneF & plane)
  273. {
  274. mPlanes.push_back(plane);
  275. return(mPlanes.size() - 1);
  276. }
  277. const PlaneF & ShadowVolumeBSP::getPlane(U32 index) const
  278. {
  279. AssertFatal(index < mPlanes.size(), "ShadowVolumeBSP::getPlane - index out of range");
  280. return(mPlanes[index]);
  281. }
  282. ShadowVolumeBSP::SVNode * ShadowVolumeBSP::getShadowVolume(U32 index)
  283. {
  284. AssertFatal(index < mShadowVolumes.size(), "ShadowVolumeBSP::getShadowVolume - index out of range");
  285. return(mShadowVolumes[index]);
  286. }
  287. bool ShadowVolumeBSP::testPoint(SVNode * root, const Point3F & pnt)
  288. {
  289. const PlaneF & plane = getPlane(root->mPlaneIndex);
  290. switch(plane.whichSide(pnt))
  291. {
  292. case PlaneF::On:
  293. if(!root->mFront)
  294. return(true);
  295. else
  296. {
  297. if(testPoint(root->mFront, pnt))
  298. return(true);
  299. else
  300. {
  301. if(!root->mBack)
  302. return(false);
  303. else
  304. return(testPoint(root->mBack, pnt));
  305. }
  306. }
  307. break;
  308. //
  309. case PlaneF::Front:
  310. if(root->mFront)
  311. return(testPoint(root->mFront, pnt));
  312. else
  313. return(true);
  314. break;
  315. //
  316. case PlaneF::Back:
  317. if(root->mBack)
  318. return(testPoint(root->mBack, pnt));
  319. else
  320. return(false);
  321. break;
  322. }
  323. return(false);
  324. }
  325. //------------------------------------------------------------------------------
  326. bool ShadowVolumeBSP::testPoly(SVNode * root, SVPoly * poly)
  327. {
  328. const PlaneF & plane = getPlane(root->mPlaneIndex);
  329. switch(whichSide(poly, plane))
  330. {
  331. case SVNode::On:
  332. case SVNode::Front:
  333. if(root->mFront)
  334. return(testPoly(root->mFront, poly));
  335. recyclePoly(poly);
  336. return(true);
  337. case SVNode::Back:
  338. if(root->mBack)
  339. return(testPoly(root->mBack, poly));
  340. recyclePoly(poly);
  341. break;
  342. case SVNode::Split:
  343. {
  344. if(!root->mFront)
  345. {
  346. recyclePoly(poly);
  347. return(true);
  348. }
  349. SVPoly * front;
  350. SVPoly * back;
  351. splitPoly(poly, plane, &front, &back);
  352. recyclePoly(poly);
  353. if(testPoly(root->mFront, front))
  354. {
  355. recyclePoly(back);
  356. return(true);
  357. }
  358. if(root->mBack)
  359. return(testPoly(root->mBack, back));
  360. recyclePoly(back);
  361. break;
  362. }
  363. }
  364. return(false);
  365. }
  366. //------------------------------------------------------------------------------
  367. void ShadowVolumeBSP::buildPolyVolume(SVPoly * poly, LightInfo * light)
  368. {
  369. if(light->getType() != LightInfo::Vector)
  370. return;
  371. // build the poly
  372. Point3F pointOffset = light->getDirection() * 10.f;
  373. // create the shadow volume
  374. mShadowVolumes.increment();
  375. SVNode ** traverse = &mShadowVolumes.last();
  376. U32 shadowVolumeIndex = mShadowVolumes.size() - 1;
  377. for(U32 i = 0; i < poly->mWindingCount; i++)
  378. {
  379. U32 j = (i + 1) % poly->mWindingCount;
  380. if(poly->mWinding[i] == poly->mWinding[j])
  381. continue;
  382. (*traverse) = createNode();
  383. Point3F & a = poly->mWinding[i];
  384. Point3F & b = poly->mWinding[j];
  385. Point3F c = b + pointOffset;
  386. (*traverse)->mPlaneIndex = insertPlane(PlaneF(a,b,c));
  387. (*traverse)->mShadowVolume = shadowVolumeIndex;
  388. traverse = &(*traverse)->mFront;
  389. }
  390. // do the poly node
  391. (*traverse) = createNode();
  392. (*traverse)->mPlaneIndex = insertPlane(poly->mPlane);
  393. (*traverse)->mShadowVolume = poly->mShadowVolume = shadowVolumeIndex;
  394. }
  395. ShadowVolumeBSP::SVPoly * ShadowVolumeBSP::copyPoly(SVPoly * src)
  396. {
  397. SVPoly * poly = createPoly();
  398. dMemcpy(poly, src, sizeof(SVPoly));
  399. poly->mTarget = 0;
  400. poly->mNext = 0;
  401. return(poly);
  402. }
  403. //------------------------------------------------------------------------------
  404. void ShadowVolumeBSP::addToPolyList(SVPoly ** store, SVPoly * poly) const
  405. {
  406. poly->mNext = *store;
  407. *store = poly;
  408. }
  409. //------------------------------------------------------------------------------
  410. void ShadowVolumeBSP::clipPoly(SVNode * root, SVPoly ** store, SVPoly * poly)
  411. {
  412. if(!root)
  413. {
  414. recyclePoly(poly);
  415. return;
  416. }
  417. const PlaneF & plane = getPlane(root->mPlaneIndex);
  418. switch(whichSide(poly, plane))
  419. {
  420. case SVNode::On:
  421. case SVNode::Back:
  422. if(root->mBack)
  423. clipPoly(root->mBack, store, poly);
  424. else
  425. addToPolyList(store, poly);
  426. break;
  427. case SVNode::Front:
  428. // encountered POLY node?
  429. if(!root->mFront)
  430. {
  431. recyclePoly(poly);
  432. return;
  433. }
  434. else
  435. clipPoly(root->mFront, store, poly);
  436. break;
  437. case SVNode::Split:
  438. {
  439. SVPoly * front;
  440. SVPoly * back;
  441. splitPoly(poly, plane, &front, &back);
  442. AssertFatal(front && back, "ShadowVolumeBSP::clipPoly: invalid split");
  443. recyclePoly(poly);
  444. // front
  445. if(!root->mFront)
  446. {
  447. recyclePoly(front);
  448. return;
  449. }
  450. else
  451. clipPoly(root->mFront, store, front);
  452. // back
  453. if(root->mBack)
  454. clipPoly(root->mBack, store, back);
  455. else
  456. addToPolyList(store, back);
  457. break;
  458. }
  459. }
  460. }
  461. // clip a poly to it's own shadow volume
  462. void ShadowVolumeBSP::clipToSelf(SVNode * root, SVPoly ** store, SVPoly * poly)
  463. {
  464. if(!root)
  465. {
  466. addToPolyList(store, poly);
  467. return;
  468. }
  469. const PlaneF & plane = getPlane(root->mPlaneIndex);
  470. switch(whichSide(poly, plane))
  471. {
  472. case SVNode::Front:
  473. clipToSelf(root->mFront, store, poly);
  474. break;
  475. case SVNode::On:
  476. addToPolyList(store, poly);
  477. break;
  478. case SVNode::Back:
  479. recyclePoly(poly);
  480. break;
  481. case SVNode::Split:
  482. {
  483. SVPoly * front = 0;
  484. SVPoly * back = 0;
  485. splitPoly(poly, plane, &front, &back);
  486. AssertFatal(front && back, "ShadowVolumeBSP::clipToSelf: invalid split");
  487. recyclePoly(poly);
  488. recyclePoly(back);
  489. clipToSelf(root->mFront, store, front);
  490. break;
  491. }
  492. }
  493. }
  494. //------------------------------------------------------------------------------
  495. F32 ShadowVolumeBSP::getPolySurfaceArea(SVPoly * poly) const
  496. {
  497. if(!poly)
  498. return(0.f);
  499. Point3F areaNorm(0,0,0);
  500. for(U32 i = 0; i < poly->mWindingCount; i++)
  501. {
  502. U32 j = (i + 1) % poly->mWindingCount;
  503. Point3F tmp;
  504. mCross(poly->mWinding[i], poly->mWinding[j], &tmp);
  505. areaNorm += tmp;
  506. }
  507. F32 area = mDot(poly->mPlane, areaNorm);
  508. if(area < 0.f)
  509. area *= -0.5f;
  510. else
  511. area *= 0.5f;
  512. if(poly->mNext)
  513. area += getPolySurfaceArea(poly->mNext);
  514. return(area);
  515. }
  516. //------------------------------------------------------------------------------
  517. F32 ShadowVolumeBSP::getClippedSurfaceArea(SVNode * root, SVPoly * poly)
  518. {
  519. SVPoly * store = 0;
  520. clipPoly(root, &store, poly);
  521. F32 area = getPolySurfaceArea(store);
  522. recyclePoly(store);
  523. return(area);
  524. }
  525. //-------------------------------------------------------------------------------
  526. // Class SceneLighting::ShadowVolumeBSP
  527. //-------------------------------------------------------------------------------
  528. void ShadowVolumeBSP::movePolyList(SVPoly ** dest, SVPoly * list) const
  529. {
  530. while(list)
  531. {
  532. SVPoly * next = list->mNext;
  533. addToPolyList(dest, list);
  534. list = next;
  535. }
  536. }
  537. F32 ShadowVolumeBSP::getLitSurfaceArea(SVPoly * poly, SurfaceInfo * surfaceInfo)
  538. {
  539. // clip the poly to the shadow volumes
  540. SVPoly * polyStore = poly;
  541. for(U32 i = 0; polyStore && (i < surfaceInfo->mShadowed.size()); i++)
  542. {
  543. SVPoly * polyList = 0;
  544. SVPoly * traverse = polyStore;
  545. while(traverse)
  546. {
  547. SVPoly * next = traverse->mNext;
  548. traverse->mNext = 0;
  549. SVPoly * currentStore = 0;
  550. clipPoly(mShadowVolumes[surfaceInfo->mShadowed[i]], &currentStore, traverse);
  551. if(currentStore)
  552. movePolyList(&polyList, currentStore);
  553. traverse = next;
  554. }
  555. polyStore = polyList;
  556. }
  557. // get the lit area
  558. F32 area = getPolySurfaceArea(polyStore);
  559. recyclePoly(polyStore);
  560. return(area);
  561. }
  562. //------------------------------------------------------------------------------
  563. void ShadowVolumeBSP::removeLastInterior()
  564. {
  565. if(!mSVRoot || !mFirstInteriorNode)
  566. return;
  567. AssertFatal(mFirstInteriorNode->mSurfaceInfo, "No surface info for first interior node!");
  568. // reset the planes
  569. mPlanes.setSize(mFirstInteriorNode->mPlaneIndex);
  570. U32 i;
  571. // flush the shadow volumes
  572. for(i = mFirstInteriorNode->mShadowVolume; i < mShadowVolumes.size(); i++)
  573. recycleNode(mShadowVolumes[i]);
  574. mShadowVolumes.setSize(mFirstInteriorNode->mShadowVolume);
  575. // flush the interior nodes
  576. if(!mParentNodes.size() && (mFirstInteriorNode->mShadowVolume == mSVRoot->mShadowVolume))
  577. {
  578. recycleNode(mSVRoot);
  579. mSVRoot = 0;
  580. }
  581. else
  582. {
  583. for(i = 0; i < mParentNodes.size(); i++)
  584. {
  585. recycleNode(mParentNodes[i]->mBack);
  586. mParentNodes[i]->mBack = 0;
  587. }
  588. }
  589. // flush the surfaces
  590. for(i = 0; i < mSurfaces.size(); i++)
  591. delete mSurfaces[i];
  592. mSurfaces.clear();
  593. mFirstInteriorNode = 0;
  594. }