转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件使用 >> 系统软件 >> 正文
3ds Max Exporter------Skin Bone Animation         

3ds Max Exporter------Skin Bone Animation

作者:闵涛 文章来源:闵涛的学习笔记 点击数:2035 更新时间:2009/4/25 0:44:42
 wData.vertIdx=i;
       wData.weight=vtxBlendedInt->GetWeight(j);
       //check vertex existence for this bone
       bool notfound = true;  
       for(int v=0;notfound&&v<BD[boneIdx].weightVect.size();v++)
       {
        if(BD[boneIdx].weightVect[v].vertIdx==wData.vertIdx&&BD[boneIdx].weightVect[v].meshIdx==wData.meshIdx)
        {
         BD[boneIdx].weightVect[v].weight += wData.weight;
          notfound = false;
        }
       }
       if(notfound)
       {
        BD[boneIdx].weightVect.push_back(wData);
        BD[boneIdx].boneHdr.vertexCnt=BD[boneIdx].weightVect.size();
       }
      }
     }
    }
   }
   phyInterface->ReleaseContextInterface(modContextInt);
  }
  pMod->ReleaseInterface(I_PHYINTERFACE, phyInterface);
 }
 
 return FALSE;
}
//===========================================
Matrix3 GetBoneTM(INode *pNode, TimeValue t)
{
 Matrix3 tm(1);

 tm = pNode->GetNodeTM(t);

 tm.NoScale();
 return tm;
}
// ============================================================================
// Recursive iterator to get a bone index, used with GetBoneIndex
int RecursiveGetBoneIndex(INode *pRoot, INode *pNodeTest, int &boneCount)
{
 int boneIdx = -1;

 if(IsBone(pRoot))
 {
  boneIdx = boneCount;
  boneCount++;

  if(pRoot == pNodeTest)
   return boneIdx;
 }

 // recurse child nodes
 for(int i = 0; i < pRoot->NumberOfChildren(); i++)
 {
  int boneIdx = RecursiveGetBoneIndex(pRoot->GetChildNode(i), pNodeTest, boneCount);
  if(boneIdx >= 0)
   return boneIdx;
 }

 return -1;
}
// Get the number of direct child bones of a node
int GetChildBoneCount(INode *pNode)
{
 int count = 0;

 for(int i = 0; i < pNode->NumberOfChildren(); i++)
 {
  if(IsBone(pNode->GetChildNode(i)))
   count++;
 }
 return count;
}
int ProcessBoneStruct(INode *pNode, INode *pRoot,int parentIdx, BoneData* BD)
{
 if(IsBone(pNode))
 {
  int currIdx=GetBoneIndex(pRoot,pNode);
  assert(-1!=currIdx);
  Bone_hdr &boneHdr=BD[currIdx].boneHdr;
  // get the bones inverse base matrix at time 0 
  Matrix3 tm=GetBoneTM(pNode,0);
  tm.Invert();
  MAXtoGL(tm,boneHdr.inverseOrientationTM);
  boneHdr.parentIdx=parentIdx;
  boneHdr.childCnt=GetChildBoneCount(pNode);
  if(boneHdr.childCnt>0)
  {
   BD[currIdx].childIdxVect.reserve(boneHdr.childCnt);
   for(int i=0;i<pNode->NumberOfChildren();i++)
   {
    int cIdx=ProcessBoneStruct(pNode->GetChildNode(i),pRoot,currIdx,BD);
    if(cIdx>=0)
     BD[currIdx].childIdxVect.push_back(cIdx);
   }
  }
  assert(BD[currIdx].childIdxVect.size()==BD[currIdx].boneHdr.childCnt);
  return currIdx;
 }
 else
 {
  for (int i=0; i<pNode->NumberOfChildren(); ++i)
   ProcessBoneStruct(pNode->GetChildNode(i),pRoot,-1, BD);
  return -1;
 }
}
// used by GetBoneByIndex
static bool BuildIter(INode* pnode, INode** const Iterator, int& currIdx) {
 
 if(IsBone(pnode)){
  Iterator[currIdx++] = pnode;
 }

 for(int i = 0; i < pnode->NumberOfChildren(); i++) {
  BuildIter(pnode->GetChildNode(i),Iterator,currIdx);
 }

 return true;
}
// Get bone pointer from an index, this should get passed the root node
INode* GetBoneByIndex(INode* const pRoot, int index) {
 INode* bone = NULL;
 const int bone_cnt = CountBones(pRoot);
 
 if (index>=bone_cnt)
  return NULL;

 INode** const Iterator = new INode* [bone_cnt];
 int currIdx=0;
 
  BuildIter(pRoot,Iterator,currIdx);
 
 assert(currIdx==bone_cnt);

 bone = Iterator[index];
 
 assert (GetBoneIndex(pRoot,bone)==index);

 delete [] Iterator;
  
 assert (IsBone(bone));
 return bone;
}

int ProcessBoneAnim (INode *pRoot, Interval range, ULONG sampleD, BoneData* BD)
{
 int keycnt=0;
 int totalbones=CountBones(pRoot);
 const ULONG start = TicksToMilliSec(range.Start());
 const ULONG end   = TicksToMilliSec(range.End());
 if(!totalbones)
  return 0;
 for(int idx=0;idx<totalbones;idx++)
 {
  INode *pBone=GetBoneByIndex(pRoot,idx);
  assert(IsBone(pBone));
  ULONG msec=0;
  for(msec=start;msec<end+sampleD;msec+=sampleD)
  {
   BoneKey_hdr keyHdr;
   memset(&keyHdr,0,sizeof(BoneKey_hdr));
   if(msec>end)
    keyHdr.time=end;
   else
    keyHdr.time=msec;
   Matrix3 tm;
   TimeValue t;
   t=MilliSecToTicks(msec);
   tm=GetBoneTM(pBone,t);
   MAXtoGL(tm);

   Point3 pt=tm.GetTrans();
   keyHdr.pos[0]=pt.x;
   keyHdr.pos[1]=pt.y;
   keyHdr.pos[2]=pt.z;

   Quat quat(tm);
   quat.Normalize();
   keyHdr.quat[0] = quat.x;
   keyHdr.quat[1] = quat.y;
   keyHdr.quat[2] = quat.z;
   keyHdr.quat[3] = quat.w;
   BD[idx].keyVect.push_back(keyHdr);
   
  }
 }
 keycnt = BD[0].keyVect.size();
 return keycnt;
}

上一页  [1] [2] 


[MySql]mysql max 版本如何修改默认字符集。  
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · 办公软件  · 系统软件
    · 常用软件  · 聊天工具
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台