本文整理汇总了C++中StaticModel::SetFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticModel::SetFilename方法的具体用法?C++ StaticModel::SetFilename怎么用?C++ StaticModel::SetFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticModel
的用法示例。
在下文中一共展示了StaticModel::SetFilename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadStaticModel
//! Loads and returns a static model from a file.
StaticModel* ModelImporter::LoadStaticModel(string filename)
{
// Is the model already loaded?
if(mStaticModelMap.find(filename) != mStaticModelMap.end())
return mStaticModelMap[filename];
Assimp::Importer importer;
mFilename = filename;
StaticModel* model = NULL;
// Important! Makes sure that if the angle between two face normals is > 80 they are not smoothed together.
// Since the angle between a cubes face normals is 90 the lighting looks very bad if we don't specify this.
importer.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f);
importer.SetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 1);
importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE);
// Load scene from the file.
const aiScene* scene = importer.ReadFile(filename,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_GenSmoothNormals |
aiProcess_SplitLargeMeshes |
aiProcess_ConvertToLeftHanded |
aiProcess_SortByPType);
// Successfully loaded the scene.
if(scene)
{
// Create the model that is getting filled out.
model = new StaticModel();
// Loop through all meshes.
for(int i = 0; i < scene->mNumMeshes; i++)
{
aiMesh* assimpMesh = scene->mMeshes[i];
vector<Vertex> vertices;
vector<UINT> indices;
// Add vertices to the vertex list.
for(int i = 0; i < assimpMesh->mNumVertices; i++)
{
aiVector3D v = assimpMesh->mVertices[i];
aiVector3D n = assimpMesh->mNormals[i];
aiVector3D t = aiVector3D(0, 0, 0);
if(assimpMesh->HasTextureCoords(0))
t = assimpMesh->mTextureCoords[0][i];
n = n.Normalize();
Vertex vertex(v.x, v.y, v.z, n.x, n.y, n.z, 0, 0, 0, t.x, t.y);
vertices.push_back(vertex);
}
// Add indices to the index list.
for(int i = 0; i < assimpMesh->mNumFaces; i++)
for(int j = 0; j < assimpMesh->mFaces[i].mNumIndices; j++)
indices.push_back(assimpMesh->mFaces[i].mIndices[j]);
// Get the path to the texture in the directory.
aiString path;
aiMaterial* material = scene->mMaterials[assimpMesh->mMaterialIndex];
material->Get(AI_MATKEY_TEXTURE_DIFFUSE(0), path);
FindValidPath(&path);
// Extract all the ambient, diffuse and specular colors.
aiColor4D ambient, diffuse, specular;
material->Get(AI_MATKEY_COLOR_AMBIENT, ambient);
material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse);
material->Get(AI_MATKEY_COLOR_SPECULAR, specular);
// Create the mesh and its primitive.
StaticMesh* mesh = new StaticMesh();
Primitive* primitive = new Primitive(GlobalApp::GetD3DDevice(), vertices, indices);
mesh->SetPrimitive(primitive);
mesh->SetVertices(vertices);
mesh->SetIndices(indices);
mPrimtiveFactory->AddPrimitive(path.C_Str(), primitive);
// Any texture?
if(_stricmp(path.C_Str(), "") != 0)
mesh->LoadTexture(path.C_Str());
// Any normal map?
aiString nmap;
material->Get(AI_MATKEY_TEXTURE_HEIGHT(0), nmap);
FindValidPath(&nmap);
if(_stricmp(nmap.C_Str(), "") != 0)
mesh->SetNormalMap(GlobalApp::GetGraphics()->LoadTexture(nmap.C_Str()));
// [NOTE] The material is set to white.
mesh->SetMaterial(Material(Colors::White)); // Was before [NOTE]
model->SetFilename(filename);
// Add the mesh to the model.
model->AddMesh(mesh);
}
// Add to the model map and return it.
mStaticModelMap[filename] = model;
//.........这里部分代码省略.........