Ejemplo n.º 1
0
static void ioMB_exportSkeleton(const BrfSkeleton &s){
  for (int i=0; i<(int)s.bone.size(); i++) {
    const BrfBone &bone(s.bone[i]);

    fprintf(f,"createNode joint -n \"%s\" ",substitute(bone.name,'.','_'));
    if (bone.attach!=-1)
    fprintf(f,"-p \"%s\" ",substitute(s.bone[bone.attach].name,'.','_'));
    fprintf(f,";\n");

    float *abc;
    abc = matrix2euler(s.getRotationMatrix( i ).transpose() );
    Point3f t = bone.t;
    if (bone.attach==-1) { float tmp=t[1]; t[1]=t[2]; t[2]=tmp;}
    t.X()*=-1;
    t.Y()*=-1;
    t*=SCALE;

    fprintf(f,
      "\taddAttr -ci true -sn \"liw\" -ln \"lockInfluenceWeights\" -bt \"lock\" -min 0 -max 1 -at \"bool\";\n"
      "\tsetAttr \".uoc\" yes;\n"
      "\tsetAttr \".t\" -type \"double3\" %f %f %f ;\n"
      "\tsetAttr \".r\" -type \"double3\" %f %f %f ;\n"
      "\tsetAttr \".mnrl\" -type \"double3\" -360 -360 -360 ;\n"
      "\tsetAttr \".mxrl\" -type \"double3\" 360 360 360 ;\n",
      -t[0],t[2],-t[1],
      abc[0]*180/M_PI,abc[1]*180/M_PI,abc[2]*180/M_PI
    );

    //qDebug()<< "[" << i << "]: abc" << abc[0]*180/M_PI << abc[1]*180/M_PI <<abc[2]*180/M_PI <<"\n";
  }
}
Ejemplo n.º 2
0
bool IoMB::Import(const wchar_t*filename, std::vector<BrfMesh> &m , BrfSkeleton &s, int want){
  debug=wfopen(L"debug.txt","w");

  lastErr = QString("Unkonwn error??");
  f = wfopen(filename,"rb"); lineN=0;
  if (!f) {
    lastErr =QString("cannot open file '%1' for reading").arg(QString::fromStdWString(filename));
    return false;
  }
  s.root= -1;
  s.bone.clear();

  while (nextCreateNode()) {
    QString t =  token();
    fprintf(debug,"[%s]\n",t.toAscii().data()); fflush(debug);
    if (t=="joint") {
      if (want ==1) if (!ioMB_importBone(s)) return false;
    }
    if (t=="mesh") {
      if (want ==0)  {
        BrfMesh m0;
        if (!ioMB_importMesh(m0)) return false;
        if (m0.face.size()>0) m.push_back(m0);
      }
    }
    if (t=="skinCluster"){
      //qDebug("rigging");

      if (want==0) {
        int n = ioMB_importRiggingSize();
        // find a mesh
        int found=-1;
        for (int i=0;i<(int)m.size();i++) if ((int)m[i].frame[0].pos.size()==n) found=i;

        if (found>=0) ioMB_importRigging(m[found]);
        else qDebug("cannot find any mesh with %d vert",n);
      }
    }
    skipCreate();
  }
  if (want==1) {
    if (!s.bone.size()) {
      lastErr = QString("No skeleton found (not a single bone).");
      return false;
    }
    s.BuildTree();
  }
  if (want==0) {
    if (m.size()==0) {
      lastErr = QString("No mesh found.");
      return false;
    }
  }
  //qDebug("Done");
  return true;
}
Ejemplo n.º 3
0
static bool ioMB_importBone(BrfSkeleton &s ){
  if (!expect( "-n" )) return false;
  BrfBone b;
  b.attach = -1;

  readStrQuotesChar( b.name );

  if (!lineEnd) {
    int tmp = oneOf("-p",";");
    if (!tmp) return false;
    if (tmp==1) {
      QString parentName = readStrQuotes(  );
      b.attach = s.FindBoneByName(parentName.toAscii().data());
      if (b.attach==-1) {
        lastErr = QString("Can't find bone \"%1\"").arg(parentName);
        return false;
      }
    }
  } else {
    if (s.root != -1) {
      lastErr = QString("Found multiple skeleton's roots (bone \"%1\"").arg(b.name);
      return false;
    }
    s.root = s.bone.size();
  }
  skipLine();
  bool hasT=false;
  bool hasR=false;
  vcg::Point3f rot;
  while (nextSetAttr()) {
    QString t =  token();
    if (t=="\".t\"") {
      if (!expectType("double3")) return false;
      b.t = readPoint()/SCALE;
      b.t.X()*=-1;
      b.t.Y()*=-1;
      if (b.attach==-1) { float tmp=b.t[1]; b.t[1]=b.t[2]; b.t[2]=tmp;}
      hasT=true;
      //b.t*=3.0;
    }
    if (t=="\".r\"") {
      if (!expectType("double3")) return false;
      rot = readPointRot();
      //rot[2]*=-1;
      hasR=true;
    }
    if (t=="\".bps\"") {
      qDebug("bps");
      if (!expectType("matrix")) return false;


      for (int i=0; i<4; i++) {
        float a,b,c,d;
        a = readFloat();b = readFloat();c = readFloat();d = readFloat();
        qDebug("%7.2f %7.2f %7.2f %7.2f",a,b,c,d);
      }
    }
    if (t=="\".s\"") {
      if (!expectType("double3")) return false;
      if (b.attach==-1) globalScale = readPointRot();
    }
    skipLine();
  }
  if (!hasT) {lastErr=QString("No translation found for bone '%1'").arg(b.name); return false; };
  if (!hasR) {lastErr=QString("No rotation found for bone '%1'").arg(b.name); return false; };
  s.bone.push_back(b);
  int i = s.bone.size()-1;
  s.setRotationMatrix( euler2matrix(&(rot[0])) , i );
  s.BuildTree();
  vector<Matrix44f> v = s.GetBoneMatrices();
      qDebug("Versus:");
      Matrix44f m = v[i]; //s.getRotationMatrix(i);
      for (int i=0; i<4; i++) {
        qDebug("%7.2f %7.2f %7.2f %7.2f",m[0][i],m[1][i],m[2][i],m[3][i]);
      }
      //qDebug("T: %7.2f %7.2f  %7.2f ",b.t[0],b.t[1],b.t[2]);
      qDebug("-----------");
  qDebug()<< "[" << i << "]: abc" << rot[0]*180/M_PI << rot[1]*180/M_PI <<rot[2]*180/M_PI <<"\n";
  return true;
}
Ejemplo n.º 4
0
void IoOBJ::writeHitbox(QFile &/*f*/, const BrfBody& b, const BrfSkeleton& s){
  assert(b.part.size()==s.bone.size());
  std::vector<vcg::Matrix44f> v = s.GetBoneMatrices();
  //s.getRotationMatrix(0)
}