我有這樣定義的頂點:刪除Vector中的重複項?
struct VERTEX
{
XMFLOAT3 Pos
XMFLOAT2 UV
};
我定義的指標,紋理協調指數,UVcoordinate像這樣
vector <int> indices ;
vector <int> Texcoordindex ;
vector <XMFLOAT2> UVCoinate ;
vector <XMFLOAT3> Verices;
OK頂點。我從3D文件(在這種情況下是一個obj文件)設置索引,紋理協調索引,UV座標和頂點。
現在,當我想定義一個faces數組時,我發現一些頂點是用多個UV座標定義的。我想刪除具有相同UV座標的重複頂點,並創建新的索引和頂點向量,以僅存儲具有頂點的新索引的非重複頂點。
這裏是OBJ文件:
# This file uses centimeters as units for non-parametric coordinates.
v -12.830015 0.000000 12.061520
v 12.027525 0.000000 12.061520
v -12.830015 15.862570 12.061520
v 12.027525 15.862570 12.061520
v -12.830015 15.862570 -12.622024
v 12.027525 15.862570 -12.622024
v -12.830015 0.000000 -12.622024
v 12.027525 0.000000 -12.622024
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.375000 0.250000
vt 0.625000 0.250000
vt 0.375000 0.500000
vt 0.625000 0.500000
vt 0.375000 0.750000
vt 0.625000 0.750000
vt 0.375000 1.000000
vt 0.625000 1.000000
vt 0.875000 0.000000
vt 0.875000 0.250000
vt 0.125000 0.000000
vt 0.125000 0.250000
f 1/1 2/2 3/3
f 3/3 2/2 4/4
f 3/3 4/4 5/5
f 5/5 4/4 6/6
f 5/5 6/6 7/7
f 7/7 6/6 8/8
f 7/7 8/8 1/9
f 1/9 8/8 2/10
f 2/2 8/11 4/4
f 4/4 8/11 6/12
f 7/13 1/1 5/14
f 5/14 1/1 3/3
我想要的結果是這樣的
# This file uses centimeters as units for non-parametric coordinates.
v -12.830015 0.000000 12.061520
v 12.027525 0.000000 12.061520
v -12.830015 15.862570 12.061520
v 12.027525 15.862570 12.061520
v -12.830015 15.862570 -12.622024
v 12.027525 15.862570 -12.622024
v -12.830015 0.000000 -12.622024
v 12.027525 0.000000 -12.622024
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.375000 0.250000
vt 0.625000 0.250000
vt 0.375000 0.500000
vt 0.625000 0.500000
vt 0.375000 0.750000
vt 0.625000 0.750000
vt 0.375000 1.000000
vt 0.625000 1.000000
vt 0.875000 0.000000
vt 0.875000 0.250000
vt 0.125000 0.000000
vt 0.125000 0.250000
新頂點刪除重複
f 1/1 2/2 3/3
f 4/4 5/5 6/6
f 7/7 8/8 1/9
f 2/10 8/116/12
f7/13 5/14
我嘗試使用後排序和唯一,但我得到編譯錯誤:
error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const
std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const std::vector<_Ty,_Ax> &,const std::vector<_Ty,_Ax> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'VERTEX' c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C2676: binary '<' : 'VERTEX' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
error C1903: unable to recover from previous error(s); stopping compilation c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 3559 1 Mesh_test
也許這將是一個好主意,向我們展示了代碼和編譯器錯誤。 – Simon
您是否有重載相等運算符? – Hauleth
不,我不重載平等運營商 – user943998