Changeset 13041 for OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp
r12292 r13041 1 /* -*-c++-*- 1 /* -*-c++-*- 2 2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 * This library is open source and may be redistributed and/or modified under 5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 4 * This library is open source and may be redistributed and/or modified under 5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 6 6 * (at your option) any later version. The full license is in LICENSE file 7 7 * included with this distribution, and on the openscenegraph.org website. 8 * 8 * 9 9 * This library is distributed in the hope that it will be useful, 10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 * OpenSceneGraph Public License for more details. 13 13 */ … … 55 55 fr[3].getFloat(att[2]); 56 56 fr[4].getFloat(att[3]); 57 57 58 58 fr += 5; 59 59 iteratorAdvanced = true; … … 67 67 fr[2].getFloat(pos[1]); 68 68 fr[3].getFloat(pos[2]); 69 69 70 70 fr += 4; 71 71 iteratorAdvanced = true; … … 79 79 fr[2].getFloat(scale[1]); 80 80 fr[3].getFloat(scale[2]); 81 81 82 82 fr += 4; 83 83 iteratorAdvanced = true; … … 87 87 if (fr.matchSequence("InvBindMatrixInSkeletonSpace {")) 88 88 { 89 Matrix matrix; 89 Matrix matrix; 90 90 if (readMatrix(matrix,fr, "InvBindMatrixInSkeletonSpace")) 91 91 { … … 96 96 if (fr.matchSequence("MatrixInSkeletonSpace {")) 97 97 { 98 Matrix matrix; 98 Matrix matrix; 99 99 if (readMatrix(matrix,fr, "MatrixInSkeletonSpace")) 100 100 { … … 127 127 128 128 129 bool Skeleton_readLocalData(Object& obj, Input& fr) 130 { 129 bool Skeleton_readLocalData(Object& obj, Input& fr) 130 { 131 131 return false; 132 132 } 133 bool Skeleton_writeLocalData(const Object& obj, Output& fr) 134 { 135 return true; 133 bool Skeleton_writeLocalData(const Object& obj, Output& fr) 134 { 135 return true; 136 136 } 137 137 RegisterDotOsgWrapperProxy g_SkeletonProxy … … 150 150 bool iteratorAdvanced = false; 151 151 std::string name = "unknown"; 152 if (fr.matchSequence("name %s")) 152 if (fr.matchSequence("name %s")) 153 153 { 154 154 if (fr[1].getStr()) … … 160 160 161 161 std::string target = "unknown"; 162 if (fr.matchSequence("target %s")) 162 if (fr.matchSequence("target %s")) 163 163 { 164 164 if (fr[1].getStr()) … … 171 171 // we dont need this info 172 172 float weight = 1.0; 173 if (fr.matchSequence("weight %f")) 173 if (fr.matchSequence("weight %f")) 174 174 { 175 175 fr[1].getFloat(weight); … … 196 196 } 197 197 198 if (fr.matchSequence("weight %f")) 198 if (fr.matchSequence("weight %f")) 199 199 { 200 200 float weight; … … 204 204 anim.setWeight(weight); 205 205 } 206 207 if (fr.matchSequence("duration %f")) 206 207 if (fr.matchSequence("duration %f")) 208 208 { 209 209 float duration; … … 214 214 } 215 215 216 if (fr.matchSequence("starttime %f")) 216 if (fr.matchSequence("starttime %f")) 217 217 { 218 218 float starttime; … … 224 224 225 225 int nbChannels = 0; 226 if (fr.matchSequence("num_channels %i")) 226 if (fr.matchSequence("num_channels %i")) 227 227 { 228 228 fr[1].getInt(nbChannels); … … 231 231 } 232 232 233 for (int i = 0; i < nbChannels; i++) 234 { 235 if (fr.matchSequence("DoubleLinearChannel {")) 233 for (int i = 0; i < nbChannels; i++) 234 { 235 if (fr.matchSequence("DoubleLinearChannel {")) 236 236 { 237 237 fr += 2; … … 241 241 if (Animation_readChannel(channel, fr)) 242 242 iteratorAdvanced = true; 243 243 244 244 int nbKeys; 245 if (fr.matchSequence("Keyframes %i {")) 245 if (fr.matchSequence("Keyframes %i {")) 246 246 { 247 247 fr[1].getInt(nbKeys); … … 249 249 iteratorAdvanced = true; 250 250 251 for (int k = 0; k < nbKeys; k++) 251 for (int k = 0; k < nbKeys; k++) 252 252 { 253 253 double v; … … 270 270 fr += 1; 271 271 } 272 else if (fr.matchSequence("FloatLinearChannel {")) 272 else if (fr.matchSequence("FloatLinearChannel {")) 273 273 { 274 274 fr += 2; … … 278 278 if (Animation_readChannel(channel, fr)) 279 279 iteratorAdvanced = true; 280 280 281 281 int nbKeys; 282 if (fr.matchSequence("Keyframes %i {")) 282 if (fr.matchSequence("Keyframes %i {")) 283 283 { 284 284 fr[1].getInt(nbKeys); … … 286 286 iteratorAdvanced = true; 287 287 288 for (int k = 0; k < nbKeys; k++) 288 for (int k = 0; k < nbKeys; k++) 289 289 { 290 290 float v; … … 307 307 fr += 1; 308 308 } 309 else if (fr.matchSequence("Vec2LinearChannel {")) 309 else if (fr.matchSequence("Vec2LinearChannel {")) 310 310 { 311 311 fr += 2; … … 315 315 if (Animation_readChannel(channel, fr)) 316 316 iteratorAdvanced = true; 317 317 318 318 int nbKeys; 319 if (fr.matchSequence("Keyframes %i {")) 319 if (fr.matchSequence("Keyframes %i {")) 320 320 { 321 321 fr[1].getInt(nbKeys); … … 323 323 iteratorAdvanced = true; 324 324 325 for (int k = 0; k < nbKeys; k++) 325 for (int k = 0; k < nbKeys; k++) 326 326 { 327 327 osg::Vec2 v; … … 345 345 fr += 1; 346 346 } 347 else if (fr.matchSequence("Vec3LinearChannel {")) 347 else if (fr.matchSequence("Vec3LinearChannel {")) 348 348 { 349 349 fr += 2; … … 353 353 if (Animation_readChannel(channel, fr)) 354 354 iteratorAdvanced = true; 355 355 356 356 int nbKeys; 357 if (fr.matchSequence("Keyframes %i {")) 357 if (fr.matchSequence("Keyframes %i {")) 358 358 { 359 359 fr[1].getInt(nbKeys); … … 361 361 iteratorAdvanced = true; 362 362 363 for (int k = 0; k < nbKeys; k++) 363 for (int k = 0; k < nbKeys; k++) 364 364 { 365 365 osg::Vec3 v; … … 384 384 fr += 1; 385 385 } 386 else if (fr.matchSequence("Vec4LinearChannel {")) 386 else if (fr.matchSequence("Vec4LinearChannel {")) 387 387 { 388 388 fr += 2; … … 392 392 if (Animation_readChannel(channel, fr)) 393 393 iteratorAdvanced = true; 394 394 395 395 int nbKeys; 396 if (fr.matchSequence("Keyframes %i {")) 396 if (fr.matchSequence("Keyframes %i {")) 397 397 { 398 398 fr[1].getInt(nbKeys); … … 400 400 iteratorAdvanced = true; 401 401 402 for (int k = 0; k < nbKeys; k++) 402 for (int k = 0; k < nbKeys; k++) 403 403 { 404 404 osg::Vec4 v; … … 424 424 fr += 1; 425 425 } 426 else if (fr.matchSequence("QuatSphericalLinearChannel {")) 426 else if (fr.matchSequence("QuatSphericalLinearChannel {")) 427 427 { 428 428 fr += 2; … … 432 432 if (Animation_readChannel(channel, fr)) 433 433 iteratorAdvanced = true; 434 434 435 435 int nbKeys; 436 if (fr.matchSequence("Keyframes %i {")) 436 if (fr.matchSequence("Keyframes %i {")) 437 437 { 438 438 fr[1].getInt(nbKeys); … … 440 440 iteratorAdvanced = true; 441 441 442 for (int k = 0; k < nbKeys; k++) 442 for (int k = 0; k < nbKeys; k++) 443 443 { 444 444 osg::Quat q; … … 465 465 } 466 466 // Deprecated 467 // Reading of old channel info 467 // Reading of old channel info 468 468 // Kept here for easy conversion of old .osg data to new format 469 else if (fr.matchSequence("Channel {")) 469 else if (fr.matchSequence("Channel {")) 470 470 { 471 471 fr += 2; 472 472 473 473 std::string name = "unknown"; 474 if (fr.matchSequence("name %s")) 474 if (fr.matchSequence("name %s")) 475 475 { 476 476 if (fr[1].getStr()) … … 480 480 } 481 481 std::string target = "unknown"; 482 if (fr.matchSequence("target %s")) 482 if (fr.matchSequence("target %s")) 483 483 { 484 484 if (fr[1].getStr()) … … 490 490 std::string type = "unknown"; 491 491 int nbKeys; 492 if (fr.matchSequence("Keyframes %s %i {")) 492 if (fr.matchSequence("Keyframes %s %i {")) 493 493 { 494 494 if (fr[1].getStr()) … … 499 499 500 500 osgAnimation::Channel* channel = 0; 501 if (type == "Quat") 501 if (type == "Quat") 502 502 { 503 503 osgAnimation::QuatSphericalLinearChannel* c = new osgAnimation::QuatSphericalLinearChannel; … … 505 505 channel = c; 506 506 } 507 else if (type == "Vec3") 507 else if (type == "Vec3") 508 508 { 509 509 osgAnimation::Vec3LinearChannel* c = new osgAnimation::Vec3LinearChannel; … … 512 512 } 513 513 514 if (channel) 514 if (channel) 515 515 { 516 for (int k = 0; k < nbKeys; k++) 516 for (int k = 0; k < nbKeys; k++) 517 517 { 518 if (type == "Quat") 518 if (type == "Quat") 519 519 { 520 520 osg::Quat q; … … 531 531 iteratorAdvanced = true; 532 532 } 533 else if (type == "Vec3") 533 else if (type == "Vec3") 534 534 { 535 535 osg::Vec3 v; … … 577 577 fw.indent() << "Keyframes " << kfc->size() << " {" << std::endl; 578 578 fw.moveIn(); 579 for (unsigned int k = 0; k < kfc->size(); k++) 579 for (unsigned int k = 0; k < kfc->size(); k++) 580 580 { 581 581 fw.indent() << "key " << (*kfc)[k].getTime() << " " << (*kfc)[k].getValue() << std::endl; … … 592 592 const osgAnimation::Animation& anim = dynamic_cast<const osgAnimation::Animation&>(obj); 593 593 594 switch (anim.getPlayMode()) 594 switch (anim.getPlayMode()) 595 595 { 596 596 case osgAnimation::Animation::ONCE: … … 603 603 fw.indent() << "playmode LOOP" << std::endl; 604 604 break; 605 case osgAnimation::Animation::PPONG: 605 case osgAnimation::Animation::PPONG: 606 606 fw.indent() << "playmode PPONG" << std::endl; 607 607 break; … … 615 615 616 616 fw.indent() << "num_channels " << anim.getChannels().size() << std::endl; 617 for (unsigned int i = 0; i < anim.getChannels().size(); i++) 617 for (unsigned int i = 0; i < anim.getChannels().size(); i++) 618 618 { 619 619 osgAnimation::Channel* pChannel = anim.getChannels()[i].get(); … … 699 699 700 700 701 bool AnimationManagerBase_readLocalData(osgAnimation::AnimationManagerBase& manager, Input& fr) 701 bool AnimationManagerBase_readLocalData(osgAnimation::AnimationManagerBase& manager, Input& fr) 702 702 { 703 703 int nbAnims = 0; 704 704 bool iteratorAdvanced = false; 705 705 706 if (fr.matchSequence("num_animations %i")) 706 if (fr.matchSequence("num_animations %i")) 707 707 { 708 708 fr[1].getInt(nbAnims); … … 715 715 Object* o = fr.readObject(); 716 716 osgAnimation::Animation* a = dynamic_cast<osgAnimation::Animation*>(o); 717 if (a) 717 if (a) 718 718 { 719 719 manager.registerAnimation(a); 720 720 iteratorAdvanced = true; 721 } 721 } 722 722 else 723 osg::notify(osg::WARN)<<"Warning: can't read an animation object"<< std::endl; 723 osg::notify(osg::WARN)<<"Warning: can't read an animation object"<< std::endl; 724 724 } 725 725 … … 728 728 729 729 730 bool BasicAnimationManager_readLocalData(Object& obj, Input& fr) 730 bool BasicAnimationManager_readLocalData(Object& obj, Input& fr) 731 731 { 732 732 osgAnimation::BasicAnimationManager& manager = dynamic_cast<osgAnimation::BasicAnimationManager&>(obj); … … 734 734 } 735 735 736 bool TimelineAnimationManager_readLocalData(Object& obj, Input& fr) 736 bool TimelineAnimationManager_readLocalData(Object& obj, Input& fr) 737 737 { 738 738 osgAnimation::TimelineAnimationManager& manager = dynamic_cast<osgAnimation::TimelineAnimationManager&>(obj); … … 749 749 { 750 750 if (!fw.writeObject(**it)) 751 osg::notify(osg::WARN)<<"Warning: can't write an animation object"<< std::endl; 751 osg::notify(osg::WARN)<<"Warning: can't write an animation object"<< std::endl; 752 752 } 753 753 return true; … … 788 788 789 789 790 bool RigGeometry_readLocalData(Object& obj, Input& fr) 790 bool RigGeometry_readLocalData(Object& obj, Input& fr) 791 791 { 792 792 osgAnimation::RigGeometry& geom = dynamic_cast<osgAnimation::RigGeometry&>(obj); … … 795 795 int nbGroups = 0; 796 796 bool iteratorAdvanced = false; 797 if (fr.matchSequence("num_influences %i")) 797 if (fr.matchSequence("num_influences %i")) 798 798 { 799 799 fr[1].getInt(nbGroups); … … 802 802 } 803 803 804 for (int i = 0; i < nbGroups; i++) 804 for (int i = 0; i < nbGroups; i++) 805 805 { 806 806 int nbVertexes = 0; 807 807 std::string name; 808 if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {")) 808 if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {")) 809 809 { 810 810 name = fr[1].getStr(); … … 817 817 vi.setName(name); 818 818 vi.reserve(nbVertexes); 819 for (int j = 0; j < nbVertexes; j++) 819 for (int j = 0; j < nbVertexes; j++) 820 820 { 821 821 int index = -1; 822 822 float weight = 1; 823 if (fr.matchSequence("%i %f")) 823 if (fr.matchSequence("%i %f")) 824 824 { 825 825 fr[0].getInt(index); … … 830 830 vi.push_back(osgAnimation::VertexIndexWeight(index, weight)); 831 831 } 832 if (fr.matchSequence("}")) 832 if (fr.matchSequence("}")) 833 833 { 834 834 fr+=1; … … 849 849 } 850 850 851 bool RigGeometry_writeLocalData(const Object& obj, Output& fw) 851 bool RigGeometry_writeLocalData(const Object& obj, Output& fw) 852 852 { 853 853 const osgAnimation::RigGeometry& geom = dynamic_cast<const osgAnimation::RigGeometry&>(obj); … … 857 857 fw.indent() << "num_influences " << vm->size() << std::endl; 858 858 fw.moveIn(); 859 for (osgAnimation::VertexInfluenceMap::const_iterator it = vm->begin(); it != vm->end(); ++it) 859 for (osgAnimation::VertexInfluenceMap::const_iterator it = vm->begin(); it != vm->end(); ++it) 860 860 { 861 861 std::string name = it->first; … … 865 865 fw.moveIn(); 866 866 const osgAnimation::VertexInfluence& vi = it->second; 867 for (osgAnimation::VertexInfluence::const_iterator itv = vi.begin(); itv != vi.end(); itv++) 867 for (osgAnimation::VertexInfluence::const_iterator itv = vi.begin(); itv != vi.end(); itv++) 868 868 { 869 869 fw.indent() << itv->first << " " << itv->second << std::endl; … … 889 889 890 890 891 bool MorphGeometry_readLocalData(Object& obj, Input& fr) 891 bool MorphGeometry_readLocalData(Object& obj, Input& fr) 892 892 { 893 893 osgAnimation::MorphGeometry& geom = dynamic_cast<osgAnimation::MorphGeometry&>(obj); … … 947 947 948 948 float weight = 1.0; 949 if (fr.matchSequence("weight %f")) 949 if (fr.matchSequence("weight %f")) 950 950 { 951 951 fr[1].getFloat(weight); … … 966 966 } 967 967 968 bool MorphGeometry_writeLocalData(const Object& obj, Output& fw) 968 bool MorphGeometry_writeLocalData(const Object& obj, Output& fw) 969 969 { 970 970 const osgAnimation::MorphGeometry& geom = dynamic_cast<const osgAnimation::MorphGeometry&>(obj); … … 977 977 978 978 fw.indent() << "morphNormals "; 979 if (geom.getMorphNormals()) 979 if (geom.getMorphNormals()) 980 980 fw << "TRUE" << std::endl; 981 else 981 else 982 982 fw << "FALSE" << std::endl; 983 983 … … 1033 1033 1034 1034 1035 bool UpdateSkeleton_readLocalData(Object& obj, Input& fr) 1035 bool UpdateSkeleton_readLocalData(Object& obj, Input& fr) 1036 1036 { 1037 1037 bool iteratorAdvanced = false; … … 1055 1055 1056 1056 1057 bool UpdateMorph_readLocalData(Object& obj, Input& fr) 1057 bool UpdateMorph_readLocalData(Object& obj, Input& fr) 1058 1058 { 1059 1059 bool iteratorAdvanced = false;
