Fix Path functions

Fix XFilePrefix for mesh name
Add Color for faces in Step Export
pull/549/head
Madrich 2015-05-02 12:19:20 +02:00
parent 2dde962f0d
commit b6d91ec11a
3 changed files with 30 additions and 12 deletions

View File

@ -171,12 +171,12 @@ bool DefaultIOSystem::ComparePaths (const char* one, const char* second) const
std::string DefaultIOSystem::fileName(std::string path)
{
std::string ret = path;
std::less<const char*> comp;
const char* end_path = comp(strrchr(path.c_str(), '\\'), strrchr(path.c_str(), '/')) ? strrchr(path.c_str(), '/') : strrchr(path.c_str(), '\\');
if(end_path != NULL) ret = ret.substr(end_path + 1 - path.c_str(), ret.npos);
std::size_t last = ret.find_last_of("\\/");
if (last != std::string::npos) ret = ret.substr(last + 1);
return ret;
}
std::string DefaultIOSystem::completeBaseName(std::string path)
{
std::string ret = fileName(path);
@ -185,12 +185,12 @@ std::string DefaultIOSystem::completeBaseName(std::string path)
return ret;
}
std::string DefaultIOSystem::absolutePath(std::string path)
{
std::string ret;
std::less<const char*> comp;
const char* end_path = comp(strrchr(path.c_str(), '\\'), strrchr(path.c_str(), '/')) ? strrchr(path.c_str(), '/') : strrchr(path.c_str(), '\\');
if(end_path != NULL) ret = std::string(path.c_str(), end_path + 1 - path.c_str());
std::string ret = path;
std::size_t last = ret.find_last_of("\\/");
if (last != std::string::npos) ret = ret.substr(0, last);
return ret;
}

View File

@ -178,6 +178,12 @@ void StepExporter::WriteFile()
mOutput.setf(std::ios::fixed);
mOutput.precision(16); // precission for double
// standard color
aiColor4D fColor;
fColor.r = 0.8f;
fColor.g = 0.8f;
fColor.b = 0.8f;
int ind = 100; // the start index to be used
int faceEntryLen = 30; // number of entries for a triangle/face
// prepare unique (count triangles and vertices)
@ -310,6 +316,18 @@ void StepExporter::WriteFile()
int pid1 = uniqueVerts.find(v1)->second;
int pid2 = uniqueVerts.find(v2)->second;
int pid3 = uniqueVerts.find(v3)->second;
// mean vertex color for the face if available
if (mesh->HasVertexColors(0))
{
fColor.r = 0.0;
fColor.g = 0.0;
fColor.b = 0.0;
fColor += mesh->mColors[0][face->mIndices[0]];
fColor += mesh->mColors[0][face->mIndices[1]];
fColor += mesh->mColors[0][face->mIndices[2]];
fColor /= 3.0f;
}
int sid = ind; // the sub index
mOutput << "#" << sid << "=STYLED_ITEM('',(#" << sid+1 << "),#" << sid+8 << ")" << endstr; /* the item that must be referenced in #1 */
@ -320,7 +338,7 @@ void StepExporter::WriteFile()
mOutput << "#" << sid+4 << "=SURFACE_STYLE_FILL_AREA(#" << sid+5 << ")" << endstr;
mOutput << "#" << sid+5 << "=FILL_AREA_STYLE('',(#" << sid+6 << "))" << endstr;
mOutput << "#" << sid+6 << "=FILL_AREA_STYLE_COLOUR('',#" << sid+7 << ")" << endstr;
mOutput << "#" << sid+7 << "=COLOUR_RGB('',0.0,0.0,1.0)" << endstr;
mOutput << "#" << sid+7 << "=COLOUR_RGB(''," << fColor.r << "," << fColor.g << "," << fColor.b << ")" << endstr;
/* this is the geometry */
mOutput << "#" << sid+8 << "=FACE_SURFACE('',(#" << sid+13 << "),#" << sid+9<< ",.T.)" << endstr; /* the face that must be referenced in 29 */

View File

@ -500,13 +500,13 @@ void XFileExporter::WriteMesh(aiMesh* mesh)
std::string XFileExporter::toXFileString(aiString &name)
{
std::string pref = "NN_"; // node name prefix to prevent unexpected start of string
std::string pref = ""; // node name prefix to prevent unexpected start of string
std::string str = pref + std::string(name.C_Str());
for (int i=0; i < (int) str.length(); ++i)
{
if ((str[i] >= 48 && str[i] <= 57) || // 0-9
(str[i] >= 65 && str[i] <= 90) || // A-Z
(str[i] >= 97 && str[i] <= 122)) // a-z
if ((str[i] >= '0' && str[i] <= '9') || // 0-9
(str[i] >= 'A' && str[i] <= 'Z') || // A-Z
(str[i] >= 'a' && str[i] <= 'z')) // a-z
continue;
str[i] = '_';
}