Ejemplo n.º 1
0
//-----------------------------------------------------------------------------------------------------------
bool RawMesh::read(const char* fileName)
{
    if(fileName == nullptr)
        return false;

    std::ifstream stream(fileName, std::ios::binary);
    if(!stream)
    {
        std::cout << "error: could not open file" << std::endl;
        return false;
    }

    if(!readHeader(stream))
        return false;

    if(!readVertices(stream))
        return false;

    if(!readFaces(stream))
        return false;

    if(!readMaterials(stream))
        return false;

    if(!readBones(stream))
        return false;

    if(stream.fail())
    {
        std::cout << "error: broken file" << std::endl;
        return false;
    }

    return true;
}
Ejemplo n.º 2
0
void Reader::readShape(){
	shape = new Shape;
	readVertices();
	readColor();
	readFaces();
	model->addShape(shape);
}
Ejemplo n.º 3
0
void ObjLoader::readSubMesh(ifstream &in, Mesh3D *pMesh)
{

  char strLine[256];
  while(!in.eof())
  {
    in>>type_;
    if(type_ == string("#"))
    {
      in.getline(strLine,256);
      continue;
    }
    //case: Vertex
    else if(type_ == string("v"))
      readVertices(in,strLine);
    //case: TexCoord
    //case: Face
    else if(type_ == string("f"))
    {
      readFaces(in, strLine);
      break;
    }
    //default
    else
      in.getline(strLine,256);
  }//end while

  //assign number of vertices
  pMesh->vertices_ = vertices_;

  pMesh->numVerts_=vertices_.size();
  pMesh->numFaces_=faces_.size();
  pMesh->numTexCoords_=texCoords_.size();
  pMesh->texCoords_.reserve(texCoords_.size());
  pMesh->faces_.reserve(faces_.size());

  for(unsigned int i=0;i<vertices_.size();i++)
  {
    pMesh->vertices_[i] = vertices_[i];
  }

  for(unsigned int i=0;i<texCoords_.size();i++)
  {
    pMesh->texCoords_[i] = texCoords_[i];
  }

  for(unsigned int i=0;i<faces_.size();i++)
  {
    pMesh->faces_.push_back(TriFace(faces_[i].VertexIndex));
  }//end for

  //reset the vectors
  faces_.clear();
  texCoords_.clear();
  vertices_.clear();

}
Ejemplo n.º 4
0
void readShape(ifstream* file, Model* m){	
	readVertices(file, m);
	skipLine(file);		// Skip # verts
	skipLine(file);		// Skip blank line
	skipLine(file);		// Skip object name
	
	readFaces(file, m);
	skipLine(file);		// Skip # faces
}
Ejemplo n.º 5
0
PLYObject::PLYObject(FILE *in)
{
  int i;
  
  nproperties = 0;
  hasnormal = hascolor = hastexture = false;

  nv = nf = ne = 0;

  vertices = NULL;
#ifndef INTERLEAVED
  normals = NULL;
  colors = NULL;
#endif
  texcoords = NULL;
  faces = NULL;

  // init bounding box
  for (i = 0; i < 3; i++) {
    min[i] = FLT_MAX;
    max[i] = -FLT_MAX;
  }
  
  // default order
  for (i = 0; i < 11; i++)
    order[i] = -1;

  if (!checkHeader(in)) {
    fprintf(stderr, "Error: could not read PLY file.\n");
    return;
  }

#ifdef INTERLEAVED
  vertices = (RenderPoint*)calloc(nv, sizeof(RenderPoint));
#else
  vertices = (Vector3f*)calloc(nv, sizeof(Vector3f));
  normals = (Vector3f*)calloc(nv, sizeof(Vector3f));
  if (hascolor)
    colors = (Color3u*)calloc(nv, sizeof(Color3u));
#endif
  if (hastexture){
	texcoords = (Texture2f*)calloc(nf, sizeof(Texture2f));
  }

  faces = (Index3i*)calloc(nf, sizeof(Index3i));
  fnormals = (Vector3f*)calloc(nf, sizeof(Vector3f));

  readVertices(in);
  readFaces(in);
}
Ejemplo n.º 6
0
void PartitionIO<MeshType>::read (mesh_ptrtype& meshPart)
{
    meshPart.reset();
    M_meshPartIn.reset (new mesh_type);

    M_HDF5IO.openFile (M_fileName, M_comm, true);
    readStats();
    readPoints();
    readEdges();
    readFaces();
    readElements();
    M_HDF5IO.closeFile();

    meshPart = M_meshPartIn;
    M_meshPartIn.reset();
}
MeshData* LoadObj::readObjFile(std::string pObj)
{
	bool first = true;
	fstream f(pObj.c_str());
	string tmp;

	if(f)
	{
		while(f.eof() != true)
		{
			f >> tmp;

			if(tmp == "v")
				readVertices(f);
			if(tmp == "vt")
				readTexC(f);
			if(tmp == "vn")
				readNormal(f);
			if(tmp == "f")	
				readFaces(f);
			if(tmp == "mtllib")
				readMtl(f);
			if(tmp == "g")
				readGroup(f);
			if(f.eof())
				break;
		}
	}

	MeshData* data = new MeshData();

	data->position			= position;
	data->textureCoordinate	= textureCoordinate;
	data->normal			= normal;

	data->vertices			= vertices;
	data->indices			= indices;

	reset();

	return data;
}