3DS Export: Add support for aiShadingMode_PBR_BRDF
Export as Phong. If no Diffuse texture, export the PBR base color instead,pull/4159/head
parent
2b4b3e820b
commit
ee19ce6021
|
@ -330,6 +330,7 @@ void Discreet3DSExporter::WriteMaterials() {
|
||||||
case aiShadingMode_Blinn:
|
case aiShadingMode_Blinn:
|
||||||
case aiShadingMode_CookTorrance:
|
case aiShadingMode_CookTorrance:
|
||||||
case aiShadingMode_Fresnel:
|
case aiShadingMode_Fresnel:
|
||||||
|
case aiShadingMode_PBR_BRDF: // Possibly should be Discreet3DS::Metal in some cases but this is undocumented
|
||||||
shading_mode_out = Discreet3DS::Phong;
|
shading_mode_out = Discreet3DS::Phong;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -356,7 +357,10 @@ void Discreet3DSExporter::WriteMaterials() {
|
||||||
writer.PutI2(1);
|
writer.PutI2(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteTexture(mat, aiTextureType_DIFFUSE, Discreet3DS::CHUNK_MAT_TEXTURE);
|
// Fallback to BASE_COLOR if no DIFFUSE
|
||||||
|
if (!WriteTexture(mat, aiTextureType_DIFFUSE, Discreet3DS::CHUNK_MAT_TEXTURE))
|
||||||
|
WriteTexture(mat, aiTextureType_BASE_COLOR, Discreet3DS::CHUNK_MAT_TEXTURE);
|
||||||
|
|
||||||
WriteTexture(mat, aiTextureType_HEIGHT, Discreet3DS::CHUNK_MAT_BUMPMAP);
|
WriteTexture(mat, aiTextureType_HEIGHT, Discreet3DS::CHUNK_MAT_BUMPMAP);
|
||||||
WriteTexture(mat, aiTextureType_OPACITY, Discreet3DS::CHUNK_MAT_OPACMAP);
|
WriteTexture(mat, aiTextureType_OPACITY, Discreet3DS::CHUNK_MAT_OPACMAP);
|
||||||
WriteTexture(mat, aiTextureType_SHININESS, Discreet3DS::CHUNK_MAT_MAT_SHINMAP);
|
WriteTexture(mat, aiTextureType_SHININESS, Discreet3DS::CHUNK_MAT_MAT_SHINMAP);
|
||||||
|
@ -367,20 +371,21 @@ void Discreet3DSExporter::WriteMaterials() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Discreet3DSExporter::WriteTexture(const aiMaterial &mat, aiTextureType type, uint16_t chunk_flags) {
|
// returns true if the texture existed
|
||||||
|
bool Discreet3DSExporter::WriteTexture(const aiMaterial &mat, aiTextureType type, uint16_t chunk_flags) {
|
||||||
aiString path;
|
aiString path;
|
||||||
aiTextureMapMode map_mode[2] = {
|
aiTextureMapMode map_mode[2] = {
|
||||||
aiTextureMapMode_Wrap, aiTextureMapMode_Wrap
|
aiTextureMapMode_Wrap, aiTextureMapMode_Wrap
|
||||||
};
|
};
|
||||||
ai_real blend = 1.0;
|
ai_real blend = 1.0;
|
||||||
if (mat.GetTexture(type, 0, &path, nullptr, nullptr, &blend, nullptr, map_mode) != AI_SUCCESS || !path.length) {
|
if (mat.GetTexture(type, 0, &path, nullptr, nullptr, &blend, nullptr, map_mode) != AI_SUCCESS || !path.length) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle embedded textures properly
|
// TODO: handle embedded textures properly
|
||||||
if (path.data[0] == '*') {
|
if (path.data[0] == '*') {
|
||||||
ASSIMP_LOG_ERROR("Ignoring embedded texture for export: ", path.C_Str());
|
ASSIMP_LOG_ERROR("Ignoring embedded texture for export: ", path.C_Str());
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunkWriter chunk(writer, chunk_flags);
|
ChunkWriter chunk(writer, chunk_flags);
|
||||||
|
@ -402,6 +407,7 @@ void Discreet3DSExporter::WriteTexture(const aiMaterial &mat, aiTextureType type
|
||||||
writer.PutU2(val);
|
writer.PutU2(val);
|
||||||
}
|
}
|
||||||
// TODO: export texture transformation (i.e. UV offset, scale, rotation)
|
// TODO: export texture transformation (i.e. UV offset, scale, rotation)
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void WriteMeshes();
|
void WriteMeshes();
|
||||||
void WriteMaterials();
|
void WriteMaterials();
|
||||||
void WriteTexture(const aiMaterial& mat, aiTextureType type, uint16_t chunk_flags);
|
bool WriteTexture(const aiMaterial& mat, aiTextureType type, uint16_t chunk_flags);
|
||||||
void WriteFaceMaterialChunk(const aiMesh& mesh);
|
void WriteFaceMaterialChunk(const aiMesh& mesh);
|
||||||
int WriteHierarchy(const aiNode& node, int level, int sibling_level);
|
int WriteHierarchy(const aiNode& node, int level, int sibling_level);
|
||||||
void WriteString(const std::string& s);
|
void WriteString(const std::string& s);
|
||||||
|
|
Loading…
Reference in New Issue