Пример #1
0
	void IntroScene::initScene()
	{
		mSceneMgr = mRoot->createSceneManager( ST_GENERIC , "intro" );
		mCamera = mSceneMgr->createCamera("Cam1");
		mVp = mWindow->addViewport(mCamera);
		mVp->setBackgroundColour(ColourValue(1.0f, 0.0f,0.0f));
		mCamera->setAspectRatio(Real(mVp->getActualWidth())/mVp->getActualHeight());
		mSceneMgr->setAmbientLight( ColourValue( 1, 1, 1 ) );

		Ogre::MaterialManager *matMgr = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialPtr mat = (Ogre::MaterialPtr )matMgr->create("intro2","General");

		mat->getTechnique(0)->getPass(0)->createTextureUnitState("cybernetic.jpg");
		mat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
		mat->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
		mat->getTechnique(0)->getPass(0)->setLightingEnabled(false);

		Ogre::Rectangle2D *rect = new Ogre::Rectangle2D(true);
		rect->setCorners( -1.0 , 1.0 , 1.0 , -1.0 );
		rect->setMaterial("intro2");
		rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
		SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
		node->attachObject(rect);
		AxisAlignedBox aabInf;
		aabInf.setInfinite();
		rect->setBoundingBox(aabInf);
	
	}
Пример #2
0
    void OgreModel::setMaterial(Ogre::String resName, Ogre::String const &resourceGroupName)
    {
        Ogre::MaterialManager *mm = Ogre::MaterialManager::getSingletonPtr();
        Ogre::MaterialPtr mat;

        if(!mm->resourceExists(resName))
        {
            Debug::error(STEEL_METH_INTRO, "material ").quotes(resName)(" does not exist. Using default.").endl();
            resName = OgreModel::MISSING_MATERIAL_NAME;
        }

        mEntity->setMaterial(mm->getByName(resName));
        mHasMaterialOverride = true;
    }
//-----------------------------------------------------------------------
void MaterialTab::OnNewMaterial(wxCommandEvent& event)
{
	if (mMaterialListBox)
	{
		wxString name = wxT("Material") + ogre2wx(ParticleUniverse::StringConverter::toString(mNewMaterialCounter));
		mMaterialListBox->addMaterialName(name);
		mNewMaterialCounter++;
		Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::String nameString = wx2ogre(name);
		materialManager->create(nameString, TEMP_MATERIAL_GROUP);
		Ogre::MaterialPtr material = materialManager->getByName(nameString, TEMP_MATERIAL_GROUP);
		selectMaterial(name);
	}
}
Пример #4
0
	void GroundFog::findFogPassesByName (const Ogre::String& passName) {
		Ogre::MaterialManager *matManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialManager::ResourceMapIterator matIt = matManager->getResourceIterator();
		while (matIt.hasMoreElements()) {
			Ogre::MaterialPtr mat = matIt.getNext();
			Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
			while (techIt.hasMoreElements()) {
				Ogre::Technique *tech = techIt.getNext();
				Ogre::Technique::PassIterator passIt = tech->getPassIterator();
				while (passIt.hasMoreElements()) {
					Ogre::Pass *pass = passIt.getNext();
					if (pass->getName() == passName) {
						mPasses.insert(pass);
					}
				}
			}
		}
		forceUpdate();
	}
Пример #5
0
	void GroundFog::findFogPassesByName (const Ogre::String& passName) {
		Ogre::MaterialManager *matManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialManager::ResourceMapIterator matIt = matManager->getResourceIterator();
		while (matIt.hasMoreElements()) {
#if (OGRE_VERSION < ((1 << 16) | (9 << 8) | 0))
            Ogre::MaterialPtr mat = matIt.getNext();
#else
            Ogre::MaterialPtr mat = Ogre::static_pointer_cast<Ogre::Material>(matIt.getNext());
#endif
			for (Ogre::Technique* tech : mat->getTechniques()) {
				for (auto* pass : tech->getPasses()) {
					if (pass->getName() == passName) {
						mPasses.insert(pass);
					}
				}
			}
		}
		forceUpdate();
	}
