diff --git a/code/3MF/D3MFExporter.cpp b/code/3MF/D3MFExporter.cpp index 092b947e9..83036b236 100644 --- a/code/3MF/D3MFExporter.cpp +++ b/code/3MF/D3MFExporter.cpp @@ -181,7 +181,7 @@ bool D3MFExporter::export3DModel() { writeHeader(); 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; mModelOutput << "<" << XmlTag::resources << ">"; mModelOutput << std::endl; @@ -212,7 +212,7 @@ bool D3MFExporter::export3DModel() { } void D3MFExporter::writeHeader() { - mModelOutput << ""; + mModelOutput << ""; mModelOutput << std::endl; } @@ -254,16 +254,28 @@ void D3MFExporter::writeBaseMaterials() { if ( mat->Get( AI_MATKEY_COLOR_DIFFUSE, color ) == aiReturn_SUCCESS ) { hexDiffuseColor.clear(); tmp.clear(); - hexDiffuseColor = "#"; - - tmp = DecimalToHexa( (ai_real) color.r ); - hexDiffuseColor += tmp; - tmp = DecimalToHexa((ai_real)color.g); - hexDiffuseColor += tmp; - tmp = DecimalToHexa((ai_real)color.b); - hexDiffuseColor += tmp; - tmp = DecimalToHexa((ai_real)color.a); - hexDiffuseColor += tmp; + // 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 ); + hexDiffuseColor += tmp; + tmp = DecimalToHexa((ai_real)color.g); + hexDiffuseColor += tmp; + tmp = DecimalToHexa((ai_real)color.b); + hexDiffuseColor += tmp; + tmp = DecimalToHexa((ai_real)color.a); + hexDiffuseColor += tmp; + } } else { hexDiffuseColor = "#FFFFFFFF"; } @@ -284,7 +296,7 @@ void D3MFExporter::writeObjects() { if ( nullptr == currentNode ) { continue; } - mModelOutput << "<" << XmlTag::object << " id=\"" << currentNode->mName.C_Str() << "\" type=\"model\">"; + mModelOutput << "<" << XmlTag::object << " id=\"" << i + 2 << "\" type=\"model\">"; mModelOutput << std::endl; for ( unsigned int j = 0; j < currentNode->mNumMeshes; ++j ) { aiMesh *currentMesh = mScene->mMeshes[ currentNode->mMeshes[ j ] ]; @@ -348,7 +360,7 @@ void D3MFExporter::writeBuild() { mModelOutput << "<" << XmlTag::build << ">" << std::endl; 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 << ""; diff --git a/include/assimp/StringUtils.h b/include/assimp/StringUtils.h index 894eada60..7e1cb4ce0 100644 --- a/include/assimp/StringUtils.h +++ b/include/assimp/StringUtils.h @@ -145,4 +145,21 @@ std::string DecimalToHexa( T toConvert ) { 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 diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp index c8f86bbec..733d3d620 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp @@ -22,7 +22,7 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc aiProcess_Triangulate | aiProcess_ConvertToLeftHanded); - if (pScene == NULL) + if (pScene == nullptr) return false; this->directory_ = filename.substr(0, filename.find_last_of("/\\")); diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp index 1ef4a401f..90338105e 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp @@ -126,7 +126,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, int argc; LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (!argv) { - MessageBox(NULL, + MessageBox(nullptr, TEXT("An error occured while reading command line arguments."), TEXT("Error!"), MB_ICONERROR | MB_OK); @@ -143,7 +143,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, // Ensure that a model file has been specified. if (argc < 2) { - MessageBox(NULL, + MessageBox(nullptr, TEXT("No model file specified. The program will now close."), TEXT("Error!"), MB_ICONERROR | MB_OK); @@ -165,16 +165,16 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; - wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; + wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION); + wc.hCursor = LoadCursor(nullptr, IDC_ARROW); + wc.hbrBackground = nullptr; + wc.lpszMenuName = nullptr; wc.lpszClassName = g_szClassName; - wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION); if (!RegisterClassEx(&wc)) { - MessageBox(NULL, "Window Registration Failed!", "Error!", + MessageBox(nullptr, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } @@ -188,12 +188,12 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, " Simple Textured Directx11 Sample ", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, wr.right - wr.left, wr.bottom - wr.top, - NULL, NULL, hInstance, NULL + nullptr, nullptr, hInstance, nullptr ); - if (g_hwnd == NULL) + if (g_hwnd == nullptr) { - MessageBox(NULL, "Window Creation Failed!", "Error!", + MessageBox(nullptr, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } @@ -210,7 +210,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, while (true) { - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); @@ -372,7 +372,7 @@ void InitD3D(HINSTANCE /*hinstance*/, HWND hWnd) ID3D11Texture2D *pBackBuffer; swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); - dev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer); + dev->CreateRenderTargetView(pBackBuffer, nullptr, &backbuffer); pBackBuffer->Release(); D3D11_TEXTURE2D_DESC descDepth; @@ -440,7 +440,7 @@ void InitD3D(HINSTANCE /*hinstance*/, HWND hWnd) void CleanD3D(void) { if (swapchain) - swapchain->SetFullscreenState(FALSE, NULL); + swapchain->SetFullscreenState(FALSE, nullptr); if (ourModel) { ourModel->Close(); @@ -513,8 +513,8 @@ void InitPipeline() if(FAILED(CompileShaderFromFile(SHADER_PATH PIXEL_SHADER_FILE, 0, "main", "ps_4_0", &PS))) Throwanerror(UTFConverter(L"Failed to compile shader from file " PIXEL_SHADER_FILE).c_str()); - dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS); - dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS); + dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), nullptr, &pVS); + dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), nullptr, &pPS); D3D11_INPUT_ELEMENT_DESC ied[] = { @@ -576,16 +576,16 @@ HRESULT CompileShaderFromFile(LPCWSTR pFileName, const D3D_SHADER_MACRO* pDefine compileFlags |= D3DCOMPILE_DEBUG; #endif - ID3DBlob* pErrorBlob = NULL; + ID3DBlob* pErrorBlob = nullptr; HRESULT result = D3DCompileFromFile(pFileName, pDefines, D3D_COMPILE_STANDARD_FILE_INCLUDE, pEntryPoint, pShaderModel, compileFlags, 0, ppBytecodeBlob, &pErrorBlob); if (FAILED(result)) { - if (pErrorBlob != NULL) + if (pErrorBlob != nullptr) OutputDebugStringA((LPCSTR)pErrorBlob->GetBufferPointer()); } - if (pErrorBlob != NULL) + if (pErrorBlob != nullptr) pErrorBlob->Release(); return result;