use const chars
parent
79802ad836
commit
55fd820ed7
|
@ -102,13 +102,14 @@ private:
|
||||||
// preserves the mesh's given name if it has one. |index| is the index
|
// preserves the mesh's given name if it has one. |index| is the index
|
||||||
// of the mesh in |aiScene::mMeshes|.
|
// of the mesh in |aiScene::mMeshes|.
|
||||||
std::string GetMeshName(const aiMesh &mesh, unsigned int index, const aiNode &node) {
|
std::string GetMeshName(const aiMesh &mesh, unsigned int index, const aiNode &node) {
|
||||||
static const std::string underscore = "_";
|
static const char underscore = '_';
|
||||||
char postfix[10] = { 0 };
|
char postfix[10] = { 0 };
|
||||||
ASSIMP_itoa10(postfix, index);
|
ASSIMP_itoa10(postfix, index);
|
||||||
|
|
||||||
std::string result = node.mName.C_Str();
|
std::string result = node.mName.C_Str();
|
||||||
if (mesh.mName.length > 0) {
|
if (mesh.mName.length > 0) {
|
||||||
result += underscore + mesh.mName.C_Str();
|
result += underscore;
|
||||||
|
result += mesh.mName.C_Str();
|
||||||
}
|
}
|
||||||
return result + underscore + postfix;
|
return result + underscore + postfix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,62 +44,65 @@ namespace Assimp {
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
|
|
||||||
namespace XmlTag {
|
namespace XmlTag {
|
||||||
|
// Root tag
|
||||||
|
static const char *RootTag = "3MF";
|
||||||
|
|
||||||
// Meta-data
|
// Meta-data
|
||||||
static const std::string meta = "metadata";
|
static const char *meta = "metadata";
|
||||||
static const std::string meta_name = "name";
|
static const char *meta_name = "name";
|
||||||
|
|
||||||
// Model-data specific tags
|
// Model-data specific tags
|
||||||
static const std::string model = "model";
|
static const char *model = "model";
|
||||||
static const std::string model_unit = "unit";
|
static const char *model_unit = "unit";
|
||||||
static const std::string metadata = "metadata";
|
static const char *metadata = "metadata";
|
||||||
static const std::string resources = "resources";
|
static const char *resources = "resources";
|
||||||
static const std::string object = "object";
|
static const char *object = "object";
|
||||||
static const std::string mesh = "mesh";
|
static const char *mesh = "mesh";
|
||||||
static const std::string components = "components";
|
static const char *components = "components";
|
||||||
static const std::string component = "component";
|
static const char *component = "component";
|
||||||
static const std::string vertices = "vertices";
|
static const char *vertices = "vertices";
|
||||||
static const std::string vertex = "vertex";
|
static const char *vertex = "vertex";
|
||||||
static const std::string triangles = "triangles";
|
static const char *triangles = "triangles";
|
||||||
static const std::string triangle = "triangle";
|
static const char *triangle = "triangle";
|
||||||
static const std::string x = "x";
|
static const char *x = "x";
|
||||||
static const std::string y = "y";
|
static const char *y = "y";
|
||||||
static const std::string z = "z";
|
static const char *z = "z";
|
||||||
static const std::string v1 = "v1";
|
static const char *v1 = "v1";
|
||||||
static const std::string v2 = "v2";
|
static const char *v2 = "v2";
|
||||||
static const std::string v3 = "v3";
|
static const char *v3 = "v3";
|
||||||
static const std::string id = "id";
|
static const char *id = "id";
|
||||||
static const std::string pid = "pid";
|
static const char *pid = "pid";
|
||||||
static const std::string pindex = "pindex";
|
static const char *pindex = "pindex";
|
||||||
static const std::string p1 = "p1";
|
static const char *p1 = "p1";
|
||||||
static const std::string name = "name";
|
static const char *name = "name";
|
||||||
static const std::string type = "type";
|
static const char *type = "type";
|
||||||
static const std::string build = "build";
|
static const char *build = "build";
|
||||||
static const std::string item = "item";
|
static const char *item = "item";
|
||||||
static const std::string objectid = "objectid";
|
static const char *objectid = "objectid";
|
||||||
static const std::string transform = "transform";
|
static const char *transform = "transform";
|
||||||
|
|
||||||
// Material definitions
|
// Material definitions
|
||||||
static const std::string basematerials = "basematerials";
|
static const char *basematerials = "basematerials";
|
||||||
static const std::string basematerials_id = "id";
|
static const char *basematerials_id = "id";
|
||||||
static const std::string basematerials_base = "base";
|
static const char *basematerials_base = "base";
|
||||||
static const std::string basematerials_name = "name";
|
static const char *basematerials_name = "name";
|
||||||
static const std::string basematerials_displaycolor = "displaycolor";
|
static const char *basematerials_displaycolor = "displaycolor";
|
||||||
|
|
||||||
// Meta info tags
|
// Meta info tags
|
||||||
static const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
|
static const char *CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
|
||||||
static const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
|
static const char *ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
|
||||||
static const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
|
static const char *SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
|
||||||
static const std::string SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
static const char *SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
||||||
static const std::string RELS_RELATIONSHIP_CONTAINER = "Relationships";
|
static const char *RELS_RELATIONSHIP_CONTAINER = "Relationships";
|
||||||
static const std::string RELS_RELATIONSHIP_NODE = "Relationship";
|
static const char *RELS_RELATIONSHIP_NODE = "Relationship";
|
||||||
static const std::string RELS_ATTRIB_TARGET = "Target";
|
static const char *RELS_ATTRIB_TARGET = "Target";
|
||||||
static const std::string RELS_ATTRIB_TYPE = "Type";
|
static const char *RELS_ATTRIB_TYPE = "Type";
|
||||||
static const std::string RELS_ATTRIB_ID = "Id";
|
static const char *RELS_ATTRIB_ID = "Id";
|
||||||
static const std::string PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
static const char *PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
||||||
static const std::string PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
|
static const char *PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
|
||||||
static const std::string PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
|
static const char *PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
|
||||||
static const std::string PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
static const char *PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
||||||
static const std::string PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
|
static const char *PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Namespace D3MF
|
} // Namespace D3MF
|
||||||
|
|
|
@ -307,18 +307,26 @@ void D3MFExporter::writeMesh(aiMesh *mesh) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mModelOutput << "<" << XmlTag::mesh << ">" << std::endl;
|
mModelOutput << "<"
|
||||||
mModelOutput << "<" << XmlTag::vertices << ">" << std::endl;
|
<< XmlTag::mesh
|
||||||
|
<< ">" << "\n";
|
||||||
|
mModelOutput << "<"
|
||||||
|
<< XmlTag::vertices
|
||||||
|
<< ">" << "\n";
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
||||||
writeVertex(mesh->mVertices[i]);
|
writeVertex(mesh->mVertices[i]);
|
||||||
}
|
}
|
||||||
mModelOutput << "</" << XmlTag::vertices << ">" << std::endl;
|
mModelOutput << "</"
|
||||||
|
<< XmlTag::vertices << ">"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
const unsigned int matIdx(mesh->mMaterialIndex);
|
const unsigned int matIdx(mesh->mMaterialIndex);
|
||||||
|
|
||||||
writeFaces(mesh, matIdx);
|
writeFaces(mesh, matIdx);
|
||||||
|
|
||||||
mModelOutput << "</" << XmlTag::mesh << ">" << std::endl;
|
mModelOutput << "</"
|
||||||
|
<< XmlTag::mesh << ">"
|
||||||
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFExporter::writeVertex(const aiVector3D &pos) {
|
void D3MFExporter::writeVertex(const aiVector3D &pos) {
|
||||||
|
@ -334,27 +342,34 @@ void D3MFExporter::writeFaces(aiMesh *mesh, unsigned int matIdx) {
|
||||||
if (!mesh->HasFaces()) {
|
if (!mesh->HasFaces()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mModelOutput << "<" << XmlTag::triangles << ">" << std::endl;
|
mModelOutput << "<"
|
||||||
|
<< XmlTag::triangles << ">"
|
||||||
|
<< "\n";
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
for (unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
||||||
aiFace ¤tFace = mesh->mFaces[i];
|
aiFace ¤tFace = mesh->mFaces[i];
|
||||||
mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[0] << "\" v2=\""
|
mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[0] << "\" v2=\""
|
||||||
<< currentFace.mIndices[1] << "\" v3=\"" << currentFace.mIndices[2]
|
<< currentFace.mIndices[1] << "\" v3=\"" << currentFace.mIndices[2]
|
||||||
<< "\" pid=\"1\" p1=\"" + ai_to_string(matIdx) + "\" />";
|
<< "\" pid=\"1\" p1=\"" + ai_to_string(matIdx) + "\" />";
|
||||||
mModelOutput << std::endl;
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
mModelOutput << "</" << XmlTag::triangles << ">";
|
mModelOutput << "</"
|
||||||
mModelOutput << std::endl;
|
<< XmlTag::triangles
|
||||||
|
<< ">";
|
||||||
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFExporter::writeBuild() {
|
void D3MFExporter::writeBuild() {
|
||||||
mModelOutput << "<" << XmlTag::build << ">" << std::endl;
|
mModelOutput << "<"
|
||||||
|
<< XmlTag::build
|
||||||
|
<< ">"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
for (size_t i = 0; i < mBuildItems.size(); ++i) {
|
for (size_t i = 0; i < mBuildItems.size(); ++i) {
|
||||||
mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 2 << "\"/>";
|
mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 2 << "\"/>";
|
||||||
mModelOutput << std::endl;
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
mModelOutput << "</" << XmlTag::build << ">";
|
mModelOutput << "</" << XmlTag::build << ">";
|
||||||
mModelOutput << std::endl;
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFExporter::zipContentType(const std::string &filename) {
|
void D3MFExporter::zipContentType(const std::string &filename) {
|
||||||
|
|
|
@ -72,32 +72,39 @@ enum class ResourceType {
|
||||||
RT_Unknown
|
RT_Unknown
|
||||||
}; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...)
|
}; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...)
|
||||||
|
|
||||||
class Resource
|
class Resource {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Resource(int id) :
|
|
||||||
mId(id) {}
|
|
||||||
|
|
||||||
virtual ~Resource() {}
|
|
||||||
|
|
||||||
int mId;
|
int mId;
|
||||||
|
|
||||||
virtual ResourceType getType() {
|
Resource(int id) :
|
||||||
|
mId(id) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Resource() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ResourceType getType() const {
|
||||||
return ResourceType::RT_Unknown;
|
return ResourceType::RT_Unknown;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class BaseMaterials : public Resource {
|
class BaseMaterials : public Resource {
|
||||||
public:
|
public:
|
||||||
BaseMaterials(int id) :
|
|
||||||
Resource(id),
|
|
||||||
mMaterials(),
|
|
||||||
mMaterialIndex() {}
|
|
||||||
|
|
||||||
std::vector<aiMaterial *> mMaterials;
|
std::vector<aiMaterial *> mMaterials;
|
||||||
std::vector<unsigned int> mMaterialIndex;
|
std::vector<unsigned int> mMaterialIndex;
|
||||||
|
|
||||||
virtual ResourceType getType() {
|
BaseMaterials(int id) :
|
||||||
|
Resource(id),
|
||||||
|
mMaterials(),
|
||||||
|
mMaterialIndex() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
~BaseMaterials() = default;
|
||||||
|
|
||||||
|
ResourceType getType() const override {
|
||||||
return ResourceType::RT_BaseMaterials;
|
return ResourceType::RT_BaseMaterials;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -109,24 +116,26 @@ struct Component {
|
||||||
|
|
||||||
class Object : public Resource {
|
class Object : public Resource {
|
||||||
public:
|
public:
|
||||||
std::vector<aiMesh*> mMeshes;
|
std::vector<aiMesh *> mMeshes;
|
||||||
std::vector<unsigned int> mMeshIndex;
|
std::vector<unsigned int> mMeshIndex;
|
||||||
std::vector<Component> mComponents;
|
std::vector<Component> mComponents;
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
|
||||||
Object(int id) :
|
Object(int id) :
|
||||||
Resource(id),
|
Resource(id),
|
||||||
mName(std::string("Object_") + ai_to_string(id)) {}
|
mName(std::string("Object_") + ai_to_string(id)) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
virtual ResourceType getType() {
|
~Object() = default;
|
||||||
|
|
||||||
|
ResourceType getType() const override {
|
||||||
return ResourceType::RT_Object;
|
return ResourceType::RT_Object;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class XmlSerializer {
|
class XmlSerializer {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
XmlSerializer(XmlParser *xmlParser) :
|
XmlSerializer(XmlParser *xmlParser) :
|
||||||
mResourcesDictionnary(),
|
mResourcesDictionnary(),
|
||||||
mMaterialCount(0),
|
mMaterialCount(0),
|
||||||
|
@ -136,7 +145,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
~XmlSerializer() {
|
~XmlSerializer() {
|
||||||
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
|
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); ++it ) {
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,28 +155,28 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scene->mRootNode = new aiNode("3MF");
|
scene->mRootNode = new aiNode(XmlTag::RootTag);
|
||||||
|
|
||||||
XmlNode node = mXmlParser->getRootNode().child("model");
|
XmlNode node = mXmlParser->getRootNode().child(XmlTag::model);
|
||||||
if (node.empty()) {
|
if (node.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
XmlNode resNode = node.child("resources");
|
XmlNode resNode = node.child(XmlTag::resources);
|
||||||
for (XmlNode currentNode = resNode.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
for (auto ¤tNode : resNode.children()) {
|
||||||
const std::string ¤tNodeName = currentNode.name();
|
const std::string ¤tNodeName = currentNode.name();
|
||||||
if (currentNodeName == D3MF::XmlTag::object) {
|
if (currentNodeName == XmlTag::object) {
|
||||||
ReadObject(currentNode);;
|
ReadObject(currentNode);
|
||||||
} else if (currentNodeName == D3MF::XmlTag::basematerials) {
|
} else if (currentNodeName == XmlTag::basematerials) {
|
||||||
ReadBaseMaterials(currentNode);
|
ReadBaseMaterials(currentNode);
|
||||||
} else if (currentNodeName == D3MF::XmlTag::meta) {
|
} else if (currentNodeName == XmlTag::meta) {
|
||||||
ReadMetadata(currentNode);
|
ReadMetadata(currentNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlNode buildNode = node.child("build");
|
XmlNode buildNode = node.child(XmlTag::build);
|
||||||
for (XmlNode currentNode = buildNode.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
for (auto ¤tNode : resNode.children()) {
|
||||||
const std::string ¤tNodeName = currentNode.name();
|
const std::string ¤tNodeName = currentNode.name();
|
||||||
if (currentNodeName == D3MF::XmlTag::item) {
|
if (currentNodeName == XmlTag::item) {
|
||||||
int objectId = -1;
|
int objectId = -1;
|
||||||
std::string transformationMatrixStr;
|
std::string transformationMatrixStr;
|
||||||
aiMatrix4x4 transformationMatrix;
|
aiMatrix4x4 transformationMatrix;
|
||||||
|
@ -186,7 +195,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// import the metadata
|
// import the metadata
|
||||||
if (!mMetaData.empty()) {
|
if (!mMetaData.empty()) {
|
||||||
const size_t numMeta(mMetaData.size());
|
const size_t numMeta(mMetaData.size());
|
||||||
|
@ -201,22 +209,21 @@ public:
|
||||||
scene->mNumMeshes = static_cast<unsigned int>(mMeshCount);
|
scene->mNumMeshes = static_cast<unsigned int>(mMeshCount);
|
||||||
if (scene->mNumMeshes != 0) {
|
if (scene->mNumMeshes != 0) {
|
||||||
scene->mMeshes = new aiMesh *[scene->mNumMeshes]();
|
scene->mMeshes = new aiMesh *[scene->mNumMeshes]();
|
||||||
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
|
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); ++it) {
|
||||||
if (it->second->getType() == ResourceType::RT_Object) {
|
if (it->second->getType() == ResourceType::RT_Object) {
|
||||||
Object *obj = static_cast<Object*>(it->second);
|
Object *obj = static_cast<Object *>(it->second);
|
||||||
for (unsigned int i = 0; i < obj->mMeshes.size(); ++i) {
|
for (unsigned int i = 0; i < obj->mMeshes.size(); ++i) {
|
||||||
scene->mMeshes[obj->mMeshIndex[i]] = obj->mMeshes[i];
|
scene->mMeshes[obj->mMeshIndex[i]] = obj->mMeshes[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// import the materials
|
// import the materials
|
||||||
scene->mNumMaterials = static_cast<unsigned int>(mMaterialCount);
|
scene->mNumMaterials = mMaterialCount;
|
||||||
if (scene->mNumMaterials != 0) {
|
if (scene->mNumMaterials != 0) {
|
||||||
scene->mMaterials = new aiMaterial *[scene->mNumMaterials];
|
scene->mMaterials = new aiMaterial *[scene->mNumMaterials];
|
||||||
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
|
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); ++it) {
|
||||||
if (it->second->getType() == ResourceType::RT_BaseMaterials) {
|
if (it->second->getType() == ResourceType::RT_BaseMaterials) {
|
||||||
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
|
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
|
||||||
for (unsigned int i = 0; i < baseMaterials->mMaterials.size(); ++i) {
|
for (unsigned int i = 0; i < baseMaterials->mMaterials.size(); ++i) {
|
||||||
|
@ -228,35 +235,36 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addObjectToNode(aiNode *parent, Object *obj, aiMatrix4x4 nodeTransform) {
|
||||||
|
ai_assert(nullptr != obj);
|
||||||
|
|
||||||
void addObjectToNode(aiNode* parent, Object* obj, aiMatrix4x4 nodeTransform) {
|
|
||||||
aiNode *sceneNode = new aiNode(obj->mName);
|
aiNode *sceneNode = new aiNode(obj->mName);
|
||||||
sceneNode->mNumMeshes = static_cast<unsigned int>(obj->mMeshes.size());
|
sceneNode->mNumMeshes = static_cast<unsigned int>(obj->mMeshes.size());
|
||||||
sceneNode->mMeshes = new unsigned int[sceneNode->mNumMeshes];
|
sceneNode->mMeshes = new unsigned int[sceneNode->mNumMeshes];
|
||||||
std::copy(obj->mMeshIndex.begin(), obj->mMeshIndex.end(), sceneNode->mMeshes);
|
std::copy(obj->mMeshIndex.begin(), obj->mMeshIndex.end(), sceneNode->mMeshes);
|
||||||
|
|
||||||
sceneNode->mTransformation = nodeTransform;
|
sceneNode->mTransformation = nodeTransform;
|
||||||
|
if (nullptr != parent) {
|
||||||
parent->addChildren(1, &sceneNode);
|
parent->addChildren(1, &sceneNode);
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < obj->mComponents.size(); ++i) {
|
for (size_t i = 0; i < obj->mComponents.size(); ++i) {
|
||||||
Component c = obj->mComponents[i];
|
Component c = obj->mComponents[i];
|
||||||
auto it = mResourcesDictionnary.find(c.mObjectId);
|
auto it = mResourcesDictionnary.find(c.mObjectId);
|
||||||
if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
|
if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
|
||||||
addObjectToNode(sceneNode, static_cast<Object*>(it->second), c.mTransformation);
|
addObjectToNode(sceneNode, static_cast<Object *>(it->second), c.mTransformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getNodeAttribute(const XmlNode& node, const std::string& attribute, std::string& value) {
|
bool getNodeAttribute(const XmlNode &node, const std::string &attribute, std::string &value) {
|
||||||
pugi::xml_attribute objectAttribute = node.attribute(attribute.c_str());
|
pugi::xml_attribute objectAttribute = node.attribute(attribute.c_str());
|
||||||
if (!objectAttribute.empty()) {
|
if (!objectAttribute.empty()) {
|
||||||
value = objectAttribute.as_string();
|
value = objectAttribute.as_string();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getNodeAttribute(const XmlNode &node, const std::string &attribute, int &value) {
|
bool getNodeAttribute(const XmlNode &node, const std::string &attribute, int &value) {
|
||||||
|
@ -265,9 +273,9 @@ private:
|
||||||
if (ret) {
|
if (ret) {
|
||||||
value = std::atoi(strValue.c_str());
|
value = std::atoi(strValue.c_str());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
return false;
|
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
aiMatrix4x4 parseTransformMatrix(std::string matrixStr) {
|
aiMatrix4x4 parseTransformMatrix(std::string matrixStr) {
|
||||||
|
@ -287,7 +295,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentNumber.size() > 0) {
|
if (currentNumber.size() > 0) {
|
||||||
float f = std::stof(currentNumber);
|
const float f = std::stof(currentNumber);
|
||||||
numbers.push_back(f);
|
numbers.push_back(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,29 +319,26 @@ private:
|
||||||
transformMatrix.b4 = numbers[10];
|
transformMatrix.b4 = numbers[10];
|
||||||
transformMatrix.c4 = numbers[11];
|
transformMatrix.c4 = numbers[11];
|
||||||
transformMatrix.d4 = 1;
|
transformMatrix.d4 = 1;
|
||||||
|
|
||||||
return transformMatrix;
|
return transformMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadObject(XmlNode &node) {
|
void ReadObject(XmlNode &node) {
|
||||||
int id = -1, pid = -1, pindex = -1;
|
int id = -1, pid = -1, pindex = -1;
|
||||||
bool hasId = getNodeAttribute(node, D3MF::XmlTag::id, id);
|
bool hasId = getNodeAttribute(node, XmlTag::id, id);
|
||||||
//bool hasType = getNodeAttribute(node, D3MF::XmlTag::type, type); not used currently
|
bool hasPid = getNodeAttribute(node, XmlTag::pid, pid);
|
||||||
bool hasPid = getNodeAttribute(node, D3MF::XmlTag::pid, pid);
|
bool hasPindex = getNodeAttribute(node, XmlTag::pindex, pindex);
|
||||||
bool hasPindex = getNodeAttribute(node, D3MF::XmlTag::pindex, pindex);
|
|
||||||
|
|
||||||
std::string idStr = ai_to_string(id);
|
|
||||||
|
|
||||||
if (!hasId) {
|
if (!hasId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *obj = new Object(id);
|
Object *obj = new Object(id);
|
||||||
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
if (currentName == D3MF::XmlTag::mesh) {
|
if (currentName == D3MF::XmlTag::mesh) {
|
||||||
auto mesh = ReadMesh(currentNode);
|
auto mesh = ReadMesh(currentNode);
|
||||||
mesh->mName.Set(idStr);
|
mesh->mName.Set(ai_to_string(id));
|
||||||
|
|
||||||
if (hasPid) {
|
if (hasPid) {
|
||||||
auto it = mResourcesDictionnary.find(pid);
|
auto it = mResourcesDictionnary.find(pid);
|
||||||
|
@ -347,7 +352,7 @@ private:
|
||||||
obj->mMeshIndex.push_back(mMeshCount);
|
obj->mMeshIndex.push_back(mMeshCount);
|
||||||
mMeshCount++;
|
mMeshCount++;
|
||||||
} else if (currentName == D3MF::XmlTag::components) {
|
} else if (currentName == D3MF::XmlTag::components) {
|
||||||
for (XmlNode currentSubNode = currentNode.first_child(); currentSubNode; currentSubNode = currentSubNode.next_sibling()) {
|
for (XmlNode ¤tSubNode : currentNode.children()) {
|
||||||
if (currentSubNode.name() == D3MF::XmlTag::component) {
|
if (currentSubNode.name() == D3MF::XmlTag::component) {
|
||||||
int objectId = -1;
|
int objectId = -1;
|
||||||
std::string componentTransformStr;
|
std::string componentTransformStr;
|
||||||
|
@ -369,21 +374,20 @@ private:
|
||||||
aiMesh *ReadMesh(XmlNode &node) {
|
aiMesh *ReadMesh(XmlNode &node) {
|
||||||
aiMesh *mesh = new aiMesh();
|
aiMesh *mesh = new aiMesh();
|
||||||
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
if (currentName == D3MF::XmlTag::vertices) {
|
if (currentName == XmlTag::vertices) {
|
||||||
ImportVertices(currentNode, mesh);
|
ImportVertices(currentNode, mesh);
|
||||||
} else if (currentName == D3MF::XmlTag::triangles) {
|
} else if (currentName == XmlTag::triangles) {
|
||||||
ImportTriangles(currentNode, mesh);
|
ImportTriangles(currentNode, mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadMetadata(XmlNode &node) {
|
void ReadMetadata(XmlNode &node) {
|
||||||
pugi::xml_attribute attribute = node.attribute(D3MF::XmlTag::meta_name.c_str());
|
pugi::xml_attribute attribute = node.attribute(D3MF::XmlTag::meta_name);
|
||||||
const std::string name = attribute.as_string();
|
const std::string name = attribute.as_string();
|
||||||
const std::string value = node.value();
|
const std::string value = node.value();
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
|
@ -398,7 +402,7 @@ private:
|
||||||
|
|
||||||
void ImportVertices(XmlNode &node, aiMesh *mesh) {
|
void ImportVertices(XmlNode &node, aiMesh *mesh) {
|
||||||
std::vector<aiVector3D> vertices;
|
std::vector<aiVector3D> vertices;
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
if (currentName == D3MF::XmlTag::vertex) {
|
if (currentName == D3MF::XmlTag::vertex) {
|
||||||
vertices.push_back(ReadVertex(currentNode));
|
vertices.push_back(ReadVertex(currentNode));
|
||||||
|
@ -412,9 +416,9 @@ private:
|
||||||
|
|
||||||
aiVector3D ReadVertex(XmlNode &node) {
|
aiVector3D ReadVertex(XmlNode &node) {
|
||||||
aiVector3D vertex;
|
aiVector3D vertex;
|
||||||
vertex.x = ai_strtof(node.attribute(D3MF::XmlTag::x.c_str()).as_string(), nullptr);
|
vertex.x = ai_strtof(node.attribute(D3MF::XmlTag::x).as_string(), nullptr);
|
||||||
vertex.y = ai_strtof(node.attribute(D3MF::XmlTag::y.c_str()).as_string(), nullptr);
|
vertex.y = ai_strtof(node.attribute(D3MF::XmlTag::y).as_string(), nullptr);
|
||||||
vertex.z = ai_strtof(node.attribute(D3MF::XmlTag::z.c_str()).as_string(), nullptr);
|
vertex.z = ai_strtof(node.attribute(D3MF::XmlTag::z).as_string(), nullptr);
|
||||||
|
|
||||||
return vertex;
|
return vertex;
|
||||||
}
|
}
|
||||||
|
@ -433,8 +437,7 @@ private:
|
||||||
|
|
||||||
if (hasPid && hasP1) {
|
if (hasPid && hasP1) {
|
||||||
auto it = mResourcesDictionnary.find(pid);
|
auto it = mResourcesDictionnary.find(pid);
|
||||||
if (it != mResourcesDictionnary.end())
|
if (it != mResourcesDictionnary.end()) {
|
||||||
{
|
|
||||||
if (it->second->getType() == ResourceType::RT_BaseMaterials) {
|
if (it->second->getType() == ResourceType::RT_BaseMaterials) {
|
||||||
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
|
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
|
||||||
mesh->mMaterialIndex = baseMaterials->mMaterialIndex[p1];
|
mesh->mMaterialIndex = baseMaterials->mMaterialIndex[p1];
|
||||||
|
@ -457,9 +460,9 @@ private:
|
||||||
|
|
||||||
face.mNumIndices = 3;
|
face.mNumIndices = 3;
|
||||||
face.mIndices = new unsigned int[face.mNumIndices];
|
face.mIndices = new unsigned int[face.mNumIndices];
|
||||||
face.mIndices[0] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v1.c_str()).as_string()));
|
face.mIndices[0] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v1).as_string()));
|
||||||
face.mIndices[1] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v2.c_str()).as_string()));
|
face.mIndices[1] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v2).as_string()));
|
||||||
face.mIndices[2] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v3.c_str()).as_string()));
|
face.mIndices[2] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v3).as_string()));
|
||||||
|
|
||||||
return face;
|
return face;
|
||||||
}
|
}
|
||||||
|
@ -467,11 +470,10 @@ private:
|
||||||
void ReadBaseMaterials(XmlNode &node) {
|
void ReadBaseMaterials(XmlNode &node) {
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if (getNodeAttribute(node, D3MF::XmlTag::basematerials_id, id)) {
|
if (getNodeAttribute(node, D3MF::XmlTag::basematerials_id, id)) {
|
||||||
BaseMaterials* baseMaterials = new BaseMaterials(id);
|
BaseMaterials *baseMaterials = new BaseMaterials(id);
|
||||||
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling())
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
{
|
if (currentNode.name() == XmlTag::basematerials_base) {
|
||||||
if (currentNode.name() == D3MF::XmlTag::basematerials_base) {
|
|
||||||
baseMaterials->mMaterialIndex.push_back(mMaterialCount);
|
baseMaterials->mMaterialIndex.push_back(mMaterialCount);
|
||||||
baseMaterials->mMaterials.push_back(readMaterialDef(currentNode, id));
|
baseMaterials->mMaterials.push_back(readMaterialDef(currentNode, id));
|
||||||
mMaterialCount++;
|
mMaterialCount++;
|
||||||
|
@ -488,7 +490,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
//format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1)
|
//format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1)
|
||||||
const size_t len(strlen(color));
|
const size_t len = strlen(color);
|
||||||
if (9 != len && 7 != len) {
|
if (9 != len && 7 != len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -517,7 +519,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void assignDiffuseColor(XmlNode &node, aiMaterial *mat) {
|
void assignDiffuseColor(XmlNode &node, aiMaterial *mat) {
|
||||||
const char *color = node.attribute(D3MF::XmlTag::basematerials_displaycolor.c_str()).as_string();
|
const char *color = node.attribute(XmlTag::basematerials_displaycolor).as_string();
|
||||||
aiColor4D diffuse;
|
aiColor4D diffuse;
|
||||||
if (parseColor(color, diffuse)) {
|
if (parseColor(color, diffuse)) {
|
||||||
mat->AddProperty<aiColor4D>(&diffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
|
mat->AddProperty<aiColor4D>(&diffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
|
@ -531,7 +533,7 @@ private:
|
||||||
bool hasName = getNodeAttribute(node, D3MF::XmlTag::basematerials_name, name);
|
bool hasName = getNodeAttribute(node, D3MF::XmlTag::basematerials_name, name);
|
||||||
|
|
||||||
std::string stdMaterialName;
|
std::string stdMaterialName;
|
||||||
std::string strId(ai_to_string(basematerialsId));
|
const std::string strId(ai_to_string(basematerialsId));
|
||||||
stdMaterialName += "id";
|
stdMaterialName += "id";
|
||||||
stdMaterialName += strId;
|
stdMaterialName += strId;
|
||||||
stdMaterialName += "_";
|
stdMaterialName += "_";
|
||||||
|
@ -556,7 +558,7 @@ private:
|
||||||
std::string value;
|
std::string value;
|
||||||
};
|
};
|
||||||
std::vector<MetaEntry> mMetaData;
|
std::vector<MetaEntry> mMetaData;
|
||||||
std::map<unsigned int, Resource*> mResourcesDictionnary;
|
std::map<unsigned int, Resource *> mResourcesDictionnary;
|
||||||
unsigned int mMaterialCount, mMeshCount;
|
unsigned int mMaterialCount, mMeshCount;
|
||||||
XmlParser *mXmlParser;
|
XmlParser *mXmlParser;
|
||||||
};
|
};
|
||||||
|
|
|
@ -103,9 +103,9 @@ public:
|
||||||
std::string name = currentNode.name();
|
std::string name = currentNode.name();
|
||||||
if (name == "Relationship") {
|
if (name == "Relationship") {
|
||||||
OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship());
|
OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship());
|
||||||
relPtr->id = currentNode.attribute(XmlTag::RELS_ATTRIB_ID.c_str()).as_string();
|
relPtr->id = currentNode.attribute(XmlTag::RELS_ATTRIB_ID).as_string();
|
||||||
relPtr->type = currentNode.attribute(XmlTag::RELS_ATTRIB_TYPE.c_str()).as_string();
|
relPtr->type = currentNode.attribute(XmlTag::RELS_ATTRIB_TYPE).as_string();
|
||||||
relPtr->target = currentNode.attribute(XmlTag::RELS_ATTRIB_TARGET.c_str()).as_string();
|
relPtr->target = currentNode.attribute(XmlTag::RELS_ATTRIB_TARGET).as_string();
|
||||||
if (validateRels(relPtr)) {
|
if (validateRels(relPtr)) {
|
||||||
m_relationShips.push_back(relPtr);
|
m_relationShips.push_back(relPtr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,10 +428,10 @@ void AMFImporter::Postprocess_BuildMeshSet(const AMFMesh &pNodeElement, const st
|
||||||
|
|
||||||
if (pBiggerThan != nullptr) {
|
if (pBiggerThan != nullptr) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
const size_t biggerThan = *pBiggerThan;
|
||||||
for (const SComplexFace &face : pFaceList) {
|
for (const SComplexFace &face : pFaceList) {
|
||||||
for (size_t idx_vert = 0; idx_vert < face.Face.mNumIndices; idx_vert++) {
|
for (size_t idx_vert = 0; idx_vert < face.Face.mNumIndices; idx_vert++) {
|
||||||
if (face.Face.mIndices[idx_vert] > *pBiggerThan) {
|
if (face.Face.mIndices[idx_vert] > biggerThan) {
|
||||||
rv = face.Face.mIndices[idx_vert];
|
rv = face.Face.mIndices[idx_vert];
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
CIOStreamWrapper::~CIOStreamWrapper(void) {
|
CIOStreamWrapper::~CIOStreamWrapper() {
|
||||||
/* Various places depend on this destructor to close the file */
|
/* Various places depend on this destructor to close the file */
|
||||||
if (mFile) {
|
if (mFile) {
|
||||||
mIO->mFileSystem->CloseProc(mIO->mFileSystem, mFile);
|
mIO->mFileSystem->CloseProc(mIO->mFileSystem, mFile);
|
||||||
|
@ -78,7 +78,7 @@ aiReturn CIOStreamWrapper::Seek(size_t pOffset,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...................................................................
|
// ...................................................................
|
||||||
size_t CIOStreamWrapper::Tell(void) const {
|
size_t CIOStreamWrapper::Tell() const {
|
||||||
return mFile->TellProc(mFile);
|
return mFile->TellProc(mFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#pragma warning(disable : 4706)
|
#pragma warning(disable : 4706 4244 4028)
|
||||||
|
|
||||||
#define ftruncate(fd, sz) (-(_chsize_s((fd), (sz)) != 0))
|
#define ftruncate(fd, sz) (-(_chsize_s((fd), (sz)) != 0))
|
||||||
#define fileno _fileno
|
#define fileno _fileno
|
||||||
|
|
Loading…
Reference in New Issue