Пример #6
0
	void OgreModule::initEnd()
	{
		Ogre::CompositorManager2* compositorManager = mOgreRoot.getCompositorManager2();
		compositorManager->createBasicWorkspaceDef("Basic Workspace", Ogre::ColourValue(0.15f, 0.15f, 0.15f));
		compositorManager->createBasicWorkspaceDef("Black Workspace", Ogre::ColourValue::Black);

		Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialPtr material = materialManager->create("debug_invisible", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		material->setReceiveShadows(false);
		Ogre::Pass* pass = material->getTechnique(0)->getPass(0);
#if OGRE_VERSION_MAJOR == 2 && OGRE_VERSION_MINOR > 0
#else
		pass->setCullingMode(Ogre::CULL_NONE);
		pass->setColourWriteEnabled(false);
		pass->setDepthWriteEnabled(false);
#endif

		this->loadResources();
	}
Пример #7
0
Ogre::MaterialPtr AssetLoader::createMaterial(Ogre::String name, int index, aiMaterial* mat)
{
	Ogre::MaterialManager* omatMgr = Ogre::MaterialManager::getSingletonPtr();

	std::ostringstream matname;
	matname << name.data() << "_mat";
	matname.widen(4);
	matname.fill('0');
	matname << index;
	Ogre::String matName = matname.str();

	Ogre::ResourceManager::ResourceCreateOrRetrieveResult status = omatMgr->createOrRetrieve(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
	Ogre::MaterialPtr omat = status.first;

	aiColor4D clr(1.0, 1.0, 1.0, 1.0);
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_DIFFUSE, &clr);
	omat->getTechnique(0)->getPass(0)->setDiffuse(clr.r, clr.g, clr.b, clr.a);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_SPECULAR, &clr);
	omat->getTechnique(0)->getPass(0)->setSpecular(clr.r, clr.g, clr.b, clr.a);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_AMBIENT, &clr);
	omat->getTechnique(0)->getPass(0)->setAmbient(clr.r, clr.g, clr.b);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_EMISSIVE, &clr);
	omat->getTechnique(0)->getPass(0)->setSelfIllumination(clr.r, clr.g, clr.b);

	omat->getTechnique(0)->getPass(0)->setShadingMode(Ogre::SO_GOURAUD);
	omat->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
	omat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
	omat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(true);
	//omat->getTechnique(0)->getPass(0)->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	
	aiString path;
	aiReturn res = mat->GetTexture(aiTextureType_DIFFUSE, 0, &path);
	if (res == AI_SUCCESS) {
		Ogre::TextureUnitState* stateBase = omat->getTechnique(0)->getPass(0)->createTextureUnitState();
		stateBase->setColourOperation(Ogre::LBO_MODULATE);
		stateBase->setTextureName(path.data);
	}
	
	return omat;
}
Пример #8
0
void
Terrain::_deleteMaterials(void)
{
    Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
    // So we can delete this terrain after material manager is delete
    if (materialManager)
    {
        for (MaterialMap::const_iterator it = mMaterials.begin(); it != mMaterials.end(); ++it)
        {
            Ogre::ResourceHandle handle = it->second->getHandle();

            materialManager->remove(handle);
        }
    }
    mMaterials.clear();

    Ogre::TextureManager* textureManager = Ogre::TextureManager::getSingletonPtr();
    if (textureManager)
    {
        for (AtlasArray::const_iterator it = mAtlases.begin(); it != mAtlases.end(); ++it)
        {
            // Only remove composited textures.
            if (!it->texture.isNull() && !it->image.isNull())
            {
                textureManager->remove(it->texture->getHandle());
            }
        }

        for (TextureList::const_iterator it = mLightmapTextures.begin(); it != mLightmapTextures.end(); ++it)
        {
            textureManager->remove((*it)->getHandle());
        }
    }
    mAtlases.clear();
    mLightmapTextures.clear();

    mAtlasPixmaps.clear();

    // Mark as invalidate
    mSolidAtlasAllocInfo.blockId = mMaxAtlasBlockId;
    mTransparentAtlasAllocInfo.blockId = mMaxAtlasBlockId;
}
//-----------------------------------------------------------------------
void MaterialTab::OnChangeName(wxCommandEvent& event)
{
	wxString newName = mTxtMaterialName->GetValue();
	wxString oldName = mMaterialListBox->GetStringSelection();
	Ogre::String newMaterialName = wx2ogre(newName);
	Ogre::String oldMaterialName = wx2ogre(oldName);
	Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(oldMaterialName);
	if (!material.isNull())
	{
		Ogre::MaterialPtr clonedMaterial = material->clone(newMaterialName);
		if (!clonedMaterial.isNull())
		{
			// Load the new resource, unload the old one, remove it from the list and set the new material as the selected
			clonedMaterial->load();
			Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
			materialManager->remove(oldMaterialName);
			mMaterialListBox->Delete(mMaterialListBox->GetSelection());
			mMaterialListBox->addMaterialName(newName);
			selectMaterial(newName);
		}
	}
}
Пример #10
0
	void GroundFog::findFogPassesByName (const Ogre::String& passName) {
		Ogre::MaterialManager *matManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialManager::ResourceMapIterator matIt = matManager->getResourceIterator();
		while (matIt.hasMoreElements()) {
#if (OGRE_VERSION < ((1 << 16) | (9 << 8) | 0))
            Ogre::MaterialPtr mat = matIt.getNext();
#else
            Ogre::MaterialPtr mat = matIt.getNext().staticCast<Ogre::Material>();
#endif
			Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
			while (techIt.hasMoreElements()) {
				Ogre::Technique *tech = techIt.getNext();
				Ogre::Technique::PassIterator passIt = tech->getPassIterator();
				while (passIt.hasMoreElements()) {
					Ogre::Pass *pass = passIt.getNext();
					if (pass->getName() == passName) {
						mPasses.insert(pass);
					}
				}
			}
		}
		forceUpdate();
	}
