示例#1
0
MaterialFactory::MaterialFactory() : 
	bNormalMap(1), bEnvMap(1), bShadows(1), bShadowsDepth(1), bShadowsSoft(1), bShadowsFade(0),
	iTexSize(4096), iNumShadowTex(3), iShadowsFilterSize(4), fShaderQuality(0.5), fShadowsFadeDistance(20.f),
	bReflect(0), bRefract(0),
	bSettingsChanged(1), // always have to generate at start
	
	mSceneMgr(0), mTerrain(0), mPSSM(0)
{
	QTimer ti;  ti.update(); /// time
	
	// find all files with *.matdef extension in all resource groups
	StringVector resourceGroups = ResourceGroupManager::getSingleton().getResourceGroups();
	for (StringVector::iterator it = resourceGroups.begin();
		it != resourceGroups.end(); ++it)
	{
		StringVectorPtr files = ResourceGroupManager::getSingleton().findResourceNames(
			(*it),
			"*.matdef");
		
		for (StringVector::iterator fit = files->begin();
			fit != files->end(); ++fit)
		{
			loadDefsFromFile( (*fit) );
		}
	}
	
	// create our generators
	mGenerator = new MaterialGenerator();
	mGenerator->mParent = this;
	
	MaterialGenerator* glass = static_cast<MaterialGenerator*>(new GlassMaterialGenerator());
	glass->mParent = this;
	mCustomGenerators.push_back(glass);
	
	MaterialGenerator* pipeglass = static_cast<MaterialGenerator*>(new PipeGlassMaterialGenerator());
	pipeglass->mParent = this;
	mCustomGenerators.push_back(pipeglass);
	
	MaterialGenerator* arrow = static_cast<MaterialGenerator*>(new ArrowMaterialGenerator());
	arrow->mParent = this;
	mCustomGenerators.push_back(arrow);
	
	MaterialGenerator* water = static_cast<MaterialGenerator*>(new WaterMaterialGenerator());
	water->mParent = this;
	mCustomGenerators.push_back(water);
	
	MaterialGenerator* impostor = static_cast<MaterialGenerator*>(new ImpostorMaterialGenerator());
	impostor->mParent = this;
	mCustomGenerators.push_back(impostor);
	
	MaterialGenerator* particle = static_cast<MaterialGenerator*>(new ParticleMaterialGenerator());
	particle->mParent = this;
	mCustomGenerators.push_back(particle);
	
	ti.update(); /// time
	float dt = ti.dt * 1000.f;
	LogO(String("::: Time loading material definitions: ") + toStr(dt) + " ms");
}
示例#2
0
    vector<vector<string> > findLadders0(string start, string end, unordered_set<string> &dict) {

        dict.insert(start);

        StringVectorQ q;
        q.push_back( StringVectorPtr(new StringVector(1, start)) );
        const int L = end.size();
        StringVectorQ result;
        StringSet visitedS = {start};
        while( !q.empty() ) {
            StringVectorPtr pv = q.front();
            q.pop_front();
            if( pv->size() > shortest )
                continue;
            string s = pv->back();
            for(int i=0; i<L; ++i) {
                string newStr = s;
                char ch = s[i];
                do {
                    ch++;
                    if( ch > 'z') ch = 'a';
                    if( ch == s[i]) break;

                    newStr[i] = ch;
                    if( newStr == end ) {  // found it
                        StringVectorPtr newV(new StringVector(*pv));
                        newV->push_back(newStr);
                        result.push_back(newV);
                        if( newV->size() < shortest)
                            shortest = newV->size();
                    } if( dict.end() != dict.find(newStr) && std::find(pv->begin(), pv->end(), newStr) == pv->end() ) {  // continue with next search
                        StringVectorPtr newV(new StringVector(*pv));
                        newV->push_back(newStr);
                        visitedS.insert(newStr);
                        q.push_back(newV);
                    }
                }while(true);
            }
        }
        struct Smaller{
            int x;
            Smaller(int a):x(a){}
            bool operator()(StringVectorPtr& v) {
                return v->size() < x;
            }
        };

        StringVectorVector vv;
//        std::copy_if(result.begin(), result.end(), std::back_inserter(vv), Smaller(shortest));
        for(StringVectorQ::iterator it=result.begin(); it!=result.end(); ++it) {
            if( (**it).size() <= shortest )
                vv.push_back(std::move(**it));
        }
        return std::move(vv);
    }
    //-----------------------------------------------------------------------
    void RenderSystemCapabilitiesManager::parseCapabilitiesFromArchive(const String& filename, const String& archiveType, bool recursive)
    {
        // get the list of .rendercaps files
        Archive* arch = ArchiveManager::getSingleton().load(filename, archiveType);
        StringVectorPtr files = arch->find(mScriptPattern, recursive);

        // loop through .rendercaps files and load each one
        for (StringVector::iterator it = files->begin(), end = files->end(); it != end; it++)
        {
            DataStreamPtr stream = arch->open(*it);
            mSerializer->parseScript(stream);
            stream->close();
        }
    }
