Esempio n. 1
0
void BlenderSceneExporter::initialize( const char* filesystemRoot, const char* exportDir, int entitiesCount, const TamyExportSettings& exportSettings )
{ 
   // store the export settings
   m_exportSettings = exportSettings;

   // set the filesystem path
   std::string normalizedFilesystemRoot;
   FilesystemUtils::normalize( filesystemRoot, normalizedFilesystemRoot );
   TSingleton< Filesystem >::initialize().changeRootDir( normalizedFilesystemRoot );
   TSingleton< ResourcesManager>::initialize();

   Filesystem& fs = TSingleton< Filesystem >::getInstance();

   // build the types registry 
   {
      // load patching definitions
      FilePath patchesDBDefPath( "/Renderer/patchesDB.xml" );
      File* patchesDBFile = fs.open( patchesDBDefPath, std::ios_base::in );
      StreamBuffer< char > fileBuf( *patchesDBFile );
      std::string patchesDBContents = fileBuf.getBuffer();
      delete patchesDBFile;

      PatchesDB& patchesDB = TSingleton< PatchesDB >::getInstance();
      PatchesDBSerializer::load( patchesDB, patchesDBContents );

      TSingleton< ReflectionTypesRegistry >::getInstance().build( patchesDB );
   }

   // setup the export directories
   std::string normalizedExportDir;
   FilesystemUtils::normalize( exportDir, normalizedExportDir );
   std::string relativeExportDir = fs.toRelativePath( normalizedExportDir );

   m_texturesExportDir = relativeExportDir + TEXTURES_EXPORT_DIR;
   m_meshesExportDir = relativeExportDir + MESHES_EXPORT_DIR;
   m_scenesExportDir = relativeExportDir + SCENES_EXPORT_DIR;
   m_materialsExportDir = relativeExportDir + MATERIALS_EXPORT_DIR;
   m_animationsExportDir = relativeExportDir + ANIMATIONS_EXPORT_DIR;
   m_prefabsExportDir = relativeExportDir + PREFABS_EXPORT_DIR;

   // physically create the directories
   FilesystemUtils::mkdir( fs.toAbsolutePath( m_texturesExportDir ).c_str() ); 
   FilesystemUtils::mkdir( fs.toAbsolutePath( m_meshesExportDir ).c_str() );
   FilesystemUtils::mkdir( fs.toAbsolutePath( m_scenesExportDir ).c_str() );
   FilesystemUtils::mkdir( fs.toAbsolutePath( m_materialsExportDir ).c_str() );
   FilesystemUtils::mkdir( fs.toAbsolutePath( m_animationsExportDir ).c_str() );
   FilesystemUtils::mkdir( fs.toAbsolutePath( m_prefabsExportDir ).c_str() );


   // clear the storages
   m_textures.clear();
   m_materialDefinitions.clear();

   m_exportedSkeletons.clear();

   m_exportedNodes.clear();
   m_exportedNodes.resizeWithoutInitializing( entitiesCount );
   m_nextNodeIdx = 0;

   m_worldEntity = NULL;
}
Esempio n. 2
0
void newBufTest()
{
    std::cout << "*** Testing AsnBuf ****\n";
    try {
        SNACC::AsnBuf testBufExcept;
        testBufExcept.GetByte();
    } catch (SNACC::SnaccException &e) {
        std::cout << "Caught buffer exception as expected: " << e.what()
                  << "\n";
    }

    std::fstream fs("test.txt");

    unsigned char test[10000];
    int j;
    try {
        fillTestBuffer(&test[0], 10000);

        // file test
        std::filebuf fb;
        fb.open("test.txt", std::ios_base::out | std::ios_base::binary);
        fb.sputn((char *)&test[0], 10000);
        fb.close();

        SNACC::AsnBuf fileBuf("test.txt");
        if (fileBuf.length() != 10000) {
            std::cout << "ERROR: AsnBuf() file length check failed!\n";
        } else {
            char fileData[10000];
            try {
                fileBuf.GetSeg(&fileData[0], 10000);
                if (memcmp(fileData, test, 10000) != 0) {
                    std::cout << "ERROR: AsnBuf() file data check failed!\n";
                }
            } catch(...) {
                std::cout << "ERROR: AsnBuf() file GetSeg() failed!\n";
            }
        }

        SNACC::AsnBuf buf2[1000];

        for (j = 0; j < 1; j++) {

            SNACC::AsnBuf tmpBuf((char *)test,4200);
#ifdef _DEBUG
            tmpBuf.status(std::cout);
#endif
            tmpBuf.ResetMode();
            char ch = tmpBuf.GetByte();
            char ch2 = tmpBuf.GetByte();
            std::cout << "ch == " << (int)ch
                      << " ch2 == " << (int)ch2 << "\n";

            buf2[j].PutSegRvs((char *)test, 10000);

#ifdef _DEBUG
            buf2[j].status(std::cout);
#endif
            SNACC::AsnBuf buf;
            buf = buf2[j];
            buf.ResetMode();
            if (buf.length() != 10000) {
                std::cout << "length() after PutSegRvs() test FAILED!\n";
            }

            std::stringstream ss, ss2;

            ss << buf;
            buf.ResetMode();
            ss2 << buf;

#ifdef _DEBUG
            buf.status(std::cout);
#endif
            buf.ResetMode();
            const char *ps = ss.str().data(); // buf.GetSeg(10000)

            checkTestBuffer((unsigned char *) ps, 10000);

            if ((ss.str().length() == 10000) &&
                (memcmp(test, ps, 10000) == 0)) {
                std::cout << "ss is good!" << std::endl;
            } else {
                std::cout << "[" << j << "] ss is not good!" << std::endl;
            }

            const char *ps2 = ss2.str().data();
            if (ss2.str().length() == 10000 &&
                memcmp(test, ps2, 10000) == 0){
                std::cout << "ss2 is good!" << std::endl;
            } else{
                std::cout << "[" << j << "] ss2 is not good" << std::endl;
            }
        }
    } catch (std::exception &e) {
        std::cout << "Caught Standard Exception: " << e.what() << std::endl;
    } catch (...) {
        std::cout << "Caught un-handled exception!" << std::endl;
    }

    std::cout << "*** end of AsnBuf test ***\n";
}