当前位置: 首页>>代码示例>>C++>>正文


C++ Stream::EnableTextMode方法代码示例

本文整理汇总了C++中Stream::EnableTextMode方法的典型用法代码示例。如果您正苦于以下问题:C++ Stream::EnableTextMode方法的具体用法?C++ Stream::EnableTextMode怎么用?C++ Stream::EnableTextMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream::EnableTextMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Save

	bool MTLParser::Save(Stream& stream) const
	{
		m_currentStream = &stream;

		// Force stream in text mode, reset it at the end
		Nz::CallOnExit resetTextMode;
		if ((stream.GetStreamOptions() & StreamOption_Text) == 0)
		{
			stream.EnableTextMode(true);

			resetTextMode.Reset([&stream] ()
			{
				stream.EnableTextMode(false);
			});
		}

		m_outputStream.Clear();

		EmitLine("# Exported by Nazara Engine");
		EmitLine();

		Emit("# material count: ");
		Emit(m_materials.size());
		EmitLine();

		for (auto& pair : m_materials)
		{
			const String& matName = pair.first;
			const Material& mat = pair.second;

			Emit("newmtl ");
			EmitLine(matName);
			EmitLine();

			Emit("Ka ");
			Emit(mat.ambient.r / 255.f);
			Emit(' ');
			Emit(mat.ambient.g / 255.f);
			Emit(' ');
			Emit(mat.ambient.b / 255.f);
			EmitLine();

			Emit("Kd ");
			Emit(mat.diffuse.r / 255.f);
			Emit(' ');
			Emit(mat.diffuse.g / 255.f);
			Emit(' ');
			Emit(mat.diffuse.b / 255.f);
			EmitLine();

			Emit("Ks ");
			Emit(mat.specular.r / 255.f);
			Emit(' ');
			Emit(mat.specular.g / 255.f);
			Emit(' ');
			Emit(mat.specular.b / 255.f);
			EmitLine();

			if (!NumberEquals(mat.alpha, 1.f))
			{
				Emit("d ");
				EmitLine(mat.alpha);
			}

			if (!NumberEquals(mat.refractionIndex, 1.f))
			{
				Emit("ni ");
				EmitLine(mat.refractionIndex);
			}

			if (!NumberEquals(mat.shininess, 1.f))
			{
				Emit("ns ");
				EmitLine(mat.shininess);
			}

			if (mat.illumModel != 0)
			{
				Emit("illum ");
				EmitLine(mat.illumModel);
			}

			if (!mat.ambientMap.IsEmpty())
			{
				Emit("map_Ka ");
				EmitLine(mat.ambientMap);
			}

			if (!mat.diffuseMap.IsEmpty())
			{
				Emit("map_Kd ");
				EmitLine(mat.diffuseMap);
			}

			if (!mat.specularMap.IsEmpty())
			{
				Emit("map_Ks ");
				EmitLine(mat.specularMap);
			}

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例2: Parse

	bool MTLParser::Parse(Stream& stream)
	{
		m_currentStream = &stream;

		// Force stream in text mode, reset it at the end
		Nz::CallOnExit resetTextMode;
		if ((stream.GetStreamOptions() & StreamOption_Text) == 0)
		{
			stream.EnableTextMode(true);

			resetTextMode.Reset([&stream] ()
			{
				stream.EnableTextMode(false);
			});
		}

		m_keepLastLine = false;
		m_lineCount = 0;
		m_materials.clear();

		Material* currentMaterial = nullptr;

		while (Advance(false))
		{
			String keyword = m_currentLine.GetWord(0).ToLower();
			if (keyword == "ka")
			{
				float r, g, b;
				if (std::sscanf(&m_currentLine[3], "%f %f %f", &r, &g, &b) == 3)
				{
					if (!currentMaterial)
						currentMaterial = AddMaterial("default");

					currentMaterial->ambient = Color(static_cast<UInt8>(r*255.f), static_cast<UInt8>(g*255.f), static_cast<UInt8>(b*255.f));
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
			}
			else if (keyword == "kd")
			{
				float r, g, b;
				if (std::sscanf(&m_currentLine[3], "%f %f %f", &r, &g, &b) == 3)
				{
					if (!currentMaterial)
						currentMaterial = AddMaterial("default");

					currentMaterial->diffuse = Color(static_cast<UInt8>(r*255.f), static_cast<UInt8>(g*255.f), static_cast<UInt8>(b*255.f));
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
			}
			else if (keyword == "ks")
			{
				float r, g, b;
				if (std::sscanf(&m_currentLine[3], "%f %f %f", &r, &g, &b) == 3)
				{
					if (!currentMaterial)
						currentMaterial = AddMaterial("default");

					currentMaterial->specular = Color(static_cast<UInt8>(r*255.f), static_cast<UInt8>(g*255.f), static_cast<UInt8>(b*255.f));
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
			}
			else if (keyword == "ni")
			{
				float density;
				if (std::sscanf(&m_currentLine[3], "%f", &density) == 1)
				{
					if (!currentMaterial)
						currentMaterial = AddMaterial("default");

					currentMaterial->refractionIndex = density;
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
			}
			else if (keyword == "ns")
			{
				float coef;
				if (std::sscanf(&m_currentLine[3], "%f", &coef) == 1)
				{
					if (!currentMaterial)
						currentMaterial = AddMaterial("default");

					currentMaterial->shininess = coef;
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
			}
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的Stream::EnableTextMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。