コード例 #1
0
ファイル: StreamerMMF.cpp プロジェクト: MeisterYeti/Rendering
//!	(static)
Mesh * StreamerMMF::loadMesh(std::istream & input) {

//	std::cout << "\nloadMMF...";
	Reader reader(input);

	uint32_t format = reader.read_uint32();
	if(format!=MMF_HEADER)    {
		WARN(std::string("wrong mesh format: ") + Util::StringUtils::toString(format));
		return nullptr;
	}
	uint32_t version = reader.read_uint32();
	if(version>MMF_VERSION)    {
		WARN(std::string("can't read mesh, version to high: ") + Util::StringUtils::toString(version));
		return nullptr;
	}

	auto mesh = new Mesh;
	uint32_t blockType = reader.read_uint32();
	while(blockType != StreamerMMF::MMF_END && input.good()) {
		// blocksize is discarded.
		uint32_t blockSize = reader.read_uint32();
		switch(blockType) {
			case StreamerMMF::MMF_VERTEX_DATA:
				readVertexData(mesh, reader);
				break;
			case StreamerMMF::MMF_INDEX_DATA:
				readIndexData(mesh, reader);
				break;
			default:
				WARN("LoaderMMF::loadMesh: unknown data block found.");
				std::cout << "blockSize:"<<blockSize<<" \n";
				reader.skip(blockSize);
				break;
		}
		blockType = reader.read_uint32();
	}

//	std::cout << "done.\n";
	return mesh;
}
コード例 #2
0
ファイル: Dtb.cpp プロジェクト: daisy/amis
//--------------------------------------------------
//process an NCX file
//--------------------------------------------------
bool amis::dtb::Dtb::processNcx(const ambulant::net::url* filepath, bool isLocal)
{
	amis::io::NcxFileReader ncx_file_reader;
	ncx_file_reader.setAreFilenamesLowercase(isLocal);
	if (!ncx_file_reader.readFromFile(filepath)) return false;

	mpNavModel = ncx_file_reader.getNavModel();
	mpCustomTests = ncx_file_reader.getCustomTests();
	
	mpTitle = ncx_file_reader.getTitle();
	mpAuthor = ncx_file_reader.getAuthor();
	 //note that this step takes a very long time if the book is large, because
	//it involves walking the nav model and also opening all the SMIL files
	amis::dtb::nav::ResolveSmilDataVisitor resolve_smil_visitor;
	
	if (mThreadYielder != 0) mThreadYielder->peekAndPump();

	resolve_smil_visitor.setThreadYielder(mThreadYielder);
	
	if (!indexExistsOnDisk())
	{
		resolve_smil_visitor.resolve(mpNavModel, mpSpine, false);
		this->mpTextSmilMap = resolve_smil_visitor.getSmilTextMap();
		if (mCacheIndex) saveIndexData();
	}
	else
	{
		//try to read the saved index data.  if it couldn't be read, then re-calculate it.
		if (!readIndexData())
		{
			amis::util::Log::Instance()->writeWarning("Could not read index file", "Dtb::processNcc");
			resolve_smil_visitor.resolve(mpNavModel, mpSpine, true);
			this->mpTextSmilMap = resolve_smil_visitor.getSmilTextMap();	
			if (mCacheIndex) saveIndexData();
		}
	}

	return true;
}
コード例 #3
0
ファイル: Dtb.cpp プロジェクト: daisy/amis
//--------------------------------------------------
//process an NCC file
//--------------------------------------------------
bool amis::dtb::Dtb::processNcc(const ambulant::net::url* filepath, bool isLocal)
{
	amis::io::NccFileReader ncc_file_reader;
	amis::dtb::nav::BuildSpineVisitor spine_visitor;
	//TODO: this might just apply for windows
	ncc_file_reader.setAreFilenamesLowercase(isLocal);
	if (!ncc_file_reader.readFromFile(filepath)) 
	{
		amis::util::Log::Instance()->writeError("Could not read NCC file!", "Dtb::processNcc");
		return false;
	}
	mpNavModel = ncc_file_reader.getNavModel();
	mpMetadata = ncc_file_reader.getMetadata();
	mpCustomTests = ncc_file_reader.getCustomTests();
	amis::dtb::nav::NavPoint* p_title = ncc_file_reader.getTitle();

	//if this NCC file turned out to be a protected book, then we need to get custom tests and a nav model
	//from an encrypted file
	mbCanDecodePdtb = false;
	if (checkForCopyProtection(mpMetadata))
	{
		amis::util::Log::Instance()->writeMessage("This is a protected book", "Dtb::processNcc");
		mbIsProtected = true;
		if (mpCallbackForPreprocessingBookKey != NULL) 
		{
			if (mpCallbackForPreprocessingBookKey(
				getFileSet()->getProtectedNavFilepath(),
				getFileSet()->getProtectedBookKeyFilepath()
				) == true)
			{
				//reparse the ncc.pdtb file
				if (!ncc_file_reader.readFromFile(getFileSet()->getProtectedNavFilepath()))
				{
					mbCanDecodePdtb = false;
					return false;
				}
				else
				{
					mbCanDecodePdtb = true;
					if (mpNavModel) delete mpNavModel;
					if (mpCustomTests) delete mpCustomTests;
					mpNavModel = ncc_file_reader.getNavModel();
					mpCustomTests = ncc_file_reader.getCustomTests();
					p_title = ncc_file_reader.getTitle();
				}
			}
		}
		else
		{
			/* if: 1. no function registered to handle protected books or
					2. that function failed
			then: playback of NCC.html continues and it will say "this book is protected... "
			*/
			mbCanDecodePdtb = false;
			amis::util::Log::Instance()->writeError("Protected book could not be read", 
				"Dtb::processNcc");
		}
	}

	//the spine visitor also makes the smil file paths absolute
	mpSpine = spine_visitor.getSpine(mpNavModel, this->getFileSet()->getBookDirectory());

	//fill in the text for the title and the author
	mUid = getUid();
	mpTitle = new amis::MediaGroup();
	amis::TextNode* p_title_text = new amis::TextNode();
	p_title_text->setTextString(mpMetadata->getMetadataContent("dc:title"));
	mpTitle->setText(p_title_text);
	
	mpAuthor = new amis::MediaGroup();
	amis::TextNode* p_author_text = new amis::TextNode();
	p_author_text->setTextString(mpMetadata->getMetadataContent("dc:creator"));
	mpAuthor->setText(p_author_text);

	mpFiles->setAdditionalDataAfterInitialParse(mUid, NULL, NULL, mpHistory);
	amis::dtb::nav::ResolveSmilDataVisitor resolve_smil_visitor;
	
	if (mThreadYielder != 0) mThreadYielder->peekAndPump();

	resolve_smil_visitor.setThreadYielder(mThreadYielder);
	
	if (!indexExistsOnDisk())
	{
		resolve_smil_visitor.resolve(mpNavModel, mpSpine, true);
		this->mpTextSmilMap = resolve_smil_visitor.getSmilTextMap();	
		if (mCacheIndex) saveIndexData();
	}
	else
	{
		//try to read the saved index data.  if it couldn't be read, then re-calculate it.
		if (!readIndexData())
		{
			amis::util::Log::Instance()->writeWarning("Could not read index file", "Dtb::processNcc");
			resolve_smil_visitor.resolve(mpNavModel, mpSpine, true);
			this->mpTextSmilMap = resolve_smil_visitor.getSmilTextMap();	
			if (mCacheIndex) saveIndexData();
		}
	}

	//wait until after the smil data is parsed to set the title audio (otherwise it's not available)
	if (p_title != NULL && p_title->getLabel() != NULL && p_title->getLabel()->hasAudio())
		mpTitle->addAudioClip(p_title->getLabel()->getAudio(0)->clone());

	return true;
}