浏览代码

Add support for texture file in PLY exports

The PLY format has an unofficial way to specify an associated texture, using the "comment TextureFile"  comment line. The PLY loader supports this, but the exporter does not. The change looks for a diffuse texture in the scene's materials, and if it finds one, it adds it to the exported mesh using "comment TextureFile".
JeffH-BMG 7 年之前
父节点
当前提交
5ea06e1bb6
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      code/PlyExporter.cpp

+ 11 - 0
code/PlyExporter.cpp

@@ -148,6 +148,17 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina
         << aiGetVersionMajor() << '.' << aiGetVersionMinor() << '.'
         << aiGetVersionRevision() << ")" << endl;
 
+    // Look through materials for a diffuse texture, and add it if found
+    for ( unsigned int i = 0; i < pScene->mNumMaterials; ++i )
+    {
+        const aiMaterial* const mat = pScene->mMaterials[i];
+        aiString s;
+        if ( AI_SUCCESS == mat->Get( AI_MATKEY_TEXTURE_DIFFUSE( 0 ), s ) )
+        {
+            mOutput << "comment TextureFile " << s.data << endl;
+        }
+    }
+
     // TODO: probably want to check here rather than just assume something
     //       definitely not good to always write float even if we might have double precision