Exemple #1
0
int main(int argc, char **argv)
{
    ExportFromFbx fbx("test.FBX");
    fbx.saveData("test\\test");

    system("pause");
    return 0;
}
Exemple #2
0
		void run(void)
		{
			int i;  fbx_struct stressfb;
			memset(&stressfb, 0, sizeof(stressfb));

			try {

			int mywidth, myheight, myx=0, myy=0;
			if(myrank<2) {mywidth=width/2;  myx=0;}
			else {mywidth=width-width/2;  myx=width/2;}
			if(myrank%2==0) {myheight=height/2;  myy=0;}
			else {myheight=height-height/2;  myy=height/2;}
			fbx(fbx_init(&stressfb, wh, mywidth, myheight, useshm));
			if(useshm && !stressfb.shm) _throw("MIT-SHM not available");
			initbuf(myx, myy, mywidth, stressfb.pitch, myheight, stressfb.format, (unsigned char *)stressfb.bits);
			for (i=0; i<iter; i++)
				fbx(fbx_write(&stressfb, 0, 0, myx, myy, mywidth, myheight));

			} catch(...) {fbx_term(&stressfb);  throw;}
		}
Exemple #3
0
		void run(void)
		{
			fbx_struct stressfb;
			memset(&stressfb, 0, sizeof(stressfb));

			try {

			int i, mywidth, myheight, myx=0, myy=0;
			if(myrank<2) {mywidth=width/2;  myx=0;}
			else {mywidth=width-width/2;  myx=width/2;}
			if(myrank%2==0) {myheight=height/2;  myy=0;}
			else {myheight=height-height/2;  myy=height/2;}
			fbx(fbx_init(&stressfb, wh, mywidth, myheight, useshm));
			if(useshm && !stressfb.shm) _throw("MIT-SHM not available");
			int ps=fbx_ps[stressfb.format];
			memset(stressfb.bits, 0, mywidth*myheight*ps);
			for(i=0; i<iter; i++)
				fbx(fbx_read(&stressfb, myx, myy));
			if(!cmpbuf(myx, myy, mywidth, stressfb.pitch, myheight, stressfb.format, (unsigned char *)stressfb.bits))
				_throw("ERROR: Bogus data read back.");

			} catch(...) {fbx_term(&stressfb);  throw;}
		}
