StaticModel.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. //
  2. // Copyright (c) 2008-2017 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 "../Core/Context.h"
  24. #include "../Core/Profiler.h"
  25. #include "../Graphics/AnimatedModel.h"
  26. #include "../Graphics/Batch.h"
  27. #include "../Graphics/Camera.h"
  28. #include "../Graphics/Geometry.h"
  29. #include "../Graphics/Material.h"
  30. #include "../Graphics/OcclusionBuffer.h"
  31. #include "../Graphics/OctreeQuery.h"
  32. #include "../Graphics/VertexBuffer.h"
  33. #include "../IO/FileSystem.h"
  34. #include "../IO/Log.h"
  35. #include "../Resource/ResourceCache.h"
  36. #include "../Resource/ResourceEvents.h"
  37. #include "../DebugNew.h"
  38. namespace Atomic
  39. {
  40. extern const char* GEOMETRY_CATEGORY;
  41. StaticModel::StaticModel(Context* context) :
  42. Drawable(context, DRAWABLE_GEOMETRY),
  43. occlusionLodLevel_(M_MAX_UNSIGNED),
  44. materialsAttr_(Material::GetTypeStatic()),
  45. // ATOMIC BEGIN
  46. lightmap_(false),
  47. lightmapScale_(1.0f),
  48. lightmapSize_(0),
  49. lightmapIndex_(0),
  50. lightmapTilingOffset_(1.0f, 1.0f, 0.0f, 0.0f)
  51. // ATOMIC END
  52. {
  53. }
  54. StaticModel::~StaticModel()
  55. {
  56. }
  57. void StaticModel::RegisterObject(Context* context)
  58. {
  59. context->RegisterFactory<StaticModel>(GEOMETRY_CATEGORY);
  60. ATOMIC_ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
  61. ATOMIC_MIXED_ACCESSOR_ATTRIBUTE("Model", GetModelAttr, SetModelAttr, ResourceRef, ResourceRef(Model::GetTypeStatic()), AM_DEFAULT);
  62. ATOMIC_ACCESSOR_ATTRIBUTE("Material", GetMaterialsAttr, SetMaterialsAttr, ResourceRefList, ResourceRefList(Material::GetTypeStatic()),
  63. AM_DEFAULT);
  64. ATOMIC_ATTRIBUTE("Is Occluder", bool, occluder_, false, AM_DEFAULT);
  65. ATOMIC_ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
  66. ATOMIC_ATTRIBUTE("Cast Shadows", bool, castShadows_, false, AM_DEFAULT);
  67. ATOMIC_ACCESSOR_ATTRIBUTE("Draw Distance", GetDrawDistance, SetDrawDistance, float, 0.0f, AM_DEFAULT);
  68. ATOMIC_ACCESSOR_ATTRIBUTE("Shadow Distance", GetShadowDistance, SetShadowDistance, float, 0.0f, AM_DEFAULT);
  69. ATOMIC_ACCESSOR_ATTRIBUTE("LOD Bias", GetLodBias, SetLodBias, float, 1.0f, AM_DEFAULT);
  70. ATOMIC_COPY_BASE_ATTRIBUTES(Drawable);
  71. ATOMIC_ATTRIBUTE("Occlusion LOD Level", int, occlusionLodLevel_, M_MAX_UNSIGNED, AM_DEFAULT);
  72. // ATOMIC BEGIN
  73. ATOMIC_ACCESSOR_ATTRIBUTE("Geometry Enabled", GetGeometryEnabledAttr, SetGeometryEnabledAttr, VariantVector,
  74. Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
  75. ATOMIC_ATTRIBUTE("Lightmap", bool, lightmap_, false, AM_DEFAULT);
  76. ATOMIC_ATTRIBUTE("Lightmap Scale", float, lightmapScale_, 1.0f, AM_DEFAULT);
  77. ATOMIC_ATTRIBUTE("Lightmap Size", unsigned, lightmapSize_, 0, AM_DEFAULT);
  78. ATOMIC_ATTRIBUTE("Lightmap Index", unsigned, lightmapIndex_, 0, AM_FILE | AM_NOEDIT);
  79. ATOMIC_ATTRIBUTE("Lightmap Tiling Offset", Vector4, lightmapTilingOffset_ , Vector4(1.0f, 1.0f, 0.0f, 0.0f), AM_FILE | AM_NOEDIT);
  80. // ATOMIC END
  81. }
  82. void StaticModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
  83. {
  84. RayQueryLevel level = query.level_;
  85. switch (level)
  86. {
  87. case RAY_AABB:
  88. Drawable::ProcessRayQuery(query, results);
  89. break;
  90. case RAY_OBB:
  91. case RAY_TRIANGLE:
  92. case RAY_TRIANGLE_UV:
  93. Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
  94. Ray localRay = query.ray_.Transformed(inverse);
  95. float distance = localRay.HitDistance(boundingBox_);
  96. Vector3 normal = -query.ray_.direction_;
  97. Vector2 geometryUV;
  98. unsigned hitBatch = M_MAX_UNSIGNED;
  99. if (level >= RAY_TRIANGLE && distance < query.maxDistance_)
  100. {
  101. distance = M_INFINITY;
  102. for (unsigned i = 0; i < batches_.Size(); ++i)
  103. {
  104. Geometry* geometry = batches_[i].geometry_;
  105. if (geometry)
  106. {
  107. Vector3 geometryNormal;
  108. float geometryDistance = level == RAY_TRIANGLE ? geometry->GetHitDistance(localRay, &geometryNormal) :
  109. geometry->GetHitDistance(localRay, &geometryNormal, &geometryUV);
  110. if (geometryDistance < query.maxDistance_ && geometryDistance < distance)
  111. {
  112. distance = geometryDistance;
  113. normal = (node_->GetWorldTransform() * Vector4(geometryNormal, 0.0f)).Normalized();
  114. hitBatch = i;
  115. }
  116. }
  117. }
  118. }
  119. if (distance < query.maxDistance_)
  120. {
  121. RayQueryResult result;
  122. result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
  123. result.normal_ = normal;
  124. result.textureUV_ = geometryUV;
  125. result.distance_ = distance;
  126. result.drawable_ = this;
  127. result.node_ = node_;
  128. result.subObject_ = hitBatch;
  129. results.Push(result);
  130. }
  131. break;
  132. }
  133. }
  134. void StaticModel::UpdateBatches(const FrameInfo& frame)
  135. {
  136. const BoundingBox& worldBoundingBox = GetWorldBoundingBox();
  137. distance_ = frame.camera_->GetDistance(worldBoundingBox.Center());
  138. if (batches_.Size() == 1)
  139. batches_[0].distance_ = distance_;
  140. else
  141. {
  142. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  143. for (unsigned i = 0; i < batches_.Size(); ++i)
  144. batches_[i].distance_ = frame.camera_->GetDistance(worldTransform * geometryData_[i].center_);
  145. }
  146. float scale = worldBoundingBox.Size().DotProduct(DOT_SCALE);
  147. float newLodDistance = frame.camera_->GetLodDistance(distance_, scale, lodBias_);
  148. if (newLodDistance != lodDistance_)
  149. {
  150. lodDistance_ = newLodDistance;
  151. CalculateLodLevels();
  152. }
  153. // ATOMIC BEGIN
  154. if (geometryDisabled_)
  155. {
  156. UpdateBatchesHideGeometry();
  157. }
  158. if (lightmap_)
  159. {
  160. for (unsigned i = 0; i < batches_.Size(); ++i)
  161. {
  162. batches_[i].lightmapTextureID_ = lightmapIndex_;
  163. batches_[i].geometryType_ = GEOM_STATIC_NOINSTANCING;
  164. batches_[i].lightmapTilingOffset_ = &lightmapTilingOffset_;
  165. }
  166. }
  167. // ATOMIC END
  168. }
  169. Geometry* StaticModel::GetLodGeometry(unsigned batchIndex, unsigned level)
  170. {
  171. if (batchIndex >= geometries_.Size())
  172. return 0;
  173. // If level is out of range, use visible geometry
  174. if (level < geometries_[batchIndex].Size())
  175. return geometries_[batchIndex][level];
  176. else
  177. return batches_[batchIndex].geometry_;
  178. }
  179. unsigned StaticModel::GetNumOccluderTriangles()
  180. {
  181. unsigned triangles = 0;
  182. for (unsigned i = 0; i < batches_.Size(); ++i)
  183. {
  184. Geometry* geometry = GetLodGeometry(i, occlusionLodLevel_);
  185. if (!geometry)
  186. continue;
  187. // Check that the material is suitable for occlusion (default material always is)
  188. Material* mat = batches_[i].material_;
  189. if (mat && !mat->GetOcclusion())
  190. continue;
  191. triangles += geometry->GetIndexCount() / 3;
  192. }
  193. return triangles;
  194. }
  195. bool StaticModel::DrawOcclusion(OcclusionBuffer* buffer)
  196. {
  197. for (unsigned i = 0; i < batches_.Size(); ++i)
  198. {
  199. Geometry* geometry = GetLodGeometry(i, occlusionLodLevel_);
  200. if (!geometry)
  201. continue;
  202. // Check that the material is suitable for occlusion (default material always is) and set culling mode
  203. Material* material = batches_[i].material_;
  204. if (material)
  205. {
  206. if (!material->GetOcclusion())
  207. continue;
  208. buffer->SetCullMode(material->GetCullMode());
  209. }
  210. else
  211. buffer->SetCullMode(CULL_CCW);
  212. const unsigned char* vertexData;
  213. unsigned vertexSize;
  214. const unsigned char* indexData;
  215. unsigned indexSize;
  216. const PODVector<VertexElement>* elements;
  217. geometry->GetRawData(vertexData, vertexSize, indexData, indexSize, elements);
  218. // Check for valid geometry data
  219. if (!vertexData || !indexData || !elements || VertexBuffer::GetElementOffset(*elements, TYPE_VECTOR3, SEM_POSITION) != 0)
  220. continue;
  221. unsigned indexStart = geometry->GetIndexStart();
  222. unsigned indexCount = geometry->GetIndexCount();
  223. // Draw and check for running out of triangles
  224. if (!buffer->AddTriangles(node_->GetWorldTransform(), vertexData, vertexSize, indexData, indexSize, indexStart, indexCount))
  225. return false;
  226. }
  227. return true;
  228. }
  229. void StaticModel::SetModel(Model* model)
  230. {
  231. if (model == model_)
  232. return;
  233. // ATOMIC BEGIN
  234. // If script erroneously calls StaticModel::SetModel on an AnimatedModel, warn and redirect
  235. if (GetType() == AnimatedModel::GetTypeStatic())
  236. {
  237. ATOMIC_LOGWARNING("StaticModel::SetModel() called on AnimatedModel. Redirecting to AnimatedModel::SetModel()");
  238. AnimatedModel* animatedModel = static_cast<AnimatedModel*>(this);
  239. animatedModel->SetModel(model);
  240. return;
  241. }
  242. // ATOMIC END
  243. if (!node_)
  244. {
  245. ATOMIC_LOGERROR("Can not set model while model component is not attached to a scene node");
  246. return;
  247. }
  248. // Unsubscribe from the reload event of previous model (if any), then subscribe to the new
  249. if (model_)
  250. UnsubscribeFromEvent(model_, E_RELOADFINISHED);
  251. model_ = model;
  252. if (model)
  253. {
  254. SubscribeToEvent(model, E_RELOADFINISHED, ATOMIC_HANDLER(StaticModel, HandleModelReloadFinished));
  255. // Copy the subgeometry & LOD level structure
  256. SetNumGeometries(model->GetNumGeometries());
  257. const Vector<Vector<SharedPtr<Geometry> > >& geometries = model->GetGeometries();
  258. const PODVector<Vector3>& geometryCenters = model->GetGeometryCenters();
  259. const Matrix3x4* worldTransform = node_ ? &node_->GetWorldTransform() : (const Matrix3x4*)0;
  260. for (unsigned i = 0; i < geometries.Size(); ++i)
  261. {
  262. batches_[i].worldTransform_ = worldTransform;
  263. geometries_[i] = geometries[i];
  264. geometryData_[i].center_ = geometryCenters[i];
  265. // ATOMIC BEGIN
  266. geometryData_[i].enabled_ = true;
  267. geometryData_[i].batchGeometry_ = 0;
  268. // ATOMIC END
  269. }
  270. SetBoundingBox(model->GetBoundingBox());
  271. ResetLodLevels();
  272. }
  273. else
  274. {
  275. SetNumGeometries(0);
  276. SetBoundingBox(BoundingBox());
  277. }
  278. MarkNetworkUpdate();
  279. }
  280. void StaticModel::SetMaterial(Material* material)
  281. {
  282. for (unsigned i = 0; i < batches_.Size(); ++i)
  283. batches_[i].material_ = material;
  284. MarkNetworkUpdate();
  285. }
  286. bool StaticModel::SetMaterial(unsigned index, Material* material)
  287. {
  288. if (index >= batches_.Size())
  289. {
  290. ATOMIC_LOGERROR("Material index out of bounds");
  291. return false;
  292. }
  293. batches_[index].material_ = material;
  294. MarkNetworkUpdate();
  295. return true;
  296. }
  297. void StaticModel::SetOcclusionLodLevel(unsigned level)
  298. {
  299. occlusionLodLevel_ = level;
  300. MarkNetworkUpdate();
  301. }
  302. void StaticModel::ApplyMaterialList(const String& fileName)
  303. {
  304. String useFileName = fileName;
  305. if (useFileName.Trimmed().Empty() && model_)
  306. useFileName = ReplaceExtension(model_->GetName(), ".txt");
  307. ResourceCache* cache = GetSubsystem<ResourceCache>();
  308. SharedPtr<File> file = cache->GetFile(useFileName, false);
  309. if (!file)
  310. return;
  311. unsigned index = 0;
  312. while (!file->IsEof() && index < batches_.Size())
  313. {
  314. Material* material = cache->GetResource<Material>(file->ReadLine());
  315. if (material)
  316. SetMaterial(index, material);
  317. ++index;
  318. }
  319. }
  320. Material* StaticModel::GetMaterial(unsigned index) const
  321. {
  322. return index < batches_.Size() ? batches_[index].material_ : (Material*)0;
  323. }
  324. bool StaticModel::IsInside(const Vector3& point) const
  325. {
  326. if (!node_)
  327. return false;
  328. Vector3 localPosition = node_->GetWorldTransform().Inverse() * point;
  329. return IsInsideLocal(localPosition);
  330. }
  331. bool StaticModel::IsInsideLocal(const Vector3& point) const
  332. {
  333. // Early-out if point is not inside bounding box
  334. if (boundingBox_.IsInside(point) == OUTSIDE)
  335. return false;
  336. Ray localRay(point, Vector3(1.0f, -1.0f, 1.0f));
  337. for (unsigned i = 0; i < batches_.Size(); ++i)
  338. {
  339. Geometry* geometry = batches_[i].geometry_;
  340. if (geometry)
  341. {
  342. if (geometry->IsInside(localRay))
  343. return true;
  344. }
  345. }
  346. return false;
  347. }
  348. void StaticModel::SetBoundingBox(const BoundingBox& box)
  349. {
  350. boundingBox_ = box;
  351. OnMarkedDirty(node_);
  352. }
  353. void StaticModel::SetNumGeometries(unsigned num)
  354. {
  355. batches_.Resize(num);
  356. geometries_.Resize(num);
  357. geometryData_.Resize(num);
  358. ResetLodLevels();
  359. }
  360. void StaticModel::SetModelAttr(const ResourceRef& value)
  361. {
  362. ResourceCache* cache = GetSubsystem<ResourceCache>();
  363. SetModel(cache->GetResource<Model>(value.name_));
  364. }
  365. void StaticModel::SetMaterialsAttr(const ResourceRefList& value)
  366. {
  367. ResourceCache* cache = GetSubsystem<ResourceCache>();
  368. for (unsigned i = 0; i < value.names_.Size(); ++i)
  369. SetMaterial(i, cache->GetResource<Material>(value.names_[i]));
  370. }
  371. ResourceRef StaticModel::GetModelAttr() const
  372. {
  373. return GetResourceRef(model_, Model::GetTypeStatic());
  374. }
  375. const ResourceRefList& StaticModel::GetMaterialsAttr() const
  376. {
  377. materialsAttr_.names_.Resize(batches_.Size());
  378. for (unsigned i = 0; i < batches_.Size(); ++i)
  379. materialsAttr_.names_[i] = GetResourceName(GetMaterial(i));
  380. return materialsAttr_;
  381. }
  382. void StaticModel::OnWorldBoundingBoxUpdate()
  383. {
  384. worldBoundingBox_ = boundingBox_.Transformed(node_->GetWorldTransform());
  385. }
  386. void StaticModel::ResetLodLevels()
  387. {
  388. // Ensure that each subgeometry has at least one LOD level, and reset the current LOD level
  389. for (unsigned i = 0; i < batches_.Size(); ++i)
  390. {
  391. if (!geometries_[i].Size())
  392. geometries_[i].Resize(1);
  393. batches_[i].geometry_ = geometries_[i][0];
  394. geometryData_[i].lodLevel_ = 0;
  395. }
  396. // Find out the real LOD levels on next geometry update
  397. lodDistance_ = M_INFINITY;
  398. }
  399. void StaticModel::CalculateLodLevels()
  400. {
  401. for (unsigned i = 0; i < batches_.Size(); ++i)
  402. {
  403. const Vector<SharedPtr<Geometry> >& batchGeometries = geometries_[i];
  404. // If only one LOD geometry, no reason to go through the LOD calculation
  405. if (batchGeometries.Size() <= 1)
  406. continue;
  407. unsigned j;
  408. for (j = 1; j < batchGeometries.Size(); ++j)
  409. {
  410. if (batchGeometries[j] && lodDistance_ <= batchGeometries[j]->GetLodDistance())
  411. break;
  412. }
  413. unsigned newLodLevel = j - 1;
  414. if (geometryData_[i].lodLevel_ != newLodLevel)
  415. {
  416. geometryData_[i].lodLevel_ = newLodLevel;
  417. batches_[i].geometry_ = batchGeometries[newLodLevel];
  418. }
  419. }
  420. }
  421. void StaticModel::HandleModelReloadFinished(StringHash eventType, VariantMap& eventData)
  422. {
  423. Model* currentModel = model_;
  424. model_.Reset(); // Set null to allow to be re-set
  425. SetModel(currentModel);
  426. }
  427. // ATOMIC BEGIN
  428. bool StaticModel::GetGeometryVisible(const String& name)
  429. {
  430. if (!model_)
  431. return false;
  432. const Vector<String>& names = model_->GetGeometryNames();
  433. for (unsigned i = 0; i < names.Size(); i++)
  434. {
  435. if (name == names[i])
  436. return geometryData_[i].enabled_;
  437. }
  438. return false;
  439. }
  440. void StaticModel::ShowGeometry(const String& name)
  441. {
  442. if (!model_)
  443. return;
  444. const Vector<String>& names = model_->GetGeometryNames();
  445. for (unsigned i = 0; i < names.Size(); i++)
  446. {
  447. if (name == names[i])
  448. {
  449. if (geometryData_[i].batchGeometry_)
  450. batches_[i].geometry_ = geometryData_[i].batchGeometry_;
  451. geometryData_[i].batchGeometry_ = 0;
  452. geometryData_[i].enabled_ = true;
  453. }
  454. }
  455. geometryDisabled_ = false;
  456. for (unsigned i = 0; i < geometryData_.Size(); i++)
  457. {
  458. if (!geometryData_[i].enabled_)
  459. {
  460. geometryDisabled_ = true;
  461. break;
  462. }
  463. }
  464. }
  465. void StaticModel::HideGeometry(const String& name)
  466. {
  467. if (!model_)
  468. return;
  469. const Vector<String>& names = model_->GetGeometryNames();
  470. for (unsigned i = 0; i < names.Size(); i++)
  471. {
  472. if (name == names[i])
  473. {
  474. geometryDisabled_ = true;
  475. if (batches_[i].geometry_)
  476. geometryData_[i].batchGeometry_ = batches_[i].geometry_;
  477. geometryData_[i].enabled_ = false;
  478. }
  479. }
  480. }
  481. void StaticModel::SetGeometryEnabledAttr(const VariantVector& value)
  482. {
  483. if (!value.Size() || value.Size() != geometryData_.Size())
  484. {
  485. geometryDisabled_ = false;
  486. geometryEnabled_.Clear();
  487. return;
  488. }
  489. bool init = !geometryEnabled_.Size();
  490. geometryEnabled_ = value;
  491. for (unsigned i = 0; i < geometryData_.Size(); i++)
  492. {
  493. geometryData_[i].enabled_ = geometryEnabled_[i].GetBool();
  494. if (!geometryData_[i].enabled_)
  495. geometryDisabled_ = true;
  496. if (init)
  497. geometryData_[i].batchGeometry_ = 0;
  498. }
  499. }
  500. const VariantVector& StaticModel::GetGeometryEnabledAttr() const
  501. {
  502. geometryEnabled_.Resize(geometryData_.Size());
  503. geometryDisabled_ = false;
  504. for (unsigned i = 0; i < geometryData_.Size(); i++)
  505. {
  506. geometryEnabled_[i] = geometryData_[i].enabled_;
  507. if (!geometryData_[i].enabled_)
  508. geometryDisabled_ = true;
  509. }
  510. return geometryEnabled_;
  511. }
  512. void StaticModel::UpdateBatchesHideGeometry()
  513. {
  514. if (!geometryDisabled_ || !batches_.Size())
  515. return;
  516. for (unsigned i = 0; i < batches_.Size(); ++i)
  517. {
  518. SourceBatch* batch = &batches_[i];
  519. StaticModelGeometryData* data = &geometryData_[i];
  520. if (batch->geometry_)
  521. data->batchGeometry_ = batch->geometry_;
  522. if (data->enabled_ && !batch->geometry_)
  523. {
  524. batch->geometry_ = data->batchGeometry_;
  525. }
  526. else if (!data->enabled_ && batch->geometry_)
  527. {
  528. data->batchGeometry_ = batch->geometry_;
  529. batch->geometry_ = 0;
  530. }
  531. }
  532. }
  533. // ATOMIC END
  534. }