//! Changes the current Working Directory to the given string.
bool CFileSystem::changeWorkingDirectoryTo(const io::path& newDirectory)
{
	bool success=false;

	if (FileSystemType != FILESYSTEM_NATIVE)
	{
		WorkingDirectory[FILESYSTEM_VIRTUAL].append(newDirectory);
		flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], "");
		success = 1;
	}
	else
	{
		WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory;

#if defined(_IRR_WINDOWS_CE_PLATFORM_)
		success = true;
#elif defined(_MSC_VER)
	#if defined(_IRR_WCHAR_FILESYSTEM)
		success=(_wchdir(newDirectory.c_str()) == 0);
	#else
		success=(_chdir(newDirectory.c_str()) == 0);
	#endif
#else
		success=(chdir(newDirectory.c_str()) == 0);
#endif
	}

	return success;
}
//! returns the base part of a filename, i.e. all except for the directory
//! part. If no directory path is prefixed, the full name is returned.
io::path CFileSystem::getFileBasename(const io::path& filename, bool keepExtension) const
{
	// find last forward or backslash
	s32 lastSlash = filename.findLast('/');
	const s32 lastBackSlash = filename.findLast('\\');
	lastSlash = core::max_(lastSlash, lastBackSlash);

	// get number of chars after last dot
	s32 end = 0;
	if (!keepExtension)
	{
		// take care to search only after last slash to check only for
		// dots in the filename
		end = filename.findLast('.');
		if (end == -1 || end < lastSlash)
			end=0;
		else
			end = filename.size()-end;
	}

	if ((u32)lastSlash < filename.size())
		return filename.subString(lastSlash+1, filename.size()-lastSlash-1-end);
	else if (end != 0)
		return filename.subString(0, filename.size()-end);
	else
		return filename;
}
//! returns the directory part of a filename, i.e. all until the first
//! slash or backslash, excluding it. If no directory path is prefixed, a '.'
//! is returned.
io::path CFileSystem::getFileDir(const io::path& filename) const
{
	// find last forward or backslash
	s32 lastSlash = filename.findLast('/');
	const s32 lastBackSlash = filename.findLast('\\');
	lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;

	if ((u32)lastSlash < filename.size())
		return filename.subString(0, lastSlash);
	else
		return ".";
}
//! Writes attributes of the scene node.
void CMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
	IMeshSceneNode::serializeAttributes(out, options);

	if (options && (options->Flags&io::EARWF_USE_RELATIVE_PATHS) && options->Filename)
	{
		const io::path path = SceneManager->getFileSystem()->getRelativeFilename(
				SceneManager->getFileSystem()->getAbsolutePath(SceneManager->getMeshCache()->getMeshName(Mesh).getPath()),
				options->Filename);
		out->addString("Mesh", path.c_str());
	}
	else
		out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getPath().c_str());
	out->addBool("ReadOnlyMaterials", ReadOnlyMaterials);
}
//! determines if a file exists and would be able to be opened.
bool CFileSystem::existFile(const io::path& filename) const
{
	for (u32 i=0; i < FileArchives.size(); ++i)
		if (FileArchives[i]->getFileList()->findFile(filename)!=-1)
			return true;

	_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
#if defined(_IRR_WCHAR_FILESYSTEM)
	return (_waccess(filename.c_str(), 0) != -1);
#elif defined(_MSC_VER)
	return (_access(filename.c_str(), 0) != -1);
#else
	return (access(filename.c_str(), F_OK) != -1);
#endif
}
//! Writes attributes of the scene node.
void CAnimatedMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
	IAnimatedMeshSceneNode::serializeAttributes(out, options);

	if (options && (options->Flags&io::EARWF_USE_RELATIVE_PATHS) && options->Filename)
	{
		const io::path path = SceneManager->getFileSystem()->getRelativeFilename(
				SceneManager->getFileSystem()->getAbsolutePath(SceneManager->getMeshCache()->getMeshName(Mesh).getPath()),
				options->Filename);
		out->addString("Mesh", path.c_str());
	}
	else
		out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getPath().c_str());
	out->addBool("Looping", Looping);
	out->addBool("ReadOnlyMaterials", ReadOnlyMaterials);
	out->addFloat("FramesPerSecond", FramesPerSecond);
	out->addInt("StartFrame", StartFrame);
	out->addInt("EndFrame", EndFrame);
}
io::path CFileSystem::getAbsolutePath(const io::path& filename) const
{
	fschar_t *p=0;

#if defined(_IRR_WINDOWS_CE_PLATFORM_)
	return filename;
#elif defined(_IRR_WINDOWS_API_)

	#if defined(_IRR_WCHAR_FILESYSTEM )
		c16 fpath[_MAX_PATH];
		p = _wfullpath(fpath, filename.c_str(), _MAX_PATH);
	#else
		c8 fpath[_MAX_PATH];
		p = _fullpath(fpath, filename.c_str(), _MAX_PATH);
	#endif

#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
	c8 fpath[4096];
	fpath[0]=0;
	p = realpath(filename.c_str(), fpath);
	if (!p)
	{
		// content in fpath is undefined at this point
		if (!fpath[0]) // seems like fpath wasn't altered
		{
			// at least remove a ./ prefix
			if ('.'==filename[0] && '/'==filename[1])
				return filename.subString(2, filename.size()-2);
			else
				return filename;
		}
		else
			return io::path(fpath);
	}

#endif

	return io::path(p);
}
bool Image::write(const io::path & path, boost::optional<std::pair<int, int>> compression) const {
    io::path p;
    if (path.empty()) {
        p = _filename;
    } else {
        p = path;
    }
    std::vector<int> compress_vec;
    if (compression) {
        compress_vec.push_back(std::get<0>(compression.get()));
        compress_vec.push_back(std::get<1>(compression.get()));
    }
    return cv::imwrite(p.string(), _mat, compress_vec);
}
Example #9
0
        void loadHeightmap(io::path path)
        {
            Height= video->getTexture(path.c_str());

            video::IImage* image= video->createImage(Height, core::position2d<s32>(0,0), Height->getSize());
            Normal= video->addTexture("normal", image);
            video->makeNormalMapTexture(Normal, ((gui::IGUISpinBox*)gui->getRootGUIElement()->getElementFromId(EGI_HEIGHT, true))->getValue());
            image->drop();

            gui::IGUIEditBox* edit= (gui::IGUIEditBox*)gui->getRootGUIElement()->getElementFromId(EGI_FILENAME, true);
            core::stringw name= path;
            core::array<core::stringw> splited;
            //name.split(splited, ".");

            edit->setText(name.c_str());

            Node->setMaterialTexture(0, Height);
            Node->setMaterialTexture(1, Normal);
        }