Пример #11
0
void OGKSceneManager::_initRTT()
{
    if(mTransitionTexture.isNull()) {
        Ogre::TextureManager *mgr = Ogre::TextureManager::getSingletonPtr();
        
        mTransitionTexture = mgr->createManual(kTransitionTextureName,
                                               Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                               Ogre::TEX_TYPE_2D,
                                               OGKGame::getSingletonPtr()->mRenderWindow->getWidth(),
                                               OGKGame::getSingletonPtr()->mRenderWindow->getHeight(),
                                               0,
                                               Ogre::PF_R8G8B8A8,
                                               Ogre::TU_RENDERTARGET);
    }
    
    if(!mRenderTexture) {
        mRenderTexture = mTransitionTexture->getBuffer()->getRenderTarget();
        mRenderTexture->setAutoUpdated(false);
        mRenderTexture->addListener(this);
    }
    
    if(!mPanel) {
        Ogre::MaterialManager *mgr = Ogre::MaterialManager::getSingletonPtr();
        
#ifdef OGRE_IS_IOS
        mTransitionMaterial = mgr->getByName("OGK/SceneTransitionMaterial");
        
        //mTransitionMaterial->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
        //Ogre::TextureUnitState* state = mTransitionMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();
#else
        mTransitionMaterial = mgr->create(kTransitionMaterialName,
                                          Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        mTransitionMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
        mTransitionMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        mTransitionMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(kTransitionTextureName);
        
#endif
        mTransitionTextureUnitState = mTransitionMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0);
        
#ifdef OGRE_IS_IOS
//        mTransitionTextureUnitState->setTextureFiltering( Ogre::FO_ANISOTROPIC, Ogre::FO_ANISOTROPIC, Ogre::FO_LINEAR );
//        mTransitionTextureUnitState->setTextureAnisotropy( 8 );
//        mTransitionTextureUnitState->setTextureName( kTransitionTextureName );
        mTransitionTextureUnitState->setTexture(mTransitionTexture);
#endif
        
        mPanel = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement( "Panel", kTransitionOverlayPanelName));
        mPanel->setMetricsMode(Ogre::GMM_RELATIVE);
        mPanel->setPosition(0.0, 0.0);
        mPanel->setDimensions(1.0, 1.0);
#ifdef OGRE_IS_IOS
        mPanel->setMaterialName( "OGK/SceneTransitionMaterial" );
#else
        mPanel->setMaterialName( kTransitionMaterialName );
#endif
//        mPanel->setMaterialName( "OGK/Debug/Yellow" );
//        mPanel->setMaterialName( "BaseWhiteNoLighting" );
        mOverlay->add2D(mPanel);
        mOverlay->show();
    }
}
Пример #12
0
//--------------------------------------------------------------------------------------------------
bool DiscoApplication::frameStarted( const Ogre::FrameEvent& evt )
{
	static Ogre::Timer a;

	static uint32_t lastTimeMS;
	static uint32_t curTimeMS;

	curTimeMS = a.getMilliseconds();
	uint32_t timeDiffMS = curTimeMS - lastTimeMS;

	if ( timeDiffMS > 0 )
	{
		//printf( "FPS = %f\n", 1000.0/(float)timeDiffMS );//1.0/((float)timeDiffMS/1000.0) );
	}
	lastTimeMS = curTimeMS;

	const int32_t MAX_DEPTH_MM = 10000;
	const float FOCAL_LENGTH = 0.525f;	// Focal length in metres
	const float FADE_START_XZ_DISTANCE = 0.5f;
	const float FADE_MAX_XZ_DISTANCE = 6.0f;

	xn::SceneMetaData sceneMD;
	xn::DepthMetaData depthMD;

	mpKinectController->getContext().WaitAndUpdateAll();
	mpKinectController->getDepthGenerator().GetMetaData( depthMD );
	mpKinectController->getUserGenerator().GetUserPixels( 0, sceneMD );

	XnUserID userIdx[15];
	XnUInt16 numUsers = 15;
	mpKinectController->getUserGenerator().GetUsers( userIdx, numUsers );

	if ( 0 == numUsers )
	{
		// Restart the time if there are no users to record
		mRecordingGapTimer.reset();
	}
	else
	{
		for ( uint32_t i = 0; i < numUsers; i++ )
		{
			if ( tryToAttachParticleToUser( userIdx[ i ] ) )
			{
				break;
			}
		}
	}

	// Start recording if we see a person
	if ( numUsers > 0 && !mbRecording
		&& mRecordingGapTimer.getMilliseconds() > TIME_BETWEEN_RECORDINGS_MS )
	{
		mbRecording = true;
		memset( mpImageData, 0, RECORDED_DATA_SIZE );
		mRecordingFrameIdx = 0;
	}


	// Build an accumulative histogram to work out the colour for each point
	uint32_t depthHist[ MAX_DEPTH_MM ];
	memset( depthHist, 0, sizeof( depthHist ) );

	uint32_t numPoints = 0;

	const XnDepthPixel* pDepth = depthMD.Data();

	int32_t recordingPixelStepX = depthMD.XRes() / SMALL_FRAME_WIDTH;
	int32_t recordingPixelStepY = depthMD.YRes() / SMALL_FRAME_HEIGHT;
	if ( recordingPixelStepX <= 0 ) recordingPixelStepX = 1;
	if ( recordingPixelStepY <= 0 ) recordingPixelStepY = 1;

	for ( uint32_t y = 0; y < depthMD.YRes(); y++ )
	{
		for ( uint32_t x = 0; x < depthMD.XRes(); x++ )
		{
			XnUInt16 value = *pDepth;

			if ( 0 != value )
			{
				depthHist[ value ]++;
				numPoints++;
			}

			pDepth++;
		}
	}

	for ( uint32_t i = 1; i < MAX_DEPTH_MM; i++ )
	{
		depthHist[ i ] += depthHist[ i - 1 ];
	}

	if ( numPoints > 0 )
	{
		for ( uint32_t i = 1; i < MAX_DEPTH_MM; i++ )
		{
			depthHist[ i ] = (unsigned int)(256 * (1.0f - ((float)depthHist[ i ] / numPoints)));
		}
	}

	// Update the point cloud to reflect the depth data
	const float COLOURS[][3] =
	{
		{0,1,1},
		{0,0,1},
		{0,1,0},
		{1,1,0},
		{1,0,0},
		{1,.5,0},
		{.5,1,0},
		{0,.5,1},
		{.5,0,1},
		{1,1,.5},
		{1,1,1}
	};
	const uint32_t NUM_COLOURS = 10;

	pDepth = depthMD.Data();
	const XnLabel* pLabels = sceneMD.Data();


	mpRosPointCloud->clear();

	ogre_tools::PointCloud::Point* pPoints = new ogre_tools::PointCloud::Point[ numPoints ];
	int32_t pointIdx = 0;

	int32_t width = depthMD.XRes();
	int32_t height = depthMD.YRes();
	int32_t halfWidth = width / 2;
	int32_t halfHeight = height / 2;

	for ( int32_t y = 0; y < height; y++ )
	{
		for ( int32_t x = 0; x < width; x++ )
		{
			XnUInt16 value = *pDepth;
			XnLabel label = *pLabels;
			XnUInt32 colorId = label % NUM_COLOURS;

			float fade = 1.0;

			if (label == 0)
			{
				// Ignore background
				colorId = NUM_COLOURS;
			}


			{

				float worldZ = (float)(*pDepth)/1000.0;		// Convert from mm to m
				float worldX = (((float)(x-halfWidth)/1000.0)*worldZ) / FOCAL_LENGTH;

				float distanceXZ = sqrtf( worldX*worldX + worldZ*worldZ );
				if ( distanceXZ > FADE_MAX_XZ_DISTANCE )
				{
					fade = 0.0f;
				}
				else if ( distanceXZ > FADE_START_XZ_DISTANCE )
				{
					fade = 1.0 - (distanceXZ - FADE_START_XZ_DISTANCE)/(FADE_MAX_XZ_DISTANCE - FADE_START_XZ_DISTANCE);
				}
			}

			if ( //mbRecording
				0 != value && fade > 0.0
				&& ( SHOW_BACKGROUND || label != 0 ) )
			{
				float worldZ = (float)(*pDepth)/1000.0;		// Convert from mm to m
				float worldX = (((float)(x-halfWidth)/1000.0)*worldZ) / FOCAL_LENGTH;
				float worldY = (((float)(y-halfHeight)/1000.0)*worldZ) / FOCAL_LENGTH;
				//float worldY = (((float)(((height-1)-y)-halfHeight)/1000.0)*worldZ) / FOCAL_LENGTH;

				float histValue = (float)depthHist[ value ]/255.0;

				pPoints[ pointIdx ].setColor(
					fade * histValue * COLOURS[ colorId ][ 0 ],
					fade * histValue * COLOURS[ colorId ][ 1 ],
					fade * histValue * COLOURS[ colorId ][ 2 ] );

				pPoints[ pointIdx ].x = worldX;
				pPoints[ pointIdx ].y = worldY;
				pPoints[ pointIdx ].z = worldZ;

				pointIdx++;

				if ( mbRecording && label != 0
					&& x%recordingPixelStepX == 0 && y%recordingPixelStepY == 0 )
				{
					int32_t smallFrameX = x / recordingPixelStepX;
					int32_t smallFrameY = y / recordingPixelStepY;

					int32_t smallPixelIdx = mRecordingFrameIdx*SMALL_FRAME_WIDTH*SMALL_FRAME_HEIGHT
						+ smallFrameY*SMALL_FRAME_WIDTH + smallFrameX;

					//((uint16_t*)mpImageData)[ smallPixelIdx ] = 0xFFFF;
					//((uint32_t*)mpImageData)[ smallPixelIdx ] = 0xFFFFFFFF;

					mpImageData[ smallPixelIdx ] = 0xFF; // 255; //(uint8_t)(fade * histValue * 255.0);
					//printf( "recorded %i to pixel %i\n", mpImageData[ smallPixelIdx ], smallPixelIdx );
				}
			}

			pDepth++;
			pLabels++;
		}
	}

	mpRosPointCloud->addPoints( pPoints, pointIdx );
	//printf( "Added %i points\n", pointIdx );

	delete [] pPoints;

	// Draw the crowd
	uint32_t numCrowdMembers = mCrowdMembers.size();
	mpCrowdObject->clear();
	mpCrowdObject->estimateVertexCount( numCrowdMembers*4 );
	mpCrowdObject->estimateIndexCount( numCrowdMembers*12 );

	for ( uint32_t personIdx = 0; personIdx < numCrowdMembers; personIdx++ )
	{
		CrowdMember& crowdMember = mCrowdMembers[ personIdx ];

		float startV = (float)crowdMember.mFrameIdx/(float)NUM_FRAMES_TO_RECORD;
		float endV = (float)(crowdMember.mFrameIdx+1)/(float)NUM_FRAMES_TO_RECORD;

		mpCrowdObject->begin( crowdMember.mMaterialName, Ogre::RenderOperation::OT_TRIANGLE_LIST );

		//float startV = 0.0; //(float)crowdMember.mFrameIdx/(float)NUM_FRAMES_TO_RECORD;
		//float endV = 1.0;// (float)(crowdMember.mFrameIdx+1)/(float)NUM_FRAMES_TO_RECORD;

		//mpCrowdObject->begin( "Template/CutOut", Ogre::RenderOperation::OT_TRIANGLE_LIST );


		mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( -0.5f, -0.375f, 0.0f ) );
		mpCrowdObject->textureCoord( 0.0, startV );
		mpCrowdObject->colour( COLOURS[ crowdMember.mColourIdx ][ 0 ],
			COLOURS[ crowdMember.mColourIdx ][ 1 ], COLOURS[ crowdMember.mColourIdx ][ 2 ], 1.0 );

		mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( 0.5f, -0.375f, 0.0f ) );
		mpCrowdObject->textureCoord( 1.0, startV );

		mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( 0.5f, 0.375f, 0.0f ) );
		mpCrowdObject->textureCoord( 1.0, endV );

		mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( -0.5f, 0.375f, 0.0f ) );
		mpCrowdObject->textureCoord( 0.0, endV );

		//mpCrowdObject->quad( 0, 1, 2, 3 );
		mpCrowdObject->quad( 3, 2, 1, 0 );

		mpCrowdObject->end();

		// Move to the next frame
		if ( crowdMember.mbReversing )
		{
			crowdMember.mFrameIdx--;
			if ( crowdMember.mFrameIdx < 0 )
			{
				crowdMember.mFrameIdx = 1;
				crowdMember.mbReversing = false;
			}
		}
		else
		{
			crowdMember.mFrameIdx++;
			if ( crowdMember.mFrameIdx >= NUM_FRAMES_TO_RECORD )
			{
				crowdMember.mFrameIdx = NUM_FRAMES_TO_RECORD-1;
				crowdMember.mbReversing = true;
			}
		}
	}


	// Check to see if we can stop recording
	if ( mbRecording )
	{
		mRecordingFrameIdx++;
		if ( mRecordingFrameIdx >= NUM_FRAMES_TO_RECORD )
		{
			// Create a new crowd member
			Ogre::Image image;
			image.loadDynamicImage(
				mpImageData, SMALL_FRAME_WIDTH, NUM_FRAMES_TO_RECORD*SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );

			std::stringstream ss;
			ss << "RecordedSequenceTex_" << numCrowdMembers;
			Ogre::String texName = ss.str();

			Ogre::TextureManager* pTextureMgr = Ogre::TextureManager::getSingletonPtr();
			Ogre::TexturePtr pTexture = pTextureMgr->loadImage( texName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image );

			ss.clear();
			ss << "RecordedSequenceMat_" << numCrowdMembers;
			Ogre::String matName = ss.str();

			Ogre::MaterialManager* pMatMgr = Ogre::MaterialManager::getSingletonPtr();
			Ogre::MaterialPtr pSrcMat = (Ogre::MaterialPtr)pMatMgr->getByName( "Template/CutOut", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
			Ogre::MaterialPtr pMat = pSrcMat->clone( matName ); //  (Ogre::MaterialPtr)pMatMgr->create( matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );

			pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
			Ogre::TextureUnitState* pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState( texName, 0 );
			pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );

			/*Ogre::Technique* pTech = pMat->getTechnique( 0 );
			pTech->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );

			Ogre::Pass *pPass = pTech->createPass();

			pPass->setLightingEnabled( false );

			pPass->setAmbient( 1.0, 1.0, 1.0 );
			pPass->setDiffuse( 1.0, 1.0, 1.0, 1.0 );
			pPass->setSpecular( 0.0, 0.0, 0.0, 0.0 );

			Ogre::ColourValue val(0.0f, 0.0f, 0.0f, 1.0f);
			pPass->setSelfIllumination(val);

			//pPass->setE ( 0.0, 0.0, 0.0, 0.0 );

			pPass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
			pPass->setDepthWriteEnabled( false );

			Ogre::TextureUnitState* pTex = pPass->createTextureUnitState( texName, 0 );
			pPass->addTextureUnitState( pTex );


			pTex->setColourOperation( Ogre::LBO_MODULATE );*/

			pMat->setCullingMode( Ogre::CULL_NONE );
			pMat->compile();

			CrowdMember crowdMember;
			crowdMember.mMaterialName = matName;
			crowdMember.mFrameIdx = 0;
			crowdMember.mColourIdx = rand()%NUM_COLOURS;
			crowdMember.mbReversing = false;

			int32_t rowIdx = rand()%NUM_ROWS;
			float angle = MIN_CROWD_ANGLE + ((float)rand()/(float)RAND_MAX)*(MAX_CROWD_ANGLE-MIN_CROWD_ANGLE);
			float x = ROW_DEPTHS[ rowIdx ]*sin( angle );
			float z = ROW_DEPTHS[ rowIdx ]*cos( angle );
			crowdMember.mPos = Ogre::Vector3( x, ROW_HEIGHTS[ rowIdx ], z );
			mCrowdMembers.push_back( crowdMember );

			mbRecording = false;
			mRecordingGapTimer.reset();		// Reset time so that there's a gap between recording
			printf( "Got frame\n" );
		}
	}

	return true;
}
Пример #13
0
void MilkshapePlugin::doExportMaterials(msModel* pModel)
{
	Ogre::LogManager& logMgr = Ogre::LogManager::getSingleton();
	Ogre::MaterialManager matMgrSgl;
	Ogre::String msg;

    matMgrSgl.initialise();

	int numMaterials = msModel_GetMaterialCount(pModel);
	msg = "Number of materials: " + Ogre::StringConverter::toString(numMaterials);
	logMgr.logMessage(msg);

	OPENFILENAME ofn;
	memset (&ofn, 0, sizeof (OPENFILENAME));

	char szFile[MS_MAX_PATH];
	char szFileTitle[MS_MAX_PATH];
	char szDefExt[32] = "material";
	char szFilter[128] = "OGRE .material Files (*.material)\0*.material\0All Files (*.*)\0*.*\0\0";
	szFile[0] = '\0';
	szFileTitle[0] = '\0';

	ofn.lStructSize = sizeof (OPENFILENAME);
	ofn.lpstrDefExt = szDefExt;
	ofn.lpstrFilter = szFilter;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = MS_MAX_PATH;
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = MS_MAX_PATH;
	ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
	ofn.lpstrTitle = "Export to OGRE Material";

	if (!::GetSaveFileName (&ofn))
		return;

	// Strip off the path
	Ogre::String matName = szFile;
	size_t lastSlash = matName.find_last_of("\\");
	matName = matName.substr(lastSlash+1);

	// Set up
	logMgr.logMessage("Trying to create Material object");

	Ogre::MaterialSerializer matSer;

	for (int i = 0; i < numMaterials; ++i)
	{
		msMaterial *mat = msModel_GetMaterialAt(pModel, i);

		msg = "Creating material " + Ogre::String(mat->szName);
		logMgr.logMessage(msg);
        Ogre::MaterialPtr ogremat = matMgrSgl.create(mat->szName, 
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		logMgr.logMessage("Created.");

		ogremat->setAmbient(msVec4ToColourValue(mat->Ambient));
		ogremat->setDiffuse(msVec4ToColourValue(mat->Diffuse));
		ogremat->setSpecular(msVec4ToColourValue(mat->Specular));
		ogremat->setShininess(mat->fShininess);

		if (0 < strlen(mat->szDiffuseTexture))
			ogremat->getTechnique(0)->getPass(0)->createTextureUnitState(mat->szDiffuseTexture);

        if (0 < strlen(mat->szAlphaTexture))
			ogremat->getTechnique(0)->getPass(0)->createTextureUnitState(mat->szAlphaTexture);


		matSer.queueForExport(ogremat);
	}

	msg = "Exporting materials to " + matName;
	logMgr.logMessage(msg);
	matSer.exportQueued(matName);
}
Пример #14
0
// 设置选中的外观颜色.
void CEditDobject_NT::SetSelectLook(Ogre::ColourValue color)
{

	if(0 == m_materialSelVector.size())
	{
		// 选中材质的名字.
		Ogre::String strCloneName;
		int iCount = m_EntityList.size();
		Ogre::Entity* pEntity = NULL;

		for(int i = 0; i < iCount; i++)
		{
			pEntity = m_EntityList[i].pEntity;
			if(pEntity)
			{
				Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
				if(pSubEntiy)
				{
					
					Ogre::MaterialPtr pMaterial = pSubEntiy->getMaterial();
					
					if(pMaterial.isNull())
					{
						return;
					}//

					const Ogre::String& strName = pMaterial->getName();

					if("BaseWhite" == strName)
					{
						continue;
					}

					strCloneName = strName;
					strCloneName += "_select";
					
					Ogre::MaterialManager* pMaterialManager = (Ogre::MaterialManager*)(pMaterial->getCreator());

					if(NULL == pMaterialManager)
					{
						return;
					}

					Ogre::MaterialPtr pMaterialClone = pMaterialManager->getByName(strCloneName); 
						
					if(pMaterialClone.isNull())
					{
						pMaterialClone = pMaterial->clone(strCloneName);
					}
					//if(!pMaterialClone)
					//{
					//	return;
					//}//

					Ogre::Technique* pTechnique = pMaterialClone->getBestTechnique();
					Ogre::Pass* pPass = pTechnique->getPass(0);

					//pPass->setSceneBlending(SBT_ADD);
					//pPass->setSceneBlending(SBF_SOURCE_ALPHA , SBF_ONE_MINUS_SOURCE_ALPHA );
					//pTextureState->setAlphaOperation(LBX_MODULATE, LBS_TEXTURE, LBS_MANUAL, 1, Transparence, 1);//
				
					Ogre::TextureUnitState* pTextureState = pPass->getTextureUnitState(0);
					pTextureState->setColourOperationEx(Ogre::LBX_ADD , Ogre::LBS_TEXTURE , Ogre::LBS_MANUAL, color, color );
					pSubEntiy->setMaterialName(strCloneName);
					m_materialSelVector.push_back(pMaterialClone);
					m_materilaOldVector.push_back(pMaterial);
					
				}

			}
		}
	}
	else
	{
		int iIndex = 0;

		int iCount = m_EntityList.size();
		Ogre::Entity* pEntity = NULL;

		for(int i = 0; i < iCount; i++)
		{
			pEntity = m_EntityList[i].pEntity;
			if(pEntity)
			{
				Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
				
				if(pSubEntiy)
				{
					if(iIndex >= (int)m_materialSelVector.size())
					{
						continue;
					}

					std::string strMaterialName = m_materialSelVector[iIndex]->getName();
					pSubEntiy->setMaterialName(strMaterialName);	
					iIndex++;
				}

			}
		}
	}
}
Пример #15
0
void RenderedTexture::renderTextures()
{
    //Set up RTT texture
    Ogre::TexturePtr renderTexture;
    if (renderTexture.isNull()) {
        renderTexture = Ogre::TextureManager::getSingleton().createManual(
            getUniqueID("RenderedEntityMaterial"), "EntityRenderer",
            Ogre::TEX_TYPE_2D, textureSize, textureSize, 0,
            Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET, 0);
    }
    renderTexture->setNumMipmaps(0);

    //Set up render target
    Ogre::RenderTexture* renderTarget = renderTexture->getBuffer()->getRenderTarget(); 
    renderTarget->setAutoUpdated(false);

    //Set up camera
    Ogre::SceneNode* camNode = sceneMgr->getSceneNode("EntityRenderer::cameraNode");
    Ogre::Camera* renderCamera = sceneMgr->createCamera(getUniqueID("EntityRendererCam"));
    camNode->attachObject(renderCamera);
    renderCamera->setLodBias(1000.0f);

    Ogre::Viewport* renderViewport = renderTarget->addViewport(renderCamera);
    renderViewport->setOverlaysEnabled(false);
    renderViewport->setClearEveryFrame(true);
    renderViewport->setShadowsEnabled(false);
    renderViewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 0.0f));

    //Set up scene node
    Ogre::SceneNode* node = sceneMgr->getSceneNode("EntityRenderer::renderNode");

    Ogre::SceneNode* oldSceneNode = entity->getParentSceneNode();
    if (oldSceneNode)
        oldSceneNode->detachObject(entity);
    node->attachObject(entity);
    node->setPosition(-entityCenter);

    //Set up camera FOV
    const Ogre::Real objDist = entityRadius * 100;
    const Ogre::Real nearDist = objDist - (entityRadius + 1); 
    const Ogre::Real farDist = objDist + (entityRadius + 1);

    renderCamera->setAspectRatio(1.0f);
    renderCamera->setFOVy(Ogre::Math::ATan(2.0 * entityRadius / objDist));
    renderCamera->setNearClipDistance(nearDist);
    renderCamera->setFarClipDistance(farDist);

    //Disable mipmapping (without this, masked textures look bad)
    Ogre::MaterialManager* mm = Ogre::MaterialManager::getSingletonPtr();
    Ogre::FilterOptions oldMinFilter = mm->getDefaultTextureFiltering(Ogre::FT_MIN);
    Ogre::FilterOptions oldMagFilter = mm->getDefaultTextureFiltering(Ogre::FT_MAG);
    Ogre::FilterOptions oldMipFilter = mm->getDefaultTextureFiltering(Ogre::FT_MIP);
    mm->setDefaultTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR,Ogre:: FO_NONE);

    //Disable fog
    Ogre::FogMode oldFogMode = sceneMgr->getFogMode();
    Ogre::ColourValue oldFogColor = sceneMgr->getFogColour();
    Ogre::Real oldFogDensity = sceneMgr->getFogDensity();
    Ogre::Real oldFogStart = sceneMgr->getFogStart();
    Ogre::Real oldFogEnd = sceneMgr->getFogEnd();
    sceneMgr->setFog(Ogre::FOG_NONE);

    // Get current status of the queue mode
    Ogre::SceneManager::SpecialCaseRenderQueueMode OldSpecialCaseRenderQueueMode =
        sceneMgr->getSpecialCaseRenderQueueMode();
    //Only render the entity
    sceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE); 
    sceneMgr->addSpecialCaseRenderQueue(renderQueueGroup);

    Ogre::uint8 oldRenderQueueGroup = entity->getRenderQueueGroup();
    entity->setRenderQueueGroup(renderQueueGroup);
    bool oldVisible = entity->getVisible();
    entity->setVisible(true);
    float oldMaxDistance = entity->getRenderingDistance();
    entity->setRenderingDistance(0);

    //Calculate the filename hash used to uniquely identity this render
    std::string strKey = entityKey;
    char key[32] = {0};
    Ogre::uint32 i = 0;
    for (std::string::const_iterator it = entityKey.begin(); it != entityKey.end(); ++it) {
        key[i] ^= *it;
        i = (i+1) % sizeof(key);
    }
    for (i = 0; i < sizeof(key); ++i)
        key[i] = (key[i] % 26) + 'A';

    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
        GetUserDir().string(), "FileSystem", "BinFolder");
    std::string fileNamePNG =
        "Rendered." + std::string(key, sizeof(key)) + '.' +
        Ogre::StringConverter::toString(textureSize) + ".png";

    //Attempt to load the pre-render file if allowed
    bool needsRegen = false;
    if (!needsRegen) {
        try{
            texture = Ogre::TextureManager::getSingleton().load(
                fileNamePNG, "BinFolder", Ogre::TEX_TYPE_2D, 0);
        } catch (...) {
            needsRegen = true;
        }
    }

    if (needsRegen) {
        //If this has not been pre-rendered, do so now

        //Position camera
        camNode->setPosition(0, 0, 0);
        // TODO camNode->setOrientation(Quaternion(yaw, Vector3::UNIT_Y) * Quaternion(-pitch, Vector3::UNIT_X));
        camNode->translate(Ogre::Vector3(0, 0, objDist), Ogre::Node::TS_LOCAL);
						
        renderTarget->update();

        //Save RTT to file
        renderTarget->writeContentsToFile((GetUserDir() / fileNamePNG).string());

        //Load the render into the appropriate texture view
        texture = Ogre::TextureManager::getSingleton().load(fileNamePNG, "BinFolder", Ogre::TEX_TYPE_2D, 0);

        ggTexture = ClientUI::GetTexture(GetUserDir() / fileNamePNG);
    }

    entity->setVisible(oldVisible);
    entity->setRenderQueueGroup(oldRenderQueueGroup);
    entity->setRenderingDistance(oldMaxDistance);
    sceneMgr->removeSpecialCaseRenderQueue(renderQueueGroup);
    // Restore original state
    sceneMgr->setSpecialCaseRenderQueueMode(OldSpecialCaseRenderQueueMode); 

    //Re-enable mipmapping
    mm->setDefaultTextureFiltering(oldMinFilter, oldMagFilter, oldMipFilter);

    //Re-enable fog
    sceneMgr->setFog(oldFogMode, oldFogColor, oldFogDensity, oldFogStart, oldFogEnd);

    //Delete camera
    renderTarget->removeViewport(0);
    renderCamera->getSceneManager()->destroyCamera(renderCamera);

    //Delete scene node
    node->detachAllObjects();
    if (oldSceneNode)
        oldSceneNode->attachObject(entity);

    //Delete RTT texture
    assert(!renderTexture.isNull());
    std::string texName2(renderTexture->getName());

    renderTexture.setNull();
    if (Ogre::TextureManager::getSingletonPtr())
        Ogre::TextureManager::getSingleton().remove(texName2);
}
Пример #16
0
/****************************************************************************
**
** Copyright (C) 2014
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

// Include
#include "mainwindow.h"
#include "Editor_dockwidget.h"
#include "constants.h"
#include "sme_asset_material.h"
#include "sme_node_material.h"
#include "sme_asset_technique.h"
#include "sme_node_technique.h"
#include "sme_asset_pass.h"
#include "sme_node_pass.h"
#include "sme_asset_texture_unit.h"
#include "sme_node_texture_unit.h"

//****************************************************************************/
EditorDockWidget::EditorDockWidget(QString title, MainWindow* parent, Qt::WindowFlags flags) : 
	QDockWidget (title, parent, flags), 
	mParent(parent)
{
    mInnerMain = new QMainWindow();
    setWidget(mInnerMain);

    // Perform standard functions
    createActions();
    createMenus();
    createToolBars();

    // Create the node editor widget.
    mNodeEditor = new Magus::QtNodeEditor(this);
    mNodeEditor->setMenuSelectionToCompoundEnabled(false); // Enabling this makes it a bit more complicated
    mNodeEditor->setMenuExpandCompoundsEnabled(false); // No compounds are used
    connect(mNodeEditor, SIGNAL(nodeRemoved(QtNode*)), this, SLOT(nodeDeleted()));
    connect(mNodeEditor, SIGNAL(nodeSelected(QtNode*)), this, SLOT(nodeSelected(QtNode*)));
    mInnerMain->setCentralWidget(mNodeEditor);
    mMaterialNode = 0;
}

