示例#1
0
void get_animation_bones(STB3D_ModelTransform *bones, STB3D_ModelAnimationSet *anim, int number, float atime, int looped, int interpolation)
{
   STB3D_ModelBoneAnimation *alist = anim->anim[number];
   int i, frames = anim->anim[number][0].num_frames;
   int a1,a2, a0,a3;
   float lerp_factor;

   a1 = (int) floor(atime);
   lerp_factor = atime - a1;
   a1 = keyframe(a1, frames, looped);

   if (interpolation == STB3D_MODEL_interpolate_nearest) {
      for (i=0; i < anim->num_bones; ++i) {
         STB3D_ModelBoneAnimation *z = &anim->anim[number][i];
         memcpy(bones+i, &z->frame[a1].rest_xform, sizeof(bones[0]));
      }
   } else {
      if (interpolation == STB3D_MODEL_interpolate_linear) {
         a2 = keyframe(a1+1, frames, looped);
         for (i=0; i < anim->num_bones; ++i) {
            STB3D_ModelBoneAnimation *z = &anim->anim[number][i];
            xform_linear_interpolate(bones+i, &z->frame[a1].rest_xform, &z->frame[a2].rest_xform, lerp_factor);
         }
      } else {
         a2 = keyframe(a1+1, frames, looped);
         a0 = keyframe(a1-1, frames, looped);
         a3 = keyframe(a2+1, frames, looped);
         for (i=0; i < anim->num_bones; ++i) {
            STB3D_ModelBoneAnimation *z = &anim->anim[number][i];
            xform_cubic_interpolate(bones+i, &z->frame[a0].rest_xform, &z->frame[a1].rest_xform, &z->frame[a2].rest_xform, &z->frame[a3].rest_xform, lerp_factor);
         }
      }
   }
}
void KeyframeWidget::show() {
  for(auto item : keyframeBox->selectedItems()) {
    auto kfitem = static_cast<KeyframeItem*>(keyframeBox->itemWidget(item));
    emit showingKeyframe(kfitem->keyframe());
    break;
  }
}
void KeyframeWidget::save() {
  KeyframeSequence ks;
  for(int i = 0; i < keyframeBox->count(); i++) {
    auto kitem = static_cast<KeyframeItem*>(keyframeBox->itemWidget(keyframeBox->item(i)));
    ks.keyframes.push_back(kitem->keyframe());
  }
  ks.save(kfconfig_.sequence_file);
}
void KeyframeItem::swap(QListWidgetItem* oitem) {
  auto kfitem = static_cast<KeyframeItem*>(list_->itemWidget(oitem));
  auto kf = kfitem->keyframe();
  kfitem->updateKeyframe(keyframe_);
  updateKeyframe(kf);

  auto s = oitem->isSelected();
  oitem->setSelected(item_->isSelected());
  item_->setSelected(s);
}
KisKeyframeSP KisRasterKeyframeChannel::createKeyframe(int time, const KisKeyframeSP copySrc, KUndo2Command *parentCommand)
{
    int srcFrame = (copySrc != 0) ? copySrc->value() : 0;

    int frameId = m_d->paintDevice->framesInterface()->createFrame((copySrc != 0), srcFrame, QPoint(), parentCommand);

    KisKeyframeSP keyframe(new KisKeyframe(this, time, (quint32)frameId));

    return keyframe;
}
void KeyframeWidget::playNextFrame() {
  // Clear selections from keyframes that have been played
  if(currentKeyframe_ > 0) {
    auto item = keyframeBox->item(currentKeyframe_ - 1);
    item->setSelected(false);
  }

  // Stop if we've played motions between each pair
  if(currentKeyframe_ >= keyframeBox->count() - 1) {
    for(int i = 0; i < keyframeBox->count(); i++)
      keyframeBox->item(i)->setSelected(false);
    return;
  }

  // Pull the first keyframe in the pair
  auto sitem = keyframeBox->item(currentKeyframe_);
  sitem->setSelected(true);
  auto kfstart = static_cast<KeyframeItem*>(keyframeBox->itemWidget(sitem));
  auto& start = kfstart->keyframe();
  
  // Pull the second keyframe in the pair
  auto fitem = keyframeBox->item(currentKeyframe_ + 1);
  fitem->setSelected(true);
  auto kffinish = static_cast<KeyframeItem*>(keyframeBox->itemWidget(fitem));
  auto& finish = kffinish->keyframe();
  
  // If we've played the transition, increment and start on the next pair
  if(currentFrame_ >= finish.frames) {
    currentKeyframe_++;
    currentFrame_ = 0;
    playNextFrame();
    return;
  }

  // Emit the start, end, and # of frames
  emit playingSequence(start, finish, currentFrame_);
  currentFrame_++;
  keyframeTimer_->start(10);
}
void KeyframeMapper::addKeyframe(
  const rgbdtools::RGBDFrame& frame, 
  const AffineTransform& pose)
{
  rgbdtools::RGBDKeyframe keyframe(frame);
  keyframe.pose = pose;
  
  if (manual_add_)
  {
    ROS_INFO("Adding frame manually");
    manual_add_ = false;
    keyframe.manually_added = true;
  }
  keyframes_.push_back(keyframe); 
}
示例#8
0
文件: saver.cpp 项目: CJFocke/vsxu
bool CalSaver::saveXmlCoreAnimation(const std::string& strFilename, CalCoreAnimation *pCoreAnimation)
{

    std::stringstream str;

    vsxTiXmlDocument doc(strFilename);

    vsxTiXmlElement animation("ANIMATION");
    //animation.SetAttribute("MAGIC",Cal::ANIMATION_XMLFILE_MAGIC);
    animation.SetAttribute("VERSION",Cal::LIBRARY_VERSION);


	str.str("");
    str << pCoreAnimation->getDuration();	
	animation.SetAttribute("DURATION",str.str());
	
	// get core track list
    std::list<CalCoreTrack *>& listCoreTrack = pCoreAnimation->getListCoreTrack();

	animation.SetAttribute("NUMTRACKS",listCoreTrack.size());
  

    // write all core bones
    std::list<CalCoreTrack *>::iterator iteratorCoreTrack;
    for(iteratorCoreTrack = listCoreTrack.begin(); iteratorCoreTrack != listCoreTrack.end(); ++iteratorCoreTrack)
	{
		CalCoreTrack *pCoreTrack=*iteratorCoreTrack;

		vsxTiXmlElement track("TRACK");
		track.SetAttribute("BONEID",pCoreTrack->getCoreBoneId());
		
		track.SetAttribute("NUMKEYFRAMES",pCoreTrack->getCoreKeyframeCount());

		// save all core keyframes
        for (int i = 0; i < pCoreTrack->getCoreKeyframeCount(); ++i)
		{
			CalCoreKeyframe *pCoreKeyframe=pCoreTrack->getCoreKeyframe(i);

			vsxTiXmlElement keyframe("KEYFRAME");

			str.str("");
            str << pCoreKeyframe->getTime();	        
			keyframe.SetAttribute("TIME",str.str());
			
			vsxTiXmlElement translation("TRANSLATION");
			const CalVector& translationVector = pCoreKeyframe->getTranslation();

			str.str("");
			str << translationVector.x << " "
				<< translationVector.y << " "
				<< translationVector.z;

			vsxTiXmlText translationdata(str.str());  

			translation.InsertEndChild(translationdata);
			keyframe.InsertEndChild(translation);

			vsxTiXmlElement rotation("ROTATION");
			const CalQuaternion& rotationQuad = pCoreKeyframe->getRotation();  

			str.str("");
			str << rotationQuad.x << " " 
				<< rotationQuad.y << " "
				<< rotationQuad.z << " "
				<< rotationQuad.w;

			vsxTiXmlText rotationdata(str.str());
			rotation.InsertEndChild(rotationdata);
			keyframe.InsertEndChild(rotation);

			track.InsertEndChild(keyframe);
		}

		animation.InsertEndChild(track);
	}

	doc.InsertEndChild(animation);
	
    if(!doc.SaveFile())
	{
	  CalError::setLastError(CalError::FILE_WRITING_FAILED, __FILE__, __LINE__, strFilename);
      return false;
	} 

  return true;
}