//------------------------------
	Mtl* MaterialCreator::createMaxMaterial( const COLLADAFW::Effect& effect, const MaterialCreator::MaterialIdentifier& materialIdentifier )
	{
		const COLLADAFW::CommonEffectPointerArray& commonEffects = effect.getCommonEffects();
		if ( commonEffects.getCount() > 0)
		{
			return createStandardMaterial(*commonEffects[0], effect.getName(), materialIdentifier);
		}

		return 0;
	}
Ejemplo n.º 2
0
	//------------------------------------------------------
	void MaterialService::loadMaterials(const FileGroupPtr& db) {
		if (!db->hasFile("TXLIST"))
			throw Exception(Exception::ERR_ITEM_NOT_FOUND, "Mission file does not contain Texture list chunk (TXLIST)",
			        "MaterialService::loadMaterials");

		// Load the TXLIST chunk from the resource mission file.
		Opde::FilePtr txtList = db->getFile("TXLIST");


		// TODO: Exception handling on the chunk readout!
		// Okay, we are ready to map the arrays
		if (mFamilies != NULL)
			delete[] mFamilies;

		if (mTextures != NULL)
			delete[] mTextures;

		try {
			// TODO: This should be implemented using dtypes
			// Read the header...
			txtList->read(&mTxlistHeader, sizeof(DarkDBChunkTXLIST));

			// now read all the families

			// allocate the needed space
			mFamilies = new DarkDBTXLIST_fam[mTxlistHeader.fam_count];
			// load
			txtList->read(&(mFamilies[0]), sizeof(DarkDBTXLIST_fam) * mTxlistHeader.fam_count);

			// Now read the textures. Same as before

			// allocate the needed space
			mTextures = new DarkDBTXLIST_texture[mTxlistHeader.txt_count];
			// load texture names
			txtList->read(&(mTextures[0]), sizeof(DarkDBTXLIST_texture) * mTxlistHeader.txt_count);
		} catch (Ogre::Exception& e) {
			if (mFamilies != NULL)
				delete[] mFamilies;
			if (mTextures != NULL)
				delete[] mTextures;


			// Connect the original exception to the printout:
			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, String("Could not load texture list : ")
					+ e.getFullDescription(), "BspLevel::loadMaterials");
		}

		// Okay, we are ready to load the materials now!

		// Our resource group
		String resourceGroup = ResourceGroupManager::getSingleton().getWorldResourceGroupName();

		// ------------- Following code loads the standard materials -------------------

		// Iterate through all materials, and load them (tries to load material as a script (named family/texture), and if it fails,
		// it constructs one with the default settings, and tries a few extensions too for the image)

		for (unsigned int id = 1; id < mTxlistHeader.txt_count; id++) {
			// Try to find the family for the texture
			std::string path = getMaterialName(id);


			// Resulting material name
			StringUtil::StrStreamType matName;
			matName << "@template" << id;

			if (MaterialManager::getSingleton().resourceExists(matName.str())) // if the material is already defined
				// remove, as we have to redefine it
				MaterialManager::getSingleton().remove(matName.str());


			// See if the material is defined by a script. If so, clone it to be named @templateXXXX (XXXX = texture number)
			// We seek material named: family/texture
			if (MaterialManager::getSingleton().resourceExists(path)) {
				LOG_INFO("loadMaterials: Found material definition for %s", path.c_str());
				MaterialPtr origMat = MaterialManager::getSingleton().getByName(path);

				MaterialPtr shadMat = origMat->clone(matName.str(), true, resourceGroup);

				shadMat->load();

				addWorldMaterialTemplate(id, shadMat);
			} else { // The material script was not found
				createStandardMaterial(id, matName.str(), path, resourceGroup);
			}
			// This is it. Material @templateXX created
		}


		// Initialize the flow textures (do this first so water specialisation will override)
		loadFlowTextures(db);

		createSkyHackMaterial(resourceGroup);
		createJorgeMaterial(resourceGroup);
	}