/**
 * @author JoSch
 * @date 04-27-2004
 */
void SoundManager::addSounds(const Ogre::String& group)
{
    StringList extlist = getExtension();
    StringList::const_iterator cit;
    for(cit = extlist.begin(); cit != extlist.end(); cit++)
    {
		StringVectorPtr sl = ResourceGroupManager::getSingleton().findResourceNames(
			group, *cit );
        StringVector::const_iterator it;
        for(it = sl->begin(); it != sl->end(); it++)
        {
            try {
                create(*it, group);
            } catch(...)
            {}
        }
    }
}
示例#5
0
void Sample_MeshLod::setupControls( int uimode /*= 0*/ )
{
    cleanupControls();

    SelectMenu* models = mTrayMgr->createLongSelectMenu(TL_TOPLEFT, "cmbModels", "Model:", 150, 8);
    models->addItem("Sinbad.mesh");
    models->addItem("ogrehead.mesh");
    models->addItem("knot.mesh");
    models->addItem("fish.mesh");
    models->addItem("penguin.mesh");
    models->addItem("ninja.mesh");
    models->addItem("dragon.mesh");
    models->addItem("athene.mesh");
    models->addItem("sibenik.mesh");

    // Add all meshes from popular:
    StringVectorPtr meshes = ResourceGroupManager::getSingleton().findResourceNames("General", "*.mesh");
    StringVector::iterator it, itEnd;
    it = meshes->begin();
    itEnd = meshes->end();
    for(; it != itEnd; it++){
        models->addItem(*it);
    }


    // Basic options:
    mWireframe = mTrayMgr->createCheckBox(TL_TOPLEFT, "chkShowWireframe", "Show wireframe", 200);
    mUseVertexNormals = mTrayMgr->createCheckBox(TL_TOPLEFT, "chkUseVertexNormals", "Use vertex normals", 200);
    mOutsideWeightSlider = mTrayMgr->createThickSlider(TL_TOPLEFT, "sldOutsideWeight", "Weighten outside", 200, 50, 0, 100, 101);
    mOutsideWalkAngle = mTrayMgr->createThickSlider(TL_TOPLEFT, "sldOutsideWalkAngle", "Outside angle", 200, 50, -1, 1, 201);
    mManualMeshes = mTrayMgr->createLongSelectMenu(TL_TOPLEFT, "cmbManualMesh", "Manual LOD:", 100, 8);
    mManualMeshes->copyItemsFrom(models);
    mManualMeshes->insertItem(0,"");
    mReductionSlider = mTrayMgr->createThickSlider(TL_TOPLEFT, "sldReductionValue", "Reduced vertices", 200, 50, 0, 100, 101);
    mTrayMgr->createButton(TL_TOPLEFT, "btnReduceMore","Reduce More");
    mTrayMgr->createButton(TL_TOPLEFT, "btnReduceLess","Reduce Less");

    // Level options:
    mDistanceLabel = mTrayMgr->createLabel(TL_TOPRIGHT, "lblDistance", "Distance: ", 250);
    mLodLevelList = mTrayMgr->createLongSelectMenu(TL_TOPRIGHT, "cmbLodLevels", "Lod level:", 150, 4);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnAddLodLevel","Add level", 220);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnRemoveSelectedLodLevel","Remove level", 220);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnRemoveInitialLodLevel","Remove level #0", 220);

    // Serializer options:
    mTrayMgr->createButton(TL_TOPRIGHT, "btnShowAll", "Show all levels", 220);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnAutoconfigure", "Show autoconfigured LODs", 220);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnShowMesh", "Show LODs stored in mesh", 220);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnSaveMesh", "Save mesh", 220);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnRestoreMesh", "Restore original mesh", 220);

    // Profile options
    mProfileList = mTrayMgr->createLongSelectMenu(TL_TOPRIGHT, "cmbProfiledVertices", "Profile:", 180, 4);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnRemoveFromProfile","Remove from profile", 220.0);
    mTrayMgr->createButton(TL_TOPRIGHT, "btnAddToProfile","Add to profile", 220.0);

    //mTrayMgr->createTextBox(TL_TOPRIGHT, "Help","Help", 200, 200)
    //  ->setText("The last reduced vertex is the selected vertex. Use the slider to select the vertex, then decide to keep or remove it. You can export the Lod buffers into the .mesh file after configuration.");

    mTrayMgr->showCursor();
}
	//-----------------------------------------------------------------------
	void MaterialService::createStandardMaterial(unsigned int idx, std::string matName, std::string textureName,
	        std::string resourceGroup) {
		Image tex;
		bool loaded = false; // indicates we were successful finding the texture

		StringVectorPtr texnames = ResourceGroupManager::getSingleton().findResourceNames(resourceGroup, textureName
		        + ".*");

		if (texnames->size() <= 0) {
			// no results, try the localised version
			// prev. path + /language/filename
			String locresname = mConfigService->getLocalisedResourcePath(textureName);

			LOG_INFO("Specified resource (%s) was not found, trying localized version: %s", textureName.c_str(), locresname.c_str());

			texnames = ResourceGroupManager::getSingleton().findResourceNames(resourceGroup, locresname
					        + ".*");
		}

		String txtfile;

		// Let's try the extensions from the extensions vector
		StringVector::iterator it = texnames->begin();

		for (; it != texnames->end(); it++) { // Try loading every given
			try {
				tex.load((*it), resourceGroup);

				TextureManager::getSingleton().loadImage(textureName, resourceGroup, tex, TEX_TYPE_2D, 5, 1.0f);

				txtfile = (*it);

				loaded = true;

				break; // we got it!
			} catch (Ogre::Exception) {
				// Nothing. We are trying more extensions
			}
		}

		if (!loaded)
			LOG_ERROR("Image %s was not found, texture will be invalid!", textureName.c_str());

		// Construct a material out of this texture. We'll just clone the material upstairs to enable lmap-txture combinations
		MaterialPtr shadMat = MaterialManager::getSingleton().create(matName, resourceGroup);

		shadMat->setReceiveShadows(true);

		Pass *shadPass = shadMat->getTechnique(0)->getPass(0);

		shadPass->setAmbient(0.5, 0.5, 0.5);
		shadPass->setDiffuse(1, 1, 1, 1);
		shadPass->setSpecular(1, 1, 1, 1);

		TextureUnitState* tus = createAnimatedTextureState(shadPass, txtfile, resourceGroup, 5);

		// Set replace on all first layer textures for now
		// tus->setColourOperation(LBO_REPLACE);
		tus->setTextureAddressingMode(TextureUnitState::TAM_WRAP);
		tus->setTextureCoordSet(0);
		tus->setTextureFiltering(TFO_BILINEAR);

		tus->setTextureUScale(1.0f);
		tus->setTextureVScale(1.0f);
		// tus->setTextureFiltering(TFO_NONE);

		// Set culling mode to none
		// shadMat->setCullingMode(CULL_ANTICLOCKWISE);

		// No dynamic lighting
		shadMat->setLightingEnabled(false);

		// DYNL:
		shadMat->load();


		// standard size
		addWorldMaterialTemplate(idx, shadMat);
	}
