Re: [osg-users] Export osgAnimation callbacks into osg files
Hi Peter, In order to be able to write your callback in .osg file you have to declare method to write it. see in src/osgPlugins/osgAnimation/ReaderWriter.cpp If you dont declare those method, osg will not be able to read/write your class because it does not know them. Cheers, Cedric -- +33 659 598 614 Cedric Pinson mailto:cedric.pin...@plopbyte.net http://www.plopbyte.net On Wed, 2009-10-14 at 17:57 +, Peter Wrobrl wrote: Hi, and thanks for your fast answer. To reconstruct my problem I take the osgAnimationNode Example and tweak its main, so that it writes an osg file instead of creating the viewer ( Attachment ). When I open the osg file with an text editor, the UpdeteCallbacks are empty, and the file crashes the osganimationviewer with the error message: no osgAnimation::AnimationManagerBase found in the subgraph, no animations available Files that I export from Blender do have osgAnimation::BasicAnimationManager and keyframe data in the UpdateCallback Block. I think the problem is, that in my case AnimtkUpdateCallback should be derived from osgAnimation::BasicAnimationManager insted of osg::NodeCallback, but I don't get it to work. Could you tweak this file so that it works ? That would be a great help, thx. Cheers, searching for Pivot of my Soul, PP !!! ( - ParticlePeter ) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=18273#18273 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org signature.asc Description: This is a digitally signed message part ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Export osgAnimation callbacks into osg files
Hi, and thanks for your fast answer. To reconstruct my problem I take the osgAnimationNode Example and tweak its main, so that it writes an osg file instead of creating the viewer ( Attachment ). When I open the osg file with an text editor, the UpdeteCallbacks are empty, and the file crashes the osganimationviewer with the error message: no osgAnimation::AnimationManagerBase found in the subgraph, no animations available Files that I export from Blender do have osgAnimation::BasicAnimationManager and keyframe data in the UpdateCallback Block. I think the problem is, that in my case AnimtkUpdateCallback should be derived from osgAnimation::BasicAnimationManager insted of osg::NodeCallback, but I don't get it to work. Could you tweak this file so that it works ? That would be a great help, thx. Cheers, searching for Pivot of my Soul, PP !!! ( - ParticlePeter ) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=18273#18273 /* -*-c++-*- * Copyright (C) 2008 Cedric Pinson morni...@plopbyte.net * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include iostream #include osg/Geometry #include osg/Shape #include osg/ShapeDrawable #include osgViewer/Viewer #include osgGA/TrackballManipulator #include osg/MatrixTransform #include osg/Material #include osgAnimation/Sampler #include osgDB/WriteFile #include stdio.h class AnimtkUpdateCallback : public osg::NodeCallback { public: META_Object(osgAnimation, AnimtkUpdateCallback); AnimtkUpdateCallback() { _sampler = new osgAnimation::Vec3CubicBezierSampler; _playing = false; _lastUpdate = 0; } AnimtkUpdateCallback(const AnimtkUpdateCallback val, const osg::CopyOp copyop = osg::CopyOp::SHALLOW_COPY): osg::Object(val, copyop), osg::NodeCallback(val, copyop), _sampler(val._sampler), _startTime(val._startTime), _currentTime(val._currentTime), _playing(val._playing), _lastUpdate(val._lastUpdate) { } /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { if (nv-getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR nv-getFrameStamp() nv-getFrameStamp()-getFrameNumber() != _lastUpdate) { _lastUpdate = nv-getFrameStamp()-getFrameNumber(); _currentTime = osg::Timer::instance()-tick(); if (_playing _sampler.get() _sampler-getKeyframeContainer()) { osg::MatrixTransform* transform = dynamic_castosg::MatrixTransform*(node); if (transform) { osg::Vec3 result; float t = osg::Timer::instance()-delta_s(_startTime, _currentTime); float duration = _sampler-getEndTime() - _sampler-getStartTime(); t = fmod(t, duration); t += _sampler-getStartTime(); _sampler-getValueAt(t, result); transform-setMatrix(osg::Matrix::translate(result)); } } } // note, callback is responsible for scenegraph traversal so // they must call traverse(node,nv) to ensure that the // scene graph subtree (and associated callbacks) are traversed. traverse(node,nv); } void start() { _startTime = osg::Timer::instance()-tick(); _currentTime = _startTime; _playing = true;} void stop() { _currentTime = _startTime; _playing = false;} osg::ref_ptrosgAnimation::Vec3CubicBezierSampler _sampler; osg::Timer_t _startTime; osg::Timer_t _currentTime; bool _playing; int _lastUpdate; }; class AnimtkStateSetUpdateCallback : public osg::StateSet::Callback { public: META_Object(osgAnimation, AnimtkStateSetUpdateCallback); AnimtkStateSetUpdateCallback() { _sampler = new osgAnimation::Vec4LinearSampler; _playing = false; _lastUpdate = 0; } AnimtkStateSetUpdateCallback(const AnimtkStateSetUpdateCallback val, const osg::CopyOp copyop = osg::CopyOp::SHALLOW_COPY): osg::Object(val, copyop), osg::StateSet::Callback(val, copyop), _sampler(val._sampler), _startTime(val._startTime), _currentTime(val._currentTime), _playing(val._playing), _lastUpdate(val._lastUpdate) { } /** Callback method called by the
Re: [osg-users] Export osgAnimation callbacks into osg files
Art Tevs wrote: Hi Peter, pp wrote: Hi Cedric and thx for fast answer. I replied in the forum already, but waiting for approval. ... Wonder why your message was still not approved? Peter, please change your profile according to our forum rules. I see your email is from our Saarland University, so on questions you can also visit me in the MPI building R219 :) cheers, art P.S. Cedric, sorry if I pollute this thread ;) No, no ... no pollution from my side, just fresh hope :-) When is a good time to find you there ? Cheers, Searching for the Pivot of my Soul, PP !!! ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Export osgAnimation callbacks into osg files
Hi Peter, pp wrote: Hi Cedric and thx for fast answer. I replied in the forum already, but waiting for approval. ... Wonder why your message was still not approved? Peter, please change your profile according to our forum rules. I see your email is from our Saarland University, so on questions you can also visit me in the MPI building R219 :) cheers, art P.S. Cedric, sorry if I pollute this thread ;) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=18393#18393 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Export osgAnimation callbacks into osg files
Cedric Pinson wrote: Hi PP, I made a simple test, i add in osganimationviewer a way to save the loaded data to then after test the saved data from the writer. I used nathan.osg, and it works fine to replay the saved data. My conclusion is it works. Anyway it does not give you the solution. Maybe you could check the osganimation examples, it create stuff from scratch not from a loaded data. If you have problem, report the bug with a minimal example that reproduce the problem. Cheers, Cedric Hi Cedric and thx for fast answer. I replied in the forum already, but waiting for approval. The issue can be reconstructed with e.g. the osgAnimationNode example. I tweak the main there to write out an osg file instead of creating a viewer ( attached ). The osg file gets written, but the UpdateCallbacks Code Block stays empty. There I would expect an animationManager entry and keyframe data, as it gets exportet from your blender exporter. When I run the file with osganimationviewer it crashes and I get a error message like no animationmanager found. My guess is that the class AnimtkUpdateCallback should derive from BasicAnimationManager instead of NodeCallback, but am not sure, and don't get it to run anyway. Would be great if you could look into this, thx. By the way it might not be possible to use your trunk, as I am developing for a software build on top of osg 2.8.2, and this might change for next stable releases only, but I will discuss this, if that is a problem. Cheers, searching for the Pivot of my soul, PP !!! ( - ParticlePeter ) /* -*-c++-*- * Copyright (C) 2008 Cedric Pinson morni...@plopbyte.net * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include iostream #include osg/Geometry #include osg/Shape #include osg/ShapeDrawable #include osgViewer/Viewer #include osgGA/TrackballManipulator #include osg/MatrixTransform #include osg/Material #include osgAnimation/Sampler #include osgAnimation/BasicAnimationManager #include osgDB/WriteFile #include stdio.h class AnimtkUpdateCallback : public osgAnimation::NodeCallback { public: META_Object(osgAnimation, AnimtkUpdateCallback); AnimtkUpdateCallback() { _sampler = new osgAnimation::Vec3CubicBezierSampler; _playing = false; _lastUpdate = 0; } AnimtkUpdateCallback(const AnimtkUpdateCallback val, const osg::CopyOp copyop = osg::CopyOp::SHALLOW_COPY): osg::Object(val, copyop), osg::NodeCallback(val, copyop), _sampler(val._sampler), _startTime(val._startTime), _currentTime(val._currentTime), _playing(val._playing), _lastUpdate(val._lastUpdate) { } /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { if (nv-getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR nv-getFrameStamp() nv-getFrameStamp()-getFrameNumber() != _lastUpdate) { _lastUpdate = nv-getFrameStamp()-getFrameNumber(); _currentTime = osg::Timer::instance()-tick(); if (_playing _sampler.get() _sampler-getKeyframeContainer()) { osg::MatrixTransform* transform = dynamic_castosg::MatrixTransform*(node); if (transform) { osg::Vec3 result; float t = osg::Timer::instance()-delta_s(_startTime, _currentTime); float duration = _sampler-getEndTime() - _sampler-getStartTime(); t = fmod(t, duration); t += _sampler-getStartTime(); _sampler-getValueAt(t, result); transform-setMatrix(osg::Matrix::translate(result)); } } } // note, callback is responsible for scenegraph traversal so // they must call traverse(node,nv) to ensure that the // scene graph subtree (and associated callbacks) are traversed. traverse(node,nv); } void start() { _startTime = osg::Timer::instance()-tick(); _currentTime = _startTime; _playing = true;} void stop() { _currentTime = _startTime; _playing = false;} osg::ref_ptrosgAnimation::Vec3CubicBezierSampler _sampler; osg::Timer_t _startTime; osg::Timer_t _currentTime; bool _playing; int _lastUpdate; }; class AnimtkStateSetUpdateCallback : public osg::StateSet::Callback { public: META_Object(osgAnimation,
[osg-users] Export osgAnimation callbacks into osg files
Hi, I'm writing an Maya to osg exporter that supports osgAnimation. The process of getting osgAnimation Callbacks into an osg file is not clear for me, all available osgAnimation examples create executables, but no osg files. When I use osgDB::writeNodeFile( *someScene , someScene.osg ) ; instead of creating a viewer, the code block between UpdateCallbacks parenthesis stays empty in the resulting osg file, but this is where I would expect keyframe and channel data. The Blender Exporter is also not helpful, as it uses its own mechanism to write out osg files through Python. Can anybody explain / post / create an example that writes a simple osgAnimation into an osg file, please ? Cedric, would this be possible ? Thanks. Cheers, searching for the Pivot of my Soul, PP !!! ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Export osgAnimation callbacks into osg files
Hi PP ? The first thing is to use the mercurial repository here hg.plopbyte.net/osg-trunk because it contains fix and code not yet inside svn. Because i wrote only exporter knowing the format it's possible that the osg writer does not do the job is supposed to do. I have some stuff to finish before putting this task in my plate. Cheers, Cedric -- +33 659 598 614 Cedric Pinson mailto:cedric.pin...@plopbyte.net http://www.plopbyte.net On Wed, 2009-10-14 at 14:57 +0200, p...@graphics.cs.uni-sb.de wrote: Hi, I'm writing an Maya to osg exporter that supports osgAnimation. The process of getting osgAnimation Callbacks into an osg file is not clear for me, all available osgAnimation examples create executables, but no osg files. When I use osgDB::writeNodeFile( *someScene , someScene.osg ) ; instead of creating a viewer, the code block between UpdateCallbacks parenthesis stays empty in the resulting osg file, but this is where I would expect keyframe and channel data. The Blender Exporter is also not helpful, as it uses its own mechanism to write out osg files through Python. Can anybody explain / post / create an example that writes a simple osgAnimation into an osg file, please ? Cedric, would this be possible ? Thanks. Cheers, searching for the Pivot of my Soul, PP !!! ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org signature.asc Description: This is a digitally signed message part ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org