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