本文整理汇总了C++中Model::AddVertex方法的典型用法代码示例。如果您正苦于以下问题:C++ Model::AddVertex方法的具体用法?C++ Model::AddVertex怎么用?C++ Model::AddVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::AddVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessMesh
void FBXScene::ProcessMesh(FbxNode* pNode)
{
FbxMesh* pFBXMesh = pNode->GetMesh();
if( !pFBXMesh )
return;
if ( pFBXMesh->GetPolygonVertexCount() != pFBXMesh->GetPolygonCount() * 3 )
{
FbxGeometryConverter GeometryConverter(pNode->GetFbxManager());
if( !GeometryConverter.TriangulateInPlace( pNode ) )
{
return;
}
pFBXMesh = pNode->GetMesh();
}
pFBXMesh->InitNormals();
pFBXMesh->ComputeVertexNormals(true);
pFBXMesh->GenerateTangentsDataForAllUVSets();
int nVertexCount = pFBXMesh->GetControlPointsCount();
if( nVertexCount <= 0 )
return;
std::vector<BoneWeights> boneWeights(nVertexCount);
ProcessBoneWeights(pFBXMesh, boneWeights);
Model* pModel = new Model(pNode->GetName(), m_Models.GetCount(), false);
FbxVector4* aControlPoints = pFBXMesh->GetControlPoints();
for( int pi = 0; pi < pFBXMesh->GetPolygonCount(); ++pi ) // Whole for-loop takes some time too, investigate further.
{
// Material
Material* pMaterial = NULL;
for( unsigned int pvi = 0; pvi < 3; ++pvi )
{
int nVertexIndex = pFBXMesh->GetPolygonVertex(pi, pvi);
if( nVertexIndex < 0 || nVertexIndex >= nVertexCount )
continue;
// Material
if( pMaterial == NULL )
pMaterial = GetMaterialLinkedWithPolygon(pFBXMesh, 0, pi, 0, nVertexIndex);
// Position
FbxVector4 fbxPosition = aControlPoints[nVertexIndex];
// Normals And Tangents
FbxVector4 fbxNormal, fbxTangent;
fbxNormal = GetNormal(pFBXMesh, 0, pi, pvi, nVertexIndex);
fbxTangent = GetTangent(pFBXMesh, 0, pi, pvi, nVertexIndex);
// Add Vertex
pModel->AddVertex(pMaterial, FbxVector4ToBTHFBX_VEC3(fbxPosition),
FbxVector4ToBTHFBX_VEC3(fbxNormal),
FbxVector4ToBTHFBX_VEC3(fbxTangent),
GetTexCoord(pFBXMesh, 0, pi, pvi, nVertexIndex),
boneWeights[nVertexIndex]);
// Update Bounding Box
UpdateBoundingBoxDataFromVertex(FbxVector4ToBTHFBX_VEC3(fbxPosition));
}
}
// Geometric Offset
pModel->SetGeometricOffset2(GetGeometricOffset2(pNode));
// Insert Model
m_Models.Add(pModel->GetName(), pModel);
}
示例2: Load
void ObjLoader::Load(char* path, Model &loadedmodel)
{
//reads the model from the path specified and stores it to the model object specified by loaded model
std::vector<std::string*> contentsoffile;
char textbuffer[256];
std::ifstream in(path);
if(!in.is_open())
{
std::cerr<<"model can not be opened"<<std::endl;
}
while(!in.eof())
{
//read to end of file
in.getline(textbuffer,256);
contentsoffile.push_back(new std::string(textbuffer));
}
for(unsigned int i=0;i<contentsoffile.size();i++)
{
//loop through read file
if(contentsoffile[i]->c_str()[0]=='#')//# means its a comment
{
continue;
}
else if(contentsoffile[i]->c_str()[0]=='v'&& contentsoffile[i]->c_str()[1]==' ')//'v ' means a vertex
{
float tmpx,tmpy,tmpz;
sscanf_s(contentsoffile[i]->c_str(),"v %f %f %f",&tmpx,&tmpy,&tmpz);
loadedmodel.AddVertex(fVector3d(tmpx,tmpy,tmpz));
}
else if(contentsoffile[i]->c_str()[0]=='v' && contentsoffile[i]->c_str()[1]=='t')//'vt' means a uv coordinate
{
float u,v;
sscanf_s(contentsoffile[i]->c_str(),"vt %f %f %f",&u,&v);
loadedmodel.AddUV(fTexCoords3d(u,v));
}
else if(contentsoffile[i]->c_str()[0]=='v'&& contentsoffile[i]->c_str()[1]=='n')//'vt' means a vector normal
{
float tmpx,tmpy,tmpz;
sscanf_s(contentsoffile[i]->c_str(),"vn %f %f %f",&tmpx,&tmpy,&tmpz);
loadedmodel.AddNormal(fVector3d(tmpx,tmpy,tmpz));
}
else if(contentsoffile[i]->c_str()[0]=='f')//'f ' means a face
{
int fa,fb,fc,na,nb,nc,ta,tb,tc;
fa=fb=fc=na=nb=nc=ta=tb=tc= 0;
for (;;)
{
if (sscanf_s(contentsoffile[i]->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d",&fa,&ta,&na,&fb,&tb,&nb,&fc,&tc,&nc) == 9){
break; }
if (sscanf_s(contentsoffile[i]->c_str(),"f %d//%d %d//%d %d//%d",&fa,&na,&fb,&nb,&fc,&nc) == 6){
break;}
if (sscanf_s(contentsoffile[i]->c_str(),"f %d/%d %d/%d %d/%d",&fa,&ta,&fb,&tb,&fc,&tc) == 6){
break;}
if (sscanf_s(contentsoffile[i]->c_str(),"f %d %d %d",&fa,&fb,&fc) == 3){
break;}
else
{
std::cerr<<"the file you loaded is invalid"<<std::endl;
break;
}
}
loadedmodel.AddTriangle(fTriangle(iVector3d(fa-1,fb-1,fc-1),iVector3d(na-1,nb-1,nc-1),iVector3d(ta-1,tb-1,tc-1)));
}
else
{
continue;
}
}
}