void BaseObject::LoadData(string filename)
{
string garbage2 = "";
char garbage;
point temp;
uvPoint temp2;
face tempFace;
group tempGroup;
materialIndex tempMat;
tempMat.polyIndex = 0;
tempGroup.groupRotation.x = 0;
tempGroup.groupRotation.y = 0;
tempGroup.groupRotation.z = 0;
tempFace.vtIndex = NULL;
ifstream infile, infile2;
infile.open(filename.c_str());
infile2.open(pivotLoc.c_str());
while(infile)
{
infile >> garbage;
if(garbage == '#')
{
getline(infile, garbage2);
}
else if(garbage == 'm')
{
infile >> garbage2;
infile >> materialLoc;
}
else if(garbage == 'v')
{
infile >> garbage;
if(garbage == 'n')
{
infile >> temp.x >> temp.y >> temp.z;
vn.push_back(temp);
}
else if(garbage == 't')
{
infile >> temp2.x >> temp2.y;
vt.push_back(temp2);
}
else
{
infile.unget();
infile >> temp.x >> temp.y >> temp.z;
v.push_back(temp);
}
}
else if(garbage == 'g')
{
numGroups++;
infile>> tempGroup.groupName;
infile >> garbage;
while(garbage == 'f' || garbage == 'u')
{
if(garbage == 'u')
{
infile >> garbage2;
infile >> tempMat.materialName;
infile >> garbage;
}
while(garbage == 'f')
{
infile >> tempFace.vIndex[0] >> garbage;
infile >> garbage;
if(garbage != '/')
{
infile.unget();
tempFace.vtIndex = new int[3];
infile >> tempFace.vtIndex[0] >> garbage >> tempFace.vnIndex[0];
infile >> tempFace.vIndex[1] >> garbage >> tempFace.vtIndex[1] >> garbage >> tempFace.vnIndex[1];
infile >> tempFace.vIndex[2] >> garbage >> tempFace.vtIndex[2] >> garbage >> tempFace.vnIndex[2];
tempGroup.faces.push_back(tempFace);
tempFace.vtIndex = NULL;
tempMat.polyIndex++;
infile >> garbage;
}
else
{
infile >> tempFace.vnIndex[0];
infile >> tempFace.vIndex[1] >> garbage >> garbage >> tempFace.vnIndex[1];
infile >> tempFace.vIndex[2] >> garbage >> garbage >> tempFace.vnIndex[2];
tempGroup.faces.push_back(tempFace);
tempMat.polyIndex++;
infile >> garbage;
}
}
tempGroup.materials.push_back(tempMat);
}
infile.unget();
infile2 >> garbage2;
while(infile2)
{
if(garbage2 == "push")
{
infile2 >> garbage2;
if(garbage2 == tempGroup.groupName)
{
infile2 >> tempGroup.pivotPoint.x >> tempGroup.pivotPoint.y >> tempGroup.pivotPoint.z;
}
}
infile2 >> garbage2;
}
groups.push_back(tempGroup);
tempGroup.groupName = "";
tempGroup.faces.clear();
tempGroup.materials.clear();
tempGroup.pivotPoint.x = 0;
tempGroup.pivotPoint.y = 0;
tempGroup.pivotPoint.z = 0;
tempMat.polyIndex = 0;
}
}
infile.close();
infile2.close();
}
while(garbage == 'f')
{
infile >> tempFace.vIndex[0] >> garbage;
infile >> garbage;
if(garbage != '/')
{
infile.unget();
tempFace.vtIndex = new int[3];
infile >> tempFace.vtIndex[0] >> garbage >> tempFace.vnIndex[0];
infile >> tempFace.vIndex[1] >> garbage >> tempFace.vtIndex[1] >> garbage >> tempFace.vnIndex[1];
infile >> tempFace.vIndex[2] >> garbage >> tempFace.vtIndex[2] >> garbage >> tempFace.vnIndex[2];
tempGroup.faces.push_back(tempFace);
tempFace.vtIndex = NULL;
tempMat.polyIndex++;
infile >> garbage;
}
else
{
infile >> tempFace.vnIndex[0];
infile >> tempFace.vIndex[1] >> garbage >> garbage >> tempFace.vnIndex[1];
infile >> tempFace.vIndex[2] >> garbage >> garbage >> tempFace.vnIndex[2];
tempGroup.faces.push_back(tempFace);
tempMat.polyIndex++;
infile >> garbage;
}
}