From 8ee242f23392fe1d71607b10b53a3b990302548c Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 31 May 2019 19:03:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=90=E8=B4=A8=E5=A2=9E=E5=8A=A0=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=EF=BC=8C=E8=AF=BB=E5=8F=96=E5=A2=9E=E5=8A=A0=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=8F=90=E5=8D=87=E6=98=93=E7=94=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/Material.h | 45 +++++++-- inc/hgl/graph/Mesh.h | 5 + src/SceneGraph/Mesh.cpp | 2 +- src/SceneGraph/SceneFile.cpp | 4 +- src/Tools/ModelConvert/AssimpLoader.cpp | 120 +++++++++++++----------- src/Tools/ModelConvert/AssimpLoader.h | 3 + 6 files changed, 113 insertions(+), 66 deletions(-) diff --git a/inc/hgl/graph/Material.h b/inc/hgl/graph/Material.h index 5d16a932..c67372fb 100644 --- a/inc/hgl/graph/Material.h +++ b/inc/hgl/graph/Material.h @@ -27,15 +27,29 @@ namespace hgl Set uv_use; - Color4f diffuse; - Color4f specular; - Color4f ambient; - Color4f emission; - - float shininess=0; - - bool wireframe=false; bool two_sided=false; + uint shading_model=0; + bool wireframe=false; + + uint blend_func; + + float opacity; ///<透明度 + + uint transparency_factor; + + float bump_scaling; + float shininess; + float reflectivity; ///<反射率 + float shininess_strength; + + float refracti; ///<折射率 + + Color4f diffuse; + Color4f ambient; + Color4f specular; + Color4f emission; + Color4f transparent; ///<透明色 + Color4f reflective; ///<反射颜色 public: @@ -45,6 +59,21 @@ namespace hgl tex_list=nullptr; } + void InitDefaultColor() + { + diffuse.Set(1,1,1,1); + specular.Set(0,0,0,1); + ambient.Set(0.2,0.2,0.2,1.0f); + emission.Set(0,0,0,1); + + shininess=0; + + opacity=1.0f; + refracti=0; + transparent.Set(0,0,0,1); + reflective.Set(1,1,1,1); + } + void Init(const uint32 tc) { tex_count=tc; diff --git a/inc/hgl/graph/Mesh.h b/inc/hgl/graph/Mesh.h index d8799323..c9e6ac87 100644 --- a/inc/hgl/graph/Mesh.h +++ b/inc/hgl/graph/Mesh.h @@ -40,6 +40,11 @@ namespace hgl } };//struct MeshFileHeader #pragma pack(pop) + + struct MeshData + { + VkPrimitiveTopology primitive; + };// }//namespace graph }//namespace hgl #endif//HGL_GRAPH_MESH_INCLUDE diff --git a/src/SceneGraph/Mesh.cpp b/src/SceneGraph/Mesh.cpp index 8fa105fc..e0679bac 100644 --- a/src/SceneGraph/Mesh.cpp +++ b/src/SceneGraph/Mesh.cpp @@ -9,7 +9,7 @@ namespace hgl { namespace graph { - bool LoadMeshFile(MeshFileHeader &md,const OSString &filename,MaterialData *md_list) + bool LoadMeshFile(MeshData &md,const OSString &filename,MaterialData *md_list) { MeshFileHeader mfh; diff --git a/src/SceneGraph/SceneFile.cpp b/src/SceneGraph/SceneFile.cpp index c932458e..722e26c6 100644 --- a/src/SceneGraph/SceneFile.cpp +++ b/src/SceneGraph/SceneFile.cpp @@ -41,11 +41,11 @@ namespace hgl private: uint32 mesh_count=0; - MeshFileHeader *mesh_list; + MeshData *mesh_list; void LoadMesh() { - mesh_list=new MeshFileHeader[mesh_count]; + mesh_list=new MeshData[mesh_count]; for(int i=0;iHasMaterials())return; @@ -202,6 +243,12 @@ void AssimpLoader::LoadMaterial() aiColor4D emission; float shininess; float strength; + float bump_scaling; + float opacity; + float refracti; + aiColor4D transparent; + aiColor4D reflective; + int two_sided; int wireframe; unsigned int max; // changed: to unsigned @@ -293,63 +340,26 @@ void AssimpLoader::LoadMaterial() } } - set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f); - if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse)) - color4_to_float4(&diffuse, c); - //glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c); - ms->diffuse.Set(c); + ms->two_sided =GetMaterialBool (mtl,AI_MATKEY_TWOSIDED, true); + ms->shading_model =GetMaterialInteger (mtl,AI_MATKEY_SHADING_MODEL, aiShadingMode_Phong); + ms->wireframe =GetMaterialBool (mtl,AI_MATKEY_ENABLE_WIREFRAME,false); +// ms->blend_func = + ms->opacity =GetMaterialFloat(mtl,AI_MATKEY_OPACITY, 0); +// ms->transparency_factor = - set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f); - if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular)) - color4_to_float4(&specular, c); - //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c); - ms->specular.Set(c); + ms->bump_scaling =GetMaterialFloat(mtl,AI_MATKEY_BUMPSCALING, 0); + ms->shininess =GetMaterialFloat(mtl,AI_MATKEY_SHININESS, 0); + ms->shininess_strength =GetMaterialFloat(mtl,AI_MATKEY_SHININESS_STRENGTH, 0); + ms->reflectivity =GetMaterialFloat(mtl,AI_MATKEY_REFLECTIVITY, 0); + ms->refracti =GetMaterialFloat(mtl,AI_MATKEY_REFRACTI, 0); - set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f); - if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient)) - color4_to_float4(&ambient, c); - //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c); - ms->ambient.Set(c); + ms->diffuse =GetMaterialColor(mtl,AI_MATKEY_COLOR_DIFFUSE, pure_white_color); + ms->ambient =GetMaterialColor(mtl,AI_MATKEY_COLOR_AMBIENT, Color4f(0.2,0.2,0.2,1.0)); + ms->specular =GetMaterialColor(mtl,AI_MATKEY_COLOR_SPECULAR, pure_black_color); + ms->emission =GetMaterialColor(mtl,AI_MATKEY_COLOR_EMISSIVE, pure_black_color); - set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f); - if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission)) - color4_to_float4(&emission, c); - //glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c); - ms->emission.Set(c); - - max = 1; - ret1 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max); - max = 1; - ret2 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS_STRENGTH, &strength, &max); - - if((ret1 == AI_SUCCESS) && (ret2 == AI_SUCCESS)) - { - //glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength); - - ms->shininess=shininess*strength; - } - else - { - //glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f); - ms->shininess=0; - - set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f); - //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c); - - ms->specular.Zero(); - } - - max = 1; - if(aiGetMaterialIntegerArray(mtl, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max)==AI_SUCCESS) - ms->wireframe=wireframe; - else - ms->wireframe=false; - - max = 1; - if(aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)==AI_SUCCESS) - ms->two_sided=two_sided; - else - ms->two_sided=false; + ms->transparent =GetMaterialColor(mtl,AI_MATKEY_COLOR_TRANSPARENT, pure_black_color); + ms->reflective =GetMaterialColor(mtl,AI_MATKEY_COLOR_REFLECTIVE, pure_black_color); OutMaterial(ms,main_filename+OS_TEXT(".")+OSString(m)+OS_TEXT(".material")); LOG_BR; @@ -709,7 +719,7 @@ bool AssimpLoader::LoadFile(const OSString &filename) const UTF8String ext_name=filesystem::ClipFileExtName(filename); #endif// - scene=aiImportFileFromMemory(filedata,filesize,aiProcessPreset_TargetRealtime_Quality|aiProcess_FlipUVs,ext_name.c_str()); + scene=aiImportFileFromMemory(filedata,filesize,aiProcessPreset_TargetRealtime_MaxQuality|aiProcess_FlipUVs,ext_name.c_str()); delete[] filedata; diff --git a/src/Tools/ModelConvert/AssimpLoader.h b/src/Tools/ModelConvert/AssimpLoader.h index 653a6a51..52f2d890 100644 --- a/src/Tools/ModelConvert/AssimpLoader.h +++ b/src/Tools/ModelConvert/AssimpLoader.h @@ -17,6 +17,9 @@ using namespace hgl; using namespace hgl::graph; +const Color4f pure_black_color(0,0,0,1); +const Color4f pure_white_color(1,1,1,1); + class AssimpLoader { OSString main_filename;