Exemplo n.º 1
0
void ANIM::ANIM2::read(athena::io::IStreamReader& reader)
{
    Header head;
    head.read(reader);
    evnt = head.evnt;
    mainInterval = head.interval;

    WordBitmap keyBmp;
    keyBmp.read(reader, head.keyBitmapBitCount);
    frames.clear();
    atUint32 frameAccum = 0;
    for (bool bit : keyBmp)
    {
        if (bit)
            frames.push_back(frameAccum);
        ++frameAccum;
    }
    reader.seek(8);

    bones.clear();
    bones.reserve(head.boneChannelCount);
    channels.clear();
    channels.reserve(head.boneChannelCount);
    atUint16 keyframeCount = 0;
    for (size_t b=0 ; b<head.boneChannelCount ; ++b)
    {
        ChannelDesc desc;
        desc.read(reader);
        bones.emplace_back(desc.id, desc.keyCount2 != 0);

        if (desc.keyCount1)
        {
            channels.emplace_back();
            DNAANIM::Channel& chan = channels.back();
            chan.type = DNAANIM::Channel::Type::Rotation;
            chan.i[0] = desc.initRX;
            chan.q[0] = desc.qRX;
            chan.i[1] = desc.initRY;
            chan.q[1] = desc.qRY;
            chan.i[2] = desc.initRZ;
            chan.q[2] = desc.qRZ;
        }
        keyframeCount = std::max(keyframeCount, desc.keyCount1);

        if (desc.keyCount2)
        {
            channels.emplace_back();
            DNAANIM::Channel& chan = channels.back();
            chan.type = DNAANIM::Channel::Type::Translation;
            chan.i[0] = desc.initTX;
            chan.q[0] = desc.qTX;
            chan.i[1] = desc.initTY;
            chan.q[1] = desc.qTY;
            chan.i[2] = desc.initTZ;
            chan.q[2] = desc.qTZ;
        }
    }

    size_t bsSize = DNAANIM::ComputeBitstreamSize(keyframeCount, channels);
    std::unique_ptr<atUint8[]> bsData = reader.readUBytes(bsSize);
    DNAANIM::BitstreamReader bsReader;
    chanKeys = bsReader.read(bsData.get(), keyframeCount, channels, head.rotDiv, head.translationMult);
}
Exemplo n.º 2
0
Arquivo: ANIM.cpp Projeto: AxioDL/urde
void ANIM::ANIM2::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
  Header head;
  head.read(reader);
  mainInterval = head.interval;
  looping = bool(head.looping);

  WordBitmap keyBmp;
  keyBmp.read(reader, head.keyBitmapBitCount);
  frames.clear();
  atUint32 frameAccum = 0;
  for (bool bit : keyBmp) {
    if (bit)
      frames.push_back(frameAccum);
    ++frameAccum;
  }
  reader.seek(4);

  bones.clear();
  bones.reserve(head.boneChannelCount);
  channels.clear();
  channels.reserve(head.boneChannelCount);
  atUint16 keyframeCount = 0;
  for (size_t b = 0; b < head.boneChannelCount; ++b) {
    ChannelDesc desc;
    desc.read(reader);
    bones.emplace_back(desc.id, std::make_tuple(desc.keyCount1 != 0, desc.keyCount2 != 0, desc.keyCount3 != 0));

    if (desc.keyCount1) {
      channels.emplace_back();
      DNAANIM::Channel& chan = channels.back();
      chan.type = DNAANIM::Channel::Type::Rotation;
      chan.i[0] = desc.initRX;
      chan.q[0] = desc.qRX;
      chan.i[1] = desc.initRY;
      chan.q[1] = desc.qRY;
      chan.i[2] = desc.initRZ;
      chan.q[2] = desc.qRZ;
    }
    keyframeCount = std::max(keyframeCount, desc.keyCount1);

    if (desc.keyCount2) {
      channels.emplace_back();
      DNAANIM::Channel& chan = channels.back();
      chan.type = DNAANIM::Channel::Type::Translation;
      chan.i[0] = desc.initTX;
      chan.q[0] = desc.qTX;
      chan.i[1] = desc.initTY;
      chan.q[1] = desc.qTY;
      chan.i[2] = desc.initTZ;
      chan.q[2] = desc.qTZ;
    }
    keyframeCount = std::max(keyframeCount, desc.keyCount2);

    if (desc.keyCount3) {
      channels.emplace_back();
      DNAANIM::Channel& chan = channels.back();
      chan.type = DNAANIM::Channel::Type::Scale;
      chan.i[0] = desc.initSX;
      chan.q[0] = desc.qSX;
      chan.i[1] = desc.initSY;
      chan.q[1] = desc.qSY;
      chan.i[2] = desc.initSZ;
      chan.q[2] = desc.qSZ;
    }
    keyframeCount = std::max(keyframeCount, desc.keyCount3);
  }

  size_t bsSize = DNAANIM::ComputeBitstreamSize(keyframeCount, channels);
  std::unique_ptr<atUint8[]> bsData = reader.readUBytes(bsSize);
  DNAANIM::BitstreamReader bsReader;
  chanKeys = bsReader.read(bsData.get(), keyframeCount, channels, head.rotDiv, head.translationMult, head.scaleMult);
}