Exemple #1
0
void CAnimationSetDlg::refresh (BOOL update)
{
	if (update)
	{
		CDialog::UpdateData (update);

		// Clear the combo box
		EditedObject.ResetContent ();

		// Set edited object list
		uint i;
		for (i=0; i<_ObjView->getNumInstance (); i++)
		{
			char name[512];
			_splitpath (_ObjView->getInstance (i)->Saved.ShapeFilename.c_str(), NULL, NULL, name, NULL);
			EditedObject.InsertString (-1, name);
		}

		// Get edited object
		uint instance = _ObjView->getEditedObject ();

		// Selection combo box
		EditedObject.SetCurSel ((instance==0xffffffff)?-1:(int)instance);

		// Clear the tree
		Tree.DeleteAllItems ();

		// Clear the tree
		SkelTree.DeleteAllItems ();

		// Clear the playlist
		PlayList.ResetContent ();

		if (instance != 0xffffffff)
		{
			// Get the instance
			CInstanceInfo *object = _ObjView->getInstance (instance);

			// For all tracks in the animation
			uint i;
			for (i=0; i<object->Saved.AnimationFileName.size(); i++)
			{
				// Get the animation name
				char name[512];
				_splitpath (object->Saved.AnimationFileName[i].c_str(), NULL, NULL, name, NULL);

				// Get the animation pointer
				CAnimation *anim = object->AnimationSet.getAnimation (object->AnimationSet.getAnimationIdByName (name));

				// Insert an intem
				HTREEITEM item=Tree.InsertItem (name);
				Tree.SetItemData (item, i);
				nlassert (item!=NULL);

				// For all tracks in the animation
				std::set<std::string> setString;
				anim->getTrackNames (setString);
				std::set<std::string>::iterator ite=setString.begin();
				while (ite!=setString.end())
				{
					// Add this string
					HTREEITEM newItem = Tree.InsertItem (ite->c_str(), item);
					Tree.SetItemData (newItem, 0xffffffff);

					// Get the track
					ITrack *track=anim->getTrack (anim->getIdTrackByName (*ite));

					// Keyframer ?
					UTrackKeyframer *keyTrack=dynamic_cast<UTrackKeyframer *>(track);
					if (keyTrack)
					{
						// Get number of keys
						std::vector<TAnimationTime> keys;
						keyTrack->getKeysInRange (track->getBeginTime ()-1, track->getEndTime ()+1, keys);

						// Print track info
						char name[512];
						_snprintf (name, 512, "%s (%f - %f) %d keys", typeid(*track).name(), track->getBeginTime (), track->getEndTime (), keys.size());
						HTREEITEM keyItem = Tree.InsertItem (name, newItem);
						Tree.SetItemData (keyItem, 0xffffffff);
					}
					else
					{
						// Print track info
						char name[512];
						_snprintf (name, 512, "%s (%f - %f)", typeid(*track).name(), track->getBeginTime (), track->getEndTime ());
						HTREEITEM keyItem = Tree.InsertItem (name, newItem);
						Tree.SetItemData (keyItem, 0xffffffff);
					}

					ite++;
				}
			}

			// For all tracks in the animation
			for (i=0; i<object->Saved.SWTFileName.size(); i++)
			{
				// Get the animation name
				char name[512];
				_splitpath (object->Saved.SWTFileName[i].c_str(), NULL, NULL, name, NULL);

				// Get the animation pointer
				CSkeletonWeight *swt = object->AnimationSet.getSkeletonWeight (object->AnimationSet.getSkeletonWeightIdByName (name));

				// Insert an intem
				HTREEITEM item=SkelTree.InsertItem (name);
				nlassert (item!=NULL);

				// Get number of node in this skeleton weight
				uint numNode=swt->getNumNode ();

				// Add the nodein the tree
				for (uint n=0; n<numNode; n++)
				{
					char percent[512];
					sprintf (percent, "%s (%f%%)", swt->getNodeName (n).c_str(), swt->getNodeWeight(n)*100);

					// Add this string
					SkelTree.InsertItem (percent, item);
				}
			}

			// For all tracks in the playlist
			for (i=0; i<object->Saved.PlayList.size(); i++)
			{
				// Insert an intem
				int item=PlayList.InsertString (-1, object->Saved.PlayList[i].c_str());
				nlassert (item!=LB_ERR);
			}
		}

		CDialog::UpdateData (FALSE);
	}
	else
	{
		CDialog::UpdateData (TRUE);

		// Get edited object
		uint instance = _ObjView->getEditedObject ();
		if (instance != 0xffffffff)
		{
			// Get the instance
			CInstanceInfo *object = _ObjView->getInstance (instance);

			// Clear the playlist
			object->Saved.PlayList.resize (PlayList.GetCount ());

			// For all tracks in the playlist
			uint i;
			for (i=0; i<object->Saved.PlayList.size(); i++)
			{
				// Insert an intem
				char text[512];
				PlayList.GetText( i, text);
				object->Saved.PlayList[i] = text;
			}

			CDialog::UpdateData (update);
		}
	}

	_ObjView->refreshAnimationListeners();
}
Exemple #2
0
// ***************************************************************************
void CScene::setAutomaticAnimationSet(CAnimationSet *as)
{
	// Backup the animation set
	_AutomaticAnimationSet = as;

	// Delete all auto lightmap animations
	_LMAnimsAuto.deleteAll();
	_AnimatedLightNameToIndex.clear();
	_AnimatedLight.clear();
	_AnimatedLightPtr.clear();
	_LightGroupColor.clear();

	// Register each animation as lightmap
	const uint count = _AutomaticAnimationSet->getNumAnimation();
	uint i;
	for (i=0; i<count; i++)
	{
		// Pointer on the animation
		CAnimation *pAnim = _AutomaticAnimationSet->getAnimation(i);

/*		uint nAnimNb;
		// Reset the automatic animation if no animation wanted
		if( pAnim == NULL )
		{
			_AnimatedLight.clear();
			_AnimatedLightPtr.clear();
			_AnimatedLightNameToIndex.clear();
			nAnimNb = _LightmapAnimations.getAnimationIdByName("Automatic");
			if( nAnimNb != CAnimationSet::NotFound )
			{
				CAnimation *anim = _LightmapAnimations.getAnimation( nAnimNb );
				delete anim;
			}
			_LightmapAnimations.reset();
			_LMAnimsAuto.deleteAll();
			return;
		}
		*/

		set<string> setTrackNames;
		pAnim->getTrackNames( setTrackNames );

		// nAnimNb = _LightmapAnimations.addAnimation( "Automatic", pAnim );
		// _LightmapAnimations.build();

		set<string>::iterator itSel = setTrackNames.begin();
		while ( itSel != setTrackNames.end() )
		{
			string ate = *itSel;
			if( strncmp( itSel->c_str(), "LightmapController.", 19 ) == 0 )
			{
				// The light name
				const char *lightName = strrchr ((*itSel).c_str (), '.')+1;

				// Light animation doesn't exist ?
				if (_AnimatedLightNameToIndex.find (lightName) == _AnimatedLightNameToIndex.end())
				{
					// Channel mixer for light anim
					CChannelMixer *cm = new CChannelMixer();
					cm->setAnimationSet( _AutomaticAnimationSet );

					// Add an automatic animation
					_AnimatedLight.push_back ( CAnimatedLightmap ((uint)_LightGroupColor.size ()) );
					_AnimatedLightPtr.push_back ( &_AnimatedLight.back () );
					_AnimatedLightNameToIndex.insert ( std::map<std::string, uint>::value_type (lightName, (uint32)_AnimatedLightPtr.size ()-1 ) );
					CAnimatedLightmap &animLM = _AnimatedLight.back ();
					animLM.setName( *itSel );

					cm->addChannel( animLM.getName(), &animLM, animLM.getValue(CAnimatedLightmap::FactorValue),
						animLM.getDefaultTrack(CAnimatedLightmap::FactorValue), CAnimatedLightmap::FactorValue,
						CAnimatedLightmap::OwnerBit, false);

					// Animated lightmap playlist
					CAnimationPlaylist *pl = new CAnimationPlaylist();
					pl->setAnimation( 0, i );
					pl->setWrapMode( 0, CAnimationPlaylist::Repeat );
					_LMAnimsAuto.addPlaylist(pl,cm);
				}
			}
			++itSel;
		}
	}
}