domCOLLADA* ColladaShapeLoader::readColladaFile(const String& path) { // Check if this file is already loaded into the database domCOLLADA* root = sDAE.getRoot(path.c_str()); if (root) return root; // Load the Collada file into memory FileObject fo; if (!fo.readMemory(path)) { daeErrorHandler::get()->handleError(avar("Could not read %s into memory", path.c_str())); return NULL; } root = sDAE.openFromMemory(path.c_str(), (const char*)fo.buffer()); if (!root || !root->getLibrary_visual_scenes_array().getCount()) { daeErrorHandler::get()->handleError(avar("Could not parse %s", path.c_str())); return NULL; } // Fixup issues in the model ColladaUtils::applyConditioners(root); // Recursively load external DAE references TSShapeLoader::updateProgress(TSShapeLoader::Load_ExternalRefs, "Loading external references..."); for (S32 iRef = 0; iRef < root->getDocument()->getReferencedDocuments().getCount(); iRef++) { String refPath = (daeString)root->getDocument()->getReferencedDocuments()[iRef]; if (refPath.endsWith(".dae") && !readColladaFile(refPath)) daeErrorHandler::get()->handleError(avar("Failed to load external reference: %s", refPath.c_str())); } return root; }
//----------------------------------------------------------------------------- /// Get the root collada DOM element for the given DAE file domCOLLADA* ColladaShapeLoader::getDomCOLLADA(const Torque::Path& path) { daeErrorHandler::setErrorHandler(&sErrorHandler); TSShapeLoader::updateProgress(TSShapeLoader::Load_ReadFile, path.getFullFileName().c_str()); // Check if we can use the last loaded file FileTime daeModifyTime; if (Platform::getFileTimes(path.getFullPath(), NULL, &daeModifyTime)) { if ((path == sLastPath) && (Platform::compareFileTimes(sLastModTime, daeModifyTime) >= 0)) return sDAE.getRoot(path.getFullPath().c_str()); } sDAE.clear(); sDAE.setBaseURI(""); TSShapeLoader::updateProgress(TSShapeLoader::Load_ParseFile, "Parsing XML..."); domCOLLADA* root = readColladaFile(path.getFullPath()); if (!root) { TSShapeLoader::updateProgress(TSShapeLoader::Load_Complete, "Import failed"); sDAE.clear(); return NULL; } sLastPath = path; sLastModTime = daeModifyTime; return root; }