材质增加属性,读取增加函数提升易用性
This commit is contained in:
parent
188b8f9c2a
commit
8ee242f233
@ -27,15 +27,29 @@ namespace hgl
|
|||||||
|
|
||||||
Set<int> uv_use;
|
Set<int> uv_use;
|
||||||
|
|
||||||
Color4f diffuse;
|
|
||||||
Color4f specular;
|
|
||||||
Color4f ambient;
|
|
||||||
Color4f emission;
|
|
||||||
|
|
||||||
float shininess=0;
|
|
||||||
|
|
||||||
bool wireframe=false;
|
|
||||||
bool two_sided=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:
|
public:
|
||||||
|
|
||||||
@ -45,6 +59,21 @@ namespace hgl
|
|||||||
tex_list=nullptr;
|
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)
|
void Init(const uint32 tc)
|
||||||
{
|
{
|
||||||
tex_count=tc;
|
tex_count=tc;
|
||||||
|
@ -40,6 +40,11 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
};//struct MeshFileHeader
|
};//struct MeshFileHeader
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
struct MeshData
|
||||||
|
{
|
||||||
|
VkPrimitiveTopology primitive;
|
||||||
|
};//
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_GRAPH_MESH_INCLUDE
|
#endif//HGL_GRAPH_MESH_INCLUDE
|
||||||
|
@ -9,7 +9,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
bool LoadMeshFile(MeshFileHeader &md,const OSString &filename,MaterialData *md_list)
|
bool LoadMeshFile(MeshData &md,const OSString &filename,MaterialData *md_list)
|
||||||
{
|
{
|
||||||
MeshFileHeader mfh;
|
MeshFileHeader mfh;
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ namespace hgl
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
uint32 mesh_count=0;
|
uint32 mesh_count=0;
|
||||||
MeshFileHeader *mesh_list;
|
MeshData *mesh_list;
|
||||||
|
|
||||||
void LoadMesh()
|
void LoadMesh()
|
||||||
{
|
{
|
||||||
mesh_list=new MeshFileHeader[mesh_count];
|
mesh_list=new MeshData[mesh_count];
|
||||||
|
|
||||||
for(int i=0;i<mesh_count;i++)
|
for(int i=0;i<mesh_count;i++)
|
||||||
LoadMeshFile(mesh_list[i],main_filename+OS_TEXT(".")+OSString(i)+OS_TEXT(".mesh"),md_list);
|
LoadMeshFile(mesh_list[i],main_filename+OS_TEXT(".")+OSString(i)+OS_TEXT(".mesh"),md_list);
|
||||||
|
@ -190,6 +190,47 @@ void OutMaterial(const MaterialData *ms,const OSString &filename)
|
|||||||
fos.Close();
|
fos.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GetMaterialBool(aiMaterial *mtl,const char *key,unsigned int type,unsigned int index,const bool default_value)
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
|
||||||
|
if(aiGetMaterialInteger(mtl, AI_MATKEY_TWOSIDED, &value)==AI_SUCCESS)
|
||||||
|
return value;
|
||||||
|
else
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint GetMaterialInteger(aiMaterial *mtl,const char *key,unsigned int type,unsigned int index,const uint default_value)
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
|
||||||
|
if(aiGetMaterialInteger(mtl, AI_MATKEY_TWOSIDED, &value)==AI_SUCCESS)
|
||||||
|
return value;
|
||||||
|
else
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetMaterialFloat(aiMaterial *mtl,const char *key,unsigned int type,unsigned int index,const float default_value)
|
||||||
|
{
|
||||||
|
float value;
|
||||||
|
|
||||||
|
if(aiGetMaterialFloat(mtl, AI_MATKEY_TWOSIDED, &value)==AI_SUCCESS)
|
||||||
|
return value;
|
||||||
|
else
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color4f GetMaterialColor(aiMaterial *mtl,const char *key,unsigned int type,unsigned int index,const Color4f &default_value)
|
||||||
|
{
|
||||||
|
unsigned int max = 1;
|
||||||
|
aiColor4D color;
|
||||||
|
|
||||||
|
if(aiGetMaterialColor(mtl, AI_MATKEY_TWOSIDED, &color)==AI_SUCCESS)
|
||||||
|
return Color4f(color.r,color.g,color.b,color.a);
|
||||||
|
else
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
void AssimpLoader::LoadMaterial()
|
void AssimpLoader::LoadMaterial()
|
||||||
{
|
{
|
||||||
if(!scene->HasMaterials())return;
|
if(!scene->HasMaterials())return;
|
||||||
@ -202,6 +243,12 @@ void AssimpLoader::LoadMaterial()
|
|||||||
aiColor4D emission;
|
aiColor4D emission;
|
||||||
float shininess;
|
float shininess;
|
||||||
float strength;
|
float strength;
|
||||||
|
float bump_scaling;
|
||||||
|
float opacity;
|
||||||
|
float refracti;
|
||||||
|
aiColor4D transparent;
|
||||||
|
aiColor4D reflective;
|
||||||
|
|
||||||
int two_sided;
|
int two_sided;
|
||||||
int wireframe;
|
int wireframe;
|
||||||
unsigned int max; // changed: to unsigned
|
unsigned int max; // changed: to unsigned
|
||||||
@ -293,63 +340,26 @@ void AssimpLoader::LoadMaterial()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f);
|
ms->two_sided =GetMaterialBool (mtl,AI_MATKEY_TWOSIDED, true);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
|
ms->shading_model =GetMaterialInteger (mtl,AI_MATKEY_SHADING_MODEL, aiShadingMode_Phong);
|
||||||
color4_to_float4(&diffuse, c);
|
ms->wireframe =GetMaterialBool (mtl,AI_MATKEY_ENABLE_WIREFRAME,false);
|
||||||
//glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
|
// ms->blend_func =
|
||||||
ms->diffuse.Set(c);
|
ms->opacity =GetMaterialFloat(mtl,AI_MATKEY_OPACITY, 0);
|
||||||
|
// ms->transparency_factor =
|
||||||
|
|
||||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
ms->bump_scaling =GetMaterialFloat(mtl,AI_MATKEY_BUMPSCALING, 0);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular))
|
ms->shininess =GetMaterialFloat(mtl,AI_MATKEY_SHININESS, 0);
|
||||||
color4_to_float4(&specular, c);
|
ms->shininess_strength =GetMaterialFloat(mtl,AI_MATKEY_SHININESS_STRENGTH, 0);
|
||||||
//glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
ms->reflectivity =GetMaterialFloat(mtl,AI_MATKEY_REFLECTIVITY, 0);
|
||||||
ms->specular.Set(c);
|
ms->refracti =GetMaterialFloat(mtl,AI_MATKEY_REFRACTI, 0);
|
||||||
|
|
||||||
set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f);
|
ms->diffuse =GetMaterialColor(mtl,AI_MATKEY_COLOR_DIFFUSE, pure_white_color);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient))
|
ms->ambient =GetMaterialColor(mtl,AI_MATKEY_COLOR_AMBIENT, Color4f(0.2,0.2,0.2,1.0));
|
||||||
color4_to_float4(&ambient, c);
|
ms->specular =GetMaterialColor(mtl,AI_MATKEY_COLOR_SPECULAR, pure_black_color);
|
||||||
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);
|
ms->emission =GetMaterialColor(mtl,AI_MATKEY_COLOR_EMISSIVE, pure_black_color);
|
||||||
ms->ambient.Set(c);
|
|
||||||
|
|
||||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
ms->transparent =GetMaterialColor(mtl,AI_MATKEY_COLOR_TRANSPARENT, pure_black_color);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission))
|
ms->reflective =GetMaterialColor(mtl,AI_MATKEY_COLOR_REFLECTIVE, pure_black_color);
|
||||||
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;
|
|
||||||
|
|
||||||
OutMaterial(ms,main_filename+OS_TEXT(".")+OSString(m)+OS_TEXT(".material"));
|
OutMaterial(ms,main_filename+OS_TEXT(".")+OSString(m)+OS_TEXT(".material"));
|
||||||
LOG_BR;
|
LOG_BR;
|
||||||
@ -709,7 +719,7 @@ bool AssimpLoader::LoadFile(const OSString &filename)
|
|||||||
const UTF8String ext_name=filesystem::ClipFileExtName(filename);
|
const UTF8String ext_name=filesystem::ClipFileExtName(filename);
|
||||||
#endif//
|
#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;
|
delete[] filedata;
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
|
const Color4f pure_black_color(0,0,0,1);
|
||||||
|
const Color4f pure_white_color(1,1,1,1);
|
||||||
|
|
||||||
class AssimpLoader
|
class AssimpLoader
|
||||||
{
|
{
|
||||||
OSString main_filename;
|
OSString main_filename;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user