3DSExporter.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2019, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #ifndef ASSIMP_BUILD_NO_EXPORT
  34. #ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
  35. #include "3DSExporter.h"
  36. #include "3DSLoader.h"
  37. #include "3DSHelper.h"
  38. #include <assimp/SceneCombiner.h>
  39. #include "SplitLargeMeshes.h"
  40. #include <assimp/StringComparison.h>
  41. #include <assimp/IOSystem.hpp>
  42. #include <assimp/DefaultLogger.hpp>
  43. #include <assimp/Exporter.hpp>
  44. #include <memory>
  45. using namespace Assimp;
  46. namespace Assimp {
  47. using namespace D3DS;
  48. namespace {
  49. //////////////////////////////////////////////////////////////////////////////////////
  50. // Scope utility to write a 3DS file chunk.
  51. //
  52. // Upon construction, the chunk header is written with the chunk type (flags)
  53. // filled out, but the chunk size left empty. Upon destruction, the correct chunk
  54. // size based on the then-position of the output stream cursor is filled in.
  55. class ChunkWriter {
  56. enum {
  57. CHUNK_SIZE_NOT_SET = 0xdeadbeef
  58. , SIZE_OFFSET = 2
  59. };
  60. public:
  61. ChunkWriter(StreamWriterLE& writer, uint16_t chunk_type)
  62. : writer(writer)
  63. {
  64. chunk_start_pos = writer.GetCurrentPos();
  65. writer.PutU2(chunk_type);
  66. writer.PutU4(CHUNK_SIZE_NOT_SET);
  67. }
  68. ~ChunkWriter() {
  69. std::size_t head_pos = writer.GetCurrentPos();
  70. ai_assert(head_pos > chunk_start_pos);
  71. const std::size_t chunk_size = head_pos - chunk_start_pos;
  72. writer.SetCurrentPos(chunk_start_pos + SIZE_OFFSET);
  73. writer.PutU4(static_cast<uint32_t>(chunk_size));
  74. writer.SetCurrentPos(head_pos);
  75. }
  76. private:
  77. StreamWriterLE& writer;
  78. std::size_t chunk_start_pos;
  79. };
  80. // Return an unique name for a given |mesh| attached to |node| that
  81. // preserves the mesh's given name if it has one. |index| is the index
  82. // of the mesh in |aiScene::mMeshes|.
  83. std::string GetMeshName(const aiMesh& mesh, unsigned int index, const aiNode& node) {
  84. static const std::string underscore = "_";
  85. char postfix[10] = {0};
  86. ASSIMP_itoa10(postfix, index);
  87. std::string result = node.mName.C_Str();
  88. if (mesh.mName.length > 0) {
  89. result += underscore + mesh.mName.C_Str();
  90. }
  91. return result + underscore + postfix;
  92. }
  93. // Return an unique name for a given |mat| with original position |index|
  94. // in |aiScene::mMaterials|. The name preserves the original material
  95. // name if possible.
  96. std::string GetMaterialName(const aiMaterial& mat, unsigned int index) {
  97. static const std::string underscore = "_";
  98. char postfix[10] = {0};
  99. ASSIMP_itoa10(postfix, index);
  100. aiString mat_name;
  101. if (AI_SUCCESS == mat.Get(AI_MATKEY_NAME, mat_name)) {
  102. return mat_name.C_Str() + underscore + postfix;
  103. }
  104. return "Material" + underscore + postfix;
  105. }
  106. // Collect world transformations for each node
  107. void CollectTrafos(const aiNode* node, std::map<const aiNode*, aiMatrix4x4>& trafos) {
  108. const aiMatrix4x4& parent = node->mParent ? trafos[node->mParent] : aiMatrix4x4();
  109. trafos[node] = parent * node->mTransformation;
  110. for (unsigned int i = 0; i < node->mNumChildren; ++i) {
  111. CollectTrafos(node->mChildren[i], trafos);
  112. }
  113. }
  114. // Generate a flat list of the meshes (by index) assigned to each node
  115. void CollectMeshes(const aiNode* node, std::multimap<const aiNode*, unsigned int>& meshes) {
  116. for (unsigned int i = 0; i < node->mNumMeshes; ++i) {
  117. meshes.insert(std::make_pair(node, node->mMeshes[i]));
  118. }
  119. for (unsigned int i = 0; i < node->mNumChildren; ++i) {
  120. CollectMeshes(node->mChildren[i], meshes);
  121. }
  122. }
  123. }
  124. // ------------------------------------------------------------------------------------------------
  125. // Worker function for exporting a scene to 3DS. Prototyped and registered in Exporter.cpp
  126. void ExportScene3DS(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
  127. {
  128. std::shared_ptr<IOStream> outfile (pIOSystem->Open(pFile, "wb"));
  129. if(!outfile) {
  130. throw DeadlyExportError("Could not open output .3ds file: " + std::string(pFile));
  131. }
  132. // TODO: This extra copy should be avoided and all of this made a preprocess
  133. // requirement of the 3DS exporter.
  134. //
  135. // 3DS meshes can be max 0xffff (16 Bit) vertices and faces, respectively.
  136. // SplitLargeMeshes can do this, but it requires the correct limit to be set
  137. // which is not possible with the current way of specifying preprocess steps
  138. // in |Exporter::ExportFormatEntry|.
  139. aiScene* scenecopy_tmp;
  140. SceneCombiner::CopyScene(&scenecopy_tmp,pScene);
  141. std::unique_ptr<aiScene> scenecopy(scenecopy_tmp);
  142. SplitLargeMeshesProcess_Triangle tri_splitter;
  143. tri_splitter.SetLimit(0xffff);
  144. tri_splitter.Execute(scenecopy.get());
  145. SplitLargeMeshesProcess_Vertex vert_splitter;
  146. vert_splitter.SetLimit(0xffff);
  147. vert_splitter.Execute(scenecopy.get());
  148. // Invoke the actual exporter
  149. Discreet3DSExporter exporter(outfile, scenecopy.get());
  150. }
  151. } // end of namespace Assimp
  152. // ------------------------------------------------------------------------------------------------
  153. Discreet3DSExporter:: Discreet3DSExporter(std::shared_ptr<IOStream> &outfile, const aiScene* scene)
  154. : scene(scene)
  155. , writer(outfile)
  156. {
  157. CollectTrafos(scene->mRootNode, trafos);
  158. CollectMeshes(scene->mRootNode, meshes);
  159. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAIN);
  160. {
  161. ChunkWriter chunk(writer, Discreet3DS::CHUNK_OBJMESH);
  162. WriteMaterials();
  163. WriteMeshes();
  164. {
  165. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MASTER_SCALE);
  166. writer.PutF4(1.0f);
  167. }
  168. }
  169. {
  170. ChunkWriter chunk(writer, Discreet3DS::CHUNK_KEYFRAMER);
  171. WriteHierarchy(*scene->mRootNode, -1, -1);
  172. }
  173. }
  174. // ------------------------------------------------------------------------------------------------
  175. Discreet3DSExporter::~Discreet3DSExporter() {
  176. // empty
  177. }
  178. // ------------------------------------------------------------------------------------------------
  179. int Discreet3DSExporter::WriteHierarchy(const aiNode& node, int seq, int sibling_level)
  180. {
  181. // 3DS scene hierarchy is serialized as in http://www.martinreddy.net/gfx/3d/3DS.spec
  182. {
  183. ChunkWriter chunk(writer, Discreet3DS::CHUNK_TRACKINFO);
  184. {
  185. ChunkWriter chunk(writer, Discreet3DS::CHUNK_TRACKOBJNAME);
  186. // Assimp node names are unique and distinct from all mesh-node
  187. // names we generate; thus we can use them as-is
  188. WriteString(node.mName);
  189. // Two unknown int16 values - it is even unclear if 0 is a safe value
  190. // but luckily importers do not know better either.
  191. writer.PutI4(0);
  192. int16_t hierarchy_pos = static_cast<int16_t>(seq);
  193. if (sibling_level != -1) {
  194. hierarchy_pos = sibling_level;
  195. }
  196. // Write the hierarchy position
  197. writer.PutI2(hierarchy_pos);
  198. }
  199. }
  200. // TODO: write transformation chunks
  201. ++seq;
  202. sibling_level = seq;
  203. // Write all children
  204. for (unsigned int i = 0; i < node.mNumChildren; ++i) {
  205. seq = WriteHierarchy(*node.mChildren[i], seq, i == 0 ? -1 : sibling_level);
  206. }
  207. // Write all meshes as separate nodes to be able to reference the meshes by name
  208. for (unsigned int i = 0; i < node.mNumMeshes; ++i) {
  209. const bool first_child = node.mNumChildren == 0 && i == 0;
  210. const unsigned int mesh_idx = node.mMeshes[i];
  211. const aiMesh& mesh = *scene->mMeshes[mesh_idx];
  212. ChunkWriter chunk(writer, Discreet3DS::CHUNK_TRACKINFO);
  213. {
  214. ChunkWriter chunk(writer, Discreet3DS::CHUNK_TRACKOBJNAME);
  215. WriteString(GetMeshName(mesh, mesh_idx, node));
  216. writer.PutI4(0);
  217. writer.PutI2(static_cast<int16_t>(first_child ? seq : sibling_level));
  218. ++seq;
  219. }
  220. }
  221. return seq;
  222. }
  223. // ------------------------------------------------------------------------------------------------
  224. void Discreet3DSExporter::WriteMaterials()
  225. {
  226. for (unsigned int i = 0; i < scene->mNumMaterials; ++i) {
  227. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_MATERIAL);
  228. const aiMaterial& mat = *scene->mMaterials[i];
  229. {
  230. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_MATNAME);
  231. const std::string& name = GetMaterialName(mat, i);
  232. WriteString(name);
  233. }
  234. aiColor3D color;
  235. if (mat.Get(AI_MATKEY_COLOR_DIFFUSE, color) == AI_SUCCESS) {
  236. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_DIFFUSE);
  237. WriteColor(color);
  238. }
  239. if (mat.Get(AI_MATKEY_COLOR_SPECULAR, color) == AI_SUCCESS) {
  240. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_SPECULAR);
  241. WriteColor(color);
  242. }
  243. if (mat.Get(AI_MATKEY_COLOR_AMBIENT, color) == AI_SUCCESS) {
  244. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_AMBIENT);
  245. WriteColor(color);
  246. }
  247. if (mat.Get(AI_MATKEY_COLOR_EMISSIVE, color) == AI_SUCCESS) {
  248. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_SELF_ILLUM);
  249. WriteColor(color);
  250. }
  251. aiShadingMode shading_mode = aiShadingMode_Flat;
  252. if (mat.Get(AI_MATKEY_SHADING_MODEL, shading_mode) == AI_SUCCESS) {
  253. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_SHADING);
  254. Discreet3DS::shadetype3ds shading_mode_out;
  255. switch(shading_mode) {
  256. case aiShadingMode_Flat:
  257. case aiShadingMode_NoShading:
  258. shading_mode_out = Discreet3DS::Flat;
  259. break;
  260. case aiShadingMode_Gouraud:
  261. case aiShadingMode_Toon:
  262. case aiShadingMode_OrenNayar:
  263. case aiShadingMode_Minnaert:
  264. shading_mode_out = Discreet3DS::Gouraud;
  265. break;
  266. case aiShadingMode_Phong:
  267. case aiShadingMode_Blinn:
  268. case aiShadingMode_CookTorrance:
  269. case aiShadingMode_Fresnel:
  270. shading_mode_out = Discreet3DS::Phong;
  271. break;
  272. default:
  273. shading_mode_out = Discreet3DS::Flat;
  274. ai_assert(false);
  275. };
  276. writer.PutU2(static_cast<uint16_t>(shading_mode_out));
  277. }
  278. float f;
  279. if (mat.Get(AI_MATKEY_SHININESS, f) == AI_SUCCESS) {
  280. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_SHININESS);
  281. WritePercentChunk(f);
  282. }
  283. if (mat.Get(AI_MATKEY_SHININESS_STRENGTH, f) == AI_SUCCESS) {
  284. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_SHININESS_PERCENT);
  285. WritePercentChunk(f);
  286. }
  287. int twosided;
  288. if (mat.Get(AI_MATKEY_TWOSIDED, twosided) == AI_SUCCESS && twosided != 0) {
  289. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_TWO_SIDE);
  290. writer.PutI2(1);
  291. }
  292. WriteTexture(mat, aiTextureType_DIFFUSE, Discreet3DS::CHUNK_MAT_TEXTURE);
  293. WriteTexture(mat, aiTextureType_HEIGHT, Discreet3DS::CHUNK_MAT_BUMPMAP);
  294. WriteTexture(mat, aiTextureType_OPACITY, Discreet3DS::CHUNK_MAT_OPACMAP);
  295. WriteTexture(mat, aiTextureType_SHININESS, Discreet3DS::CHUNK_MAT_MAT_SHINMAP);
  296. WriteTexture(mat, aiTextureType_SPECULAR, Discreet3DS::CHUNK_MAT_SPECMAP);
  297. WriteTexture(mat, aiTextureType_EMISSIVE, Discreet3DS::CHUNK_MAT_SELFIMAP);
  298. WriteTexture(mat, aiTextureType_REFLECTION, Discreet3DS::CHUNK_MAT_REFLMAP);
  299. }
  300. }
  301. // ------------------------------------------------------------------------------------------------
  302. void Discreet3DSExporter::WriteTexture(const aiMaterial& mat, aiTextureType type, uint16_t chunk_flags)
  303. {
  304. aiString path;
  305. aiTextureMapMode map_mode[2] = {
  306. aiTextureMapMode_Wrap, aiTextureMapMode_Wrap
  307. };
  308. ai_real blend = 1.0;
  309. if (mat.GetTexture(type, 0, &path, NULL, NULL, &blend, NULL, map_mode) != AI_SUCCESS || !path.length) {
  310. return;
  311. }
  312. // TODO: handle embedded textures properly
  313. if (path.data[0] == '*') {
  314. ASSIMP_LOG_ERROR("Ignoring embedded texture for export: " + std::string(path.C_Str()));
  315. return;
  316. }
  317. ChunkWriter chunk(writer, chunk_flags);
  318. {
  319. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAPFILE);
  320. WriteString(path);
  321. }
  322. WritePercentChunk(blend);
  323. {
  324. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_MAP_TILING);
  325. uint16_t val = 0; // WRAP
  326. if (map_mode[0] == aiTextureMapMode_Mirror) {
  327. val = 0x2;
  328. }
  329. else if (map_mode[0] == aiTextureMapMode_Decal) {
  330. val = 0x10;
  331. }
  332. writer.PutU2(val);
  333. }
  334. // TODO: export texture transformation (i.e. UV offset, scale, rotation)
  335. }
  336. // ------------------------------------------------------------------------------------------------
  337. void Discreet3DSExporter::WriteMeshes()
  338. {
  339. // NOTE: 3DS allows for instances. However:
  340. // i) not all importers support reading them
  341. // ii) instances are not as flexible as they are in assimp, in particular,
  342. // nodes can carry (and instance) only one mesh.
  343. //
  344. // This exporter currently deep clones all instanced meshes, i.e. for each mesh
  345. // attached to a node a full TRIMESH chunk is written to the file.
  346. //
  347. // Furthermore, the TRIMESH is transformed into world space so that it will
  348. // appear correctly if importers don't read the scene hierarchy at all.
  349. for (MeshesByNodeMap::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
  350. const aiNode& node = *(*it).first;
  351. const unsigned int mesh_idx = (*it).second;
  352. const aiMesh& mesh = *scene->mMeshes[mesh_idx];
  353. // This should not happen if the SLM step is correctly executed
  354. // before the scene is handed to the exporter
  355. ai_assert(mesh.mNumVertices <= 0xffff);
  356. ai_assert(mesh.mNumFaces <= 0xffff);
  357. const aiMatrix4x4& trafo = trafos[&node];
  358. ChunkWriter chunk(writer, Discreet3DS::CHUNK_OBJBLOCK);
  359. // Mesh name is tied to the node it is attached to so it can later be referenced
  360. const std::string& name = GetMeshName(mesh, mesh_idx, node);
  361. WriteString(name);
  362. // TRIMESH chunk
  363. ChunkWriter chunk2(writer, Discreet3DS::CHUNK_TRIMESH);
  364. // Vertices in world space
  365. {
  366. ChunkWriter chunk(writer, Discreet3DS::CHUNK_VERTLIST);
  367. const uint16_t count = static_cast<uint16_t>(mesh.mNumVertices);
  368. writer.PutU2(count);
  369. for (unsigned int i = 0; i < mesh.mNumVertices; ++i) {
  370. const aiVector3D& v = trafo * mesh.mVertices[i];
  371. writer.PutF4(v.x);
  372. writer.PutF4(v.y);
  373. writer.PutF4(v.z);
  374. }
  375. }
  376. // UV coordinates
  377. if (mesh.HasTextureCoords(0)) {
  378. ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAPLIST);
  379. const uint16_t count = static_cast<uint16_t>(mesh.mNumVertices);
  380. writer.PutU2(count);
  381. for (unsigned int i = 0; i < mesh.mNumVertices; ++i) {
  382. const aiVector3D& v = mesh.mTextureCoords[0][i];
  383. writer.PutF4(v.x);
  384. writer.PutF4(v.y);
  385. }
  386. }
  387. // Faces (indices)
  388. {
  389. ChunkWriter chunk(writer, Discreet3DS::CHUNK_FACELIST);
  390. ai_assert(mesh.mNumFaces <= 0xffff);
  391. // Count triangles, discard lines and points
  392. uint16_t count = 0;
  393. for (unsigned int i = 0; i < mesh.mNumFaces; ++i) {
  394. const aiFace& f = mesh.mFaces[i];
  395. if (f.mNumIndices < 3) {
  396. continue;
  397. }
  398. // TRIANGULATE step is a pre-requisite so we should not see polys here
  399. ai_assert(f.mNumIndices == 3);
  400. ++count;
  401. }
  402. writer.PutU2(count);
  403. for (unsigned int i = 0; i < mesh.mNumFaces; ++i) {
  404. const aiFace& f = mesh.mFaces[i];
  405. if (f.mNumIndices < 3) {
  406. continue;
  407. }
  408. for (unsigned int j = 0; j < 3; ++j) {
  409. ai_assert(f.mIndices[j] <= 0xffff);
  410. writer.PutI2(static_cast<uint16_t>(f.mIndices[j]));
  411. }
  412. // Edge visibility flag
  413. writer.PutI2(0x0);
  414. }
  415. // TODO: write smoothing groups (CHUNK_SMOOLIST)
  416. WriteFaceMaterialChunk(mesh);
  417. }
  418. // Transformation matrix by which the mesh vertices have been pre-transformed with.
  419. {
  420. ChunkWriter chunk(writer, Discreet3DS::CHUNK_TRMATRIX);
  421. for (unsigned int r = 0; r < 4; ++r) {
  422. for (unsigned int c = 0; c < 3; ++c) {
  423. writer.PutF4(trafo[r][c]);
  424. }
  425. }
  426. }
  427. }
  428. }
  429. // ------------------------------------------------------------------------------------------------
  430. void Discreet3DSExporter::WriteFaceMaterialChunk(const aiMesh& mesh)
  431. {
  432. ChunkWriter chunk(writer, Discreet3DS::CHUNK_FACEMAT);
  433. const std::string& name = GetMaterialName(*scene->mMaterials[mesh.mMaterialIndex], mesh.mMaterialIndex);
  434. WriteString(name);
  435. // Because assimp splits meshes by material, only a single
  436. // FACEMAT chunk needs to be written
  437. ai_assert(mesh.mNumFaces <= 0xffff);
  438. const uint16_t count = static_cast<uint16_t>(mesh.mNumFaces);
  439. writer.PutU2(count);
  440. for (unsigned int i = 0; i < mesh.mNumFaces; ++i) {
  441. writer.PutU2(static_cast<uint16_t>(i));
  442. }
  443. }
  444. // ------------------------------------------------------------------------------------------------
  445. void Discreet3DSExporter::WriteString(const std::string& s) {
  446. for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
  447. writer.PutI1(*it);
  448. }
  449. writer.PutI1('\0');
  450. }
  451. // ------------------------------------------------------------------------------------------------
  452. void Discreet3DSExporter::WriteString(const aiString& s) {
  453. for (std::size_t i = 0; i < s.length; ++i) {
  454. writer.PutI1(s.data[i]);
  455. }
  456. writer.PutI1('\0');
  457. }
  458. // ------------------------------------------------------------------------------------------------
  459. void Discreet3DSExporter::WriteColor(const aiColor3D& color) {
  460. ChunkWriter chunk(writer, Discreet3DS::CHUNK_RGBF);
  461. writer.PutF4(color.r);
  462. writer.PutF4(color.g);
  463. writer.PutF4(color.b);
  464. }
  465. // ------------------------------------------------------------------------------------------------
  466. void Discreet3DSExporter::WritePercentChunk(float f) {
  467. ChunkWriter chunk(writer, Discreet3DS::CHUNK_PERCENTF);
  468. writer.PutF4(f);
  469. }
  470. // ------------------------------------------------------------------------------------------------
  471. void Discreet3DSExporter::WritePercentChunk(double f) {
  472. ChunkWriter chunk(writer, Discreet3DS::CHUNK_PERCENTD);
  473. writer.PutF8(f);
  474. }
  475. #endif // ASSIMP_BUILD_NO_3DS_EXPORTER
  476. #endif // ASSIMP_BUILD_NO_EXPORT