示例#1
0
std::string MaterialSystem::getBlock (const std::string& texture)
{
	if (texture.empty())
		return "";

	const std::string textureDir = GlobalTexturePrefix_get();
	std::string skippedTextureDirectory = texture.substr(textureDir.length());

	if (skippedTextureDirectory.empty())
		return "";

	MaterialBlockMap::iterator i = _blocks.find(skippedTextureDirectory);
	if (i != _blocks.end())
		return i->second;

	if (!_materialLoaded)
		loadMaterials();

	if (!_materialLoaded)
		return "";

	StringOutputStream outputStream;

	StringInputStream inputStream(_material);
	AutoPtr<Tokeniser> tokeniser(GlobalScriptLibrary().createSimpleTokeniser(inputStream));
	int depth = 0;
	bool found = false;
	std::string token = tokeniser->getToken();
	while (token.length()) {
		if (token == "{") {
			depth++;
		} else if (token == "}") {
			depth--;
		}
		if (depth >= 1) {
			if (depth == 1 && token == "material") {
				token = tokeniser->getToken();
				if (token == skippedTextureDirectory) {
					found = true;
					outputStream << "{ material ";
				}
			}
			if (found)
				outputStream << token << " ";
		} else if (found) {
			outputStream << "}";
			break;
		}
		token = tokeniser->getToken();
	}
	return outputStream.toString();
}
示例#2
0
bool MaterialSystem::isDefined(const std::string& texture, const std::string& content)
{
	const std::string textureDir = GlobalTexturePrefix_get();
	if (texture == textureDir || GlobalMap().isUnnamed())
		return false;

	std::string skippedTextureDirectory = texture.substr(textureDir.length());
	std::string materialDefinition = "material " + skippedTextureDirectory;
	/* check whether there is already an entry for the selected texture */
	if (content.find(materialDefinition) != std::string::npos)
		return true;

	return false;
}
示例#3
0
bool UFOFaceTokenImporter::importTextureName (FaceShader& faceShader, Tokeniser& tokeniser)
{
	const std::string texture = tokeniser.getToken();
	if (texture.empty()) {
		Tokeniser_unexpectedError(tokeniser, texture, "#texture-name");
		return false;
	}
	if (texture == "NULL" || texture.empty()) {
		faceShader.setShader("");
	} else {
		faceShader.setShader(GlobalTexturePrefix_get() + texture);
	}
	return true;
}
示例#4
0
void MaterialSystem::generateMaterialFromTexture ()
{
	if (GlobalMap().isUnnamed()) {
		// save the map first
		gtkutil::errorDialog(_("You have to save your map before material generation can work"));
		return;
	}

	loadMaterials();
	if (!_materialLoaded)
		return;

	const std::string textureDir = GlobalTexturePrefix_get();

	std::string append = "";
	if (GlobalSelectionSystem().areFacesSelected()) {
		for (FaceInstancesList::iterator i = g_SelectedFaceInstances.m_faceInstances.begin(); i
				!= g_SelectedFaceInstances.m_faceInstances.end(); ++i) {
			const FaceInstance& faceInstance = *(*i);
			const Face &face = faceInstance.getFace();
			const std::string& texture = face.GetShader();
			// don't generate materials for common textures
			if (texture.find("tex_common") != std::string::npos)
				continue;
			std::string skippedTextureDirectory = texture.substr(textureDir.length());
			std::string materialDefinition = "material " + skippedTextureDirectory;
			/* check whether there is already an entry for the selected texture */
			if (_material.find(materialDefinition) == std::string::npos) {
				std::stringstream os;
				ContentsFlagsValue flags;
				ContentsFlagsValue faceFlags(face.GetFlags());

				os << "{" << std::endl;
				os << "\t" << materialDefinition << std::endl;
				os << "\t{" << std::endl;
				generateMaterialForFace(flags.getContentFlags(), flags.getSurfaceFlags(), skippedTextureDirectory, os);
				os << "\t}" << std::endl;
				os << "}" << std::endl;

				append += os.str();
			}
		}
	}

	showMaterialDefinitionAndAppend(append);
}
示例#5
0
void ShaderChooser::shaderSelectionChanged(const std::string& shaderName, GtkListStore* listStore) {
	if (_targetEntry != NULL) {
		const char *value = shaderName.c_str();
		if (_stripTextureDir)
			value += GlobalTexturePrefix_get().size();
		gtk_entry_set_text(GTK_ENTRY(_targetEntry), value);
	}

	// Propagate the call up to the client (e.g. SurfaceInspector)
	if (_client != NULL) {
		_client->shaderSelectionChanged(shaderName);
	}

	// Get the shader, and its image map if possible
	IShader* shader = _selector.getSelectedShader();
	if (shader != NULL) {
		// Pass the call to the static member
		ShaderSelector::displayShaderInfo(shader, listStore);

		shader->DecRef();
	}
}