Example #10
0
	virtual bool isALoadableFileExtension (const io::path &filename) const
	{
		return filename.subString(filename.size()-3, filename.size()) == "png";
	}
Example #11
0
bool CVMDCustomSkinMotion::load(const io::path &path)
{
	std::vector<char> buf;
	{
		std::ifstream io(path.c_str(), std::ios::binary);
		if(!io){
			return false;
		}

		// get filesize
		io.seekg(0, std::fstream::end);
		size_t filesize = static_cast<size_t>(io.tellg());
		io.clear();
		io.seekg(0, std::fstream::beg);
		if (filesize==0){
			std::cout << "empty file" << std::endl;
			return false;
		}

		// read all file
		buf.resize(filesize);
		io.read(&buf[0], filesize);
	}

	// parse vmd
	vmd::Loader loader;
	if(!loader.parse(&buf[0], buf.size())){
		return false;
	}

	std::cout << loader << std::endl;

	// store bone motions
	u32 lastFrame=0;
	for(vmd::Loader::BoneMap::iterator it=loader.boneMap.begin();
			it!=loader.boneMap.end();
			++it){
		SRotPosLinearCurve *curve=addBoneCurve(it->first.c_str());
		vmd::BoneBuffer::Ptr buf=it->second;
		curve->reallocate(buf->bones.size());
		for(size_t i=0; i<buf->bones.size(); ++i){
			vmd::Bone &frame=buf->bones[i];
			curve->addKeyFrame(frame.frame,
					SRotPosKey(
						core::vector3df(frame.pos.x, frame.pos.y, frame.pos.z),
						core::quaternion(
							frame.q.x, frame.q.y, frame.q.z, frame.q.w))
					);
		}
		curve->sort();
		lastFrame=std::max(lastFrame, curve->getFrameCount());
	}

	// store morphing motions
	for(vmd::Loader::MorphMap::iterator it=loader.morphMap.begin();
			it!=loader.morphMap.end();
			++it){
		SMorphLinearCurve *curve=addMorphingCurve(it->first.c_str());
		vmd::MorphBuffer::Ptr buf=it->second;
		curve->reallocate(buf->morphs.size());
		for(size_t i=0; i<buf->morphs.size(); ++i){
			vmd::Morph &frame=buf->morphs[i];
			curve->addKeyFrame(frame.frame, frame.influence);
		}
		curve->sort();
		lastFrame=std::max(lastFrame, curve->getFrameCount());
	}

	

	FrameCount=lastFrame;

	return true;
}