Пример #1
0
	// Write material data to an Ogre material script file
	MStatus Material::writeOgreScript(ParamList &params)
	{
		//Start material description
		params.outMaterial << "material " << m_name.asChar() << "\n";
		params.outMaterial << "{\n";

		//Start technique description
		params.outMaterial << "\ttechnique\n";
		params.outMaterial << "\t{\n";

		//Start render pass description
		params.outMaterial << "\t\tpass\n";
		params.outMaterial << "\t\t{\n";
		//set lighting off option if requested
		if (m_lightingOff)
			params.outMaterial << "\t\t\tlighting off\n\n";
		//set phong shading if requested (default is gouraud)
		if (m_type == MT_PHONG)
			params.outMaterial << "\t\t\tshading phong\n";
		//ambient colour
		params.outMaterial << "\t\t\tambient " << m_ambient.r << " " << m_ambient.g << " " << m_ambient.b
			<< " " << m_ambient.a << "\n";
		//diffuse colour
		params.outMaterial << "\t\t\tdiffuse " << m_diffuse.r << " " << m_diffuse.g << " " << m_diffuse.b
			<< " " << m_diffuse.a << "\n";
		//specular colour
		params.outMaterial << "\t\t\tspecular " << m_specular.r << " " << m_specular.g << " " << m_specular.b
			<< " " << m_specular.a << "\n";
		//emissive colour
		params.outMaterial << "\t\t\temissive " << m_emissive.r << " " << m_emissive.g << " " 
			<< m_emissive.b << "\n";
		//if material is transparent set blend mode and turn off depth_writing
		if (m_isTransparent)
		{
			params.outMaterial << "\n\t\t\tscene_blend alpha_blend\n";
			params.outMaterial << "\t\t\tdepth_write off\n";
		}
		//write texture units
		for (int i=0; i<m_textures.size(); i++)
		{
			//start texture unit description
			params.outMaterial << "\n\t\t\ttexture_unit\n";
			params.outMaterial << "\t\t\t{\n";
			//write texture name
			params.outMaterial << "\t\t\t\ttexture " << m_textures[i].filename.asChar() << "\n";
			//write texture coordinate index
			params.outMaterial << "\t\t\t\ttex_coord_set " << m_textures[i].uvsetIndex << "\n";
			//write colour operation
			switch (m_textures[i].opType)
			{
			case TOT_REPLACE:
				params.outMaterial << "\t\t\t\tcolour_op replace\n";
				break;
			case TOT_ADD:
				params.outMaterial << "\t\t\t\tcolour_op add\n";
				break;
			case TOT_MODULATE:
				params.outMaterial << "\t\t\t\tcolour_op modulate\n";
				break;
			case TOT_ALPHABLEND:
				params.outMaterial << "\t\t\t\tcolour_op alpha_blend\n";
				break;
			}
			//write texture transforms
			params.outMaterial << "\t\t\t\tscale " << m_textures[i].scale_u << " " << m_textures[i].scale_v << "\n";
			params.outMaterial << "\t\t\t\tscroll " << m_textures[i].scroll_u << " " << m_textures[i].scroll_v << "\n";
			params.outMaterial << "\t\t\t\trotate " << m_textures[i].rot << "\n";
			//end texture unit desription
			params.outMaterial << "\t\t\t}\n";
		}

		//End render pass description
		params.outMaterial << "\t\t}\n";

		//End technique description
		params.outMaterial << "\t}\n";

		//End material description
		params.outMaterial << "}\n";

		//Copy textures to output dir if required
		if (params.copyTextures)
			copyTextures(params);

		return MS::kSuccess;
	}
Пример #2
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;
}
Пример #3
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;
}