//****************************************************************************/
EditorDockWidget::~EditorDockWidget(void)
{
}

//****************************************************************************/
void EditorDockWidget::createActions(void)
{
    mMaterialHToolbarAction = new QAction(QIcon(ICON_MATERIAL), QString("Add a material node to the editor"), this);
    connect(mMaterialHToolbarAction, SIGNAL(triggered()), this, SLOT(doMaterialHToolbarAction()));
    mTechniqueHToolbarAction = new QAction(QIcon(ICON_TECHNIQUE), QString("Add a technique node to the editor"), this);
    connect(mTechniqueHToolbarAction, SIGNAL(triggered()), this, SLOT(doTechniqueHToolbarAction()));
    mPassHToolbarAction = new QAction(QIcon(ICON_PASS), QString("Add a pass node to the editor"), this);
    connect(mPassHToolbarAction, SIGNAL(triggered()), this, SLOT(doPassHToolbarAction()));
    mTextureHToolbarAction = new QAction(QIcon(ICON_TEXTURE), QString("Add a texture unit node to the editor"), this);
    connect(mTextureHToolbarAction, SIGNAL(triggered()), this, SLOT(doTextureHToolbarAction()));
    mCogHToolbarAction = new QAction(QIcon(ICON_COG), QString("Generate material"), this);
    connect(mCogHToolbarAction, SIGNAL(triggered()), this, SLOT(doCogHToolbarAction()));
}

