BillboardSet.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Batch.h"
  24. #include "BillboardSet.h"
  25. #include "Camera.h"
  26. #include "Context.h"
  27. #include "Geometry.h"
  28. #include "Graphics.h"
  29. #include "IndexBuffer.h"
  30. #include "Material.h"
  31. #include "MemoryBuffer.h"
  32. #include "Node.h"
  33. #include "OctreeQuery.h"
  34. #include "Profiler.h"
  35. #include "ResourceCache.h"
  36. #include "Sort.h"
  37. #include "VertexBuffer.h"
  38. #include "DebugNew.h"
  39. namespace Urho3D
  40. {
  41. extern const char* GEOMETRY_CATEGORY;
  42. static const float INV_SQRT_TWO = 1.0f / sqrtf(2.0f);
  43. const char* faceCameraModeNames[] =
  44. {
  45. "None",
  46. "Rotate XYZ",
  47. "Rotate Y",
  48. "LookAt XYZ",
  49. "LookAt Y",
  50. 0
  51. };
  52. inline bool CompareBillboards(Billboard* lhs, Billboard* rhs)
  53. {
  54. return lhs->sortDistance_ > rhs->sortDistance_;
  55. }
  56. BillboardSet::BillboardSet(Context* context) :
  57. Drawable(context, DRAWABLE_GEOMETRY),
  58. animationLodBias_(1.0f),
  59. animationLodTimer_(0.0f),
  60. relative_(true),
  61. scaled_(true),
  62. sorted_(false),
  63. faceCameraMode_(FC_ROTATE_XYZ),
  64. geometry_(new Geometry(context)),
  65. vertexBuffer_(new VertexBuffer(context_)),
  66. indexBuffer_(new IndexBuffer(context_)),
  67. bufferSizeDirty_(true),
  68. bufferDirty_(true),
  69. forceUpdate_(false),
  70. sortThisFrame_(false),
  71. sortFrameNumber_(0),
  72. previousOffset_(Vector3::ZERO)
  73. {
  74. geometry_->SetVertexBuffer(0, vertexBuffer_, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1 | MASK_TEXCOORD2);
  75. geometry_->SetIndexBuffer(indexBuffer_);
  76. batches_.Resize(1);
  77. batches_[0].geometry_ = geometry_;
  78. batches_[0].geometryType_ = GEOM_BILLBOARD;
  79. batches_[0].worldTransform_ = &transforms_[0];
  80. }
  81. BillboardSet::~BillboardSet()
  82. {
  83. }
  84. void BillboardSet::RegisterObject(Context* context)
  85. {
  86. context->RegisterFactory<BillboardSet>(GEOMETRY_CATEGORY);
  87. ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
  88. MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
  89. ACCESSOR_ATTRIBUTE("Relative Position", IsRelative, SetRelative, bool, true, AM_DEFAULT);
  90. ACCESSOR_ATTRIBUTE("Relative Scale", IsScaled, SetScaled, bool, true, AM_DEFAULT);
  91. ACCESSOR_ATTRIBUTE("Sort By Distance", IsSorted, SetSorted, bool, false, AM_DEFAULT);
  92. ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
  93. ATTRIBUTE("Cast Shadows", bool, castShadows_, false, AM_DEFAULT);
  94. ENUM_ATTRIBUTE("Face Camera Mode", faceCameraMode_, faceCameraModeNames, FC_ROTATE_XYZ, AM_DEFAULT);
  95. ACCESSOR_ATTRIBUTE("Draw Distance", GetDrawDistance, SetDrawDistance, float, 0.0f, AM_DEFAULT);
  96. ACCESSOR_ATTRIBUTE("Shadow Distance", GetShadowDistance, SetShadowDistance, float, 0.0f, AM_DEFAULT);
  97. ACCESSOR_ATTRIBUTE("Animation LOD Bias", GetAnimationLodBias, SetAnimationLodBias, float, 1.0f, AM_DEFAULT);
  98. COPY_BASE_ATTRIBUTES(Drawable);
  99. MIXED_ACCESSOR_ATTRIBUTE("Billboards", GetBillboardsAttr, SetBillboardsAttr, VariantVector, Variant::emptyVariantVector, AM_FILE);
  100. ACCESSOR_ATTRIBUTE("Network Billboards", GetNetBillboardsAttr, SetNetBillboardsAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_NET | AM_NOEDIT);
  101. }
  102. void BillboardSet::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
  103. {
  104. // If no billboard-level testing, use the Drawable test
  105. if (query.level_ < RAY_TRIANGLE)
  106. {
  107. Drawable::ProcessRayQuery(query, results);
  108. return;
  109. }
  110. // Check ray hit distance to AABB before proceeding with billboard-level tests
  111. if (query.ray_.HitDistance(GetWorldBoundingBox()) >= query.maxDistance_)
  112. return;
  113. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  114. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  115. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  116. for (unsigned i = 0; i < billboards_.Size(); ++i)
  117. {
  118. if (!billboards_[i].enabled_)
  119. continue;
  120. // Approximate the billboards as spheres for raycasting
  121. float size = INV_SQRT_TWO * (billboards_[i].size_.x_ * billboardScale.x_ + billboards_[i].size_.y_ * billboardScale.y_);
  122. Vector3 center = billboardTransform * billboards_[i].position_;
  123. Sphere billboardSphere(center, size);
  124. float distance = query.ray_.HitDistance(billboardSphere);
  125. if (distance < query.maxDistance_)
  126. {
  127. // If the code reaches here then we have a hit
  128. RayQueryResult result;
  129. result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
  130. result.normal_ = -query.ray_.direction_;
  131. result.distance_ = distance;
  132. result.drawable_ = this;
  133. result.node_ = node_;
  134. result.subObject_ = i;
  135. results.Push(result);
  136. }
  137. }
  138. }
  139. void BillboardSet::UpdateBatches(const FrameInfo& frame)
  140. {
  141. // If beginning a new frame, assume no sorting first
  142. if (frame.frameNumber_ != sortFrameNumber_)
  143. {
  144. sortThisFrame_ = false;
  145. sortFrameNumber_ = frame.frameNumber_;
  146. }
  147. Vector3 worldPos = node_->GetWorldPosition();
  148. Vector3 offset = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
  149. // Sort if position relative to camera has changed
  150. if (offset != previousOffset_ & sorted_)
  151. sortThisFrame_ = true;
  152. distance_ = frame.camera_->GetDistance(GetWorldBoundingBox().Center());
  153. // Calculate scaled distance for animation LOD
  154. float scale = GetWorldBoundingBox().Size().DotProduct(DOT_SCALE);
  155. // If there are no billboards, the size becomes zero, and LOD'ed updates no longer happen. Disable LOD in that case
  156. if (scale > M_EPSILON)
  157. lodDistance_ = frame.camera_->GetLodDistance(distance_, scale, lodBias_);
  158. else
  159. lodDistance_ = 0.0f;
  160. batches_[0].distance_ = distance_;
  161. batches_[0].numWorldTransforms_ = 2;
  162. // Billboard positioning
  163. transforms_[0] = relative_ ? node_->GetWorldTransform() : Matrix3x4::IDENTITY;
  164. // Billboard rotation
  165. transforms_[1] = Matrix3x4(Vector3::ZERO, faceCameraMode_ != FC_NONE ? frame.camera_->GetFaceCameraRotation(
  166. node_->GetWorldPosition(), node_->GetWorldRotation(), faceCameraMode_) : node_->GetWorldRotation(), Vector3::ONE);
  167. }
  168. void BillboardSet::UpdateGeometry(const FrameInfo& frame)
  169. {
  170. if (bufferSizeDirty_ || indexBuffer_->IsDataLost())
  171. UpdateBufferSize();
  172. if (bufferDirty_ || sortThisFrame_ || vertexBuffer_->IsDataLost())
  173. UpdateVertexBuffer(frame);
  174. // If using camera facing, re-update the rotation for the current view now
  175. if (faceCameraMode_ != FC_NONE)
  176. {
  177. transforms_[1] = Matrix3x4(Vector3::ZERO, frame.camera_->GetFaceCameraRotation(node_->GetWorldPosition(),
  178. node_->GetWorldRotation(), faceCameraMode_), Vector3::ONE);
  179. }
  180. }
  181. UpdateGeometryType BillboardSet::GetUpdateGeometryType()
  182. {
  183. // If using camera facing, always need some kind of geometry update, in case the billboard set is rendered from several views
  184. if (bufferDirty_ || bufferSizeDirty_ || vertexBuffer_->IsDataLost() || indexBuffer_->IsDataLost() || sortThisFrame_)
  185. return UPDATE_MAIN_THREAD;
  186. else if (faceCameraMode_ != FC_NONE)
  187. return UPDATE_WORKER_THREAD;
  188. else
  189. return UPDATE_NONE;
  190. }
  191. void BillboardSet::SetMaterial(Material* material)
  192. {
  193. batches_[0].material_ = material;
  194. MarkNetworkUpdate();
  195. }
  196. void BillboardSet::SetNumBillboards(unsigned num)
  197. {
  198. // Prevent negative value being assigned from the editor
  199. if (num > M_MAX_INT)
  200. num = 0;
  201. if (num > MAX_BILLBOARDS)
  202. num = MAX_BILLBOARDS;
  203. unsigned oldNum = billboards_.Size();
  204. billboards_.Resize(num);
  205. // Set default values to new billboards
  206. for (unsigned i = oldNum; i < num; ++i)
  207. {
  208. billboards_[i].position_ = Vector3::ZERO;
  209. billboards_[i].size_ = Vector2::ONE;
  210. billboards_[i].uv_ = Rect::POSITIVE;
  211. billboards_[i].color_ = Color(1.0f, 1.0f, 1.0f);
  212. billboards_[i].rotation_ = 0.0f;
  213. billboards_[i].enabled_ = false;
  214. }
  215. bufferSizeDirty_ = true;
  216. Commit();
  217. }
  218. void BillboardSet::SetRelative(bool enable)
  219. {
  220. relative_ = enable;
  221. Commit();
  222. }
  223. void BillboardSet::SetScaled(bool enable)
  224. {
  225. scaled_ = enable;
  226. Commit();
  227. }
  228. void BillboardSet::SetSorted(bool enable)
  229. {
  230. sorted_ = enable;
  231. Commit();
  232. }
  233. void BillboardSet::SetFaceCameraMode(FaceCameraMode mode)
  234. {
  235. faceCameraMode_ = mode;
  236. MarkNetworkUpdate();
  237. }
  238. void BillboardSet::SetAnimationLodBias(float bias)
  239. {
  240. animationLodBias_ = Max(bias, 0.0f);
  241. MarkNetworkUpdate();
  242. }
  243. void BillboardSet::Commit()
  244. {
  245. MarkPositionsDirty();
  246. MarkNetworkUpdate();
  247. }
  248. Material* BillboardSet::GetMaterial() const
  249. {
  250. return batches_[0].material_;
  251. }
  252. Billboard* BillboardSet::GetBillboard(unsigned index)
  253. {
  254. return index < billboards_.Size() ? &billboards_[index] : (Billboard*)0;
  255. }
  256. void BillboardSet::SetMaterialAttr(const ResourceRef& value)
  257. {
  258. ResourceCache* cache = GetSubsystem<ResourceCache>();
  259. SetMaterial(cache->GetResource<Material>(value.name_));
  260. }
  261. void BillboardSet::SetBillboardsAttr(const VariantVector& value)
  262. {
  263. unsigned index = 0;
  264. unsigned numBillboards = index < value.Size() ? value[index++].GetUInt() : 0;
  265. SetNumBillboards(numBillboards);
  266. for (PODVector<Billboard>::Iterator i = billboards_.Begin(); i != billboards_.End() && index < value.Size(); ++i)
  267. {
  268. i->position_ = value[index++].GetVector3();
  269. i->size_ = value[index++].GetVector2();
  270. Vector4 uv = value[index++].GetVector4();
  271. i->uv_ = Rect(uv.x_, uv.y_, uv.z_, uv.w_);
  272. i->color_ = value[index++].GetColor();
  273. i->rotation_ = value[index++].GetFloat();
  274. i->enabled_ = value[index++].GetBool();
  275. }
  276. Commit();
  277. }
  278. void BillboardSet::SetNetBillboardsAttr(const PODVector<unsigned char>& value)
  279. {
  280. MemoryBuffer buf(value);
  281. unsigned numBillboards = buf.ReadVLE();
  282. SetNumBillboards(numBillboards);
  283. for (PODVector<Billboard>::Iterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  284. {
  285. i->position_ = buf.ReadVector3();
  286. i->size_ = buf.ReadVector2();
  287. i->uv_ = buf.ReadRect();
  288. i->color_ = buf.ReadColor();
  289. i->rotation_ = buf.ReadFloat();
  290. i->enabled_ = buf.ReadBool();
  291. }
  292. Commit();
  293. }
  294. ResourceRef BillboardSet::GetMaterialAttr() const
  295. {
  296. return GetResourceRef(batches_[0].material_, Material::GetTypeStatic());
  297. }
  298. VariantVector BillboardSet::GetBillboardsAttr() const
  299. {
  300. VariantVector ret;
  301. ret.Reserve(billboards_.Size() * 6 + 1);
  302. ret.Push(billboards_.Size());
  303. for (PODVector<Billboard>::ConstIterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  304. {
  305. ret.Push(i->position_);
  306. ret.Push(i->size_);
  307. ret.Push(Vector4(i->uv_.min_.x_, i->uv_.min_.y_, i->uv_.max_.x_, i->uv_.max_.y_));
  308. ret.Push(i->color_);
  309. ret.Push(i->rotation_);
  310. ret.Push(i->enabled_);
  311. }
  312. return ret;
  313. }
  314. const PODVector<unsigned char>& BillboardSet::GetNetBillboardsAttr() const
  315. {
  316. attrBuffer_.Clear();
  317. attrBuffer_.WriteVLE(billboards_.Size());
  318. for (PODVector<Billboard>::ConstIterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  319. {
  320. attrBuffer_.WriteVector3(i->position_);
  321. attrBuffer_.WriteVector2(i->size_);
  322. attrBuffer_.WriteRect(i->uv_);
  323. attrBuffer_.WriteColor(i->color_);
  324. attrBuffer_.WriteFloat(i->rotation_);
  325. attrBuffer_.WriteBool(i->enabled_);
  326. }
  327. return attrBuffer_.GetBuffer();
  328. }
  329. void BillboardSet::OnWorldBoundingBoxUpdate()
  330. {
  331. unsigned enabledBillboards = 0;
  332. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  333. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  334. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  335. BoundingBox worldBox;
  336. for (unsigned i = 0; i < billboards_.Size(); ++i)
  337. {
  338. if (!billboards_[i].enabled_)
  339. continue;
  340. float size = INV_SQRT_TWO * (billboards_[i].size_.x_ * billboardScale.x_ + billboards_[i].size_.y_ * billboardScale.y_);
  341. Vector3 center = billboardTransform * billboards_[i].position_;
  342. Vector3 edge = Vector3::ONE * size;
  343. worldBox.Merge(BoundingBox(center - edge, center + edge));
  344. ++enabledBillboards;
  345. }
  346. // Always merge the node's own position to ensure particle emitter updates continue when the relative mode is switched
  347. worldBox.Merge(node_->GetWorldPosition());
  348. worldBoundingBox_ = worldBox;
  349. }
  350. void BillboardSet::UpdateBufferSize()
  351. {
  352. unsigned numBillboards = billboards_.Size();
  353. if (vertexBuffer_->GetVertexCount() != numBillboards * 4)
  354. vertexBuffer_->SetSize(numBillboards * 4, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1 | MASK_TEXCOORD2, true);
  355. if (indexBuffer_->GetIndexCount() != numBillboards * 6)
  356. indexBuffer_->SetSize(numBillboards * 6, false);
  357. bufferSizeDirty_ = false;
  358. bufferDirty_ = true;
  359. forceUpdate_ = true;
  360. if (!numBillboards)
  361. return;
  362. // Indices do not change for a given billboard capacity
  363. unsigned short* dest = (unsigned short*)indexBuffer_->Lock(0, numBillboards * 6, true);
  364. if (!dest)
  365. return;
  366. unsigned vertexIndex = 0;
  367. while (numBillboards--)
  368. {
  369. dest[0] = vertexIndex; dest[1] = vertexIndex + 1; dest[2] = vertexIndex + 2;
  370. dest[3] = vertexIndex + 2; dest[4] = vertexIndex + 3; dest[5] = vertexIndex;
  371. dest += 6;
  372. vertexIndex += 4;
  373. }
  374. indexBuffer_->Unlock();
  375. indexBuffer_->ClearDataLost();
  376. }
  377. void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
  378. {
  379. // If using animation LOD, accumulate time and see if it is time to update
  380. if (animationLodBias_ > 0.0f && lodDistance_ > 0.0f)
  381. {
  382. animationLodTimer_ += animationLodBias_ * frame.timeStep_ * ANIMATION_LOD_BASESCALE;
  383. if (animationLodTimer_ >= lodDistance_)
  384. animationLodTimer_ = fmodf(animationLodTimer_, lodDistance_);
  385. else
  386. {
  387. // No LOD if immediate update forced
  388. if (!forceUpdate_)
  389. return;
  390. }
  391. }
  392. unsigned numBillboards = billboards_.Size();
  393. unsigned enabledBillboards = 0;
  394. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  395. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  396. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  397. // First check number of enabled billboards
  398. for (unsigned i = 0; i < numBillboards; ++i)
  399. {
  400. if (billboards_[i].enabled_)
  401. ++enabledBillboards;
  402. }
  403. sortedBillboards_.Resize(enabledBillboards);
  404. unsigned index = 0;
  405. // Then set initial sort order and distances
  406. for (unsigned i = 0; i < numBillboards; ++i)
  407. {
  408. Billboard& billboard = billboards_[i];
  409. if (billboard.enabled_)
  410. {
  411. sortedBillboards_[index++] = &billboard;
  412. if (sorted_)
  413. billboard.sortDistance_ = frame.camera_->GetDistanceSquared(billboardTransform * billboards_[i].position_);
  414. }
  415. }
  416. batches_[0].geometry_->SetDrawRange(TRIANGLE_LIST, 0, enabledBillboards * 6, false);
  417. bufferDirty_ = false;
  418. forceUpdate_ = false;
  419. if (!enabledBillboards)
  420. return;
  421. if (sorted_)
  422. {
  423. Sort(sortedBillboards_.Begin(), sortedBillboards_.End(), CompareBillboards);
  424. Vector3 worldPos = node_->GetWorldPosition();
  425. // Store the "last sorted position" now
  426. previousOffset_ = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
  427. }
  428. float* dest = (float*)vertexBuffer_->Lock(0, enabledBillboards * 4, true);
  429. if (!dest)
  430. return;
  431. for (unsigned i = 0; i < enabledBillboards; ++i)
  432. {
  433. Billboard& billboard = *sortedBillboards_[i];
  434. Vector2 size(billboard.size_.x_ * billboardScale.x_, billboard.size_.y_ * billboardScale.y_);
  435. unsigned color = billboard.color_.ToUInt();
  436. float rotationMatrix[2][2];
  437. rotationMatrix[0][0] = Cos(billboard.rotation_);
  438. rotationMatrix[0][1] = Sin(billboard.rotation_);
  439. rotationMatrix[1][0] = -rotationMatrix[0][1];
  440. rotationMatrix[1][1] = rotationMatrix[0][0];
  441. dest[0] = billboard.position_.x_; dest[1] = billboard.position_.y_; dest[2] = billboard.position_.z_;
  442. ((unsigned&)dest[3]) = color;
  443. dest[4] = billboard.uv_.min_.x_; dest[5] = billboard.uv_.min_.y_;
  444. dest[6] = -size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
  445. dest[7] = -size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
  446. dest[8] = billboard.position_.x_; dest[9] = billboard.position_.y_; dest[10] = billboard.position_.z_;
  447. ((unsigned&)dest[11]) = color;
  448. dest[12] = billboard.uv_.max_.x_; dest[13] = billboard.uv_.min_.y_;
  449. dest[14] = size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
  450. dest[15] = size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
  451. dest[16] = billboard.position_.x_; dest[17] = billboard.position_.y_; dest[18] = billboard.position_.z_;
  452. ((unsigned&)dest[19]) = color;
  453. dest[20] = billboard.uv_.max_.x_; dest[21] = billboard.uv_.max_.y_;
  454. dest[22] = size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
  455. dest[23] = size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
  456. dest[24] = billboard.position_.x_; dest[25] = billboard.position_.y_; dest[26] = billboard.position_.z_;
  457. ((unsigned&)dest[27]) = color;
  458. dest[28] = billboard.uv_.min_.x_; dest[29] = billboard.uv_.max_.y_;
  459. dest[30] = -size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
  460. dest[31] = -size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
  461. dest += 32;
  462. }
  463. vertexBuffer_->Unlock();
  464. vertexBuffer_->ClearDataLost();
  465. }
  466. void BillboardSet::MarkPositionsDirty()
  467. {
  468. Drawable::OnMarkedDirty(node_);
  469. bufferDirty_ = true;
  470. }
  471. }