// Read node osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::notify(osg::INFO) << "ReaderWriterDirectX::readNode(" << fileName.c_str() << ")\n"; // Load DirectX mesh DX::Object obj; if (obj.load(fileName.c_str()) == false) { return ReadResult::ERROR_IN_READING_FILE; } // code for setting up the database path so that internally referenced file are searched for on relative paths. osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->setDatabasePath(osgDB::getFilePath(fileName)); // Options? bool flipTexture = true; float creaseAngle = 80.0f; if (options) { const std::string option = options->getOptionString(); if (option.find("flipTexture") != std::string::npos) { flipTexture = false; } if (option.find("creaseAngle") != std::string::npos) { // TODO } } // Convert to osg::Group osg::Group* group = convertFromDX(obj, flipTexture, creaseAngle, local_opt.get()); if (!group) { return ReadResult::ERROR_IN_READING_FILE; } return group; }
osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(std::istream& fin, const osgDB::ReaderWriter::Options* options) const { DX::Object obj; if (obj.load(fin) == false) { OSG_WARN << "ReaderWriterDirectX failed to read stream" << std::endl; return ReadResult::ERROR_IN_READING_FILE; } // Options? bool flipTexture = true; bool switchToLeftHanded = true; // when true: swap y and z for incoming files float creaseAngle = 80.0f; if (options) { const std::string option = options->getOptionString(); if (option.find("rightHanded") != std::string::npos) { switchToLeftHanded = false; } if (option.find("leftHanded") != std::string::npos) { switchToLeftHanded = true; } if (option.find("flipTexture") != std::string::npos) { flipTexture = false; } if (option.find("creaseAngle") != std::string::npos) { // TODO } } // Convert to osg::Group osg::Group* group = convertFromDX(obj, switchToLeftHanded, flipTexture, creaseAngle, options); if (!group) { OSG_WARN << "ReaderWriterDirectX failed to convert\n"; return ReadResult::ERROR_IN_READING_FILE; } return group; }