void MeshSerializerTests::testMesh_Version_1_2()
{
	// Exporting legacy Mesh not supported!
	// testMesh(MESH_VERSION_LEGACY);

#ifdef I_HAVE_LOT_OF_FREE_TIME
	// My sandboxing test. Takes a long time to complete!
	// Runs on all meshes and exports all to every Lod version.
	char* groups [] = { "Popular", "General", "Tests" };
	for (int i = 0; i < 3; i++) {
		StringVectorPtr meshes = ResourceGroupManager::getSingleton().findResourceNames(groups[i], "*.mesh");
		StringVector::iterator it, itEnd;
		it = meshes->begin();
		itEnd = meshes->end();
		for (; it != itEnd; it++) {
			try {
				mMesh = MeshManager::getSingleton().load(*it, groups[i]);
			}
			catch(std::exception e)
			{
				// OutputDebugStringA(e.what());
			}
			getResourceFullPath(mMesh, mMeshFullPath);
			if (!copyFile(mMeshFullPath + ".bak", mMeshFullPath)) {
				// If there is no backup, create one.
				copyFile(mMeshFullPath, mMeshFullPath + ".bak");
			}
			mOrigMesh = mMesh->clone(mMesh->getName() + ".orig.mesh", mMesh->getGroup());
			testMesh_XML();
			testMesh(MESH_VERSION_1_10);
			testMesh(MESH_VERSION_1_8);
			testMesh(MESH_VERSION_1_7);
			testMesh(MESH_VERSION_1_4);
			testMesh(MESH_VERSION_1_0);
		}
		meshes = ResourceGroupManager::getSingleton().findResourceNames(groups[i], "*.skeleton");
		it = meshes->begin();
		itEnd = meshes->end();
		for (; it != itEnd; it++) {
			mSkeleton = SkeletonManager::getSingleton().load(*it, groups[i]);
			getResourceFullPath(mSkeleton, mSkeletonFullPath);
			if (!copyFile(mSkeletonFullPath + ".bak", mSkeletonFullPath)) {
				// If there is no backup, create one.
				copyFile(mSkeletonFullPath, mSkeletonFullPath + ".bak");
			}
			SkeletonSerializer skeletonSerializer;
			skeletonSerializer.exportSkeleton(mSkeleton.get(), mSkeletonFullPath, SKELETON_VERSION_1_8);
			mSkeleton->reload();
			skeletonSerializer.exportSkeleton(mSkeleton.get(), mSkeletonFullPath, SKELETON_VERSION_1_0);
			mSkeleton->reload();
		}
	}
#endif /* ifdef I_HAVE_LOT_OF_FREE_TIME */
}