diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 25a78114f..784c803b0 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -103,7 +103,7 @@ void ExportSceneFBX(const char*, IOSystem*, const aiScene*, const ExportProperti void ExportSceneFBXA(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportScene3MF( const char*, IOSystem*, const aiScene*, const ExportProperties* ); void ExportSceneM3D(const char*, IOSystem*, const aiScene*, const ExportProperties*); -void ExportSceneA3D(const char*, IOSystem*, const aiScene*, const ExportProperties*); +void ExportSceneM3DA(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportAssimp2Json(const char* , IOSystem*, const aiScene* , const Assimp::ExportProperties*); @@ -177,7 +177,7 @@ static void setupExporterArray(std::vector &exporte #ifndef ASSIMP_BUILD_NO_M3D_EXPORTER exporters.push_back(Exporter::ExportFormatEntry("m3d", "Model 3D (binary)", "m3d", &ExportSceneM3D, 0)); - exporters.push_back(Exporter::ExportFormatEntry("a3d", "Model 3D (ascii)", "m3d", &ExportSceneA3D, 0)); + exporters.push_back(Exporter::ExportFormatEntry("m3da", "Model 3D (ascii)", "a3d", &ExportSceneM3DA, 0)); #endif #ifndef ASSIMP_BUILD_NO_3MF_EXPORTER diff --git a/code/M3D/M3DExporter.cpp b/code/M3D/M3DExporter.cpp index 0e84f6d4f..1fe6e7f76 100644 --- a/code/M3D/M3DExporter.cpp +++ b/code/M3D/M3DExporter.cpp @@ -268,7 +268,7 @@ void ExportSceneM3D( // --------------------------------------------------------------------- // Worker function for exporting a scene to ASCII A3D. // Prototyped and registered in Exporter.cpp -void ExportSceneA3D( +void ExportSceneM3DA( const char *pFile, IOSystem *pIOSystem, const aiScene *pScene, diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index b14d68c27..72c5ec373 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -202,6 +202,7 @@ inline void SetMaterialTextureProperty(std::vector &embeddedTexIdxs, Asset } mat->AddProperty(&uri, AI_MATKEY_TEXTURE(texType, texSlot)); + mat->AddProperty(&prop.texCoord, 1, AI_MATKEY_GLTF_TEXTURE_TEXCOORD(texType, texSlot)); if (prop.textureTransformSupported) { aiUVTransform transform; diff --git a/test/models/glTF2/BoxTexcoords-glTF/boxTexcoords.bin b/test/models/glTF2/BoxTexcoords-glTF/boxTexcoords.bin new file mode 100644 index 000000000..ae6a3f0d1 Binary files /dev/null and b/test/models/glTF2/BoxTexcoords-glTF/boxTexcoords.bin differ diff --git a/test/models/glTF2/BoxTexcoords-glTF/boxTexcoords.gltf b/test/models/glTF2/BoxTexcoords-glTF/boxTexcoords.gltf new file mode 100644 index 000000000..382127a3a --- /dev/null +++ b/test/models/glTF2/BoxTexcoords-glTF/boxTexcoords.gltf @@ -0,0 +1,172 @@ +{ + "asset" : { + "generator" : "Khronos glTF Blender I/O v1.0.5", + "version" : "2.0" + }, + "scene" : 0, + "scenes" : [ + { + "name" : "Scene", + "nodes" : [ + 0, + 1, + 2 + ] + } + ], + "nodes" : [ + { + "mesh" : 0, + "name" : "Cube" + }, + { + "name" : "Light", + "rotation" : [ + 0.16907575726509094, + 0.7558803558349609, + -0.27217137813568115, + 0.570947527885437 + ], + "translation" : [ + 4.076245307922363, + 5.903861999511719, + -1.0054539442062378 + ] + }, + { + "name" : "Camera", + "rotation" : [ + 0.483536034822464, + 0.33687159419059753, + -0.20870360732078552, + 0.7804827094078064 + ], + "translation" : [ + 7.358891487121582, + 4.958309173583984, + 6.925790786743164 + ] + } + ], + "materials" : [ + { + "doubleSided" : true, + "name" : "Material", + "pbrMetallicRoughness" : { + "baseColorTexture" : { + "index" : 0, + "texCoord" : 0 + }, + "metallicFactor" : 0, + "metallicRoughnessTexture" : { + "index" : 0, + "texCoord" : 1 + } + } + } + ], + "meshes" : [ + { + "name" : "Cube", + "primitives" : [ + { + "attributes" : { + "POSITION" : 0, + "NORMAL" : 1, + "TEXCOORD_0" : 2, + "TEXCOORD_1" : 3 + }, + "indices" : 4, + "material" : 0 + } + ] + } + ], + "textures" : [ + { + "source" : 0 + } + ], + "images" : [ + { + "mimeType" : "image/png", + "name" : "Material Base Color", + "uri" : "texture.png" + } + ], + "accessors" : [ + { + "bufferView" : 0, + "componentType" : 5126, + "count" : 24, + "max" : [ + 1, + 1, + 1 + ], + "min" : [ + -1, + -1, + -1 + ], + "type" : "VEC3" + }, + { + "bufferView" : 1, + "componentType" : 5126, + "count" : 24, + "type" : "VEC3" + }, + { + "bufferView" : 2, + "componentType" : 5126, + "count" : 24, + "type" : "VEC2" + }, + { + "bufferView" : 3, + "componentType" : 5126, + "count" : 24, + "type" : "VEC2" + }, + { + "bufferView" : 4, + "componentType" : 5123, + "count" : 36, + "type" : "SCALAR" + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteLength" : 288, + "byteOffset" : 0 + }, + { + "buffer" : 0, + "byteLength" : 288, + "byteOffset" : 288 + }, + { + "buffer" : 0, + "byteLength" : 192, + "byteOffset" : 576 + }, + { + "buffer" : 0, + "byteLength" : 192, + "byteOffset" : 768 + }, + { + "buffer" : 0, + "byteLength" : 72, + "byteOffset" : 960 + } + ], + "buffers" : [ + { + "byteLength" : 1032, + "uri" : "boxTexcoords.bin" + } + ] +} diff --git a/test/models/glTF2/BoxTexcoords-glTF/texture.png b/test/models/glTF2/BoxTexcoords-glTF/texture.png new file mode 100644 index 000000000..2350eb845 Binary files /dev/null and b/test/models/glTF2/BoxTexcoords-glTF/texture.png differ diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 6443d740f..2073a0003 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -49,6 +49,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + using namespace Assimp; class utglTF2ImportExport : public AbstractImportExportBase { @@ -464,3 +466,30 @@ TEST_F(utglTF2ImportExport, sceneMetadata) { ASSERT_EQ(strcmp(generator.C_Str(), "COLLADA2GLTF"), 0); } } + +TEST_F(utglTF2ImportExport, texcoords) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTexcoords-glTF/boxTexcoords.gltf", + aiProcess_ValidateDataStructure); + ASSERT_NE(scene, nullptr); + + ASSERT_TRUE(scene->HasMaterials()); + const aiMaterial *material = scene->mMaterials[0]; + + aiString path; + aiTextureMapMode modes[2]; + EXPECT_EQ(aiReturn_SUCCESS, material->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, + nullptr, nullptr, modes)); + EXPECT_STREQ(path.C_Str(), "texture.png"); + + int uvIndex = -1; + EXPECT_EQ(aiGetMaterialInteger(material, AI_MATKEY_GLTF_TEXTURE_TEXCOORD(aiTextureType_DIFFUSE, 0), &uvIndex), aiReturn_SUCCESS); + EXPECT_EQ(uvIndex, 0); + + // Using manual macro expansion of AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE here. + // The following works with some but not all compilers: + // #define APPLY(X, Y) X(Y) + // ..., APPLY(AI_MATKEY_GLTF_TEXTURE_TEXCOORD, AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE), ... + EXPECT_EQ(aiGetMaterialInteger(material, AI_MATKEY_GLTF_TEXTURE_TEXCOORD(aiTextureType_UNKNOWN, 0), &uvIndex), aiReturn_SUCCESS); + EXPECT_EQ(uvIndex, 1); +}