Drawable.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. //
  2. // Copyright (c) 2008-2015 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 "../Graphics/Camera.h"
  25. #include "../Graphics/DebugRenderer.h"
  26. #include "../IO/File.h"
  27. #include "../Graphics/Geometry.h"
  28. #include "../Graphics/Material.h"
  29. #include "../Graphics/Octree.h"
  30. #include "../Graphics/Renderer.h"
  31. #include "../Graphics/VertexBuffer.h"
  32. #include "../Graphics/Zone.h"
  33. #include "../IO/Log.h"
  34. #include "../Scene/Scene.h"
  35. #include "../DebugNew.h"
  36. #ifdef _MSC_VER
  37. #pragma warning(disable:6293)
  38. #endif
  39. namespace Urho3D
  40. {
  41. const char* GEOMETRY_CATEGORY = "Geometry";
  42. SourceBatch::SourceBatch() :
  43. distance_(0.0f),
  44. geometry_(0),
  45. worldTransform_(&Matrix3x4::IDENTITY),
  46. numWorldTransforms_(1),
  47. geometryType_(GEOM_STATIC)
  48. {
  49. }
  50. SourceBatch::SourceBatch(const SourceBatch& batch)
  51. {
  52. *this = batch;
  53. }
  54. SourceBatch::~SourceBatch()
  55. {
  56. }
  57. SourceBatch& SourceBatch::operator =(const SourceBatch& rhs)
  58. {
  59. distance_ = rhs.distance_;
  60. geometry_ = rhs.geometry_;
  61. material_ = rhs.material_;
  62. worldTransform_ = rhs.worldTransform_;
  63. numWorldTransforms_ = rhs.numWorldTransforms_;
  64. geometryType_ = rhs.geometryType_;
  65. return *this;
  66. }
  67. Drawable::Drawable(Context* context, unsigned char drawableFlags) :
  68. Component(context),
  69. drawableFlags_(drawableFlags),
  70. worldBoundingBoxDirty_(true),
  71. castShadows_(false),
  72. occluder_(false),
  73. occludee_(true),
  74. updateQueued_(false),
  75. zoneDirty_(false),
  76. octant_(0),
  77. zone_(0),
  78. viewMask_(DEFAULT_VIEWMASK),
  79. lightMask_(DEFAULT_LIGHTMASK),
  80. shadowMask_(DEFAULT_SHADOWMASK),
  81. zoneMask_(DEFAULT_ZONEMASK),
  82. viewFrameNumber_(0),
  83. distance_(0.0f),
  84. lodDistance_(0.0f),
  85. drawDistance_(0.0f),
  86. shadowDistance_(0.0f),
  87. sortValue_(0.0f),
  88. minZ_(0.0f),
  89. maxZ_(0.0f),
  90. lodBias_(1.0f),
  91. basePassFlags_(0),
  92. maxLights_(0),
  93. firstLight_(0)
  94. {
  95. }
  96. Drawable::~Drawable()
  97. {
  98. RemoveFromOctree();
  99. }
  100. void Drawable::RegisterObject(Context* context)
  101. {
  102. ATTRIBUTE("Max Lights", int, maxLights_, 0, AM_DEFAULT);
  103. ATTRIBUTE("View Mask", int, viewMask_, DEFAULT_VIEWMASK, AM_DEFAULT);
  104. ATTRIBUTE("Light Mask", int, lightMask_, DEFAULT_LIGHTMASK, AM_DEFAULT);
  105. ATTRIBUTE("Shadow Mask", int, shadowMask_, DEFAULT_SHADOWMASK, AM_DEFAULT);
  106. ACCESSOR_ATTRIBUTE("Zone Mask", GetZoneMask, SetZoneMask, unsigned, DEFAULT_ZONEMASK, AM_DEFAULT);
  107. }
  108. void Drawable::OnSetEnabled()
  109. {
  110. bool enabled = IsEnabledEffective();
  111. if (enabled && !octant_)
  112. AddToOctree();
  113. else if (!enabled && octant_)
  114. RemoveFromOctree();
  115. }
  116. void Drawable::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
  117. {
  118. float distance = query.ray_.HitDistance(GetWorldBoundingBox());
  119. if (distance < query.maxDistance_)
  120. {
  121. RayQueryResult result;
  122. result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
  123. result.normal_ = -query.ray_.direction_;
  124. result.distance_ = distance;
  125. result.drawable_ = this;
  126. result.node_ = GetNode();
  127. result.subObject_ = M_MAX_UNSIGNED;
  128. results.Push(result);
  129. }
  130. }
  131. void Drawable::Update(const FrameInfo& frame)
  132. {
  133. }
  134. void Drawable::UpdateBatches(const FrameInfo& frame)
  135. {
  136. const BoundingBox& worldBoundingBox = GetWorldBoundingBox();
  137. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  138. distance_ = frame.camera_->GetDistance(worldBoundingBox.Center());
  139. for (unsigned i = 0; i < batches_.Size(); ++i)
  140. {
  141. batches_[i].distance_ = distance_;
  142. batches_[i].worldTransform_ = &worldTransform;
  143. }
  144. float scale = worldBoundingBox.Size().DotProduct(DOT_SCALE);
  145. float newLodDistance = frame.camera_->GetLodDistance(distance_, scale, lodBias_);
  146. if (newLodDistance != lodDistance_)
  147. lodDistance_ = newLodDistance;
  148. }
  149. void Drawable::UpdateGeometry(const FrameInfo& frame)
  150. {
  151. }
  152. Geometry* Drawable::GetLodGeometry(unsigned batchIndex, unsigned level)
  153. {
  154. // By default return the visible batch geometry
  155. if (batchIndex < batches_.Size())
  156. return batches_[batchIndex].geometry_;
  157. else
  158. return 0;
  159. }
  160. bool Drawable::DrawOcclusion(OcclusionBuffer* buffer)
  161. {
  162. return true;
  163. }
  164. void Drawable::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
  165. {
  166. if (debug && IsEnabledEffective())
  167. debug->AddBoundingBox(GetWorldBoundingBox(), Color::GREEN, depthTest);
  168. }
  169. void Drawable::SetDrawDistance(float distance)
  170. {
  171. drawDistance_ = distance;
  172. MarkNetworkUpdate();
  173. }
  174. void Drawable::SetShadowDistance(float distance)
  175. {
  176. shadowDistance_ = distance;
  177. MarkNetworkUpdate();
  178. }
  179. void Drawable::SetLodBias(float bias)
  180. {
  181. lodBias_ = Max(bias, M_EPSILON);
  182. MarkNetworkUpdate();
  183. }
  184. void Drawable::SetViewMask(unsigned mask)
  185. {
  186. viewMask_ = mask;
  187. MarkNetworkUpdate();
  188. }
  189. void Drawable::SetLightMask(unsigned mask)
  190. {
  191. lightMask_ = mask;
  192. MarkNetworkUpdate();
  193. }
  194. void Drawable::SetShadowMask(unsigned mask)
  195. {
  196. shadowMask_ = mask;
  197. MarkNetworkUpdate();
  198. }
  199. void Drawable::SetZoneMask(unsigned mask)
  200. {
  201. zoneMask_ = mask;
  202. // Mark dirty to reset cached zone
  203. OnMarkedDirty(node_);
  204. MarkNetworkUpdate();
  205. }
  206. void Drawable::SetMaxLights(unsigned num)
  207. {
  208. maxLights_ = num;
  209. MarkNetworkUpdate();
  210. }
  211. void Drawable::SetCastShadows(bool enable)
  212. {
  213. castShadows_ = enable;
  214. MarkNetworkUpdate();
  215. }
  216. void Drawable::SetOccluder(bool enable)
  217. {
  218. occluder_ = enable;
  219. MarkNetworkUpdate();
  220. }
  221. void Drawable::SetOccludee(bool enable)
  222. {
  223. if (enable != occludee_)
  224. {
  225. occludee_ = enable;
  226. // Reinsert to octree to make sure octant occlusion does not erroneously hide this drawable
  227. if (octant_ && !updateQueued_)
  228. octant_->GetRoot()->QueueUpdate(this);
  229. MarkNetworkUpdate();
  230. }
  231. }
  232. void Drawable::MarkForUpdate()
  233. {
  234. if (!updateQueued_ && octant_)
  235. octant_->GetRoot()->QueueUpdate(this);
  236. }
  237. const BoundingBox& Drawable::GetWorldBoundingBox()
  238. {
  239. if (worldBoundingBoxDirty_)
  240. {
  241. OnWorldBoundingBoxUpdate();
  242. worldBoundingBoxDirty_ = false;
  243. }
  244. return worldBoundingBox_;
  245. }
  246. bool Drawable::IsInView() const
  247. {
  248. // Note: in headless mode there is no renderer subsystem and no view frustum tests are performed, so return
  249. // always false in that case
  250. Renderer* renderer = GetSubsystem<Renderer>();
  251. return renderer && viewFrameNumber_ == renderer->GetFrameInfo().frameNumber_ && !viewCameras_.Empty();
  252. }
  253. bool Drawable::IsInView(Camera* camera) const
  254. {
  255. Renderer* renderer = GetSubsystem<Renderer>();
  256. return renderer && viewFrameNumber_ == renderer->GetFrameInfo().frameNumber_ && (!camera || viewCameras_.Contains(camera));
  257. }
  258. bool Drawable::IsInView(const FrameInfo& frame, bool anyCamera) const
  259. {
  260. return viewFrameNumber_ == frame.frameNumber_ && (anyCamera || viewCameras_.Contains(frame.camera_));
  261. }
  262. void Drawable::SetZone(Zone* zone, bool temporary)
  263. {
  264. zone_ = zone;
  265. // If the zone assignment was temporary (inconclusive) set the dirty flag so that it will be re-evaluated on the next frame
  266. zoneDirty_ = temporary;
  267. }
  268. void Drawable::SetSortValue(float value)
  269. {
  270. sortValue_ = value;
  271. }
  272. void Drawable::MarkInView(const FrameInfo& frame)
  273. {
  274. if (frame.frameNumber_ != viewFrameNumber_)
  275. {
  276. viewFrameNumber_ = frame.frameNumber_;
  277. viewCameras_.Resize(1);
  278. viewCameras_[0] = frame.camera_;
  279. }
  280. else
  281. viewCameras_.Push(frame.camera_);
  282. basePassFlags_ = 0;
  283. firstLight_ = 0;
  284. lights_.Clear();
  285. vertexLights_.Clear();
  286. }
  287. void Drawable::MarkInView(unsigned frameNumber)
  288. {
  289. if (frameNumber != viewFrameNumber_)
  290. {
  291. viewFrameNumber_ = frameNumber;
  292. viewCameras_.Clear();
  293. }
  294. }
  295. void Drawable::LimitLights()
  296. {
  297. // Maximum lights value 0 means unlimited
  298. if (!maxLights_ || lights_.Size() <= maxLights_)
  299. return;
  300. // If more lights than allowed, move to vertex lights and cut the list
  301. const BoundingBox& box = GetWorldBoundingBox();
  302. for (unsigned i = 0; i < lights_.Size(); ++i)
  303. lights_[i]->SetIntensitySortValue(box);
  304. Sort(lights_.Begin(), lights_.End(), CompareDrawables);
  305. vertexLights_.Insert(vertexLights_.End(), lights_.Begin() + maxLights_, lights_.End());
  306. lights_.Resize(maxLights_);
  307. }
  308. void Drawable::LimitVertexLights(bool removeConvertedLights)
  309. {
  310. if (removeConvertedLights)
  311. {
  312. for (unsigned i = vertexLights_.Size() - 1; i < vertexLights_.Size(); --i)
  313. {
  314. if (!vertexLights_[i]->GetPerVertex())
  315. vertexLights_.Erase(i);
  316. }
  317. }
  318. if (vertexLights_.Size() <= MAX_VERTEX_LIGHTS)
  319. return;
  320. const BoundingBox& box = GetWorldBoundingBox();
  321. for (unsigned i = 0; i < vertexLights_.Size(); ++i)
  322. vertexLights_[i]->SetIntensitySortValue(box);
  323. Sort(vertexLights_.Begin(), vertexLights_.End(), CompareDrawables);
  324. vertexLights_.Resize(MAX_VERTEX_LIGHTS);
  325. }
  326. void Drawable::OnNodeSet(Node* node)
  327. {
  328. if (node)
  329. node->AddListener(this);
  330. }
  331. void Drawable::OnSceneSet(Scene* scene)
  332. {
  333. if (scene)
  334. AddToOctree();
  335. else
  336. RemoveFromOctree();
  337. }
  338. void Drawable::OnMarkedDirty(Node* node)
  339. {
  340. worldBoundingBoxDirty_ = true;
  341. if (!updateQueued_ && octant_)
  342. octant_->GetRoot()->QueueUpdate(this);
  343. // Mark zone assignment dirty when transform changes
  344. if (node == node_)
  345. zoneDirty_ = true;
  346. }
  347. void Drawable::AddToOctree()
  348. {
  349. // Do not add to octree when disabled
  350. if (!IsEnabledEffective())
  351. return;
  352. Scene* scene = GetScene();
  353. if (scene)
  354. {
  355. Octree* octree = scene->GetComponent<Octree>();
  356. if (octree)
  357. octree->InsertDrawable(this);
  358. else
  359. LOGERROR("No Octree component in scene, drawable will not render");
  360. }
  361. else
  362. {
  363. // We have a mechanism for adding detached nodes to an octree manually, so do not log this error
  364. //LOGERROR("Node is detached from scene, drawable will not render");
  365. }
  366. }
  367. void Drawable::RemoveFromOctree()
  368. {
  369. if (octant_)
  370. {
  371. Octree* octree = octant_->GetRoot();
  372. if (updateQueued_)
  373. octree->CancelUpdate(this);
  374. // Perform subclass specific deinitialization if necessary
  375. OnRemoveFromOctree();
  376. octant_->RemoveDrawable(this);
  377. }
  378. }
  379. bool WriteDrawablesToOBJ(PODVector<Drawable*> drawables, File* outputFile, bool writeLightmapUV)
  380. {
  381. // Must track indices independently to deal with potential mismatching of drawables vertex attributes (ie. one with UV, another without, then another with)
  382. // Using long because 65,535 isn't enough as OBJ indices do not reset the count with each new object
  383. unsigned long currentPositionIndex = 1;
  384. unsigned long currentUVIndex = 1;
  385. unsigned long currentNormalIndex = 1;
  386. bool anythingWritten = false;
  387. // Write the common "I came from X" comment
  388. outputFile->WriteLine("# OBJ file exported from Urho3D");
  389. for (unsigned i = 0; i < drawables.Size(); ++i)
  390. {
  391. Drawable* drawable = drawables[i];
  392. // Only write enabled drawables
  393. if (!drawable->IsEnabledEffective())
  394. continue;
  395. Node* node = drawable->GetNode();
  396. Matrix3x4 transMat = drawable->GetNode()->GetWorldTransform();
  397. const Vector<SourceBatch>& batches = drawable->GetBatches();
  398. for (unsigned geoIndex = 0; geoIndex < batches.Size(); ++geoIndex)
  399. {
  400. Geometry* geo = drawable->GetLodGeometry(geoIndex, 0);
  401. if (geo == 0)
  402. continue;
  403. if (geo->GetPrimitiveType() != TRIANGLE_LIST)
  404. {
  405. LOGERRORF("%s (%u) %s (%u) Geometry %u contains an unsupported geometry type %u", node->GetName().Length() > 0 ? node->GetName().CString() : "Node", node->GetID(), drawable->GetTypeName().CString(), drawable->GetID(), geoIndex, (unsigned)geo->GetPrimitiveType());
  406. continue;
  407. }
  408. // If we've reached here than we're going to actually write something to the OBJ file
  409. anythingWritten = true;
  410. const unsigned char* vertexData = 0x0;
  411. const unsigned char* indexData = 0x0;
  412. unsigned int elementSize = 0, indexSize = 0, elementMask = 0;
  413. geo->GetRawData(vertexData, elementSize, indexData, indexSize, elementMask);
  414. const bool hasNormals = (elementMask & MASK_NORMAL) != 0;
  415. const bool hasUV = (elementMask & MASK_TEXCOORD1) != 0;
  416. const bool hasLMUV = (elementMask & MASK_TEXCOORD2) != 0;
  417. if (elementSize > 0 && indexSize > 0)
  418. {
  419. const unsigned vertexStart = geo->GetVertexStart();
  420. const unsigned vertexCount = geo->GetVertexCount();
  421. const unsigned indexStart = geo->GetIndexStart();
  422. const unsigned indexCount = geo->GetIndexCount();
  423. // Name NodeID DrawableType DrawableID GeometryIndex ("Geo" is included for clarity as StaticModel_32_2 could easily be misinterpreted or even quickly misread as 322)
  424. // Generated object name example: Node_5_StaticModel_32_Geo_0 ... or ... Bob_5_StaticModel_32_Geo_0
  425. outputFile->WriteLine(String("o ").AppendWithFormat("%s_%u_%s_%u_Geo_%u", node->GetName().Length() > 0 ? node->GetName().CString() : "Node", node->GetID(), drawable->GetTypeName().CString(), drawable->GetID(), geoIndex));
  426. // Write vertex position
  427. const unsigned positionOffset = VertexBuffer::GetElementOffset(elementMask, ELEMENT_POSITION);
  428. for (unsigned j = 0; j < vertexCount; ++j)
  429. {
  430. Vector3 vertexPosition = *((const Vector3*)(&vertexData[(vertexStart + j) * elementSize + positionOffset]));
  431. vertexPosition = transMat * vertexPosition;
  432. outputFile->WriteLine("v " + String(vertexPosition));
  433. }
  434. if (hasNormals)
  435. {
  436. const unsigned normalOffset = VertexBuffer::GetElementOffset(elementMask, ELEMENT_NORMAL);
  437. for (unsigned j = 0; j < vertexCount; ++j)
  438. {
  439. Vector3 vertexNormal = *((const Vector3*)(&vertexData[(vertexStart + j) * elementSize + positionOffset]));
  440. vertexNormal = transMat * vertexNormal;
  441. vertexNormal.Normalize();
  442. outputFile->WriteLine("vn " + String(vertexNormal));
  443. }
  444. }
  445. // Write TEXCOORD1 or TEXCOORD2 if it was chosen
  446. if (hasUV || (hasLMUV && writeLightmapUV))
  447. {
  448. // if writing Lightmap UV is chosen, only use it if TEXCOORD2 exists, otherwise use TEXCOORD1
  449. const unsigned texCoordOffset = (writeLightmapUV && hasLMUV) ? VertexBuffer::GetElementOffset(elementMask, ELEMENT_TEXCOORD2) : VertexBuffer::GetElementOffset(elementMask, ELEMENT_TEXCOORD1);
  450. for (unsigned j = 0; j < vertexCount; ++j)
  451. {
  452. Vector2 uvCoords = *((const Vector2*)(&vertexData[(vertexStart + j) * elementSize + texCoordOffset]));
  453. outputFile->WriteLine("vt " + String(uvCoords));
  454. }
  455. }
  456. // Build obj indices for a triangle list
  457. if (geo->GetPrimitiveType() == TRIANGLE_LIST)
  458. {
  459. // If we don't have UV but have normals then must write a double-slash to indicate the absence of UV coords, otherwise use a single slash
  460. const String slashCharacter = hasNormals ? "//" : "/";
  461. for (unsigned indexIdx = indexStart; indexIdx < indexCount * indexSize; indexIdx += indexSize * 3)
  462. {
  463. // Deal with 16 or 32 bit indices, converting to long
  464. unsigned long longIndices[3];
  465. if (indexSize == 2)
  466. {
  467. //16 bit indices
  468. unsigned short indices[3];
  469. memcpy(indices, indexData + indexIdx, indexSize * 3);
  470. longIndices[0] = indices[0];
  471. longIndices[1] = indices[1];
  472. longIndices[2] = indices[2];
  473. }
  474. else
  475. {
  476. //32 bit indices
  477. unsigned indices[3];
  478. memcpy(indices, indexData + indexIdx, indexSize * 3);
  479. longIndices[0] = indices[0];
  480. longIndices[1] = indices[1];
  481. longIndices[2] = indices[2];
  482. }
  483. String output = "f ";
  484. if (hasNormals)
  485. {
  486. output.AppendWithFormat("%l/%l/%l %l/%l/%l %l/%l/%l",
  487. currentPositionIndex + longIndices[0],
  488. currentUVIndex + longIndices[0],
  489. currentNormalIndex + longIndices[0],
  490. currentPositionIndex + longIndices[1],
  491. currentUVIndex + longIndices[1],
  492. currentNormalIndex + longIndices[1],
  493. currentPositionIndex + longIndices[2],
  494. currentUVIndex + longIndices[2],
  495. currentNormalIndex + longIndices[2]);
  496. }
  497. else if (hasNormals || hasUV)
  498. {
  499. const unsigned secondTraitIndex = hasNormals ? currentNormalIndex : currentUVIndex;
  500. output.AppendWithFormat("%l%s%l %l%s%l %l%s%l",
  501. currentPositionIndex + longIndices[0],
  502. slashCharacter.CString(),
  503. secondTraitIndex + longIndices[0],
  504. currentPositionIndex + longIndices[1],
  505. slashCharacter.CString(),
  506. secondTraitIndex + longIndices[1],
  507. currentPositionIndex + longIndices[2],
  508. slashCharacter.CString(),
  509. secondTraitIndex + longIndices[2]);
  510. }
  511. else
  512. {
  513. output.AppendWithFormat("%l %l %l",
  514. currentPositionIndex + longIndices[0],
  515. currentPositionIndex + longIndices[1],
  516. currentPositionIndex + longIndices[2]);
  517. }
  518. outputFile->WriteLine(output);
  519. }
  520. }
  521. // Increment our positions based on what vertex attributes we have
  522. currentPositionIndex += vertexCount;
  523. currentNormalIndex += hasNormals ? vertexCount : 0;
  524. // is it possible to have TEXCOORD2 but not have TEXCOORD1, assume anything
  525. currentUVIndex += (hasUV || hasLMUV) ? vertexCount : 0;
  526. }
  527. }
  528. }
  529. return anythingWritten;
  530. }
  531. }