diff --git a/inc/hgl/graph/Material.h b/inc/hgl/graph/Material.h new file mode 100644 index 00000000..625fdfe3 --- /dev/null +++ b/inc/hgl/graph/Material.h @@ -0,0 +1,61 @@ +#ifndef HGL_GRAPH_MATERIAL_INCLUDE +#define HGL_GRAPH_MATERIAL_INCLUDE + +#include +namespace hgl +{ + namespace graph + { + struct MaterialTextureData + { + TextureType type=TextureType::None; + + int32 tex_id=-1; + + uint8 uvindex=0; + float blend=0; + uint8 op=0; + uint8 wrap_mode[2]={0,0}; + };//struct MaterialTextureData + + struct MaterialData + { + uint8 tex_count; + + MaterialTextureData *tex_list; + + Set uv_use; + + Color4f diffuse; + Color4f specular; + Color4f ambient; + Color4f emission; + + float shininess=0; + + bool wireframe=false; + bool two_sided=false; + + public: + + MaterialData() + { + tex_count=0; + tex_list=nullptr; + } + + void Init(const uint32 tc) + { + tex_count=tc; + + tex_list=new MaterialTextureData[tc]; + } + + ~MaterialData() + { + delete[] tex_list; + } + };//struct MaterialData + }//namespace graph +}//namespace hgl +#endif//HGL_GRAPH_MATERIAL_INCLUDE \ No newline at end of file diff --git a/inc/hgl/graph/Mesh.h b/inc/hgl/graph/Mesh.h new file mode 100644 index 00000000..d8799323 --- /dev/null +++ b/inc/hgl/graph/Mesh.h @@ -0,0 +1,45 @@ +#ifndef HGL_GRAPH_MESH_INCLUDE +#define HGL_GRAPH_MESH_INCLUDE + +namespace hgl +{ + namespace graph + { + #pragma pack(push,1) + struct MeshFileHeader + { + uint8 flag[4]; ///<'MESH' + uint8 sperator; ///<0x1a + uint8 version; ///<1 + + uint8 primitive_type; ///<图元类型 + + uint32 vertices_number; ///<顶点数量 + uint32 faces_number; ///<面数量 + + uint8 color_channels; ///<顶点色数量 + uint8 texcoord_channels; ///<纹理坐标数量 + + uint32 material_index; ///<材质索引 + + uint8 ntb; ///WriteUint8(mt.type); + dos->WriteUint8((uint8)mt.type); dos->WriteInt32(mt.tex_id); - dos->WriteUint8(mt.new_uvindex); + dos->WriteUint8(mt.uvindex); dos->WriteFloat(mt.blend); dos->WriteUint8(mt.op); dos->WriteUint8(mt.wrap_mode,2); - LOG_INFO(OS_TEXT("\tTexture Type: ")+OSString(mt.type)); + LOG_INFO(OS_TEXT("\tTexture Type: ")+OSString((uint)mt.type)); LOG_INFO(OS_TEXT("\tTexture ID: ")+OSString(mt.tex_id)); - LOG_INFO(OS_TEXT("\tuvindex: ")+OSString(mt.old_uvindex)); + LOG_INFO(OS_TEXT("\tuvindex: ")+OSString(mt.uvindex)); LOG_INFO(OS_TEXT("\tblend: ")+OSString(mt.blend)); LOG_INFO(OS_TEXT("\top: ")+OSString(mt.op)); LOG_INFO(OS_TEXT("\twrap_mode: ")+OSString(mt.wrap_mode[0])+OS_TEXT(",")+OSString(mt.wrap_mode[1])); } -void OutMaterial(const MaterialStruct *ms,const OSString &filename) +void OutMaterial(const MaterialData *ms,const OSString &filename) { io::FileOutputStream fos; io::LEDataOutputStream dos(&fos); @@ -219,7 +219,7 @@ void AssimpLoader::LoadMaterial() material_count=scene->mNumMaterials; - material_list=new MaterialStruct[material_count]; + material_list=new MaterialData[material_count]; for(unsigned int m=0;mmNumMaterials;m++) { @@ -236,7 +236,7 @@ void AssimpLoader::LoadMaterial() tex_count+=mtl->GetTextureCount((aiTextureType)tt); } - MaterialStruct *ms=&(material_list[m]); + MaterialData *ms=&(material_list[m]); ms->Init(tex_count); @@ -248,7 +248,7 @@ void AssimpLoader::LoadMaterial() { mtl->GetTexture((aiTextureType)tt,t,&filename,&tm,&uvindex,&blend,&op,wrap_mode); - ms->tex_list[tex_index].type=tt; + ms->tex_list[tex_index].type=(TextureType)tt; ms->uv_use.Add(uvindex); @@ -282,7 +282,7 @@ void AssimpLoader::LoadMaterial() ms->tex_list[tex_index].tex_id=tex_id; } - ms->tex_list[tex_index].old_uvindex=uvindex; + ms->tex_list[tex_index].uvindex=uvindex; ms->tex_list[tex_index].blend=blend; ms->tex_list[tex_index].op=op; @@ -293,8 +293,6 @@ void AssimpLoader::LoadMaterial() } } - ms->ProcUVIndex(); - 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); @@ -351,7 +349,7 @@ void AssimpLoader::LoadMaterial() if(aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)==AI_SUCCESS) ms->two_sided=two_sided; else - ms->two_sided=true; + ms->two_sided=false; OutMaterial(ms,main_filename+OS_TEXT(".")+OSString(m)+OS_TEXT(".material")); LOG_BR; @@ -521,7 +519,7 @@ void AssimpLoader::LoadMesh() if(pn!=3) continue; - MaterialStruct *mtl=&(material_list[mesh->mMaterialIndex]); + MaterialData *mtl=&(material_list[mesh->mMaterialIndex]); const uint uv_channels=mtl->uv_use.GetCount(); @@ -538,7 +536,7 @@ void AssimpLoader::LoadMesh() } { - MeshStruct ms; + MeshFileHeader ms; ms.primitive_type =PRIM_TRIANGLES; ms.vertices_number =mesh->mNumVertices; @@ -557,7 +555,7 @@ void AssimpLoader::LoadMesh() ms.bones_number =mesh->mNumBones; - fos.WriteFully(&ms,sizeof(MeshStruct)); + fos.WriteFully(&ms,sizeof(MeshFileHeader)); } if(mesh->HasPositions()) diff --git a/src/Tools/ModelConvert/AssimpLoader.h b/src/Tools/ModelConvert/AssimpLoader.h index 6a91d7bb..653a6a51 100644 --- a/src/Tools/ModelConvert/AssimpLoader.h +++ b/src/Tools/ModelConvert/AssimpLoader.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -15,101 +17,6 @@ using namespace hgl; using namespace hgl::graph; -#pragma pack(push,1) - -struct MaterialTextureStruct -{ - uint8 type=0; - - int32 tex_id=-1; - - uint32 old_uvindex=0; - uint32 new_uvindex=0; - float blend=0; - uint8 op=0; - uint8 wrap_mode[2]={0,0}; -};// - -struct MaterialStruct -{ - uint32 tex_count; - - MaterialTextureStruct *tex_list; - - Set uv_use; - - Color4f diffuse; - Color4f specular; - Color4f ambient; - Color4f emission; - - float shininess=0; - - bool wireframe=false; - bool two_sided=false; - -public: - - MaterialStruct() - { - tex_count=0; - tex_list=nullptr; - } - - void Init(const uint32 tc) - { - tex_count=tc; - - tex_list=new MaterialTextureStruct[tc]; - } - - ~MaterialStruct() - { - delete[] tex_list; - } - - void ProcUVIndex() - { - for(uint i=0;i