示例#1
0
文件: main.cpp 项目: huanjet/glTF
int main (int argc, char * const argv[]) {
    shared_ptr <GLTF::GLTFAsset> asset(new GLTF::GLTFAsset());
    
    if (processArgs(argc, argv, asset.get())) {
        if (asset->getInputFilePath().length() == 0) {
            return -1;
        }
        char* inputFilePathCStr = strdup(asset->getInputFilePath().c_str());

        if (!fileExists(inputFilePathCStr)) {
            free(inputFilePathCStr);
            printf("path:%s does not exists or is not accessible, please check file path and permissions\n",inputFilePathCStr);
            return -1;
        }
#ifndef WIN32 || WIN64
        struct stat attr;
        if (stat(inputFilePathCStr, &attr) != -1) {
            asset->convertionMetaData()->setString("date", ctime(&attr.st_ctime));
        }
#endif
        clock_t start = clock();
        if (asset->converterConfig()->config()->getBool("outputProgress")) {
            asset->log("convertion 0%%");
            asset->log("\n\033[F\033[J");
        } else {
            asset->log("converting:%s ... as %s \n",asset->getInputFilePath().c_str(), asset->getOutputFilePath().c_str());
        }
        if (asset->converterConfig()->config()->getBool("isKmz")) {
            std::string strJsonFilePath = asset->getInputFilePath();
            strJsonFilePath = GLTF::Kmz2Collada(strJsonFilePath);
            if (strJsonFilePath == "")
                return -1;
            asset->setInputFilePath(strJsonFilePath);
            asset->setOutputFilePath(
                replacePathExtensionWith(strJsonFilePath, "json"));
        }
        GLTF::COLLADA2GLTFWriter* writer = new GLTF::COLLADA2GLTFWriter(asset);
        writer->write();
        if (asset->converterConfig()->config()->getBool("outputProgress")) {
            asset->log("convertion 100%%");
            asset->log("\n");
        } else {
            asset->log("[completed conversion]\n");
        }
#if WIN32
        double clocks = CLK_TCK;
#else
        double clocks = CLOCKS_PER_SEC;
#endif
        std::stringstream s;
        double elapsedTime = clock() - start;
        s << std::setiosflags(std::ios::fixed) << std::setprecision(2) << elapsedTime / clocks ;
        asset->log("Runtime: %s seconds\n", s.str().c_str());
        
        free(inputFilePathCStr);
    }
    return 0;
}
示例#2
0
int main (int argc, char * const argv[]) {
    GLTF::GLTFConverterContext converterContext;
    
    if (processArgs(argc, argv, &converterContext)) {
        if (converterContext.inputFilePath.length() == 0) {
            return -1;
        }
        const char* inputFilePathCStr = converterContext.inputFilePath.c_str();
        
        if (!fileExists(converterContext.inputFilePath.c_str())) {
            printf("path:%s does not exists or is not accessible, please check file path and permissions\n",inputFilePathCStr);
            return -1;
        }
        
        clock_t start = clock();

#if !STDOUT_OUTPUT
        FILE* fd = fopen(converterContext.outputFilePath.c_str(), "w");
        if (fd) {
            rapidjson::FileStream s(fd);
#else
            rapidjson::FileStream s(stdout);
#endif
            rapidjson::PrettyWriter <rapidjson::FileStream> jsonWriter(s);
            if (converterContext.outputProgress) {
                printf("convertion 0%%");
                printf("\n\033[F\033[J");
            } else {
                printf("converting:%s ... as %s \n",converterContext.inputFilePath.c_str(), converterContext.outputFilePath.c_str());
            }
            GLTF::COLLADA2GLTFWriter* writer = new GLTF::COLLADA2GLTFWriter(converterContext, &jsonWriter);
            writer->write();
            if (converterContext.outputProgress) {
                printf("convertion 100%%");
                printf("\n");
            } else {
                printf("[completed conversion]\n");
            }
#if !STDOUT_OUTPUT
            fclose(fd);
            delete writer;
        }
#endif

        std::stringstream s;
        s << std::setiosflags(std::ios::fixed) << std::setprecision(2) << float(clock() - start) / CLK_TCK;
        std::cout << "Runtime: " << s.str() << " seconds" << std::endl;
    }
    return 0;
}