| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | #include <osgDB/FileNameUtils> |
|---|
| 17 | #include <osgDB/FileUtils> |
|---|
| 18 | #include <osgDB/ReaderWriter> |
|---|
| 19 | #include <osg/io_utils> |
|---|
| 20 | #include <osgAnimation/AnimationManagerBase> |
|---|
| 21 | #include <osgAnimation/BasicAnimationManager> |
|---|
| 22 | #include <osgAnimation/TimelineAnimationManager> |
|---|
| 23 | #include <osgAnimation/VertexInfluence> |
|---|
| 24 | #include <osgAnimation/Animation> |
|---|
| 25 | #include <osgAnimation/Bone> |
|---|
| 26 | #include <osgAnimation/UpdateBone> |
|---|
| 27 | #include <osgAnimation/UpdateMatrixTransform> |
|---|
| 28 | #include <osgAnimation/Skeleton> |
|---|
| 29 | #include <osgAnimation/RigGeometry> |
|---|
| 30 | #include <osgAnimation/MorphGeometry> |
|---|
| 31 | #include <osgAnimation/StackedTransform> |
|---|
| 32 | #include <osgAnimation/StackedTranslateElement> |
|---|
| 33 | #include <osgAnimation/StackedRotateAxisElement> |
|---|
| 34 | #include <osgAnimation/StackedMatrixElement> |
|---|
| 35 | #include <osgAnimation/StackedScaleElement> |
|---|
| 36 | #include "Matrix.h" |
|---|
| 37 | |
|---|
| 38 | #include <osgDB/Registry> |
|---|
| 39 | #include <osgDB/Input> |
|---|
| 40 | #include <osgDB/Output> |
|---|
| 41 | |
|---|
| 42 | using namespace osgDB; |
|---|
| 43 | using namespace osg; |
|---|
| 44 | |
|---|
| 45 | bool Bone_readLocalData(Object& obj, Input& fr) |
|---|
| 46 | { |
|---|
| 47 | osgAnimation::Bone& bone = dynamic_cast<osgAnimation::Bone&>(obj); |
|---|
| 48 | |
|---|
| 49 | osg::Quat att; |
|---|
| 50 | bool iteratorAdvanced = false; |
|---|
| 51 | if (fr.matchSequence("bindQuaternion %f %f %f %f")) |
|---|
| 52 | { |
|---|
| 53 | fr[1].getFloat(att[0]); |
|---|
| 54 | fr[2].getFloat(att[1]); |
|---|
| 55 | fr[3].getFloat(att[2]); |
|---|
| 56 | fr[4].getFloat(att[3]); |
|---|
| 57 | |
|---|
| 58 | fr += 5; |
|---|
| 59 | iteratorAdvanced = true; |
|---|
| 60 | osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | osg::Vec3d pos(0,0,0); |
|---|
| 64 | if (fr.matchSequence("bindPosition %f %f %f")) |
|---|
| 65 | { |
|---|
| 66 | fr[1].getFloat(pos[0]); |
|---|
| 67 | fr[2].getFloat(pos[1]); |
|---|
| 68 | fr[3].getFloat(pos[2]); |
|---|
| 69 | |
|---|
| 70 | fr += 4; |
|---|
| 71 | iteratorAdvanced = true; |
|---|
| 72 | osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | osg::Vec3d scale(1,1,1); |
|---|
| 76 | if (fr.matchSequence("bindScale %f %f %f")) |
|---|
| 77 | { |
|---|
| 78 | fr[1].getFloat(scale[0]); |
|---|
| 79 | fr[2].getFloat(scale[1]); |
|---|
| 80 | fr[3].getFloat(scale[2]); |
|---|
| 81 | |
|---|
| 82 | fr += 4; |
|---|
| 83 | iteratorAdvanced = true; |
|---|
| 84 | osg::notify(osg::WARN) << "Old osgAnimation file format update your data file" << std::endl; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | if (fr.matchSequence("InvBindMatrixInSkeletonSpace {")) |
|---|
| 88 | { |
|---|
| 89 | Matrix matrix; |
|---|
| 90 | if (readMatrix(matrix,fr, "InvBindMatrixInSkeletonSpace")) |
|---|
| 91 | { |
|---|
| 92 | bone.setInvBindMatrixInSkeletonSpace(matrix); |
|---|
| 93 | iteratorAdvanced = true; |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | if (fr.matchSequence("MatrixInSkeletonSpace {")) |
|---|
| 97 | { |
|---|
| 98 | Matrix matrix; |
|---|
| 99 | if (readMatrix(matrix,fr, "MatrixInSkeletonSpace")) |
|---|
| 100 | { |
|---|
| 101 | bone.setMatrixInSkeletonSpace(matrix); |
|---|
| 102 | iteratorAdvanced = true; |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | return iteratorAdvanced; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | bool Bone_writeLocalData(const Object& obj, Output& fw) |
|---|
| 109 | { |
|---|
| 110 | const osgAnimation::Bone& bone = dynamic_cast<const osgAnimation::Bone&>(obj); |
|---|
| 111 | bool res1 = writeMatrix(bone.getInvBindMatrixInSkeletonSpace(), fw, "InvBindMatrixInSkeletonSpace"); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | bool res2 = writeMatrix(bone.getMatrixInSkeletonSpace(), fw, "MatrixInSkeletonSpace"); |
|---|
| 115 | return (res1 || res2); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | RegisterDotOsgWrapperProxy g_BoneProxy |
|---|
| 119 | ( |
|---|
| 120 | new osgAnimation::Bone, |
|---|
| 121 | "osgAnimation::Bone", |
|---|
| 122 | "Object Node MatrixTransform osgAnimation::Bone Group", |
|---|
| 123 | &Bone_readLocalData, |
|---|
| 124 | &Bone_writeLocalData |
|---|
| 125 | ); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | bool Skeleton_readLocalData(Object& obj, Input& fr) |
|---|
| 130 | { |
|---|
| 131 | return false; |
|---|
| 132 | } |
|---|
| 133 | bool Skeleton_writeLocalData(const Object& obj, Output& fr) |
|---|
| 134 | { |
|---|
| 135 | return true; |
|---|
| 136 | } |
|---|
| 137 | RegisterDotOsgWrapperProxy g_SkeletonProxy |
|---|
| 138 | ( |
|---|
| 139 | new osgAnimation::Skeleton, |
|---|
| 140 | "osgAnimation::Skeleton", |
|---|
| 141 | "Object Node MatrixTransform osgAnimation::Skeleton Group", |
|---|
| 142 | &Skeleton_readLocalData, |
|---|
| 143 | &Skeleton_writeLocalData, |
|---|
| 144 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 145 | ); |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | bool Animation_readChannel(osgAnimation::Channel* pChannel, Input& fr) |
|---|
| 149 | { |
|---|
| 150 | bool iteratorAdvanced = false; |
|---|
| 151 | std::string name = "unknown"; |
|---|
| 152 | if (fr.matchSequence("name %s")) |
|---|
| 153 | { |
|---|
| 154 | if (fr[1].getStr()) |
|---|
| 155 | name = fr[1].getStr(); |
|---|
| 156 | fr += 2; |
|---|
| 157 | iteratorAdvanced = true; |
|---|
| 158 | } |
|---|
| 159 | pChannel->setName(name); |
|---|
| 160 | |
|---|
| 161 | std::string target = "unknown"; |
|---|
| 162 | if (fr.matchSequence("target %s")) |
|---|
| 163 | { |
|---|
| 164 | if (fr[1].getStr()) |
|---|
| 165 | target = fr[1].getStr(); |
|---|
| 166 | fr += 2; |
|---|
| 167 | iteratorAdvanced = true; |
|---|
| 168 | } |
|---|
| 169 | pChannel->setTargetName(target); |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | float weight = 1.0; |
|---|
| 173 | if (fr.matchSequence("weight %f")) |
|---|
| 174 | { |
|---|
| 175 | fr[1].getFloat(weight); |
|---|
| 176 | fr += 2; |
|---|
| 177 | iteratorAdvanced = true; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | return iteratorAdvanced; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | bool Animation_readLocalData(Object& obj, Input& fr) |
|---|
| 184 | { |
|---|
| 185 | osgAnimation::Animation& anim = dynamic_cast<osgAnimation::Animation&>(obj); |
|---|
| 186 | bool iteratorAdvanced = false; |
|---|
| 187 | |
|---|
| 188 | if (fr.matchSequence("playmode %w")) |
|---|
| 189 | { |
|---|
| 190 | if (fr[1].matchWord("ONCE")) anim.setPlaymode(osgAnimation::Animation::ONCE); |
|---|
| 191 | else if (fr[1].matchWord("STAY")) anim.setPlaymode(osgAnimation::Animation::STAY); |
|---|
| 192 | else if (fr[1].matchWord("LOOP")) anim.setPlaymode(osgAnimation::Animation::LOOP); |
|---|
| 193 | else if (fr[1].matchWord("PPONG")) anim.setPlaymode(osgAnimation::Animation::PPONG); |
|---|
| 194 | fr += 2; |
|---|
| 195 | iteratorAdvanced = true; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | if (fr.matchSequence("weight %f")) |
|---|
| 199 | { |
|---|
| 200 | float weight; |
|---|
| 201 | fr[1].getFloat(weight); |
|---|
| 202 | fr += 2; |
|---|
| 203 | iteratorAdvanced = true; |
|---|
| 204 | anim.setWeight(weight); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | if (fr.matchSequence("duration %f")) |
|---|
| 208 | { |
|---|
| 209 | float duration; |
|---|
| 210 | fr[1].getFloat(duration); |
|---|
| 211 | fr += 2; |
|---|
| 212 | iteratorAdvanced = true; |
|---|
| 213 | anim.setDuration(duration); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if (fr.matchSequence("starttime %f")) |
|---|
| 217 | { |
|---|
| 218 | float starttime; |
|---|
| 219 | fr[1].getFloat(starttime); |
|---|
| 220 | fr += 2; |
|---|
| 221 | iteratorAdvanced = true; |
|---|
| 222 | anim.setStartTime(starttime); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | int nbChannels = 0; |
|---|
| 226 | if (fr.matchSequence("num_channels %i")) |
|---|
| 227 | { |
|---|
| 228 | fr[1].getInt(nbChannels); |
|---|
| 229 | fr += 2; |
|---|
| 230 | iteratorAdvanced = true; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | for (int i = 0; i < nbChannels; i++) |
|---|
| 234 | { |
|---|
| 235 | if (fr.matchSequence("DoubleLinearChannel {")) |
|---|
| 236 | { |
|---|
| 237 | fr += 2; |
|---|
| 238 | |
|---|
| 239 | osgAnimation::DoubleLinearChannel* channel = new osgAnimation::DoubleLinearChannel; |
|---|
| 240 | |
|---|
| 241 | if (Animation_readChannel(channel, fr)) |
|---|
| 242 | iteratorAdvanced = true; |
|---|
| 243 | |
|---|
| 244 | int nbKeys; |
|---|
| 245 | if (fr.matchSequence("Keyframes %i {")) |
|---|
| 246 | { |
|---|
| 247 | fr[1].getInt(nbKeys); |
|---|
| 248 | fr += 3; |
|---|
| 249 | iteratorAdvanced = true; |
|---|
| 250 | |
|---|
| 251 | for (int k = 0; k < nbKeys; k++) |
|---|
| 252 | { |
|---|
| 253 | double v; |
|---|
| 254 | float time; |
|---|
| 255 | if (fr.matchSequence("key %f %f")) |
|---|
| 256 | { |
|---|
| 257 | fr[1].getFloat(time); |
|---|
| 258 | fr[2].getFloat(v); |
|---|
| 259 | fr += 3; |
|---|
| 260 | channel->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::DoubleKeyframe(time, v)); |
|---|
| 261 | iteratorAdvanced = true; |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | anim.addChannel(channel); |
|---|
| 265 | |
|---|
| 266 | if (fr.matchSequence("}")) |
|---|
| 267 | fr += 1; |
|---|
| 268 | } |
|---|
| 269 | if (fr.matchSequence("}")) |
|---|
| 270 | fr += 1; |
|---|
| 271 | } |
|---|
| 272 | else if (fr.matchSequence("FloatLinearChannel {")) |
|---|
| 273 | { |
|---|
| 274 | fr += 2; |
|---|
| 275 | |
|---|
| 276 | osgAnimation::FloatLinearChannel* channel = new osgAnimation::FloatLinearChannel; |
|---|
| 277 | |
|---|
| 278 | if (Animation_readChannel(channel, fr)) |
|---|
| 279 | iteratorAdvanced = true; |
|---|
| 280 | |
|---|
| 281 | int nbKeys; |
|---|
| 282 | if (fr.matchSequence("Keyframes %i {")) |
|---|
| 283 | { |
|---|
| 284 | fr[1].getInt(nbKeys); |
|---|
| 285 | fr += 3; |
|---|
| 286 | iteratorAdvanced = true; |
|---|
| 287 | |
|---|
| 288 | for (int k = 0; k < nbKeys; k++) |
|---|
| 289 | { |
|---|
| 290 | float v; |
|---|
| 291 | float time; |
|---|
| 292 | if (fr.matchSequence("key %f %f")) |
|---|
| 293 | { |
|---|
| 294 | fr[1].getFloat(time); |
|---|
| 295 | fr[2].getFloat(v); |
|---|
| 296 | fr += 3; |
|---|
| 297 | channel->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(time, v)); |
|---|
| 298 | iteratorAdvanced = true; |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | anim.addChannel(channel); |
|---|
| 302 | |
|---|
| 303 | if (fr.matchSequence("}")) |
|---|
| 304 | fr += 1; |
|---|
| 305 | } |
|---|
| 306 | if (fr.matchSequence("}")) |
|---|
| 307 | fr += 1; |
|---|
| 308 | } |
|---|
| 309 | else if (fr.matchSequence("Vec2LinearChannel {")) |
|---|
| 310 | { |
|---|
| 311 | fr += 2; |
|---|
| 312 | |
|---|
| 313 | osgAnimation::Vec2LinearChannel* channel = new osgAnimation::Vec2LinearChannel; |
|---|
| 314 | |
|---|
| 315 | if (Animation_readChannel(channel, fr)) |
|---|
| 316 | iteratorAdvanced = true; |
|---|
| 317 | |
|---|
| 318 | int nbKeys; |
|---|
| 319 | if (fr.matchSequence("Keyframes %i {")) |
|---|
| 320 | { |
|---|
| 321 | fr[1].getInt(nbKeys); |
|---|
| 322 | fr += 3; |
|---|
| 323 | iteratorAdvanced = true; |
|---|
| 324 | |
|---|
| 325 | for (int k = 0; k < nbKeys; k++) |
|---|
| 326 | { |
|---|
| 327 | osg::Vec2 v; |
|---|
| 328 | float time; |
|---|
| 329 | if (fr.matchSequence("key %f %f %f")) |
|---|
| 330 | { |
|---|
| 331 | fr[1].getFloat(time); |
|---|
| 332 | fr[2].getFloat(v[0]); |
|---|
| 333 | fr[3].getFloat(v[1]); |
|---|
| 334 | fr += 4; |
|---|
| 335 | channel->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec2Keyframe(time, v)); |
|---|
| 336 | iteratorAdvanced = true; |
|---|
| 337 | } |
|---|
| 338 | } |
|---|
| 339 | anim.addChannel(channel); |
|---|
| 340 | |
|---|
| 341 | if (fr.matchSequence("}")) |
|---|
| 342 | fr += 1; |
|---|
| 343 | } |
|---|
| 344 | if (fr.matchSequence("}")) |
|---|
| 345 | fr += 1; |
|---|
| 346 | } |
|---|
| 347 | else if (fr.matchSequence("Vec3LinearChannel {")) |
|---|
| 348 | { |
|---|
| 349 | fr += 2; |
|---|
| 350 | |
|---|
| 351 | osgAnimation::Vec3LinearChannel* channel = new osgAnimation::Vec3LinearChannel; |
|---|
| 352 | |
|---|
| 353 | if (Animation_readChannel(channel, fr)) |
|---|
| 354 | iteratorAdvanced = true; |
|---|
| 355 | |
|---|
| 356 | int nbKeys; |
|---|
| 357 | if (fr.matchSequence("Keyframes %i {")) |
|---|
| 358 | { |
|---|
| 359 | fr[1].getInt(nbKeys); |
|---|
| 360 | fr += 3; |
|---|
| 361 | iteratorAdvanced = true; |
|---|
| 362 | |
|---|
| 363 | for (int k = 0; k < nbKeys; k++) |
|---|
| 364 | { |
|---|
| 365 | osg::Vec3 v; |
|---|
| 366 | float time; |
|---|
| 367 | if (fr.matchSequence("key %f %f %f %f")) |
|---|
| 368 | { |
|---|
| 369 | fr[1].getFloat(time); |
|---|
| 370 | fr[2].getFloat(v[0]); |
|---|
| 371 | fr[3].getFloat(v[1]); |
|---|
| 372 | fr[4].getFloat(v[2]); |
|---|
| 373 | fr += 5; |
|---|
| 374 | channel->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec3Keyframe(time, v)); |
|---|
| 375 | iteratorAdvanced = true; |
|---|
| 376 | } |
|---|
| 377 | } |
|---|
| 378 | anim.addChannel(channel); |
|---|
| 379 | |
|---|
| 380 | if (fr.matchSequence("}")) |
|---|
| 381 | fr += 1; |
|---|
| 382 | } |
|---|
| 383 | if (fr.matchSequence("}")) |
|---|
| 384 | fr += 1; |
|---|
| 385 | } |
|---|
| 386 | else if (fr.matchSequence("Vec4LinearChannel {")) |
|---|
| 387 | { |
|---|
| 388 | fr += 2; |
|---|
| 389 | |
|---|
| 390 | osgAnimation::Vec4LinearChannel* channel = new osgAnimation::Vec4LinearChannel; |
|---|
| 391 | |
|---|
| 392 | if (Animation_readChannel(channel, fr)) |
|---|
| 393 | iteratorAdvanced = true; |
|---|
| 394 | |
|---|
| 395 | int nbKeys; |
|---|
| 396 | if (fr.matchSequence("Keyframes %i {")) |
|---|
| 397 | { |
|---|
| 398 | fr[1].getInt(nbKeys); |
|---|
| 399 | fr += 3; |
|---|
| 400 | iteratorAdvanced = true; |
|---|
| 401 | |
|---|
| 402 | for (int k = 0; k < nbKeys; k++) |
|---|
| 403 | { |
|---|
| 404 | osg::Vec4 v; |
|---|
| 405 | float time; |
|---|
| 406 | if (fr.matchSequence("key %f %f %f %f %f")) |
|---|
| 407 | { |
|---|
| 408 | fr[1].getFloat(time); |
|---|
| 409 | fr[2].getFloat(v[0]); |
|---|
| 410 | fr[3].getFloat(v[1]); |
|---|
| 411 | fr[4].getFloat(v[2]); |
|---|
| 412 | fr[5].getFloat(v[3]); |
|---|
| 413 | fr += 6; |
|---|
| 414 | channel->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec4Keyframe(time, v)); |
|---|
| 415 | iteratorAdvanced = true; |
|---|
| 416 | } |
|---|
| 417 | } |
|---|
| 418 | anim.addChannel(channel); |
|---|
| 419 | |
|---|
| 420 | if (fr.matchSequence("}")) |
|---|
| 421 | fr += 1; |
|---|
| 422 | } |
|---|
| 423 | if (fr.matchSequence("}")) |
|---|
| 424 | fr += 1; |
|---|
| 425 | } |
|---|
| 426 | else if (fr.matchSequence("QuatSphericalLinearChannel {")) |
|---|
| 427 | { |
|---|
| 428 | fr += 2; |
|---|
| 429 | |
|---|
| 430 | osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel; |
|---|
| 431 | |
|---|
| 432 | if (Animation_readChannel(channel, fr)) |
|---|
| 433 | iteratorAdvanced = true; |
|---|
| 434 | |
|---|
| 435 | int nbKeys; |
|---|
| 436 | if (fr.matchSequence("Keyframes %i {")) |
|---|
| 437 | { |
|---|
| 438 | fr[1].getInt(nbKeys); |
|---|
| 439 | fr += 3; |
|---|
| 440 | iteratorAdvanced = true; |
|---|
| 441 | |
|---|
| 442 | for (int k = 0; k < nbKeys; k++) |
|---|
| 443 | { |
|---|
| 444 | osg::Quat q; |
|---|
| 445 | float time; |
|---|
| 446 | if (fr.matchSequence("key %f %f %f %f %f")) |
|---|
| 447 | { |
|---|
| 448 | fr[1].getFloat(time); |
|---|
| 449 | fr[2].getFloat(q[0]); |
|---|
| 450 | fr[3].getFloat(q[1]); |
|---|
| 451 | fr[4].getFloat(q[2]); |
|---|
| 452 | fr[5].getFloat(q[3]); |
|---|
| 453 | fr += 6; |
|---|
| 454 | channel->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::QuatKeyframe(time, q)); |
|---|
| 455 | iteratorAdvanced = true; |
|---|
| 456 | } |
|---|
| 457 | } |
|---|
| 458 | anim.addChannel(channel); |
|---|
| 459 | |
|---|
| 460 | if (fr.matchSequence("}")) |
|---|
| 461 | fr += 1; |
|---|
| 462 | } |
|---|
| 463 | if (fr.matchSequence("}")) |
|---|
| 464 | fr += 1; |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | else if (fr.matchSequence("Channel {")) |
|---|
| 470 | { |
|---|
| 471 | fr += 2; |
|---|
| 472 | |
|---|
| 473 | std::string name = "unknown"; |
|---|
| 474 | if (fr.matchSequence("name %s")) |
|---|
| 475 | { |
|---|
| 476 | if (fr[1].getStr()) |
|---|
| 477 | name = fr[1].getStr(); |
|---|
| 478 | fr += 2; |
|---|
| 479 | iteratorAdvanced = true; |
|---|
| 480 | } |
|---|
| 481 | std::string target = "unknown"; |
|---|
| 482 | if (fr.matchSequence("target %s")) |
|---|
| 483 | { |
|---|
| 484 | if (fr[1].getStr()) |
|---|
| 485 | target = fr[1].getStr(); |
|---|
| 486 | fr += 2; |
|---|
| 487 | iteratorAdvanced = true; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | std::string type = "unknown"; |
|---|
| 491 | int nbKeys; |
|---|
| 492 | if (fr.matchSequence("Keyframes %s %i {")) |
|---|
| 493 | { |
|---|
| 494 | if (fr[1].getStr()) |
|---|
| 495 | type = fr[1].getStr(); |
|---|
| 496 | fr[2].getInt(nbKeys); |
|---|
| 497 | fr += 4; |
|---|
| 498 | iteratorAdvanced = true; |
|---|
| 499 | |
|---|
| 500 | osgAnimation::Channel* channel = 0; |
|---|
| 501 | if (type == "Quat") |
|---|
| 502 | { |
|---|
| 503 | osgAnimation::QuatSphericalLinearChannel* c = new osgAnimation::QuatSphericalLinearChannel; |
|---|
| 504 | c->getOrCreateSampler()->getOrCreateKeyframeContainer(); |
|---|
| 505 | channel = c; |
|---|
| 506 | } |
|---|
| 507 | else if (type == "Vec3") |
|---|
| 508 | { |
|---|
| 509 | osgAnimation::Vec3LinearChannel* c = new osgAnimation::Vec3LinearChannel; |
|---|
| 510 | c->getOrCreateSampler()->getOrCreateKeyframeContainer(); |
|---|
| 511 | channel = c; |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | if (channel) |
|---|
| 515 | { |
|---|
| 516 | for (int k = 0; k < nbKeys; k++) |
|---|
| 517 | { |
|---|
| 518 | if (type == "Quat") |
|---|
| 519 | { |
|---|
| 520 | osg::Quat q; |
|---|
| 521 | float time; |
|---|
| 522 | fr.matchSequence("key %f %f %f %f %f"); |
|---|
| 523 | fr[1].getFloat(time); |
|---|
| 524 | fr[2].getFloat(q[0]); |
|---|
| 525 | fr[3].getFloat(q[1]); |
|---|
| 526 | fr[4].getFloat(q[2]); |
|---|
| 527 | fr[5].getFloat(q[3]); |
|---|
| 528 | fr += 6; |
|---|
| 529 | osgAnimation::QuatSphericalLinearChannel* c = dynamic_cast<osgAnimation::QuatSphericalLinearChannel*>(channel); |
|---|
| 530 | c->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::QuatKeyframe(time, q)); |
|---|
| 531 | iteratorAdvanced = true; |
|---|
| 532 | } |
|---|
| 533 | else if (type == "Vec3") |
|---|
| 534 | { |
|---|
| 535 | osg::Vec3 v; |
|---|
| 536 | float time; |
|---|
| 537 | fr.matchSequence("key %f %f %f %f"); |
|---|
| 538 | fr[1].getFloat(time); |
|---|
| 539 | fr[2].getFloat(v[0]); |
|---|
| 540 | fr[3].getFloat(v[1]); |
|---|
| 541 | fr[4].getFloat(v[2]); |
|---|
| 542 | fr += 5; |
|---|
| 543 | osgAnimation::Vec3LinearChannel* c = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel); |
|---|
| 544 | c->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec3Keyframe(time, v)); |
|---|
| 545 | iteratorAdvanced = true; |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | channel->setName(name); |
|---|
| 549 | channel->setTargetName(target); |
|---|
| 550 | anim.addChannel(channel); |
|---|
| 551 | } |
|---|
| 552 | if (fr.matchSequence("}")) |
|---|
| 553 | fr += 1; |
|---|
| 554 | |
|---|
| 555 | if (fr.matchSequence("}")) |
|---|
| 556 | fr += 1; |
|---|
| 557 | } |
|---|
| 558 | } |
|---|
| 559 | } |
|---|
| 560 | return iteratorAdvanced; |
|---|
| 561 | } |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | template <typename ChannelType, typename ContainerType> |
|---|
| 565 | void Animation_writeChannel(const std::string& channelString, ChannelType* pChannel, Output& fw) |
|---|
| 566 | { |
|---|
| 567 | fw.indent() << channelString.c_str() << " {" << std::endl; |
|---|
| 568 | fw.moveIn(); |
|---|
| 569 | fw.indent() << "name \"" << pChannel->getName() << "\"" << std::endl; |
|---|
| 570 | fw.indent() << "target \"" << pChannel->getTargetName() << "\"" << std::endl; |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | ContainerType* kfc = pChannel->getSamplerTyped()->getKeyframeContainerTyped(); |
|---|
| 575 | if (kfc) |
|---|
| 576 | { |
|---|
| 577 | fw.indent() << "Keyframes " << kfc->size() << " {" << std::endl; |
|---|
| 578 | fw.moveIn(); |
|---|
| 579 | for (unsigned int k = 0; k < kfc->size(); k++) |
|---|
| 580 | { |
|---|
| 581 | fw.indent() << "key " << (*kfc)[k].getTime() << " " << (*kfc)[k].getValue() << std::endl; |
|---|
| 582 | } |
|---|
| 583 | fw.moveOut(); |
|---|
| 584 | fw.indent() << "}" << std::endl; |
|---|
| 585 | fw.moveOut(); |
|---|
| 586 | fw.indent() << "}" << std::endl; |
|---|
| 587 | } |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | bool Animation_writeLocalData(const Object& obj, Output& fw) |
|---|
| 591 | { |
|---|
| 592 | const osgAnimation::Animation& anim = dynamic_cast<const osgAnimation::Animation&>(obj); |
|---|
| 593 | |
|---|
| 594 | switch (anim.getPlayMode()) |
|---|
| 595 | { |
|---|
| 596 | case osgAnimation::Animation::ONCE: |
|---|
| 597 | fw.indent() << "playmode ONCE" << std::endl; |
|---|
| 598 | break; |
|---|
| 599 | case osgAnimation::Animation::STAY: |
|---|
| 600 | fw.indent() << "playmode STAY" << std::endl; |
|---|
| 601 | break; |
|---|
| 602 | case osgAnimation::Animation::LOOP: |
|---|
| 603 | fw.indent() << "playmode LOOP" << std::endl; |
|---|
| 604 | break; |
|---|
| 605 | case osgAnimation::Animation::PPONG: |
|---|
| 606 | fw.indent() << "playmode PPONG" << std::endl; |
|---|
| 607 | break; |
|---|
| 608 | default: |
|---|
| 609 | break; |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | fw.indent() << "weight " << anim.getWeight() << std::endl; |
|---|
| 613 | fw.indent() << "duration " << anim.getDuration() << std::endl; |
|---|
| 614 | fw.indent() << "starttime " << anim.getStartTime() << std::endl; |
|---|
| 615 | |
|---|
| 616 | fw.indent() << "num_channels " << anim.getChannels().size() << std::endl; |
|---|
| 617 | for (unsigned int i = 0; i < anim.getChannels().size(); i++) |
|---|
| 618 | { |
|---|
| 619 | osgAnimation::Channel* pChannel = anim.getChannels()[i].get(); |
|---|
| 620 | |
|---|
| 621 | osgAnimation::DoubleLinearChannel* pDlc = dynamic_cast<osgAnimation::DoubleLinearChannel*>(pChannel); |
|---|
| 622 | if (pDlc) |
|---|
| 623 | { |
|---|
| 624 | Animation_writeChannel<osgAnimation::DoubleLinearChannel, osgAnimation::DoubleKeyframeContainer>("DoubleLinearChannel", pDlc, fw); |
|---|
| 625 | continue; |
|---|
| 626 | } |
|---|
| 627 | osgAnimation::FloatLinearChannel* pFlc = dynamic_cast<osgAnimation::FloatLinearChannel*>(pChannel); |
|---|
| 628 | if (pFlc) |
|---|
| 629 | { |
|---|
| 630 | Animation_writeChannel<osgAnimation::FloatLinearChannel, osgAnimation::FloatKeyframeContainer>("FloatLinearChannel", pFlc, fw); |
|---|
| 631 | continue; |
|---|
| 632 | } |
|---|
| 633 | osgAnimation::Vec2LinearChannel* pV2lc = dynamic_cast<osgAnimation::Vec2LinearChannel*>(pChannel); |
|---|
| 634 | if (pV2lc) |
|---|
| 635 | { |
|---|
| 636 | Animation_writeChannel<osgAnimation::Vec2LinearChannel, osgAnimation::Vec2KeyframeContainer>("Vec2LinearChannel", pV2lc, fw); |
|---|
| 637 | continue; |
|---|
| 638 | } |
|---|
| 639 | osgAnimation::Vec3LinearChannel* pV3lc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(pChannel); |
|---|
| 640 | if (pV3lc) |
|---|
| 641 | { |
|---|
| 642 | Animation_writeChannel<osgAnimation::Vec3LinearChannel, osgAnimation::Vec3KeyframeContainer>("Vec3LinearChannel", pV3lc, fw); |
|---|
| 643 | continue; |
|---|
| 644 | } |
|---|
| 645 | osgAnimation::Vec4LinearChannel* pV4lc = dynamic_cast<osgAnimation::Vec4LinearChannel*>(pChannel); |
|---|
| 646 | if (pV4lc) |
|---|
| 647 | { |
|---|
| 648 | Animation_writeChannel<osgAnimation::Vec4LinearChannel, osgAnimation::Vec4KeyframeContainer>("Vec4LinearChannel", pV4lc, fw); |
|---|
| 649 | continue; |
|---|
| 650 | } |
|---|
| 651 | osgAnimation::QuatSphericalLinearChannel* pQslc = dynamic_cast<osgAnimation::QuatSphericalLinearChannel*>(pChannel); |
|---|
| 652 | if (pQslc) |
|---|
| 653 | { |
|---|
| 654 | Animation_writeChannel<osgAnimation::QuatSphericalLinearChannel, osgAnimation::QuatKeyframeContainer>("QuatSphericalLinearChannel", pQslc, fw); |
|---|
| 655 | continue; |
|---|
| 656 | } |
|---|
| 657 | osgAnimation::FloatCubicBezierChannel* pFcbc = dynamic_cast<osgAnimation::FloatCubicBezierChannel*>(pChannel); |
|---|
| 658 | if (pFcbc) |
|---|
| 659 | { |
|---|
| 660 | Animation_writeChannel<osgAnimation::FloatCubicBezierChannel, osgAnimation::FloatCubicBezierKeyframeContainer>("FloatCubicBezierChannel", pFcbc, fw); |
|---|
| 661 | continue; |
|---|
| 662 | } |
|---|
| 663 | osgAnimation::DoubleCubicBezierChannel* pDcbc = dynamic_cast<osgAnimation::DoubleCubicBezierChannel*>(pChannel); |
|---|
| 664 | if (pDcbc) |
|---|
| 665 | { |
|---|
| 666 | Animation_writeChannel<osgAnimation::DoubleCubicBezierChannel, osgAnimation::DoubleCubicBezierKeyframeContainer>("DoubleCubicBezierChannel", pDcbc, fw); |
|---|
| 667 | continue; |
|---|
| 668 | } |
|---|
| 669 | osgAnimation::Vec2CubicBezierChannel* pV2cbc = dynamic_cast<osgAnimation::Vec2CubicBezierChannel*>(pChannel); |
|---|
| 670 | if (pV2cbc) |
|---|
| 671 | { |
|---|
| 672 | Animation_writeChannel<osgAnimation::Vec2CubicBezierChannel, osgAnimation::Vec2CubicBezierKeyframeContainer>("Vec2CubicBezierChannel", pV2cbc, fw); |
|---|
| 673 | continue; |
|---|
| 674 | } |
|---|
| 675 | osgAnimation::Vec3CubicBezierChannel* pV3cbc = dynamic_cast<osgAnimation::Vec3CubicBezierChannel*>(pChannel); |
|---|
| 676 | if (pV3cbc) |
|---|
| 677 | { |
|---|
| 678 | Animation_writeChannel<osgAnimation::Vec3CubicBezierChannel, osgAnimation::Vec3CubicBezierKeyframeContainer>("Vec3CubicBezierChannel", pV3cbc, fw); |
|---|
| 679 | continue; |
|---|
| 680 | } |
|---|
| 681 | osgAnimation::Vec4CubicBezierChannel* pV4cbc = dynamic_cast<osgAnimation::Vec4CubicBezierChannel*>(pChannel); |
|---|
| 682 | if (pV4cbc) |
|---|
| 683 | { |
|---|
| 684 | Animation_writeChannel<osgAnimation::Vec4CubicBezierChannel, osgAnimation::Vec4CubicBezierKeyframeContainer>("Vec4CubicBezierChannel", pV4cbc, fw); |
|---|
| 685 | continue; |
|---|
| 686 | } |
|---|
| 687 | } |
|---|
| 688 | return true; |
|---|
| 689 | } |
|---|
| 690 | RegisterDotOsgWrapperProxy g_atkAnimationProxy |
|---|
| 691 | ( |
|---|
| 692 | new osgAnimation::Animation, |
|---|
| 693 | "osgAnimation::Animation", |
|---|
| 694 | "Object osgAnimation::Animation", |
|---|
| 695 | &Animation_readLocalData, |
|---|
| 696 | &Animation_writeLocalData |
|---|
| 697 | ); |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | bool AnimationManagerBase_readLocalData(osgAnimation::AnimationManagerBase& manager, Input& fr) |
|---|
| 702 | { |
|---|
| 703 | int nbAnims = 0; |
|---|
| 704 | bool iteratorAdvanced = false; |
|---|
| 705 | |
|---|
| 706 | if (fr.matchSequence("num_animations %i")) |
|---|
| 707 | { |
|---|
| 708 | fr[1].getInt(nbAnims); |
|---|
| 709 | fr += 2; |
|---|
| 710 | iteratorAdvanced = true; |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | for (int i = 0; i < nbAnims; i++) |
|---|
| 714 | { |
|---|
| 715 | Object* o = fr.readObject(); |
|---|
| 716 | osgAnimation::Animation* a = dynamic_cast<osgAnimation::Animation*>(o); |
|---|
| 717 | if (a) |
|---|
| 718 | { |
|---|
| 719 | manager.registerAnimation(a); |
|---|
| 720 | iteratorAdvanced = true; |
|---|
| 721 | } |
|---|
| 722 | else |
|---|
| 723 | osg::notify(osg::WARN)<<"Warning: can't read an animation object"<< std::endl; |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | return iteratorAdvanced; |
|---|
| 727 | } |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | bool BasicAnimationManager_readLocalData(Object& obj, Input& fr) |
|---|
| 731 | { |
|---|
| 732 | osgAnimation::BasicAnimationManager& manager = dynamic_cast<osgAnimation::BasicAnimationManager&>(obj); |
|---|
| 733 | return AnimationManagerBase_readLocalData(manager, fr); |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | bool TimelineAnimationManager_readLocalData(Object& obj, Input& fr) |
|---|
| 737 | { |
|---|
| 738 | osgAnimation::TimelineAnimationManager& manager = dynamic_cast<osgAnimation::TimelineAnimationManager&>(obj); |
|---|
| 739 | return AnimationManagerBase_readLocalData(manager, fr); |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | bool AnimationManagerBase_writeLocalData(const osgAnimation::AnimationManagerBase& manager, Output& fw) |
|---|
| 744 | { |
|---|
| 745 | const osgAnimation::AnimationList& animList = manager.getAnimationList(); |
|---|
| 746 | |
|---|
| 747 | fw.indent() << "num_animations " << animList.size() << std::endl; |
|---|
| 748 | for (osgAnimation::AnimationList::const_iterator it = animList.begin(); it != animList.end(); ++it) |
|---|
| 749 | { |
|---|
| 750 | if (!fw.writeObject(**it)) |
|---|
| 751 | osg::notify(osg::WARN)<<"Warning: can't write an animation object"<< std::endl; |
|---|
| 752 | } |
|---|
| 753 | return true; |
|---|
| 754 | } |
|---|
| 755 | |
|---|
| 756 | bool BasicAnimationManager_writeLocalData(const Object& obj, Output& fw) |
|---|
| 757 | { |
|---|
| 758 | const osgAnimation::BasicAnimationManager& manager = dynamic_cast<const osgAnimation::BasicAnimationManager&>(obj); |
|---|
| 759 | return AnimationManagerBase_writeLocalData(manager, fw); |
|---|
| 760 | } |
|---|
| 761 | |
|---|
| 762 | bool TimelineAnimationManager_writeLocalData(const Object& obj, Output& fw) |
|---|
| 763 | { |
|---|
| 764 | const osgAnimation::TimelineAnimationManager& manager = dynamic_cast<const osgAnimation::TimelineAnimationManager&>(obj); |
|---|
| 765 | return AnimationManagerBase_writeLocalData(manager, fw); |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | RegisterDotOsgWrapperProxy g_BasicAnimationManagerProxy |
|---|
| 770 | ( |
|---|
| 771 | new osgAnimation::BasicAnimationManager, |
|---|
| 772 | "osgAnimation::BasicAnimationManager", |
|---|
| 773 | "Object NodeCallback osgAnimation::BasicAnimationManager", |
|---|
| 774 | &BasicAnimationManager_readLocalData, |
|---|
| 775 | &BasicAnimationManager_writeLocalData, |
|---|
| 776 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 777 | ); |
|---|
| 778 | |
|---|
| 779 | RegisterDotOsgWrapperProxy g_TimelineAnimationManagerProxy |
|---|
| 780 | ( |
|---|
| 781 | new osgAnimation::TimelineAnimationManager, |
|---|
| 782 | "osgAnimation::TimelineAnimationManager", |
|---|
| 783 | "Object NodeCallback osgAnimation::TimelineAnimationManager", |
|---|
| 784 | &TimelineAnimationManager_readLocalData, |
|---|
| 785 | &TimelineAnimationManager_writeLocalData, |
|---|
| 786 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 787 | ); |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | bool RigGeometry_readLocalData(Object& obj, Input& fr) |
|---|
| 791 | { |
|---|
| 792 | osgAnimation::RigGeometry& geom = dynamic_cast<osgAnimation::RigGeometry&>(obj); |
|---|
| 793 | osg::ref_ptr<osgAnimation::VertexInfluenceMap> vmap = new osgAnimation::VertexInfluenceMap; |
|---|
| 794 | |
|---|
| 795 | int nbGroups = 0; |
|---|
| 796 | bool iteratorAdvanced = false; |
|---|
| 797 | if (fr.matchSequence("num_influences %i")) |
|---|
| 798 | { |
|---|
| 799 | fr[1].getInt(nbGroups); |
|---|
| 800 | fr += 2; |
|---|
| 801 | iteratorAdvanced = true; |
|---|
| 802 | } |
|---|
| 803 | |
|---|
| 804 | for (int i = 0; i < nbGroups; i++) |
|---|
| 805 | { |
|---|
| 806 | int nbVertexes = 0; |
|---|
| 807 | std::string name; |
|---|
| 808 | if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {")) |
|---|
| 809 | { |
|---|
| 810 | name = fr[1].getStr(); |
|---|
| 811 | fr[2].getInt(nbVertexes); |
|---|
| 812 | fr += 4; |
|---|
| 813 | iteratorAdvanced = true; |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | osgAnimation::VertexInfluence vi; |
|---|
| 817 | vi.setName(name); |
|---|
| 818 | vi.reserve(nbVertexes); |
|---|
| 819 | for (int j = 0; j < nbVertexes; j++) |
|---|
| 820 | { |
|---|
| 821 | int index = -1; |
|---|
| 822 | float weight = 1; |
|---|
| 823 | if (fr.matchSequence("%i %f")) |
|---|
| 824 | { |
|---|
| 825 | fr[0].getInt(index); |
|---|
| 826 | fr[1].getFloat(weight); |
|---|
| 827 | fr += 2; |
|---|
| 828 | iteratorAdvanced = true; |
|---|
| 829 | } |
|---|
| 830 | vi.push_back(osgAnimation::VertexIndexWeight(index, weight)); |
|---|
| 831 | } |
|---|
| 832 | if (fr.matchSequence("}")) |
|---|
| 833 | { |
|---|
| 834 | fr+=1; |
|---|
| 835 | } |
|---|
| 836 | (*vmap)[name] = vi; |
|---|
| 837 | } |
|---|
| 838 | if (!vmap->empty()) |
|---|
| 839 | geom.setInfluenceMap(vmap.get()); |
|---|
| 840 | |
|---|
| 841 | if (fr.matchSequence("Geometry {")) |
|---|
| 842 | { |
|---|
| 843 | osg::Geometry* source = dynamic_cast<osg::Geometry*>(fr.readObject()); |
|---|
| 844 | geom.setSourceGeometry(source); |
|---|
| 845 | iteratorAdvanced = true; |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | return iteratorAdvanced; |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | bool RigGeometry_writeLocalData(const Object& obj, Output& fw) |
|---|
| 852 | { |
|---|
| 853 | const osgAnimation::RigGeometry& geom = dynamic_cast<const osgAnimation::RigGeometry&>(obj); |
|---|
| 854 | const osgAnimation::VertexInfluenceMap* vm = geom.getInfluenceMap(); |
|---|
| 855 | if (!vm) |
|---|
| 856 | return true; |
|---|
| 857 | fw.indent() << "num_influences " << vm->size() << std::endl; |
|---|
| 858 | fw.moveIn(); |
|---|
| 859 | for (osgAnimation::VertexInfluenceMap::const_iterator it = vm->begin(); it != vm->end(); ++it) |
|---|
| 860 | { |
|---|
| 861 | std::string name = it->first; |
|---|
| 862 | if (name.empty()) |
|---|
| 863 | name = "Empty"; |
|---|
| 864 | fw.indent() << "osgAnimation::VertexInfluence \"" << name << "\" " << it->second.size() << " {" << std::endl; |
|---|
| 865 | fw.moveIn(); |
|---|
| 866 | const osgAnimation::VertexInfluence& vi = it->second; |
|---|
| 867 | for (osgAnimation::VertexInfluence::const_iterator itv = vi.begin(); itv != vi.end(); itv++) |
|---|
| 868 | { |
|---|
| 869 | fw.indent() << itv->first << " " << itv->second << std::endl; |
|---|
| 870 | } |
|---|
| 871 | fw.moveOut(); |
|---|
| 872 | fw.indent() << "}" << std::endl; |
|---|
| 873 | } |
|---|
| 874 | fw.moveOut(); |
|---|
| 875 | |
|---|
| 876 | fw.writeObject(*geom.getSourceGeometry()); |
|---|
| 877 | return true; |
|---|
| 878 | } |
|---|
| 879 | |
|---|
| 880 | RegisterDotOsgWrapperProxy g_atkRigGeometryProxy |
|---|
| 881 | ( |
|---|
| 882 | new osgAnimation::RigGeometry, |
|---|
| 883 | "osgAnimation::RigGeometry", |
|---|
| 884 | "Object osgAnimation::RigGeometry Drawable Geometry", |
|---|
| 885 | &RigGeometry_readLocalData, |
|---|
| 886 | &RigGeometry_writeLocalData, |
|---|
| 887 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 888 | ); |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | bool MorphGeometry_readLocalData(Object& obj, Input& fr) |
|---|
| 892 | { |
|---|
| 893 | osgAnimation::MorphGeometry& geom = dynamic_cast<osgAnimation::MorphGeometry&>(obj); |
|---|
| 894 | |
|---|
| 895 | bool iteratorAdvanced = false; |
|---|
| 896 | |
|---|
| 897 | if (fr[0].matchWord("method")) |
|---|
| 898 | { |
|---|
| 899 | if (fr[1].matchWord("NORMALIZED")) |
|---|
| 900 | { |
|---|
| 901 | geom.setMethod(osgAnimation::MorphGeometry::NORMALIZED); |
|---|
| 902 | fr+=2; |
|---|
| 903 | iteratorAdvanced = true; |
|---|
| 904 | } |
|---|
| 905 | else if (fr[1].matchWord("RELATIVE")) |
|---|
| 906 | { |
|---|
| 907 | geom.setMethod(osgAnimation::MorphGeometry::RELATIVE); |
|---|
| 908 | fr+=2; |
|---|
| 909 | iteratorAdvanced = true; |
|---|
| 910 | } |
|---|
| 911 | } |
|---|
| 912 | |
|---|
| 913 | if (fr[0].matchWord("morphNormals")) |
|---|
| 914 | { |
|---|
| 915 | if (fr[1].matchWord("TRUE")) |
|---|
| 916 | { |
|---|
| 917 | geom.setMorphNormals(true); |
|---|
| 918 | fr+=2; |
|---|
| 919 | iteratorAdvanced = true; |
|---|
| 920 | } |
|---|
| 921 | else if (fr[1].matchWord("FALSE")) |
|---|
| 922 | { |
|---|
| 923 | geom.setMorphNormals(false); |
|---|
| 924 | fr+=2; |
|---|
| 925 | iteratorAdvanced = true; |
|---|
| 926 | } |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | int num_morphTargets = 0; |
|---|
| 930 | if (fr.matchSequence("num_morphTargets %i")) |
|---|
| 931 | { |
|---|
| 932 | fr[1].getInt(num_morphTargets); |
|---|
| 933 | fr += 2; |
|---|
| 934 | iteratorAdvanced = true; |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | for (int i = 0; i < num_morphTargets; i++) |
|---|
| 938 | { |
|---|
| 939 | if (fr.matchSequence("MorphTarget {")) |
|---|
| 940 | { |
|---|
| 941 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 942 | fr += 2; |
|---|
| 943 | iteratorAdvanced = true; |
|---|
| 944 | |
|---|
| 945 | while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) |
|---|
| 946 | { |
|---|
| 947 | |
|---|
| 948 | float weight = 1.0; |
|---|
| 949 | if (fr.matchSequence("weight %f")) |
|---|
| 950 | { |
|---|
| 951 | fr[1].getFloat(weight); |
|---|
| 952 | fr += 2; |
|---|
| 953 | } |
|---|
| 954 | osg::Drawable* drawable = NULL; |
|---|
| 955 | drawable = fr.readDrawable(); |
|---|
| 956 | osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(drawable); |
|---|
| 957 | if (geometry) |
|---|
| 958 | geom.addMorphTarget(geometry, weight); |
|---|
| 959 | } |
|---|
| 960 | if (fr.matchSequence("}")) |
|---|
| 961 | fr += 1; |
|---|
| 962 | } |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | return iteratorAdvanced; |
|---|
| 966 | } |
|---|
| 967 | |
|---|
| 968 | bool MorphGeometry_writeLocalData(const Object& obj, Output& fw) |
|---|
| 969 | { |
|---|
| 970 | const osgAnimation::MorphGeometry& geom = dynamic_cast<const osgAnimation::MorphGeometry&>(obj); |
|---|
| 971 | |
|---|
| 972 | switch(geom.getMethod()) |
|---|
| 973 | { |
|---|
| 974 | case(osgAnimation::MorphGeometry::NORMALIZED): fw.indent() << "method NORMALIZED"<<std::endl; break; |
|---|
| 975 | case(osgAnimation::MorphGeometry::RELATIVE): fw.indent() << "method RELATIVE"<<std::endl; break; |
|---|
| 976 | } |
|---|
| 977 | |
|---|
| 978 | fw.indent() << "morphNormals "; |
|---|
| 979 | if (geom.getMorphNormals()) |
|---|
| 980 | fw << "TRUE" << std::endl; |
|---|
| 981 | else |
|---|
| 982 | fw << "FALSE" << std::endl; |
|---|
| 983 | |
|---|
| 984 | const osgAnimation::MorphGeometry::MorphTargetList& morphTargets = geom.getMorphTargetList(); |
|---|
| 985 | fw.indent() << "num_morphTargets " << morphTargets.size() << std::endl; |
|---|
| 986 | for (unsigned int i = 0; i < morphTargets.size(); i++) |
|---|
| 987 | { |
|---|
| 988 | fw.indent() << "MorphTarget {" << std::endl; |
|---|
| 989 | fw.moveIn(); |
|---|
| 990 | fw.indent() << "weight " << morphTargets[i].getWeight() <<std::endl; |
|---|
| 991 | fw.writeObject(*morphTargets[i].getGeometry()); |
|---|
| 992 | fw.moveOut(); |
|---|
| 993 | fw.indent() << "}" << std::endl; |
|---|
| 994 | } |
|---|
| 995 | return true; |
|---|
| 996 | } |
|---|
| 997 | |
|---|
| 998 | RegisterDotOsgWrapperProxy g_osgAnimationMorphGeometryProxy |
|---|
| 999 | ( |
|---|
| 1000 | new osgAnimation::MorphGeometry, |
|---|
| 1001 | "osgAnimation::MorphGeometry", |
|---|
| 1002 | "Object Drawable osgAnimation::MorphGeometry Geometry", |
|---|
| 1003 | &MorphGeometry_readLocalData, |
|---|
| 1004 | &MorphGeometry_writeLocalData, |
|---|
| 1005 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 1006 | ); |
|---|
| 1007 | |
|---|
| 1008 | |
|---|
| 1009 | |
|---|
| 1010 | |
|---|
| 1011 | |
|---|
| 1012 | bool UpdateBone_readLocalData(Object& obj, Input& fr) |
|---|
| 1013 | { |
|---|
| 1014 | bool iteratorAdvanced = false; |
|---|
| 1015 | return iteratorAdvanced; |
|---|
| 1016 | } |
|---|
| 1017 | |
|---|
| 1018 | bool UpdateBone_writeLocalData(const Object& obj, Output& fw) |
|---|
| 1019 | { |
|---|
| 1020 | return true; |
|---|
| 1021 | } |
|---|
| 1022 | |
|---|
| 1023 | RegisterDotOsgWrapperProxy g_UpdateBoneProxy |
|---|
| 1024 | ( |
|---|
| 1025 | new osgAnimation::UpdateBone, |
|---|
| 1026 | "osgAnimation::UpdateBone", |
|---|
| 1027 | "Object NodeCallback osgAnimation::UpdateMatrixTransform osgAnimation::UpdateBone", |
|---|
| 1028 | &UpdateBone_readLocalData, |
|---|
| 1029 | &UpdateBone_writeLocalData, |
|---|
| 1030 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 1031 | ); |
|---|
| 1032 | |
|---|
| 1033 | |
|---|
| 1034 | |
|---|
| 1035 | bool UpdateSkeleton_readLocalData(Object& obj, Input& fr) |
|---|
| 1036 | { |
|---|
| 1037 | bool iteratorAdvanced = false; |
|---|
| 1038 | return iteratorAdvanced; |
|---|
| 1039 | } |
|---|
| 1040 | |
|---|
| 1041 | bool UpdateSkeleton_writeLocalData(const Object& obj, Output& fw) |
|---|
| 1042 | { |
|---|
| 1043 | return true; |
|---|
| 1044 | } |
|---|
| 1045 | |
|---|
| 1046 | RegisterDotOsgWrapperProxy g_UpdateSkeletonProxy |
|---|
| 1047 | ( |
|---|
| 1048 | new osgAnimation::Skeleton::UpdateSkeleton, |
|---|
| 1049 | "osgAnimation::UpdateSkeleton", |
|---|
| 1050 | "Object NodeCallback osgAnimation::UpdateSkeleton", |
|---|
| 1051 | &UpdateSkeleton_readLocalData, |
|---|
| 1052 | &UpdateSkeleton_writeLocalData, |
|---|
| 1053 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 1054 | ); |
|---|
| 1055 | |
|---|
| 1056 | |
|---|
| 1057 | bool UpdateMorph_readLocalData(Object& obj, Input& fr) |
|---|
| 1058 | { |
|---|
| 1059 | bool iteratorAdvanced = false; |
|---|
| 1060 | return iteratorAdvanced; |
|---|
| 1061 | } |
|---|
| 1062 | |
|---|
| 1063 | bool UpdateMorph_writeLocalData(const Object& obj, Output& fw) |
|---|
| 1064 | { |
|---|
| 1065 | return true; |
|---|
| 1066 | } |
|---|
| 1067 | |
|---|
| 1068 | RegisterDotOsgWrapperProxy g_UpdateMorphProxy |
|---|
| 1069 | ( |
|---|
| 1070 | new osgAnimation::UpdateMorph, |
|---|
| 1071 | "osgAnimation::UpdateMorph", |
|---|
| 1072 | "Object NodeCallback osgAnimation::UpdateMorph", |
|---|
| 1073 | &UpdateMorph_readLocalData, |
|---|
| 1074 | &UpdateMorph_writeLocalData, |
|---|
| 1075 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 1076 | ); |
|---|