Drawable.cpp 21 KB

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