Пример #1
0
	string FileSystem::GetFilePathWithoutExtension(const string& filePath)
	{
		auto directory		= GetDirectoryFromFilePath(filePath);
		auto fileNameNoExt	= GetFileNameNoExtensionFromFilePath(filePath);

		return directory + fileNameNoExt;
	}
Пример #2
0
	bool FileSystem::CopyFileFromTo(const string& source, const string& destination)
	{
		if (source == destination)
			return true;

		// In case the destination path doesn't exist, create it
		if (!DirectoryExists(GetDirectoryFromFilePath(destination)))
		{
			CreateDirectory_(GetDirectoryFromFilePath(destination));
		}

		try 
		{
			return copy_file(source, destination, copy_options::overwrite_existing);
		}
		catch (filesystem_error& e) 
		{
			LOG_ERROR("FileSystem: Could not copy \"" + source + "\". " + string(e.what()));
			return true;
		}
	}
Пример #3
0
static string GetExpandedShaderCode(const wchar* path, vector<wstring>& filePaths)
{
    for(uint64 i = 0; i < filePaths.size(); ++i)
        if(filePaths[i] == path)
            throw Exception(L"File \"" + wstring(path) + L" is recursively included");

    filePaths.push_back(path);

    string fileContents = ReadFileAsString(path);
    wstring fileDirectory = GetDirectoryFromFilePath(path);

    // Look for includes
    size_t lineStart = 0;
    size_t lineEnd = std::string::npos;
    while(true)
    {
        size_t lineEnd = fileContents.find('\n', lineStart);
        size_t lineLength = 0;
        if(lineEnd == string::npos)
            lineLength = string::npos;
        else
            lineLength = lineEnd - lineStart;

        string line = fileContents.substr(lineStart, lineLength);
        if(line.find("#include") == 0)
        {
            size_t startQuote = line.find('\"');
            size_t endQuote = line.find('\"', startQuote + 1);
            string includePath = line.substr(startQuote + 1, endQuote - startQuote - 1);
            wstring fullIncludePath = fileDirectory + AnsiToWString(includePath.c_str());
            if(FileExists(fullIncludePath.c_str()) == false)
                throw Exception(L"Couldn't find #included file \"" + fullIncludePath + L"\"");

            string includeCode = GetExpandedShaderCode(fullIncludePath.c_str(), filePaths);
            fileContents.insert(lineEnd + 1, includeCode);
            lineEnd += includeCode.length();
        }

        if(lineEnd == string::npos)
            break;

        lineStart = lineEnd + 1;
    }

    return fileContents;
}
Пример #4
0
Model *Scene::addModel(const std::wstring &modelPath)
{
	std::wstring dir = GetDirectoryFromFilePath(modelPath.c_str());
	std::wstring name = GetFileName(modelPath.c_str());
	std::wstring fullPath = dir + name;

	if (_modelCache.find(fullPath) != _modelCache.end())
	{
		return _modelCache[fullPath];
	}

	std::wstring ext = GetFileExtension(modelPath.c_str());

	// TODO: error handling
	if (ext == L"meshdata")
	{
		_models[_numTotalModelsShared].CreateFromMeshData(_device, fullPath.c_str());
		ModelPartsBound & data = (_modelsData[_numTotalModelsShared] = ModelPartsBound());
		ComputeModelBounds(_device, _context, &_models[_numTotalModelsShared], data.BoundingSpheres, data.BoundingBoxes);
		_numTotalModelsShared++;
	}
	else if (ext == L"sdkmesh")
	{
		_models[_numTotalModelsShared].CreateFromSDKMeshFile(_device, fullPath.c_str());
		ModelPartsBound & data = (_modelsData[_numTotalModelsShared] = ModelPartsBound());
		ComputeModelBounds(_device, _context, &_models[_numTotalModelsShared], data.BoundingSpheres, data.BoundingBoxes);
		_numTotalModelsShared++;
	}
	else
	{
		_models[_numTotalModelsShared].CreateWithAssimp(_device, fullPath.c_str());
		ModelPartsBound & data = (_modelsData[_numTotalModelsShared] = ModelPartsBound());
		ComputeModelBounds(_device, _context, &_models[_numTotalModelsShared], data.BoundingSpheres, data.BoundingBoxes);
		_numTotalModelsShared++;
	}

	_modelIndices.push_back(_numTotalModelsShared - 1);
	_modelCache.insert(std::make_pair(fullPath, &_models[_numTotalModelsShared - 1]));

	return &_models[_numTotalModelsShared - 1];
}