Drawable.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. // Copyright (c) 2008-2023 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(mask32 mask)
  143. {
  144. viewMask_ = mask;
  145. MarkNetworkUpdate();
  146. }
  147. void Drawable::SetLightMask(mask32 mask)
  148. {
  149. lightMask_ = mask;
  150. MarkNetworkUpdate();
  151. }
  152. void Drawable::SetShadowMask(mask32 mask)
  153. {
  154. shadowMask_ = mask;
  155. MarkNetworkUpdate();
  156. }
  157. void Drawable::SetZoneMask(mask32 mask)
  158. {
  159. zoneMask_ = mask;
  160. // Mark dirty to reset cached zone
  161. OnMarkedDirty(node_);
  162. MarkNetworkUpdate();
  163. }
  164. void Drawable::SetMaxLights(i32 num)
  165. {
  166. assert(num >= 0);
  167. maxLights_ = num;
  168. MarkNetworkUpdate();
  169. }
  170. void Drawable::SetCastShadows(bool enable)
  171. {
  172. castShadows_ = enable;
  173. MarkNetworkUpdate();
  174. }
  175. void Drawable::SetOccluder(bool enable)
  176. {
  177. occluder_ = enable;
  178. MarkNetworkUpdate();
  179. }
  180. void Drawable::SetOccludee(bool enable)
  181. {
  182. if (enable != occludee_)
  183. {
  184. occludee_ = enable;
  185. // Reinsert to octree to make sure octant occlusion does not erroneously hide this drawable
  186. if (octant_ && !updateQueued_)
  187. octant_->GetRoot()->QueueUpdate(this);
  188. MarkNetworkUpdate();
  189. }
  190. }
  191. void Drawable::MarkForUpdate()
  192. {
  193. if (!updateQueued_ && octant_)
  194. octant_->GetRoot()->QueueUpdate(this);
  195. }
  196. const BoundingBox& Drawable::GetWorldBoundingBox()
  197. {
  198. if (worldBoundingBoxDirty_)
  199. {
  200. OnWorldBoundingBoxUpdate();
  201. worldBoundingBoxDirty_ = false;
  202. }
  203. return worldBoundingBox_;
  204. }
  205. bool Drawable::IsInView() const
  206. {
  207. // Note: in headless mode there is no renderer subsystem and no view frustum tests are performed, so return
  208. // always false in that case
  209. auto* renderer = GetSubsystem<Renderer>();
  210. return renderer && viewFrameNumber_ == renderer->GetFrameInfo().frameNumber_ && !viewCameras_.Empty();
  211. }
  212. bool Drawable::IsInView(Camera* camera) const
  213. {
  214. auto* renderer = GetSubsystem<Renderer>();
  215. return renderer && viewFrameNumber_ == renderer->GetFrameInfo().frameNumber_ && (!camera || viewCameras_.Contains(camera));
  216. }
  217. bool Drawable::IsInView(const FrameInfo& frame, bool anyCamera) const
  218. {
  219. return viewFrameNumber_ == frame.frameNumber_ && (anyCamera || viewCameras_.Contains(frame.camera_));
  220. }
  221. void Drawable::SetZone(Zone* zone, bool temporary)
  222. {
  223. zone_ = zone;
  224. // If the zone assignment was temporary (inconclusive) set the dirty flag so that it will be re-evaluated on the next frame
  225. zoneDirty_ = temporary;
  226. }
  227. void Drawable::SetSortValue(float value)
  228. {
  229. sortValue_ = value;
  230. }
  231. void Drawable::MarkInView(const FrameInfo& frame)
  232. {
  233. if (frame.frameNumber_ != viewFrameNumber_)
  234. {
  235. viewFrameNumber_ = frame.frameNumber_;
  236. viewCameras_.Resize(1);
  237. viewCameras_[0] = frame.camera_;
  238. }
  239. else
  240. viewCameras_.Push(frame.camera_);
  241. basePassFlags_ = 0;
  242. firstLight_ = nullptr;
  243. lights_.Clear();
  244. vertexLights_.Clear();
  245. }
  246. void Drawable::MarkInView(i32 frameNumber)
  247. {
  248. assert(frameNumber > 0);
  249. if (frameNumber != viewFrameNumber_)
  250. {
  251. viewFrameNumber_ = frameNumber;
  252. viewCameras_.Clear();
  253. }
  254. }
  255. void Drawable::LimitLights()
  256. {
  257. // Maximum lights value 0 means unlimited
  258. if (!maxLights_ || lights_.Size() <= maxLights_)
  259. return;
  260. // If more lights than allowed, move to vertex lights and cut the list
  261. const BoundingBox& box = GetWorldBoundingBox();
  262. for (unsigned i = 0; i < lights_.Size(); ++i)
  263. lights_[i]->SetIntensitySortValue(box);
  264. Sort(lights_.Begin(), lights_.End(), CompareDrawables);
  265. vertexLights_.Insert(vertexLights_.End(), lights_.Begin() + maxLights_, lights_.End());
  266. lights_.Resize(maxLights_);
  267. }
  268. void Drawable::LimitVertexLights(bool removeConvertedLights)
  269. {
  270. if (removeConvertedLights)
  271. {
  272. for (i32 i = vertexLights_.Size() - 1; i >= 0; --i)
  273. {
  274. if (!vertexLights_[i]->GetPerVertex())
  275. vertexLights_.Erase(i);
  276. }
  277. }
  278. if (vertexLights_.Size() <= MAX_VERTEX_LIGHTS)
  279. return;
  280. const BoundingBox& box = GetWorldBoundingBox();
  281. for (unsigned i = 0; i < vertexLights_.Size(); ++i)
  282. vertexLights_[i]->SetIntensitySortValue(box);
  283. Sort(vertexLights_.Begin(), vertexLights_.End(), CompareDrawables);
  284. vertexLights_.Resize(MAX_VERTEX_LIGHTS);
  285. }
  286. void Drawable::OnNodeSet(Node* node)
  287. {
  288. if (node)
  289. node->AddListener(this);
  290. }
  291. void Drawable::OnSceneSet(Scene* scene)
  292. {
  293. if (scene)
  294. AddToOctree();
  295. else
  296. RemoveFromOctree();
  297. }
  298. void Drawable::OnMarkedDirty(Node* node)
  299. {
  300. worldBoundingBoxDirty_ = true;
  301. if (!updateQueued_ && octant_)
  302. octant_->GetRoot()->QueueUpdate(this);
  303. // Mark zone assignment dirty when transform changes
  304. if (node == node_)
  305. zoneDirty_ = true;
  306. }
  307. void Drawable::AddToOctree()
  308. {
  309. // Do not add to octree when disabled
  310. if (!IsEnabledEffective())
  311. return;
  312. Scene* scene = GetScene();
  313. if (scene)
  314. {
  315. auto* octree = scene->GetComponent<Octree>();
  316. if (octree)
  317. octree->InsertDrawable(this);
  318. else
  319. URHO3D_LOGERROR("No Octree component in scene, drawable will not render");
  320. }
  321. else
  322. {
  323. // We have a mechanism for adding detached nodes to an octree manually, so do not log this error
  324. //URHO3D_LOGERROR("Node is detached from scene, drawable will not render");
  325. }
  326. }
  327. void Drawable::RemoveFromOctree()
  328. {
  329. if (octant_)
  330. {
  331. Octree* octree = octant_->GetRoot();
  332. if (updateQueued_)
  333. octree->CancelUpdate(this);
  334. // Perform subclass specific deinitialization if necessary
  335. OnRemoveFromOctree();
  336. octant_->RemoveDrawable(this);
  337. }
  338. }
  339. bool WriteDrawablesToOBJ(const Vector<Drawable*>& drawables, File* outputFile, bool asZUp, bool asRightHanded, bool writeLightmapUV)
  340. {
  341. // Must track indices independently to deal with potential mismatching of drawables vertex attributes (ie. one with UV, another without, then another with)
  342. unsigned currentPositionIndex = 1;
  343. unsigned currentUVIndex = 1;
  344. unsigned currentNormalIndex = 1;
  345. bool anythingWritten = false;
  346. // Write the common "I came from X" comment
  347. outputFile->WriteLine("# OBJ file exported from Urho3D");
  348. for (unsigned i = 0; i < drawables.Size(); ++i)
  349. {
  350. Drawable* drawable = drawables[i];
  351. // Only write enabled drawables
  352. if (!drawable->IsEnabledEffective())
  353. continue;
  354. Node* node = drawable->GetNode();
  355. Matrix3x4 transMat = drawable->GetNode()->GetWorldTransform();
  356. Matrix3x4 n = transMat.Inverse();
  357. Matrix3 normalMat = Matrix3(n.m00_, n.m01_, n.m02_, n.m10_, n.m11_, n.m12_, n.m20_, n.m21_, n.m22_);
  358. normalMat = normalMat.Transpose();
  359. const Vector<SourceBatch>& batches = drawable->GetBatches();
  360. for (unsigned geoIndex = 0; geoIndex < batches.Size(); ++geoIndex)
  361. {
  362. Geometry* geo = drawable->GetLodGeometry(geoIndex, 0);
  363. if (geo == nullptr)
  364. continue;
  365. if (geo->GetPrimitiveType() != TRIANGLE_LIST)
  366. {
  367. 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());
  368. continue;
  369. }
  370. // If we've reached here than we're going to actually write something to the OBJ file
  371. anythingWritten = true;
  372. const byte* vertexData;
  373. const byte* indexData;
  374. i32 elementSize, indexSize;
  375. const Vector<VertexElement>* elements;
  376. geo->GetRawData(vertexData, elementSize, indexData, indexSize, elements);
  377. if (!vertexData || !elements)
  378. continue;
  379. bool hasPosition = VertexBuffer::HasElement(*elements, TYPE_VECTOR3, SEM_POSITION);
  380. if (!hasPosition)
  381. {
  382. 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);
  383. continue;
  384. }
  385. bool hasNormals = VertexBuffer::HasElement(*elements, TYPE_VECTOR3, SEM_NORMAL);
  386. bool hasUV = VertexBuffer::HasElement(*elements, TYPE_VECTOR2, SEM_TEXCOORD, 0);
  387. bool hasLMUV = VertexBuffer::HasElement(*elements, TYPE_VECTOR2, SEM_TEXCOORD, 1);
  388. if (elementSize > 0 && indexSize > 0)
  389. {
  390. unsigned vertexStart = geo->GetVertexStart();
  391. unsigned vertexCount = geo->GetVertexCount();
  392. unsigned indexStart = geo->GetIndexStart();
  393. unsigned indexCount = geo->GetIndexCount();
  394. // Name NodeID DrawableType DrawableID GeometryIndex ("Geo" is included for clarity as StaticModel_32_2 could easily be misinterpreted or even quickly misread as 322)
  395. // Generated object name example: Node_5_StaticModel_32_Geo_0 ... or ... Bob_5_StaticModel_32_Geo_0
  396. 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));
  397. // Write vertex position
  398. unsigned positionOffset = VertexBuffer::GetElementOffset(*elements, TYPE_VECTOR3, SEM_POSITION);
  399. for (unsigned j = 0; j < vertexCount; ++j)
  400. {
  401. Vector3 vertexPosition = *((const Vector3*)(&vertexData[(vertexStart + j) * elementSize + positionOffset]));
  402. vertexPosition = transMat * vertexPosition;
  403. // Convert coordinates as requested
  404. if (asRightHanded)
  405. vertexPosition.x_ *= -1;
  406. if (asZUp)
  407. {
  408. float yVal = vertexPosition.y_;
  409. vertexPosition.y_ = vertexPosition.z_;
  410. vertexPosition.z_ = yVal;
  411. }
  412. outputFile->WriteLine("v " + String(vertexPosition));
  413. }
  414. if (hasNormals)
  415. {
  416. unsigned normalOffset = VertexBuffer::GetElementOffset(*elements, TYPE_VECTOR3, SEM_NORMAL);
  417. for (unsigned j = 0; j < vertexCount; ++j)
  418. {
  419. Vector3 vertexNormal = *((const Vector3*)(&vertexData[(vertexStart + j) * elementSize + normalOffset]));
  420. vertexNormal = normalMat * vertexNormal;
  421. vertexNormal.Normalize();
  422. if (asRightHanded)
  423. vertexNormal.x_ *= -1;
  424. if (asZUp)
  425. {
  426. float yVal = vertexNormal.y_;
  427. vertexNormal.y_ = vertexNormal.z_;
  428. vertexNormal.z_ = yVal;
  429. }
  430. outputFile->WriteLine("vn " + String(vertexNormal));
  431. }
  432. }
  433. // Write TEXCOORD1 or TEXCOORD2 if it was chosen
  434. if (hasUV || (hasLMUV && writeLightmapUV))
  435. {
  436. // if writing Lightmap UV is chosen, only use it if TEXCOORD2 exists, otherwise use TEXCOORD1
  437. unsigned texCoordOffset = (writeLightmapUV && hasLMUV) ? VertexBuffer::GetElementOffset(*elements, TYPE_VECTOR2, SEM_TEXCOORD, 1) :
  438. VertexBuffer::GetElementOffset(*elements, TYPE_VECTOR2, SEM_TEXCOORD, 0);
  439. for (unsigned j = 0; j < vertexCount; ++j)
  440. {
  441. Vector2 uvCoords = *((const Vector2*)(&vertexData[(vertexStart + j) * elementSize + texCoordOffset]));
  442. outputFile->WriteLine("vt " + String(uvCoords));
  443. }
  444. }
  445. // 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
  446. const String slashCharacter = hasNormals ? "//" : "/";
  447. // Amount by which to offset indices in the OBJ vs their values in the Urho3D geometry, basically the lowest index value
  448. // Compensates for the above vertex writing which doesn't write ALL vertices, just the used ones
  449. unsigned indexOffset = M_MAX_INT;
  450. for (unsigned indexIdx = indexStart; indexIdx < indexStart + indexCount; indexIdx++)
  451. {
  452. if (indexSize == 2)
  453. indexOffset = Min(indexOffset, (unsigned)*((unsigned short*)(indexData + indexIdx * indexSize)));
  454. else
  455. indexOffset = Min(indexOffset, *((unsigned*)(indexData + indexIdx * indexSize)));
  456. }
  457. for (unsigned indexIdx = indexStart; indexIdx < indexStart + indexCount; indexIdx += 3)
  458. {
  459. // Deal with 16 or 32 bit indices
  460. unsigned longIndices[3];
  461. if (indexSize == 2)
  462. {
  463. //16 bit indices
  464. unsigned short indices[3];
  465. memcpy(indices, indexData + (indexIdx * indexSize), (size_t)indexSize * 3);
  466. longIndices[0] = indices[0] - indexOffset;
  467. longIndices[1] = indices[1] - indexOffset;
  468. longIndices[2] = indices[2] - indexOffset;
  469. }
  470. else
  471. {
  472. //32 bit indices
  473. unsigned indices[3];
  474. memcpy(indices, indexData + (indexIdx * indexSize), (size_t)indexSize * 3);
  475. longIndices[0] = indices[0] - indexOffset;
  476. longIndices[1] = indices[1] - indexOffset;
  477. longIndices[2] = indices[2] - indexOffset;
  478. }
  479. String output = "f ";
  480. if (hasNormals)
  481. {
  482. output.AppendWithFormat("%u/%u/%u %u/%u/%u %u/%u/%u",
  483. currentPositionIndex + longIndices[0],
  484. currentUVIndex + longIndices[0],
  485. currentNormalIndex + longIndices[0],
  486. currentPositionIndex + longIndices[1],
  487. currentUVIndex + longIndices[1],
  488. currentNormalIndex + longIndices[1],
  489. currentPositionIndex + longIndices[2],
  490. currentUVIndex + longIndices[2],
  491. currentNormalIndex + longIndices[2]);
  492. }
  493. else if (hasNormals || hasUV)
  494. {
  495. unsigned secondTraitIndex = hasNormals ? currentNormalIndex : currentUVIndex;
  496. output.AppendWithFormat("%u%s%u %u%s%u %u%s%u",
  497. currentPositionIndex + longIndices[0],
  498. slashCharacter.CString(),
  499. secondTraitIndex + longIndices[0],
  500. currentPositionIndex + longIndices[1],
  501. slashCharacter.CString(),
  502. secondTraitIndex + longIndices[1],
  503. currentPositionIndex + longIndices[2],
  504. slashCharacter.CString(),
  505. secondTraitIndex + longIndices[2]);
  506. }
  507. else
  508. {
  509. output.AppendWithFormat("%u %u %u",
  510. currentPositionIndex + longIndices[0],
  511. currentPositionIndex + longIndices[1],
  512. currentPositionIndex + longIndices[2]);
  513. }
  514. outputFile->WriteLine(output);
  515. }
  516. // Increment our positions based on what vertex attributes we have
  517. currentPositionIndex += vertexCount;
  518. currentNormalIndex += hasNormals ? vertexCount : 0;
  519. // is it possible to have TEXCOORD2 but not have TEXCOORD1, assume anything
  520. currentUVIndex += (hasUV || hasLMUV) ? vertexCount : 0;
  521. }
  522. }
  523. }
  524. return anythingWritten;
  525. }
  526. }