//****************************************************************************/
void EditorDockWidget::createMenus(void)
{

}

//****************************************************************************/
void EditorDockWidget::createToolBars(void)
{
    mHToolBar = new QToolBar();
    mInnerMain->addToolBar(Qt::TopToolBarArea, mHToolBar);
    mHToolBar->setMinimumHeight(TB_ICON_AND_SPACING);
    mHToolBar->setMinimumWidth(1200);
    mHToolBar->addAction(mMaterialHToolbarAction);
    mHToolBar->addAction(mTechniqueHToolbarAction);
    mHToolBar->addAction(mPassHToolbarAction);
    mHToolBar->addAction(mTextureHToolbarAction);
    mHToolBar->addAction(mCogHToolbarAction);
}

//****************************************************************************/
void EditorDockWidget::doMaterialHToolbarAction(void)
{
    // Add a material node; only 1 is allowed
    if (!mMaterialNode)
    {
        mMaterialNode = new Magus::QtNodeMaterial(NODE_TITLE_MATERIAL);
        mNodeEditor->addNode(mMaterialNode);
    }
}

//****************************************************************************/
void EditorDockWidget::doTechniqueHToolbarAction(void)
{
    // Add a technique node
    Magus::QtNodeTechnique* techniqueNode = new Magus::QtNodeTechnique(NODE_TITLE_TECHNIQUE);
    mNodeEditor->addNode(techniqueNode);
}

