2
0

Drawable.cpp 21 KB

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