26 mSceneLoader = alSceneLoader;
30 mIsLoaderMode = isLoaderMode;
31 resGroup = ressourceGroup;
32 mSceneName = sceneName;
36 resPath = mSceneLoader->
getFilePath().remove_filename().generic_string();
47 return (mScene) ? true :
false;
52 return mMaterialNames;
62 aiMatrix4x4 fullTrans = toThis->mTransformation;
63 aiNode* parent = toThis->mParent;
64 while(parent && parent != mScene->mRootNode)
66 fullTrans = parent->mTransformation * fullTrans;
67 parent = parent->mParent;
73 bool ALScene::load(std::vector<SNode*> &scolNodes, std::vector<SMaterial*> &scolMats)
82 if(mScene->mRootNode != 0)
85 std::vector<bool> vertexColorList;
86 vertexColorList.resize(mScene->mNumMaterials,
false);
87 for (
unsigned int n = 0; n<mScene->mNumMeshes; ++n)
89 if (mScene->mMeshes[n]->GetNumColorChannels() > 0)
90 vertexColorList[mScene->mMeshes[n]->mMaterialIndex] =
true;
94 loadMaterials(vertexColorList, scolMats);
96 for (
unsigned int i=0; i < scolMats.size(); ++i)
98 mMaterialNames.push_back(scolMats[i]->GetName());
105 for(
unsigned int n=0; n<mScene->mNumMeshes; ++n)
107 for(
unsigned int i=0; i<mScene->mMeshes[n]->mNumBones; ++i)
109 aiNode* bnode = mScene->mRootNode->FindNode(mScene->mMeshes[n]->mBones[i]->mName);
115 std::vector<aiCamera*> cams;
116 for(
unsigned int n=0; n<mScene->mNumCameras; ++n)
117 cams.push_back(mScene->mCameras[n]);
119 std::vector<aiLight*> light;
120 for(
unsigned int n=0; n<mScene->mNumLights; ++n)
121 light.push_back(mScene->mLights[n]);
124 aiNode* asRootNode = mScene->mRootNode;
125 if (!loadNodes(asRootNode, cams, light, scolNodes))
128 for (
unsigned int i = 0; i < scolNodes.size(); ++i)
147 void ALScene::setBones(aiNode* bone)
151 aiNode* curBone = bone;
152 while(curBone && (curBone->mNumMeshes == 0) && (curBone != mScene->mRootNode))
155 curBone = curBone->mParent;
161 mBonesNames.insert(std::string(newBone->mName.C_Str()));
164 std::queue<aiNode*> nodes;
166 while(!nodes.empty())
168 newBone = nodes.front();
172 unsigned int nbSons = newBone->mNumChildren;
178 aiNode** sons = newBone->mChildren;
180 for(
unsigned int n=0; n<nbSons; ++n)
183 aiNode* son = sons[n];
184 if (son && (son->mNumMeshes == 0) && (son != mScene->mRootNode))
186 mBonesNames.insert(std::string(son->mName.C_Str()));
202 boost::filesystem::path expFile = expFolder;
203 expFile /= mSceneName +
".scene";
207 if(mScene->mRootNode != 0)
210 std::string sceneFileName = expFile.generic_string();
220 mainElem->
SetAttribute(
"author",
"Scol_Assimp_Exporter");
239 std::vector<bool> vertexColorList;
240 vertexColorList.resize(mScene->mNumMaterials,
false);
241 for (
unsigned int n = 0; n<mScene->mNumMeshes; ++n)
243 if (mScene->mMeshes[n]->GetNumColorChannels() > 0)
244 vertexColorList[mScene->mMeshes[n]->mMaterialIndex] =
true;
248 if (mScene->HasTextures())
250 for (
unsigned int i = 0; i < mScene->mNumTextures; i++)
252 aiTexture* tex = mScene->mTextures[i];
253 bool compressed = (tex->mHeight == 0);
284 convertMaterials(expFolder, vertexColorList, mMaterialNames);
290 std::vector<aiCamera*> cams;
291 for(
unsigned int n=0; n<mScene->mNumCameras; ++n)
292 cams.push_back(mScene->mCameras[n]);
294 std::vector<aiLight*> light;
295 for(
unsigned int n=0; n<mScene->mNumLights; ++n)
296 light.push_back(mScene->mLights[n]);
299 for(
unsigned int n=0; n<mScene->mNumMeshes; ++n)
301 for(
unsigned int i=0; i<mScene->mMeshes[n]->mNumBones; ++i)
303 aiNode* bnode = mScene->mRootNode->FindNode(mScene->mMeshes[n]->mBones[i]->mName);
310 aiNode* asRootNode = mScene->mRootNode;
311 convertNodes(asRootNode, cams, light, expFolder, xmlnodes);
316 dotScene.
SaveFile(sceneFileName.c_str());
322 void ALScene::loadMaterials(std::vector<bool> &vertexColorList, std::vector<SMaterial*> &matsList)
324 unsigned int nbMat = mScene->mNumMaterials;
325 aiMaterial** materials = mScene->mMaterials;
327 for(
unsigned int n=0; n<nbMat; ++n)
329 ALMaterial matConv(
this, materials[n], vertexColorList[n]);
333 matsList.push_back(nmat);
337 void ALScene::convertMaterials(boost::filesystem::path expPath, std::vector<bool> &vertexColorList, std::vector<std::string> &matNames)
339 unsigned int nbMat = mScene->mNumMaterials;
340 aiMaterial** materials = mScene->mMaterials;
343 for(
unsigned int n=0; n<nbMat; ++n)
345 ALMaterial matConv(
this, materials[n], vertexColorList[n]);
346 matNames.push_back(matConv.convert(expPath, Clear));
351 bool ALScene::loadNodes(aiNode* rootNode, std::vector<aiCamera*> cameras, std::vector<aiLight*> lights, std::vector<SNode*>& outNodes)
353 ALNode nconv(rootNode, (parentNode == 0) ? scolScene->
GetRootNode() : parentNode, this, cameras, lights);
354 SNode* rootScolNode = nconv.load();
356 std::pair<aiNode*,SNode*> currentRoot(rootNode, (parentNode == 0) ? scolScene->
GetRootNode() : parentNode);
357 std::queue< std::pair<aiNode*,SNode*> > file;
358 file.push(currentRoot);
361 outNodes.push_back(rootScolNode);
369 currentRoot = file.front();
373 unsigned int nbSons = currentRoot.first->mNumChildren;
379 aiNode** sons = currentRoot.first->mChildren;
381 for(
unsigned int n=0; n<nbSons; ++n)
384 aiNode* son = sons[n];
387 ALNode nconv(son, currentRoot.second,
this, cameras, lights);
388 SNode* scolSon = nconv.load();
394 std::pair<aiNode*, SNode*> sonNodes(son, scolSon);
398 outNodes.push_back(scolSon);
407 void ALScene::convertNodes(aiNode* rootNode, std::vector<aiCamera*> cameras, std::vector<aiLight*> lights, boost::filesystem::path expPath,
tinyxml2::XMLElement* xmlParent)
409 SNode* rootScolNode = parentNode;
410 ALNode nodeConverter(rootNode, rootScolNode,
this, cameras, lights, xmlParent);
418 aiNode* currentRoot(rootNode);
419 std::pair<aiNode*,tinyxml2::XMLElement*> rootinfo(currentRoot, xmlRootNode);
420 std::queue<std::pair<aiNode*,tinyxml2::XMLElement*>> file;
429 rootinfo = file.front();
430 currentRoot = rootinfo.first;
438 unsigned int nbSons = currentRoot->mNumChildren;
444 aiNode** sons = currentRoot->mChildren;
446 for(
unsigned int n=0; n<nbSons; ++n)
449 aiNode* son = sons[n];
456 ALNode nconv(son, 0,
this, cameras, lights, rootinfo.second);
460 std::pair<aiNode*,tinyxml2::XMLElement*> sonInfo(son, xnode);
470 AlTexturesMap::iterator iTextureSearched = mTextureMap.find(path);
471 if(iTextureSearched != mTextureMap.end())
474 mTextureMap.insert(AlTexturesMap::value_type(path, name));
480 AlTexturesMap::iterator iTextureSearched = mTextureMap.find(path);
481 if(iTextureSearched == mTextureMap.end())
484 return iTextureSearched->second;
519 if(mBonesNames.find(std::string(node->mName.C_Str())) != mBonesNames.end())
527 bool haveMesh = node->mNumMeshes > 0;
528 unsigned int nbSons = node->mNumChildren;
532 aiNode** sons = node->mChildren;
534 for (
unsigned int n = 0; n < nbSons && !haveMesh; ++n)
536 aiNode* son = sons[n];
537 haveMesh = son->mNumMeshes > 0;
static void resetUID()
reset the uid to 0.
std::string getRessourceGroup()
bool load(std::vector< SNode * > &scolNodes, std::vector< SMaterial * > &scolMats)
const std::vector< std::string > getMaterialNames()
aiMatrix4x4 getFullTransform(aiNode *toThis)
bool haveMeshInHierarchy(aiNode *node)
ALScene()
Empty constructor. Can be used when you can't directly use the full constructor.
bool isSceneDependent(aiNode *node)
const aiScene * getAiScene()
bool addTextureRef(std::string name, std::string path)
void convert(boost::filesystem::path exportFolder)
std::string getSceneName()
std::string getTextureRef(std::string path)
std::set< std::string > getBonesNames()
bool isBone(aiNode *node)
Check if a node is a bone.
bool IsLoaderModeEnable()
std::string getRessourcePath()
boost::filesystem::path getFilePath()
void DeleteNode(SNode *existingNode)
XMLElement * NewElement(const char *name)
XMLError SaveFile(const char *filename, bool compact=false)
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
XMLNode * InsertEndChild(XMLNode *addThis)