//****************************************************************************/
void EditorDockWidget::doPassHToolbarAction(void)
{
    // Add a pass node
    Magus::QtNodePass* passNode = new Magus::QtNodePass(NODE_TITLE_PASS);
    mNodeEditor->addNode(passNode);
}

//****************************************************************************/
void EditorDockWidget::doTextureHToolbarAction(void)
{
    // Add a texture unit node
    Magus::QtNodeTextureUnit* textureUnitNode = new Magus::QtNodeTextureUnit(NODE_TITLE_TEXTURE_UNIT);
    mNodeEditor->addNode(textureUnitNode);
}

//****************************************************************************/
void EditorDockWidget::doCogHToolbarAction(void)
{
    if (!mMaterialNode)
        return;

    if (mMaterialNode->getMaterialName().isEmpty())
        return;

    // ---------------------------------------- Create a material ----------------------------------------
    Ogre::LogManager* logManager = Ogre::LogManager::getSingletonPtr();
    Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
    Ogre::String materialName = mMaterialNode->getMaterialName().toStdString(); // Convert to std format
    logManager->logMessage("SME: create Ogre material: " + materialName);
    Ogre::MaterialPtr material = materialManager->create(materialName, "General");

    // Remark: Sceneblending is done for each pass individually, although it is defined on material level

    // ---------------------------------------- Add the technique ----------------------------------------
    Magus::QtNode* node = mMaterialNode->getNodeConnectedToPort(PORT_TECHNIQUE_OUT);
    if (!node)
    {
        logManager->logMessage("SME: No technique node available");
        return;
    }

    Magus::QtNodeTechnique* techniqueNode = static_cast<Magus::QtNodeTechnique*>(node);
    material->removeAllTechniques();
    Ogre::Technique* technique = material->createTechnique();
    technique->removeAllPasses();
    logManager->logMessage("SME: Technique created" + Ogre::StringConverter::toString(material->getNumTechniques()));

    // ---------------------------------------- Add the passes ----------------------------------------
    Magus::QtNodePass* passNode;
    Magus::QtNodeTextureUnit* textureUnitNode;
    Ogre::Pass* pass;
    Ogre::TextureUnitState* textureUnit;
    for (unsigned int i = 1; i < 5; ++i)
    {
        node = techniqueNode->getNodeConnectedToPort(PORT_PASS_OUT, i); // node with the same name
        if (node)
        {
            passNode = static_cast<Magus::QtNodePass*>(node);
            pass = technique->createPass();
            pass->removeAllTextureUnitStates();
            logManager->logMessage("SME: Pass on port nr. " + Ogre::StringConverter::toString(i) + " created");
            propagatePassNodeData(passNode, pass);

            // ---------------------------------------- Add the texture units ----------------------------------------
            for (unsigned int j = 1; j < 9; ++j)
            {
                node = passNode->getNodeConnectedToPort(PORT_TEXTURE_OUT, j);
                if (node)
                {
                    logManager->logMessage("SME: Texture unit on port nr. " +
                                           Ogre::StringConverter::toString(j) +
                                           " of Pass port nr. " +
                                           Ogre::StringConverter::toString(i) +
                                           " created");
                    textureUnitNode = static_cast<Magus::QtNodeTextureUnit*>(node);
                    textureUnit = pass->createTextureUnitState();
                    propagateTextureUnitNodeData(textureUnitNode, textureUnit);
                }
            }
        }
    }

    // Assign the material to the ogrehead
    material->compile();
    material->load();
    mParent->getOgreManager()->getOgreWidget(1)->mEntity->setMaterial(material);
}
Пример #17
0
void OgreCPP::createNewCrowdMember( float animationTime )
{
    char buffer[ 512 ];
    uint32_t numCrowdMembers = mCrowdMembers.size();

    // Create a new crowd member
    Ogre::TextureManager* pTextureMgr = Ogre::TextureManager::getSingletonPtr();
    Ogre::String frameTexNames[ 2*NUM_FRAMES_TO_RECORD ];
    Ogre::String lowResFrameTexNames[ 2*NUM_FRAMES_TO_RECORD ];
    for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ )
    {
        Ogre::Image image;
        image.loadDynamicImage( mpImageData + frameIdx*SMALL_FRAME_WIDTH*SMALL_FRAME_HEIGHT,
            SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );

        sprintf( buffer, "RecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx );
        frameTexNames[ frameIdx ] = buffer;

        Ogre::TexturePtr pTexture = pTextureMgr->loadImage( frameTexNames[ frameIdx ],
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image );

        sprintf( buffer, "LowResRecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx );
        lowResFrameTexNames[ frameIdx ] = buffer;

        Ogre::Image lowResImage;
        lowResImage.loadDynamicImage( mpLowResImageData + frameIdx*LOW_RES_SMALL_FRAME_WIDTH*LOW_RES_SMALL_FRAME_HEIGHT,
            LOW_RES_SMALL_FRAME_WIDTH, LOW_RES_SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );

        pTextureMgr->loadImage( lowResFrameTexNames[ frameIdx ],
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, lowResImage );
    }

    for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ )
    {
        frameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = frameTexNames[ frameIdx ];
        lowResFrameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = lowResFrameTexNames[ frameIdx ];
    }

    // Create materials for the crowd member
    sprintf( buffer, "RecordedSequenceMat_%i", numCrowdMembers );
    Ogre::String matName = buffer;

    Ogre::MaterialManager* pMatMgr = Ogre::MaterialManager::getSingletonPtr();
    Ogre::MaterialPtr pSrcMat = (Ogre::MaterialPtr)pMatMgr->getByName( "Template/CutOut",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
    Ogre::MaterialPtr pMat = pSrcMat->clone( matName );

    pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
    Ogre::TextureUnitState* pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState();
    pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );

    pTex->setAnimatedTextureName( frameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime );

    pMat->setCullingMode( Ogre::CULL_NONE );
    pMat->compile();

    sprintf( buffer, "LowResRecordedSequenceMat_%i", numCrowdMembers );
    Ogre::String lowResMatName = buffer;

    pMat = pSrcMat->clone( lowResMatName );

    pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
    pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState();
    pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );

    pTex->setAnimatedTextureName( lowResFrameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime );

    pMat->setCullingMode( Ogre::CULL_NONE );
    pMat->compile();

    CrowdMember newCrowdMember;
    newCrowdMember.mMaterialName = matName;
    newCrowdMember.mLowResMaterialName = lowResMatName;
    newCrowdMember.mFrameIdx = 0;
    newCrowdMember.mColourIdx = rand()%NUM_COLOURS;
    newCrowdMember.mbReversing = false;

    num = mCrowdMembers.size()%11;

	
	/** POSITION CROWD MEMBER HERE **/
    float x = (num*(5.0/11.0))-2.25;
    float y = 1.5;


    /* centre is 0,0, extremes are -3,+3 */
    newCrowdMember.mPos = Ogre::Vector3( x, y, 5.0 );
    newCrowdMember.mRow = 0;

    newCrowdMember.mpBillboard = OGRE_NEW PersonBillboard();
    newCrowdMember.mpBillboard->setMaterial( newCrowdMember.mMaterialName );
    newCrowdMember.mpBillboard->setCorners(
        Ogre::Vector3( -0.5f, -0.375f, 0.0f ),
        Ogre::Vector3( 0.5f, -0.375f, 0.0f ),
        Ogre::Vector3( -0.5f, 0.375f, 0.0f ),
        Ogre::Vector3( 0.5f, 0.375f, 0.0f )
    );

    // Make sure that the front row is drawn in front of everything else
    newCrowdMember.mpBillboard->setRenderQueueGroup( CROWD_FRONT_RENDER_QUEUE );

    newCrowdMember.mpSceneNode = mpDiscoNode->createChildSceneNode(
        newCrowdMember.mPos, Ogre::Quaternion::IDENTITY );
    newCrowdMember.mpSceneNode->attachObject( newCrowdMember.mpBillboard );

    mCrowdMembers.push_back( newCrowdMember );


    /* PLACING RT USER IN CROWD HERE */
    if(USER_IN_CROWD){
        float userX = (((num+1)%CROWD_WIDTH)*(12.0/(float)CROWD_WIDTH))-5.5;
        mUserNode->setPosition(userX,3.45,9.5);
    }

	

	/** PUSH ROW UP **/
    if (num >= CROWD_WIDTH-1) {
        // push last row up
        for(int j = 0; j < mCrowdMembers.size(); j++)
        {
            mCrowdMembers[j].mPos.z += CROWD_PUSH_BACK;
            mCrowdMembers[j].mPos.y += CROWD_PUSH_UP;

            mCrowdMembers[j].mpSceneNode->setPosition( mCrowdMembers[j].mPos );
            mCrowdMembers[j].mRow++;

            if ( FIRST_LOW_RES_ROW_IDX == mCrowdMembers[j].mRow )
            {
                mCrowdMembers[j].mpBillboard->setMaterial( mCrowdMembers[j].mLowResMaterialName );
            }

            if ( mCrowdMembers[j].mRow > MAX_VISIBLE_ROW_IDX )
            {
            	mCrowdMembers[j].mpBillboard->setVisible( false );
            	mCrowdMembers[j].mpBillboard->setMaterial( "BaseWhiteNoLighting" );
            }
            else
            {
            	mCrowdMembers[j].mpBillboard->setRenderQueueGroup( CROWD_FRONT_RENDER_QUEUE - mCrowdMembers[j].mRow );
            }
        }
    }
}