3ds const correctness
This commit is contained in:
parent
5ced1eb198
commit
a1e1ba882f
|
|
@ -149,7 +149,7 @@ namespace io {
|
||||||
/*
|
/*
|
||||||
function which saves in 3DS file format
|
function which saves in 3DS file format
|
||||||
*/
|
*/
|
||||||
static int SaveBinary(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
|
static int SaveBinary(const SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
|
||||||
{
|
{
|
||||||
if(m.vn > MAX_POLYGONS)//check max polygons
|
if(m.vn > MAX_POLYGONS)//check max polygons
|
||||||
return E_NOTNUMBERVERTVALID;
|
return E_NOTNUMBERVERTVALID;
|
||||||
|
|
@ -222,18 +222,18 @@ namespace io {
|
||||||
int nface = 0;
|
int nface = 0;
|
||||||
if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) )
|
if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) )
|
||||||
{
|
{
|
||||||
FaceIterator fi;
|
for(const auto& f : m.face) {
|
||||||
for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() )
|
if( !f.IsD() )
|
||||||
{
|
{
|
||||||
for(unsigned int k=0;k<3;k++)
|
for(unsigned int k=0;k<3;k++)
|
||||||
{
|
{
|
||||||
int i = GetIndexVertex(m, (*fi).V(k));
|
int i = GetIndexVertex(m, f.cV(k));
|
||||||
vcg::TexCoord2<float> t = (*fi).WT(k);
|
vcg::TexCoord2<float> t = f.cWT(k);
|
||||||
if(!m.vert[i].IsD())
|
if(!m.vert[i].IsD())
|
||||||
{
|
{
|
||||||
if(AddDuplexVertexCoord(ListOfDuplexVert,Key(i,t)))
|
if(AddDuplexVertexCoord(ListOfDuplexVert,Key(i,t)))
|
||||||
{
|
{
|
||||||
VectorOfVertexType.push_back((*(*fi).V(k)));
|
VectorOfVertexType.push_back((*f.V(k)));
|
||||||
ListOfDuplexVert[Key(i,t)] = int(VectorOfVertexType.size()-1);
|
ListOfDuplexVert[Key(i,t)] = int(VectorOfVertexType.size()-1);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
@ -246,6 +246,7 @@ namespace io {
|
||||||
return E_ABORTED;
|
return E_ABORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int number_vertex_to_duplicate = 0;
|
int number_vertex_to_duplicate = 0;
|
||||||
|
|
||||||
|
|
@ -267,7 +268,6 @@ namespace io {
|
||||||
lib3ds_mesh_new_texel_list(mesh,m.vn + number_vertex_to_duplicate); //set number of textures
|
lib3ds_mesh_new_texel_list(mesh,m.vn + number_vertex_to_duplicate); //set number of textures
|
||||||
|
|
||||||
int v_index = 0;
|
int v_index = 0;
|
||||||
VertexIterator vi;
|
|
||||||
//saves vert
|
//saves vert
|
||||||
if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ))
|
if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ))
|
||||||
{
|
{
|
||||||
|
|
@ -289,38 +289,42 @@ namespace io {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VertRemap.resize(m.vert.size(),-1);
|
VertRemap.resize(m.vert.size(),-1);
|
||||||
for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi) if( !(*vi).IsD() )
|
unsigned int vi = 0;
|
||||||
|
for(const auto& v : m.vert) {
|
||||||
|
if( !v.IsD() )
|
||||||
{
|
{
|
||||||
Lib3dsPoint point;
|
Lib3dsPoint point;
|
||||||
point.pos[0] = (*vi).P()[0];
|
point.pos[0] = v.P()[0];
|
||||||
point.pos[1] = (*vi).P()[1];
|
point.pos[1] = v.P()[1];
|
||||||
point.pos[2] = (*vi).P()[2];
|
point.pos[2] = v.P()[2];
|
||||||
|
|
||||||
mesh->pointL[v_index] = point;
|
mesh->pointL[v_index] = point;
|
||||||
VertRemap[vi-m.vert.begin()]=v_index;
|
VertRemap[vi]=v_index;
|
||||||
if (cb !=NULL)
|
if (cb !=NULL)
|
||||||
(*cb)(100.0 * (float)++current/(float)max, "writing vertices ");
|
(*cb)(100.0 * (float)++current/(float)max, "writing vertices ");
|
||||||
else
|
else
|
||||||
return E_ABORTED;
|
return E_ABORTED;
|
||||||
v_index++;
|
v_index++;
|
||||||
}
|
}
|
||||||
|
vi++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lib3ds_mesh_new_face_list (mesh, m.face.size());//set number of faces
|
lib3ds_mesh_new_face_list (mesh, m.face.size());//set number of faces
|
||||||
int f_index = 0;//face index
|
int f_index = 0;//face index
|
||||||
//int t_index = 0;//texture index
|
//int t_index = 0;//texture index
|
||||||
FaceIterator fi;
|
for(const auto& f : m.face) {
|
||||||
for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() )
|
if( !f.IsD() )
|
||||||
{
|
{
|
||||||
vcg::TexCoord2<float> t0(0,0),t1(0,0),t2(0,0);
|
vcg::TexCoord2<float> t0(0,0),t1(0,0),t2(0,0);
|
||||||
int i0 = GetIndexVertex(m, (*fi).V(0));
|
int i0 = GetIndexVertex(m, f.cV(0));
|
||||||
int i1 = GetIndexVertex(m, (*fi).V(1));
|
int i1 = GetIndexVertex(m, f.cV(1));
|
||||||
int i2 = GetIndexVertex(m, (*fi).V(2));
|
int i2 = GetIndexVertex(m, f.cV(2));
|
||||||
if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) )
|
if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) )
|
||||||
{
|
{
|
||||||
t0 = (*fi).WT(0);
|
t0 = f.cWT(0);
|
||||||
t1 = (*fi).WT(1);
|
t1 = f.cWT(1);
|
||||||
t2 = (*fi).WT(2);
|
t2 = f.cWT(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Lib3dsFace face;
|
Lib3dsFace face;
|
||||||
|
|
@ -355,14 +359,14 @@ namespace io {
|
||||||
|
|
||||||
if((mask & vcg::tri::io::Mask::IOM_FACENORMAL) | (mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) )
|
if((mask & vcg::tri::io::Mask::IOM_FACENORMAL) | (mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) )
|
||||||
{
|
{
|
||||||
face.normal[0] = (*fi).N()[0];
|
face.normal[0] = f.cN()[0];
|
||||||
face.normal[1] = (*fi).N()[1];
|
face.normal[1] = f.cN()[1];
|
||||||
face.normal[2] = (*fi).N()[2];
|
face.normal[2] = f.cN()[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if((mask & vcg::tri::io::Mask::IOM_FACECOLOR) | (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD))
|
if((mask & vcg::tri::io::Mask::IOM_FACECOLOR) | (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD))
|
||||||
{
|
{
|
||||||
int material_index = vcg::tri::io::Materials<SaveMeshType>::CreateNewMaterial(m, materials, fi);
|
int material_index = vcg::tri::io::Materials<SaveMeshType>::CreateNewMaterial(m, materials, f);
|
||||||
if(material_index == (int)materials.size())
|
if(material_index == (int)materials.size())
|
||||||
{
|
{
|
||||||
Lib3dsMaterial *material = lib3ds_material_new();//creates a new material
|
Lib3dsMaterial *material = lib3ds_material_new();//creates a new material
|
||||||
|
|
@ -417,6 +421,7 @@ namespace io {
|
||||||
f_index++;
|
f_index++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lib3ds_file_insert_mesh(file, mesh);//inserts the Mesh into file
|
lib3ds_file_insert_mesh(file, mesh);//inserts the Mesh into file
|
||||||
|
|
||||||
|
|
@ -435,7 +440,7 @@ namespace io {
|
||||||
/*
|
/*
|
||||||
function which saves in 3DS format
|
function which saves in 3DS format
|
||||||
*/
|
*/
|
||||||
static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
|
static int Save(const SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
|
||||||
{
|
{
|
||||||
return SaveBinary(m,filename,mask,cb);
|
return SaveBinary(m,filename,mask,cb);
|
||||||
}
|
}
|
||||||
|
|
@ -443,7 +448,7 @@ namespace io {
|
||||||
/*
|
/*
|
||||||
returns index of the vertex
|
returns index of the vertex
|
||||||
*/
|
*/
|
||||||
inline static int GetIndexVertex(SaveMeshType &m, VertexType *p)
|
inline static int GetIndexVertex(const SaveMeshType &m, VertexType *p)
|
||||||
{
|
{
|
||||||
return p-&*(m.vert.begin());
|
return p-&*(m.vert.begin());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ public:
|
||||||
{
|
{
|
||||||
int index=-1;
|
int index=-1;
|
||||||
if(useMaterialAttribute) index = materialIndexHandle[fi];
|
if(useMaterialAttribute) index = materialIndexHandle[fi];
|
||||||
else index = Materials<SaveMeshType>::CreateNewMaterial(m,materialVec,fi);
|
else index = Materials<SaveMeshType>::CreateNewMaterial(m,materialVec,*fi);
|
||||||
|
|
||||||
if(index != curMatIndex) {
|
if(index != curMatIndex) {
|
||||||
fprintf(fp,"\nusemtl material_%d\n", index);
|
fprintf(fp,"\nusemtl material_%d\n", index);
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ template <class SaveMeshType>
|
||||||
class Materials
|
class Materials
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef typename SaveMeshType::FaceType FaceType;
|
||||||
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
||||||
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
||||||
typedef typename SaveMeshType::VertexType VertexType;
|
typedef typename SaveMeshType::VertexType VertexType;
|
||||||
|
|
@ -93,17 +94,17 @@ public:
|
||||||
/*
|
/*
|
||||||
creates a new meterial
|
creates a new meterial
|
||||||
*/
|
*/
|
||||||
inline static int CreateNewMaterial(SaveMeshType &m, std::vector<Material> &materials, FaceIterator &fi)
|
inline static int CreateNewMaterial(const SaveMeshType &m, std::vector<Material> &materials, const FaceType& f)
|
||||||
{
|
{
|
||||||
Material mtl;
|
Material mtl;
|
||||||
|
|
||||||
if(HasPerFaceColor(m)){
|
if(HasPerFaceColor(m)){
|
||||||
mtl.Kd = Point3f((float)((*fi).C()[0])/255.0f,(float)((*fi).C()[1])/255.0f,(float)((*fi).C()[2])/255.0f);//diffuse
|
mtl.Kd = Point3f((float)(f.C()[0])/255.0f,(float)(f.C()[1])/255.0f,(float)(f.C()[2])/255.0f);//diffuse
|
||||||
mtl.Tr = (float)((*fi).C()[3])/255.0f;//alpha
|
mtl.Tr = (float)(f.C()[3])/255.0f;//alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m.textures.size() && (*fi).WT(0).n() >=0 )
|
if(m.textures.size() && f.WT(0).n() >=0 )
|
||||||
mtl.map_Kd = m.textures[(*fi).WT(0).n()];
|
mtl.map_Kd = m.textures[f.WT(0).n()];
|
||||||
else
|
else
|
||||||
mtl.map_Kd = "";
|
mtl.map_Kd = "";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue