瀏覽代碼

Merge pull request #2122 from loebl/bug/wrong-color-import-in-3mf

Correct 3MF displaycolor import
Kim Kulling 7 年之前
父節點
當前提交
a7c13eef2c
共有 1 個文件被更改,包括 8 次插入5 次删除
  1. 8 5
      code/D3MFImporter.cpp

+ 8 - 5
code/D3MFImporter.cpp

@@ -297,8 +297,9 @@ private:
             return false;
             return false;
         }
         }
 
 
+        //format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1)
         const size_t len( strlen( color ) );
         const size_t len( strlen( color ) );
-        if ( 9 != len ) {
+        if ( 9 != len && 7 != len) {
             return false;
             return false;
         }
         }
 
 
@@ -313,26 +314,28 @@ private:
         ++buf;
         ++buf;
         comp[ 1 ] = *buf;
         comp[ 1 ] = *buf;
         ++buf;
         ++buf;
-        diffuse.r = static_cast<ai_real>( strtol( comp, NULL, 16 ) );
+        diffuse.r = static_cast<ai_real>( strtol( comp, NULL, 16 ) ) / 255.0;
 
 
 
 
         comp[ 0 ] = *buf;
         comp[ 0 ] = *buf;
         ++buf;
         ++buf;
         comp[ 1 ] = *buf;
         comp[ 1 ] = *buf;
         ++buf;
         ++buf;
-        diffuse.g = static_cast< ai_real >( strtol( comp, NULL, 16 ) );
+        diffuse.g = static_cast< ai_real >( strtol( comp, NULL, 16 ) ) / 255.0;
 
 
         comp[ 0 ] = *buf;
         comp[ 0 ] = *buf;
         ++buf;
         ++buf;
         comp[ 1 ] = *buf;
         comp[ 1 ] = *buf;
         ++buf;
         ++buf;
-        diffuse.b = static_cast< ai_real >( strtol( comp, NULL, 16 ) );
+        diffuse.b = static_cast< ai_real >( strtol( comp, NULL, 16 ) ) / 255.0;
 
 
+        if(7 == len)
+            return true;
         comp[ 0 ] = *buf;
         comp[ 0 ] = *buf;
         ++buf;
         ++buf;
         comp[ 1 ] = *buf;
         comp[ 1 ] = *buf;
         ++buf;
         ++buf;
-        diffuse.a = static_cast< ai_real >( strtol( comp, NULL, 16 ) );
+        diffuse.a = static_cast< ai_real >( strtol( comp, NULL, 16 ) ) / 255.0;
 
 
         return true;
         return true;
     }
     }