Re: [osg-users] Controlling animations in FBX models
Hi Thomas, I tested your code and I got an error: OsgAnimationTools AnimationSplit XML Config ERROR: AnimationSplit nodes must contain a 'splitCount' property. The function that reads my FPS returns 0, even when I set to 30 in the xml file. Also, the function ReadAniSplitFromConfigNode() has a variable splitCount that is never used. If you can help me, I will be thankful. Renato On Mon, Feb 14, 2011 at 12:22 AM, Renato Silveira silveira@gmail.comwrote: Thank you very mutch! I will check it. Renato On Sun, Feb 13, 2011 at 7:06 PM, Thomas Hogarth thomas.hoga...@gmail.comwrote: Attached is the cpp and an example config file. I think it's pretty straight forward. Looks like the forum blocked my xml config so here is a copy in the post below ?xml version=1.0 encoding=ISO-8859-15? OsgAnimationTools sourceFile='./Data/Models/Terrorist/terrorist.FBX' destinationFile='./splitExport.osgb' fps='30' AnimationSplit sourceAnimation='Take 001' NewAnimation name='staying' startFrame='0' endFrame='49'/ NewAnimation name='fire_standing' startFrame='50' endFrame='89'/ NewAnimation name='running' startFrame='90' endFrame='111'/ NewAnimation name='walking' startFrame='112' endFrame='147'/ NewAnimation name='grenade_throw' startFrame='148' endFrame='187'/ NewAnimation name='hide_behind_wall' startFrame='188' endFrame='213'/ NewAnimation name='from_standing_to_squat' startFrame='214' endFrame='241'/ NewAnimation name='fire_sguating' startFrame='242' endFrame='291'/ NewAnimation name='from_sguating_to_stand' startFrame='292' endFrame='313'/ NewAnimation name='jump_down' startFrame='314' endFrame='359'/ NewAnimation name='fire_lying' startFrame='360' endFrame='379'/ NewAnimation name='stand_up' startFrame='380' endFrame='425'/ NewAnimation name='dying_on_belt' startFrame='426' endFrame='532'/ NewAnimation name='dying_on_spin' startFrame='533' endFrame='568'/ NewAnimation name='jump' startFrame='569' endFrame='614'/ /AnimationSplit /OsgAnimationTools -- Renato Silveira (Ph. D. Student) Informatics Institute - UFRGS Porto Alegre - RS - Brazil http://www.inf.ufrgs.br/~rsilveira -- Renato Silveira (Ph. D. Student) Informatics Institute - UFRGS Porto Alegre - RS - Brazil http://www.inf.ufrgs.br/~rsilveira ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Controlling animations in FBX models
Hi Renato / others I've finished my animation splitting system, seems to do the job for me. I used osgDB XmlPaser to allow an xml file to be used for config and have successfully loaded my original long animation file and split it into separate 'takes'. Attached is the cpp and an example config file. I think it's pretty straight forward. Let me know if you get stuck Cheers Tom PS At the moment exporting to .osgb seems to be the only format that works. Source file can be whatever you previously had e.g. fbx // //Simple animation split util, will load an xml config file from ./splitConfig.xml and //use it to specify a source file, output/destination file and a set of new split animations //key use of this tool is to split one long animatiob from 3ds max into multiple 'takes' // #include osgDB/ReadFile #include osgDB/WriteFile #include osgDB/FileUtils #include osgDB/XmlParser #include osgAnimation/BasicAnimationManager #include osgAnimation/AnimationManagerBase // //finds and returns the fist AnimationManagerBase in the subgraph struct AnimationManagerFinder : public osg::NodeVisitor { osg::ref_ptrosgAnimation::BasicAnimationManager _am; AnimationManagerFinder() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} void apply(osg::Node node) { if (_am.valid()) return; if (node.getUpdateCallback()) { osgAnimation::AnimationManagerBase* b = dynamic_castosgAnimation::AnimationManagerBase*(node.getUpdateCallback()); if (b) { _am = new osgAnimation::BasicAnimationManager(*b); node.setUpdateCallback(_am.get()); return; } } traverse(node); } }; // //Finds an Animation by name, returning a pointer to the animation //and a pointer to the manager it was found in struct FindOsgAnimationByName : public osg::NodeVisitor { //the name of the source animation we are looking for std::string _sourceAnimationName; //used to return the animation and the manager it was stored in osgAnimation::Animation* p_ani; osgAnimation::AnimationManagerBase* p_manager; FindOsgAnimationByName(std::string sourceAnimationName) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), p_ani(NULL), p_manager(NULL), _sourceAnimationName(sourceAnimationName) { } void apply(osg::Node node) { if (node.getUpdateCallback()) { osgAnimation::AnimationManagerBase* b = dynamic_castosgAnimation::AnimationManagerBase*(node.getUpdateCallback()); if (b) { //we have found a valid osgAnimation manager, now look for the single long animation inside with the desired name osgAnimation::AnimationList aniList = b-getAnimationList(); for(unsigned int i=0; ianiList.size(); i++){ if(aniList[i]-getName() == _sourceAnimationName){ p_manager = b; p_ani = aniList[i].get(); return; } } } } traverse(node); } }; class AnimationUtils { public: //returns the index of the keyframe closest to the passed time //returns -1 if the time is out of range of the key container template typename ContainerType static int GetNearestKeyFrameIndex(ContainerType* keyContainer, double time) { if(!keyContainer){return -1;} int closestFrame = -1; double closestDiff = 9.99f; //loop all the keys for(unsigned int i=0; ikeyContainer-size(); i++) { double diff = fabs(time - (*keyContainer)[i].getTime()); if( diff closestDiff){ closestFrame = i; closestDiff = diff; } } return closestFrame; } Helper method for resampling channels template typename ChannelType, typename ContainerType static osg::ref_ptrChannelType ResampleChannel(ChannelType* sourceChannel, unsigned int startFrame, unsigned int endFrame, int fps) { osg::ref_ptrChannelType newChannel = NULL; if(!sourceChannel){ return newChannel; } //get the key frame container from the source channel ContainerType* sourceKeyCont = sourceChannel-getSamplerTyped()-getKeyframeContainerTyped(); if (sourceKeyCont) { OSG_INFO OsgAnimationTools ResampleChannel INFO: Resampling source channel ' sourceChannel-getName() ', from startFrame ' startFrame ' to endFrame ' endFrame . Total frames in source channel ' sourceKeyCont-size() '. std::endl; if(startFrame = sourceKeyCont-size() || endFrame = sourceKeyCont-size()) { OSG_WARN OsgAnimationTools ResampleChannel ERROR: startFrame or endFrame is out of range, std::endl startFrame ' startFrame ', endFrame ' endFrame . Total frames in source channel ' sourceKeyCont-size() '. std::endl; return newChannel; } //determine the copy direction, i.e. lets see if we can copy frames in reverse as could come in handy unsigned int from=startFrame; unsigned int to=endFrame; if(startFrame endFrame){ from = endFrame; to = startFrame; } //get our frames as a times double fromTime = from == 0 ? 0.0f :
Re: [osg-users] Controlling animations in FBX models
Attached is the cpp and an example config file. I think it's pretty straight forward. Looks like the forum blocked my xml config so here is a copy in the post below ?xml version=1.0 encoding=ISO-8859-15? OsgAnimationTools sourceFile='./Data/Models/Terrorist/terrorist.FBX' destinationFile='./splitExport.osgb' fps='30' AnimationSplit sourceAnimation='Take 001' NewAnimation name='staying' startFrame='0' endFrame='49'/ NewAnimation name='fire_standing' startFrame='50' endFrame='89'/ NewAnimation name='running' startFrame='90' endFrame='111'/ NewAnimation name='walking' startFrame='112' endFrame='147'/ NewAnimation name='grenade_throw' startFrame='148' endFrame='187'/ NewAnimation name='hide_behind_wall' startFrame='188' endFrame='213'/ NewAnimation name='from_standing_to_squat' startFrame='214' endFrame='241'/ NewAnimation name='fire_sguating' startFrame='242' endFrame='291'/ NewAnimation name='from_sguating_to_stand' startFrame='292' endFrame='313'/ NewAnimation name='jump_down' startFrame='314' endFrame='359'/ NewAnimation name='fire_lying' startFrame='360' endFrame='379'/ NewAnimation name='stand_up' startFrame='380' endFrame='425'/ NewAnimation name='dying_on_belt' startFrame='426' endFrame='532'/ NewAnimation name='dying_on_spin' startFrame='533' endFrame='568'/ NewAnimation name='jump' startFrame='569' endFrame='614'/ /AnimationSplit /OsgAnimationTools ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Controlling animations in FBX models
Thank you very mutch! I will check it. Renato On Sun, Feb 13, 2011 at 7:06 PM, Thomas Hogarth thomas.hoga...@gmail.comwrote: Attached is the cpp and an example config file. I think it's pretty straight forward. Looks like the forum blocked my xml config so here is a copy in the post below ?xml version=1.0 encoding=ISO-8859-15? OsgAnimationTools sourceFile='./Data/Models/Terrorist/terrorist.FBX' destinationFile='./splitExport.osgb' fps='30' AnimationSplit sourceAnimation='Take 001' NewAnimation name='staying' startFrame='0' endFrame='49'/ NewAnimation name='fire_standing' startFrame='50' endFrame='89'/ NewAnimation name='running' startFrame='90' endFrame='111'/ NewAnimation name='walking' startFrame='112' endFrame='147'/ NewAnimation name='grenade_throw' startFrame='148' endFrame='187'/ NewAnimation name='hide_behind_wall' startFrame='188' endFrame='213'/ NewAnimation name='from_standing_to_squat' startFrame='214' endFrame='241'/ NewAnimation name='fire_sguating' startFrame='242' endFrame='291'/ NewAnimation name='from_sguating_to_stand' startFrame='292' endFrame='313'/ NewAnimation name='jump_down' startFrame='314' endFrame='359'/ NewAnimation name='fire_lying' startFrame='360' endFrame='379'/ NewAnimation name='stand_up' startFrame='380' endFrame='425'/ NewAnimation name='dying_on_belt' startFrame='426' endFrame='532'/ NewAnimation name='dying_on_spin' startFrame='533' endFrame='568'/ NewAnimation name='jump' startFrame='569' endFrame='614'/ /AnimationSplit /OsgAnimationTools -- Renato Silveira (Ph. D. Student) Informatics Institute - UFRGS Porto Alegre - RS - Brazil http://www.inf.ufrgs.br/~rsilveira ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Controlling animations in FBX models
Hi Renato I thought it was not possible. How can you save your FBX file with multiple animations? I'm using 3DS Max 2010 and I do not see a way to save multiple animations. I'm not familiar with modeling ... I need to do something similar at the moment. I know MotionBuilde can export fbx with multiple takes, but 3ds max can not. I plan to write a node visitor that will find and split any osg animations into multiple takes. Perhaps using a config file. Shouldn't take long, I'll send you a copy when I'm done. If you export your fbx from osg as a .osg file you can see how the data is stored and looks petty straight forward to split it. Alternatively you can use MotionBuilder and I know the FBX plugin is capable of loading the multiple takes. Cheers Tom ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Controlling animations in FBX models
Hi Renato Thomas, I came to the same conclusion :* multiple animations on the same fbx file can only be done with MotionBuilder*, until i found this PlayerMarine.FBXhttp://code.google.com/p/pfxna/source/browse/trunk/Testes/Engine/XNAnimation/XNAnimationSample/Content/Models/PlayerMarine.fbx?spec=svn454r=454%20 with multiple animations : Run, Walk , Shoot ... and at the beginning of the file there is this line: Creator: FBX SDK/FBX Plugins build 20061101 It seems a little bit contradictory Cheers *--* *Mohamed ALJI* Élève ingénieur en Informatique troisième année à l'ENSEIRB-MATMECA (Institut Polytechnique de Bordeaux - IPB) Webmaster bénévole de l'association L'eau du désert: www.l-eau-du-desert.com mr.m.a...@gmail.com 2011/2/4 Thomas Hogarth thomas.hoga...@gmail.com Hi Renato I thought it was not possible. How can you save your FBX file with multiple animations? I'm using 3DS Max 2010 and I do not see a way to save multiple animations. I'm not familiar with modeling ... I need to do something similar at the moment. I know MotionBuilde can export fbx with multiple takes, but 3ds max can not. I plan to write a node visitor that will find and split any osg animations into multiple takes. Perhaps using a config file. Shouldn't take long, I'll send you a copy when I'm done. If you export your fbx from osg as a .osg file you can see how the data is stored and looks petty straight forward to split it. Alternatively you can use MotionBuilder and I know the FBX plugin is capable of loading the multiple takes. Cheers Tom ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Controlling animations in FBX models
Hi Thomas and Alji I will try the MotionBuilder. When you write the node visitor, and if you can share it, I'll be very grateful! Thank you! Renato On Fri, Feb 4, 2011 at 12:50 PM, Mr Alji mr.m.a...@gmail.com wrote: Hi Renato Thomas, I came to the same conclusion :* multiple animations on the same fbx file can only be done with MotionBuilder*, until i found this PlayerMarine.FBXhttp://code.google.com/p/pfxna/source/browse/trunk/Testes/Engine/XNAnimation/XNAnimationSample/Content/Models/PlayerMarine.fbx?spec=svn454r=454%20 with multiple animations : Run, Walk , Shoot ... and at the beginning of the file there is this line: Creator: FBX SDK/FBX Plugins build 20061101 It seems a little bit contradictory Cheers *--* *Mohamed ALJI* Élève ingénieur en Informatique troisième année à l'ENSEIRB-MATMECA (Institut Polytechnique de Bordeaux - IPB) Webmaster bénévole de l'association L'eau du désert: www.l-eau-du-desert.com mr.m.a...@gmail.com 2011/2/4 Thomas Hogarth thomas.hoga...@gmail.com Hi Renato I thought it was not possible. How can you save your FBX file with multiple animations? I'm using 3DS Max 2010 and I do not see a way to save multiple animations. I'm not familiar with modeling ... I need to do something similar at the moment. I know MotionBuilde can export fbx with multiple takes, but 3ds max can not. I plan to write a node visitor that will find and split any osg animations into multiple takes. Perhaps using a config file. Shouldn't take long, I'll send you a copy when I'm done. If you export your fbx from osg as a .osg file you can see how the data is stored and looks petty straight forward to split it. Alternatively you can use MotionBuilder and I know the FBX plugin is capable of loading the multiple takes. Cheers Tom ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Renato Silveira (Ph. D. Student) Informatics Institute - UFRGS Porto Alegre - RS - Brazil http://www.inf.ufrgs.br/~rsilveira ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Controlling animations in FBX models
Hi Silveira, I had almost the same problem, rather than specifying the frames to be played, I choosed to use FBX Model with multiple animations, the animation Manager took care of the rest. I hope I helped a little bit *--* *Mohamed ALJI* Élève ingénieur en Informatique troisième année à l'ENSEIRB-MATMECA (Institut Polytechnique de Bordeaux - IPB) Webmaster bénévole de l'association L'eau du désert: www.l-eau-du-desert.com mr.m.a...@gmail.com 2011/2/3 Renato Silveira silveira@gmail.com Hi, In my application I’m using osg with FBX plug-in. The FBX model that I’m using has a unique sequence of animations, called “Take 001”. The sequence includes a walk, stand, and run animations. Is there a way to specify that from frame 0 to 100 I have the walk animation, from frame 1001 to 3000 I have the stand animation, and so on? I’m using the AnimationTimelineHandler, as in the example, but I could not figure out how to do it. I play the entire sequence of animations, but I cannot separate them. -- Renato Silveira (Ph. D. Student) Informatics Institute - UFRGS Porto Alegre - RS - Brazil http://www.inf.ufrgs.br/~rsilveira http://www.inf.ufrgs.br/%7Ersilveira ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Controlling animations in FBX models
Thank you! You really help me. I thought it was not possible. How can you save your FBX file with multiple animations? I'm using 3DS Max 2010 and I do not see a way to save multiple animations. I'm not familiar with modeling ... How can I split the animations? Thank you! Renato On Thu, Feb 3, 2011 at 7:42 AM, Mr Alji mr.m.a...@gmail.com wrote: Hi Silveira, I had almost the same problem, rather than specifying the frames to be played, I choosed to use FBX Model with multiple animations, the animation Manager took care of the rest. I hope I helped a little bit *--* *Mohamed ALJI* Élève ingénieur en Informatique troisième année à l'ENSEIRB-MATMECA (Institut Polytechnique de Bordeaux - IPB) Webmaster bénévole de l'association L'eau du désert: www.l-eau-du-desert.com mr.m.a...@gmail.com 2011/2/3 Renato Silveira silveira@gmail.com Hi, In my application I’m using osg with FBX plug-in. The FBX model that I’m using has a unique sequence of animations, called “Take 001”. The sequence includes a walk, stand, and run animations. Is there a way to specify that from frame 0 to 100 I have the walk animation, from frame 1001 to 3000 I have the stand animation, and so on? I’m using the AnimationTimelineHandler, as in the example, but I could not figure out how to do it. I play the entire sequence of animations, but I cannot separate them. -- Renato Silveira (Ph. D. Student) Informatics Institute - UFRGS Porto Alegre - RS - Brazil http://www.inf.ufrgs.br/~rsilveira http://www.inf.ufrgs.br/%7Ersilveira ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Renato Silveira (Ph. D. Student) Informatics Institute - UFRGS Porto Alegre - RS - Brazil http://www.inf.ufrgs.br/~rsilveira ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org