Exemple #4
0
// Platform-specific readback test
void nativeread(int useshm)
{
	fbx_struct s;  int n, i;  double rbtime;
	memset(&s, 0, sizeof(s));

	try {

	fbx(fbx_init(&s, wh, 0, 0, useshm));
	int ps=fbx_ps[s.format];
	if(useshm && !s.shm) _throw("MIT-SHM not available");
	if(s.width!=width || s.height!=height)
		_throw("The benchmark window lost input focus or was obscured.\nSkipping native read test\n");
	if(useshm)
		fprintf(stderr, "FBX read [SHM]:                   ");
	else
		fprintf(stderr, "FBX read:                         ");
	memset(s.bits, 0, width*height*ps);
	n=N;
	do
	{
		n+=n;
		timer.start();
		for(i=0; i<n; i++)
		{
			fbx(fbx_read(&s, 0, 0));
		}
		rbtime=timer.elapsed();
		if(!cmpbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits))
			_throw("ERROR: Bogus data read back.");
	} while (rbtime<1.);
	fprintf(stderr, "%f Mpixels/sec\n", (double)n*(double)(width*height)/((double)1000000.*rbtime));

	} catch(rrerror &e) {fprintf(stderr, "%s\n", e.getMessage());}

	fbx_term(&s);
}
Exemple #5
0
bool ModelPackager::loadModel() {
    // First we check the FST file (if any)
    if (_modelFile.completeSuffix().contains("fst")) {
        QFile fst(_modelFile.filePath());
        if (!fst.open(QFile::ReadOnly | QFile::Text)) {
            OffscreenUi::asyncWarning(NULL,
                                 QString("ModelPackager::loadModel()"),
                                 QString("Could not open FST file %1").arg(_modelFile.filePath()),
                                 QMessageBox::Ok);
            qWarning() << QString("ModelPackager::loadModel(): Could not open FST file %1").arg(_modelFile.filePath());
            return false;
        }
        qCDebug(interfaceapp) << "Reading FST file";
        _mapping = FSTReader::readMapping(fst.readAll());
        fst.close();
        
        _fbxInfo = QFileInfo(_modelFile.path() + "/" + _mapping.value(FILENAME_FIELD).toString());
    } else {
        _fbxInfo = QFileInfo(_modelFile.filePath());
    }
    
    // open the fbx file
    QFile fbx(_fbxInfo.filePath());
    if (!_fbxInfo.exists() || !_fbxInfo.isFile() || !fbx.open(QIODevice::ReadOnly)) {
        OffscreenUi::asyncWarning(NULL,
                             QString("ModelPackager::loadModel()"),
                             QString("Could not open FBX file %1").arg(_fbxInfo.filePath()),
                             QMessageBox::Ok);
        qWarning() << "ModelPackager::loadModel(): Could not open FBX file";
        return false;
    }
    try {
        qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath();
        QByteArray fbxContents = fbx.readAll();

        _hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath());

        // make sure we have some basic mappings
        populateBasicMapping(_mapping, _fbxInfo.filePath(), *_hfmModel);
    } catch (const QString& error) {
        qCDebug(interfaceapp) << "Error reading: " << error;
        return false;
    }
    return true;
}
Exemple #6
0
bool ModelPackager::zipModel() {
    QTemporaryDir dir;
    dir.setAutoRemove(true);
    QDir tempDir(dir.path());
    
    QByteArray nameField = _mapping.value(NAME_FIELD).toByteArray();
    tempDir.mkpath(nameField + "/textures");
    tempDir.mkpath(nameField + "/scripts");
    QDir fbxDir(tempDir.path() + "/" + nameField);
    QDir texDir(fbxDir.path() + "/textures");
    QDir scriptDir(fbxDir.path() + "/scripts");

    // Copy textures
    listTextures();
    if (!_textures.empty()) {
        QByteArray texdirField = _mapping.value(TEXDIR_FIELD).toByteArray();
        _texDir = _modelFile.path() + "/" + texdirField;
        copyTextures(_texDir, texDir);
    }

    // Copy scripts
    QByteArray scriptField = _mapping.value(SCRIPT_FIELD).toByteArray();
    _mapping.remove(SCRIPT_FIELD);
    if (scriptField.size() > 1) {
        tempDir.mkpath(nameField + "/scripts");
        _scriptDir = _modelFile.path() + "/" + scriptField;
        QDir wdir = QDir(_scriptDir);
        _mapping.remove(SCRIPT_FIELD);
        wdir.setSorting(QDir::Name | QDir::Reversed);
        auto list = wdir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries);
        for (auto script : list) {
            auto sc = tempDir.relativeFilePath(scriptDir.path()) + "/" + QUrl(script).fileName();
            _mapping.insertMulti(SCRIPT_FIELD, sc);
        }
        copyDirectoryContent(wdir, scriptDir);
    } 
    
    // Copy LODs
    QVariantHash lodField = _mapping.value(LOD_FIELD).toHash();
    if (!lodField.empty()) {
        for (auto it = lodField.constBegin(); it != lodField.constEnd(); ++it) {
            QString oldPath = _modelFile.path() + "/" + it.key();
            QFile lod(oldPath);
            QString newPath = fbxDir.path() + "/" + QFileInfo(lod).fileName();
            if (lod.exists()) {
                lod.copy(newPath);
            }
        }
    }
    
    // Copy FBX
    QFile fbx(_fbxInfo.filePath());
    QByteArray filenameField = _mapping.value(FILENAME_FIELD).toByteArray();
    QString newPath = fbxDir.path() + "/" + QFileInfo(filenameField).fileName();
    fbx.copy(newPath);
    
    // Correct FST
    _mapping[FILENAME_FIELD] = tempDir.relativeFilePath(newPath);
    _mapping[TEXDIR_FIELD] = tempDir.relativeFilePath(texDir.path());

    for (auto multi : _mapping.values(SCRIPT_FIELD)) {
        multi.fromValue(tempDir.relativeFilePath(scriptDir.path()) + multi.toString());
    }
    // Copy FST
    QFile fst(tempDir.path() + "/" + nameField + ".fst");
    if (fst.open(QIODevice::WriteOnly)) {
        fst.write(FSTReader::writeMapping(_mapping));
        fst.close();
    } else {
        qCDebug(interfaceapp) << "Couldn't write FST file" << fst.fileName();
        return false;
    }
    
    
    QString saveDirPath = QFileDialog::getExistingDirectory(nullptr, "Save Model",
                                                        "", QFileDialog::ShowDirsOnly);
    if (saveDirPath.isEmpty()) {
        qCDebug(interfaceapp) << "Invalid directory" << saveDirPath;
        return false;
    }
    
    QDir saveDir(saveDirPath);
    copyDirectoryContent(tempDir, saveDir);
    return true;
}
Exemple #7
0
bool FstReader::zip() {
    // File Dialog
    QString filename = QFileDialog::getOpenFileName(NULL,
                                                    "Select your .fst file ...",
                                                    QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
                                                    "*.fst");
    
    // First we check the FST file
    QFile fst(filename);
    if (!fst.open(QFile::ReadOnly | QFile::Text)) {
        qDebug() << "[ERROR] Could not open FST file : " << fst.fileName();
        return false;
    }
    
    // Compress and copy the fst
    if (!compressFile(QFileInfo(fst).filePath(), _zipDir.path() + "/" + QFileInfo(fst).fileName())) {
        return false;
    }
    _totalSize += QFileInfo(fst).size();
    if (!addPart(_zipDir.path() + "/" + QFileInfo(fst).fileName(),
                 QString("fst"))) {
        return false;
    }
    qDebug() << "Reading FST file : " << QFileInfo(fst).filePath();
    
    // Let's read through the FST file
    QTextStream stream(&fst);
    QList<QString> line;
    while (!stream.atEnd()) {
        line = stream.readLine().split(QRegExp("[ =]"), QString::SkipEmptyParts);
        if (line.isEmpty()) {
            continue;
        }
        
        if (_totalSize > MAX_SIZE) {
            qDebug() << "[ERROR] Model too big, over " << MAX_SIZE << " Bytes.";
            return false;
        }
        
        // according to what is read, we modify the command
        if (line.first() == NAME_FIELD) {
            QHttpPart textPart;
            textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
                               " name=\"model_name\"");
            textPart.setBody(line[1].toUtf8());
            _dataMultiPart->append(textPart);
        } else if (line.first() == FILENAME_FIELD) {
            QFileInfo fbx(QFileInfo(fst).path() + "/" + line[1]);
            if (!fbx.exists() || !fbx.isFile()) { // Check existence
                qDebug() << "[ERROR] FBX file " << fbx.absoluteFilePath() << " doesn't exist.";
                return false;
            }
            // Compress and copy
            if (!compressFile(fbx.filePath(), _zipDir.path() + "/" + line[1])) {
                return false;
            }
            _totalSize += fbx.size();
            if (!addPart(_zipDir.path() + "/" + line[1], "fbx")) {
                return false;
            }
        } else if (line.first() == TEXDIR_FIELD) { // Check existence
            QFileInfo texdir(QFileInfo(fst).path() + "/" + line[1]);
            if (!texdir.exists() || !texdir.isDir()) {
                qDebug() << "[ERROR] Texture directory " << texdir.absolutePath() << " doesn't exist.";
                return false;
            }
            if (!addTextures(texdir)) { // Recursive compress and copy
                return false;
            }
        } else if (line.first() == LOD_FIELD) {
            QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]);
            if (!lod.exists() || !lod.isFile()) { // Check existence
                qDebug() << "[ERROR] FBX file " << lod.absoluteFilePath() << " doesn't exist.";
                return false;
            }
            // Compress and copy
            if (!compressFile(lod.filePath(), _zipDir.path() + "/" + line[1])) {
                return false;
            }
            _totalSize += lod.size();
            if (!addPart(_zipDir.path() + "/" + line[1], QString("lod%1").arg(++_lodCount))) {
                return false;
            }
        }
    }
    
    _readyToSend = true;
    return true;
}
Exemple #8
0
// Platform-specific write test
void nativewrite(int useshm)
{
	fbx_struct s;  int n, i;  double rbtime;
	memset(&s, 0, sizeof(s));

	try {

	fbx(fbx_init(&s, wh, 0, 0, useshm));
	if(useshm && !s.shm) _throw("MIT-SHM not available");
	fprintf(stderr, "Native Pixel Format:  %s", fbx_formatname(s.format));
	fprintf(stderr, "\n");
	if(s.width!=width || s.height!=height)
		_throw("The benchmark window lost input focus or was obscured.\nSkipping native write test\n");

	clearfb();
	initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits);
	if(useshm)
		fprintf(stderr, "FBX bottom-up write [SHM]:        ");
	else
		fprintf(stderr, "FBX bottom-up write:              ");
	n=N;
	do
	{
		n+=n;
		timer.start();
		for (i=0; i<n; i++)
		{
			if(checkdb)
			{
				memset(s.bits, 255, s.pitch*s.height);
				fbx(fbx_awrite(&s, 0, 0, 0, 0, 0, 0));
				initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits);
			}
			fbx(fbx_flip(&s, 0, 0, 0, 0));
			fbx(fbx_write(&s, 0, 0, 0, 0, 0, 0));
		}
		rbtime=timer.elapsed();
	} while(rbtime<1.);
	fprintf(stderr, "%f Mpixels/sec\n", (double)n*(double)(width*height)/((double)1000000.*rbtime));

	clearfb();
	if(useshm)
		fprintf(stderr, "FBX top-down write [SHM]:         ");
	else
		fprintf(stderr, "FBX top-down write:               ");
	n=N;
	do
	{
		n+=n;
		timer.start();
		for (i=0; i<n; i++)
		{
			if(checkdb)
			{
				memset(s.bits, 255, s.pitch*s.height);
				fbx(fbx_awrite(&s, 0, 0, 0, 0, 0, 0));
				initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits);
			}
			fbx(fbx_write(&s, 0, 0, 0, 0, 0, 0));
		}
		rbtime=timer.elapsed();
	} while(rbtime<1.);
	fprintf(stderr, "%f Mpixels/sec\n", (double)n*(double)(width*height)/((double)1000000.*rbtime));

	} catch(rrerror &e) {fprintf(stderr, "%s\n", e.getMessage());}

	fbx_term(&s);
}
Exemple #9
0
bool ModelPackager::zipModel() {
    QTemporaryDir dir;
    dir.setAutoRemove(true);
    QDir tempDir(dir.path());
    
    QByteArray nameField = _mapping.value(NAME_FIELD).toByteArray();
    tempDir.mkpath(nameField + "/textures");
    QDir fbxDir(tempDir.path() + "/" + nameField);
    QDir texDir(fbxDir.path() + "/textures");
    
    // Copy textures
    listTextures();
    if (!_textures.empty()) {
        QByteArray texdirField = _mapping.value(TEXDIR_FIELD).toByteArray();
        _texDir = _modelFile.path() + "/" + texdirField;
        copyTextures(_texDir, texDir);
    }
    
    // Copy LODs
    QVariantHash lodField = _mapping.value(LOD_FIELD).toHash();
    if (!lodField.empty()) {
        for (auto it = lodField.constBegin(); it != lodField.constEnd(); ++it) {
            QString oldPath = _modelFile.path() + "/" + it.key();
            QFile lod(oldPath);
            QString newPath = fbxDir.path() + "/" + QFileInfo(lod).fileName();
            if (lod.exists()) {
                lod.copy(newPath);
            }
        }
    }
    
    // Copy FBX
    QFile fbx(_fbxInfo.filePath());
    QByteArray filenameField = _mapping.value(FILENAME_FIELD).toByteArray();
    QString newPath = fbxDir.path() + "/" + QFileInfo(filenameField).fileName();
    fbx.copy(newPath);
    
    // Correct FST
    _mapping[FILENAME_FIELD] = tempDir.relativeFilePath(newPath);
    _mapping[TEXDIR_FIELD] = tempDir.relativeFilePath(texDir.path());
    
    // Copy FST
    QFile fst(tempDir.path() + "/" + nameField + ".fst");
    if (fst.open(QIODevice::WriteOnly)) {
        fst.write(FSTReader::writeMapping(_mapping));
        fst.close();
    } else {
        qCDebug(interfaceapp) << "Couldn't write FST file" << fst.fileName();
        return false;
    }
    
    
    QString saveDirPath = QFileDialog::getExistingDirectory(nullptr, "Save Model",
                                                        "", QFileDialog::ShowDirsOnly);
    if (saveDirPath.isEmpty()) {
        qCDebug(interfaceapp) << "Invalid directory" << saveDirPath;
        return false;
    }
    
    QDir saveDir(saveDirPath);
    copyDirectoryContent(tempDir, saveDir);
    return true;
}