Merge pull request #3158 from Hehongyuanlove/master

3MF fix
pull/3155/head^2
Kim Kulling 2020-04-17 19:19:21 +02:00 committed by GitHub
commit 6daecdcc5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 14 deletions

View File

@ -181,7 +181,7 @@ bool D3MFExporter::export3DModel() {
writeHeader(); writeHeader();
mModelOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\"" mModelOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\""
<< "xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">" << " xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">"
<< std::endl; << std::endl;
mModelOutput << "<" << XmlTag::resources << ">"; mModelOutput << "<" << XmlTag::resources << ">";
mModelOutput << std::endl; mModelOutput << std::endl;
@ -212,7 +212,7 @@ bool D3MFExporter::export3DModel() {
} }
void D3MFExporter::writeHeader() { void D3MFExporter::writeHeader() {
mModelOutput << "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>"; mModelOutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
mModelOutput << std::endl; mModelOutput << std::endl;
} }
@ -254,8 +254,19 @@ void D3MFExporter::writeBaseMaterials() {
if ( mat->Get( AI_MATKEY_COLOR_DIFFUSE, color ) == aiReturn_SUCCESS ) { if ( mat->Get( AI_MATKEY_COLOR_DIFFUSE, color ) == aiReturn_SUCCESS ) {
hexDiffuseColor.clear(); hexDiffuseColor.clear();
tmp.clear(); tmp.clear();
hexDiffuseColor = "#"; // rgbs %
if(color.r <= 1 && color.g <= 1 && color.b <= 1 && color.a <= 1){
hexDiffuseColor = Rgba2Hex(
(int)((ai_real)color.r)*255,
(int)((ai_real)color.g)*255,
(int)((ai_real)color.b)*255,
(int)((ai_real)color.a)*255,
true
);
}else{
hexDiffuseColor = "#";
tmp = DecimalToHexa( (ai_real) color.r ); tmp = DecimalToHexa( (ai_real) color.r );
hexDiffuseColor += tmp; hexDiffuseColor += tmp;
tmp = DecimalToHexa((ai_real)color.g); tmp = DecimalToHexa((ai_real)color.g);
@ -264,6 +275,7 @@ void D3MFExporter::writeBaseMaterials() {
hexDiffuseColor += tmp; hexDiffuseColor += tmp;
tmp = DecimalToHexa((ai_real)color.a); tmp = DecimalToHexa((ai_real)color.a);
hexDiffuseColor += tmp; hexDiffuseColor += tmp;
}
} else { } else {
hexDiffuseColor = "#FFFFFFFF"; hexDiffuseColor = "#FFFFFFFF";
} }
@ -284,7 +296,7 @@ void D3MFExporter::writeObjects() {
if ( nullptr == currentNode ) { if ( nullptr == currentNode ) {
continue; continue;
} }
mModelOutput << "<" << XmlTag::object << " id=\"" << currentNode->mName.C_Str() << "\" type=\"model\">"; mModelOutput << "<" << XmlTag::object << " id=\"" << i + 2 << "\" type=\"model\">";
mModelOutput << std::endl; mModelOutput << std::endl;
for ( unsigned int j = 0; j < currentNode->mNumMeshes; ++j ) { for ( unsigned int j = 0; j < currentNode->mNumMeshes; ++j ) {
aiMesh *currentMesh = mScene->mMeshes[ currentNode->mMeshes[ j ] ]; aiMesh *currentMesh = mScene->mMeshes[ currentNode->mMeshes[ j ] ];
@ -348,7 +360,7 @@ void D3MFExporter::writeBuild() {
mModelOutput << "<" << XmlTag::build << ">" << std::endl; mModelOutput << "<" << XmlTag::build << ">" << std::endl;
for ( size_t i = 0; i < mBuildItems.size(); ++i ) { for ( size_t i = 0; i < mBuildItems.size(); ++i ) {
mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 1 << "\"/>"; mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 2 << "\"/>";
mModelOutput << std::endl; mModelOutput << std::endl;
} }
mModelOutput << "</" << XmlTag::build << ">"; mModelOutput << "</" << XmlTag::build << ">";

View File

@ -145,4 +145,21 @@ std::string DecimalToHexa( T toConvert ) {
return result; return result;
} }
/// @brief translate RGBA to String
/// @param r aiColor.r
/// @param g aiColor.g
/// @param b aiColor.b
/// @param a aiColor.a
/// @param with_head #
/// @return The hexadecimal string, is empty in case of an error.
AI_FORCE_INLINE std::string Rgba2Hex(int r, int g, int b, int a, bool with_head) {
std::stringstream ss;
if (with_head) {
ss << "#";
}
ss << std::hex << (r << 24 | g << 16 | b << 8 | a);
return ss.str();
}
#endif // INCLUDED_AI_STRINGUTILS_H #endif // INCLUDED_AI_STRINGUTILS_H