Example #1
0
  void loadHair(const FileName& fileName, OBJScene& scene, Vec3fa& offset)
  {
    /* add new hair set to scene */
    OBJScene::HairSet* hairset = new OBJScene::HairSet; 
#if CONVERT_TO_BINARY   
    offset = Vec3fa(zero);
#endif

    int numHairs = 0;
    if (fileName.ext() == "txt")
      numHairs = loadHairASCII(fileName,hairset,offset);
    else
      numHairs = loadHairBin(fileName,hairset,offset);
    
    /* reduce number of hairs */
#if 0
    PRINT(hairset->hairs.size());
    hairset = reduce_hairs(hairset);
    PRINT(hairset->hairs.size());
    hairset = reduce_hairs(hairset);
    PRINT(hairset->hairs.size());
    hairset = reduce_hairs(hairset);
    PRINT(hairset->hairs.size());
    hairset = reduce_hairs(hairset);
    PRINT(hairset->hairs.size());
#endif

    /* add hairset to scene */
    scene.hairsets.push_back(hairset);

    int numPoints = hairset->v.size();
    int numSegments = hairset->hairs.size();
    PRINT(numHairs);
    PRINT(numSegments);
    PRINT(numPoints);

#if CONVERT_TO_BINARY
    FILE* fout = fopen(fileName.setExt(".bin").c_str(),"wb");
    if (!fout) throw std::runtime_error("could not open " + fileName.str());
    fwrite(&hair_bin_magick,sizeof(int),1,fout);
    fwrite(&numHairs,sizeof(int),1,fout);
    fwrite(&numPoints,sizeof(int),1,fout);
    fwrite(&numSegments,sizeof(int),1,fout);
    if (numPoints) fwrite(&hairset->v[0],sizeof(Vec3fa),numPoints,fout);
    if (numSegments) fwrite(&hairset->hairs[0],sizeof(OBJScene::Hair),numSegments,fout);
    fclose(fout);
#endif
  }
Example #2
0
  void loadHair(const FileName& fileName, OBJScene& scene, Vec3fa& offset)
  {
    /* add new hair set to scene */
    OBJScene::HairSet* hairset = new OBJScene::HairSet; 
#if CONVERT_TO_BINARY   
    offset = Vec3fa(zero);
#endif

    int numHairs = 0;
    if (fileName.ext() == "txt")
      numHairs = loadHairASCII(fileName,hairset,offset);
    else
      numHairs = loadHairBin(fileName,hairset,offset);
    
    /* reduce number of hairs */
    if (g_reduce_hair_segment_error != 0.0f)
    {
      std::ios_base :: fmtflags   flag = std::cout.flags();
      std           :: streamsize prec = std::cout.precision();
      std::cout << "reducing number of hair segments ... " << std::flush;
      std::cout.precision(3);
      std::cout << 1E-6*float(hairset->hairs.size()) << "M" << std::flush;
      for (size_t i=0; i<10; i++) {
        hairset = reduce_hairs(hairset,g_reduce_hair_segment_error);
        std::cout << " " << 1E-6*float(hairset->hairs.size()) << "M" << std::flush;
      }
      std::cout << " [DONE]" << std::endl;
      std::cout.flags    (flag);
      std::cout.precision(prec);
    }

    /* add hairset to scene */
    scene.hairsets.push_back(hairset);

    int numPoints = hairset->v.size();
    int numSegments = hairset->hairs.size();

#if CONVERT_TO_BINARY
    FILE* fout = fopen(fileName.setExt(".bin").c_str(),"wb");
    if (!fout) THROW_RUNTIME_ERROR("could not open " + fileName.str());
    fwrite(&hair_bin_magick,sizeof(int),1,fout);
    fwrite(&numHairs,sizeof(int),1,fout);
    fwrite(&numPoints,sizeof(int),1,fout);
    fwrite(&numSegments,sizeof(int),1,fout);
    if (numPoints) fwrite(&hairset->v[0],sizeof(Vec3fa),numPoints,fout);
    if (numSegments) fwrite(&hairset->hairs[0],sizeof(OBJScene::Hair),numSegments,fout);
    fclose(fout);
#endif
  }