示例#1
0
irr::s32 effectHandler::obtainScreenQuadMaterialFromFile(const irr::core::stringc& filename, 
	irr::video::E_MATERIAL_TYPE baseMaterial)
{
	CShaderPreprocessor sPP(driver);

	sPP.addShaderDefine("SCREENX", core::stringc(ScreenRTTSize.Width));
	sPP.addShaderDefine("SCREENY", core::stringc(ScreenRTTSize.Height));

	ScreenQuadCB* SQCB = new ScreenQuadCB();
	
	video::E_VERTEX_SHADER_TYPE VertexLevel = driver->queryFeature(video::EVDF_VERTEX_SHADER_3_0) ? EVST_VS_3_0 : EVST_VS_2_0;
	video::E_PIXEL_SHADER_TYPE PixelLevel = driver->queryFeature(video::EVDF_PIXEL_SHADER_3_0) ? EPST_PS_3_0 : EPST_PS_2_0;

	const c8* VShad = (driver->getDriverType() == EDT_DIRECT3D9) ? ScreenQuadVHLSL : ScreenQuadVGLSL;

	video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();

	s32 PostMat = gpu->addHighLevelShaderMaterial(
	sPP.ppShader(VShad).c_str(), "vertexMain", VertexLevel,
	sPP.ppShaderFF(filename.c_str()).c_str(), "pixelMain", PixelLevel,
	SQCB, baseMaterial);
	
	SQCB->drop();

	return PostMat;
}
void FTEnvironment::checkError(FT_Error err, const irr::core::stringc desc)
{
    if (err)
    {
        Log::error("Freetype Environment", "Something wrong when %s!", desc.c_str());
    }
}
EffectHandler::SPostProcessingPair EffectHandler::obtainScreenQuadMaterialFromFile(const irr::core::stringc& filename,
        irr::video::E_MATERIAL_TYPE baseMaterial)
{
    CShaderPreprocessor sPP(driver);

    sPP.addShaderDefine("SCREENX", core::stringc(ScreenRTTSize.Width));
    sPP.addShaderDefine("SCREENY", core::stringc(ScreenRTTSize.Height));

    video::E_VERTEX_SHADER_TYPE VertexLevel = driver->queryFeature(video::EVDF_VERTEX_SHADER_3_0) ? EVST_VS_3_0 : EVST_VS_2_0;
    video::E_PIXEL_SHADER_TYPE PixelLevel = driver->queryFeature(video::EVDF_PIXEL_SHADER_3_0) ? EPST_PS_3_0 : EPST_PS_2_0;

    E_SHADER_EXTENSION shaderExt = (driver->getDriverType() == EDT_DIRECT3D9) ? ESE_HLSL : ESE_GLSL;

    video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();

    const stringc shaderString = sPP.ppShaderFF(filename.c_str());

    ScreenQuadCB* SQCB = new ScreenQuadCB(this, true);

    s32 PostMat = gpu->addHighLevelShaderMaterial(
                      sPP.ppShader(SCREEN_QUAD_V[shaderExt]).c_str(), "vertexMain", VertexLevel,
                      shaderString.c_str(), "pixelMain", PixelLevel,
                      SQCB, baseMaterial);

    SPostProcessingPair pPair(PostMat, SQCB);

    SQCB->drop();

    return pPair;
}
示例#4
0
irr::core::stringc CFileSystem::getAbsolutePath(irr::core::stringc &filename)
{
	c8 *p=0;
	irr::core::stringc ret;

#ifdef _IRR_WINDOWS_

	c8 fpath[_MAX_PATH];
	p = _fullpath( fpath, filename.c_str(), _MAX_PATH);
	ret = p;

#elif (defined(LINUX) || defined(MACOSX))

	c8 fpath[4096];
	p = realpath(filename.c_str(), fpath);
	ret = p;

#endif

	return ret;
}
void Configuration::load(irr::core::stringc file){
	std::string line;
	std::ifstream myfile(file.c_str());
	if (myfile.is_open()){
		while (std::getline (myfile,line) )
		{
			doLine(irr::core::stringc(line.c_str()));
		}
		myfile.close();
	}else
		printf("Unable to open editor.conf\n"); 
	return;
}
bool Configuration::getSettingAsBool(irr::core::stringc hash) const{
	setting* set = getSetting(hash);

	if (set){
		if (set->value == "true" || set->value == "1"){
			return true;
		}else if (set->value == "false" || set->value == "0"){		
			return false;
		}
		printf("[Warning] Setting '%s' is not a boolean!\n",hash.c_str());
	}	

	return false;
}
void Configuration::save(irr::core::stringc file){
	std::ofstream myfile (file.c_str());
	if (myfile.is_open()){
		for (irr::core::list<setting*>::Iterator it=list->begin();it!=list->end();it++){
			printf("Looping...\n");
			setting* set = *it;
			printf("%s = ",set->hash.c_str());
			printf("%s\n",set->value.c_str());
			myfile << set->hash.c_str();
			myfile << " = ";
			myfile << set->value.c_str();
			myfile << "\n";
		}
		myfile.close();
	}else
		printf("Unable to write to file\n");
}
示例#8
0
void IrrAssimpExport::writeFile(irr::scene::IMesh* mesh, irr::core::stringc format, irr::core::stringc filename)
{
    Assimp::Exporter exporter;

    aiScene* scene = new aiScene();
    scene->mRootNode = new aiNode();
    scene->mRootNode->mNumMeshes = mesh->getMeshBufferCount();
    scene->mRootNode->mMeshes = new unsigned int[mesh->getMeshBufferCount()];
    for (unsigned int i = 0; i < mesh->getMeshBufferCount(); ++i)
        scene->mRootNode->mMeshes[i] = i;

    scene->mNumMeshes = mesh->getMeshBufferCount();
    scene->mMeshes = new aiMesh*[scene->mNumMeshes];

    scene->mNumMaterials = scene->mNumMeshes;
    scene->mMaterials = new aiMaterial*[scene->mNumMeshes];

    for (unsigned int i = 0; i < mesh->getMeshBufferCount(); ++i)
    {
        aiMesh* assMesh = new aiMesh();
        irr::scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i);
        video::E_VERTEX_TYPE verticesType = buffer->getVertexType();

        assMesh->mNumVertices = buffer->getVertexCount();
        assMesh->mVertices = new aiVector3D[assMesh->mNumVertices];
        assMesh->mNormals = new aiVector3D[assMesh->mNumVertices];

        assMesh->mTextureCoords[0] = new aiVector3D[assMesh->mNumVertices];
        assMesh->mNumUVComponents[0] = 2;

        assMesh->mColors[0] = new aiColor4D[assMesh->mNumVertices];

        if (verticesType == video::EVT_2TCOORDS)
        {
            assMesh->mTextureCoords[1] = new aiVector3D[assMesh->mNumVertices];
            assMesh->mNumUVComponents[1] = 2;
        }
        if (verticesType == video::EVT_TANGENTS)
        {
            assMesh->mTangents = new aiVector3D[assMesh->mNumVertices];
            assMesh->mBitangents = new aiVector3D[assMesh->mNumVertices];
        }

        video::S3DVertex* vertices = (video::S3DVertex*)buffer->getVertices();

        video::S3DVertex2TCoords* tCoordsVertices;
        verticesType == video::EVT_2TCOORDS ? tCoordsVertices = (video::S3DVertex2TCoords*) vertices : tCoordsVertices = 0;

        video::S3DVertexTangents* tangentsVertices;
        verticesType == video::EVT_TANGENTS ? tangentsVertices = (video::S3DVertexTangents*) vertices : tangentsVertices = 0;

        for (unsigned int j = 0; j < buffer->getVertexCount(); ++j)
        {
            video::S3DVertex vertex = vertices[j];

            core::vector3df position = vertex.Pos;
            core::vector3df normal = vertex.Normal;
            core::vector2df uv = vertex.TCoords;
            video::SColor color = vertex.Color;

            assMesh->mVertices[j] = aiVector3D(position.X, position.Y, position.Z);
            assMesh->mNormals[j] = aiVector3D(normal.X, normal.Y, normal.Z);
            assMesh->mTextureCoords[0][j] = aiVector3D(uv.X, uv.Y, 0);
            assMesh->mColors[0][j] = aiColor4D(color.getRed() / 255.f, color.getGreen() / 255.f, color.getBlue() / 255.f, color.getAlpha() / 255.f);

            if (verticesType == video::EVT_2TCOORDS)
            {
                video::S3DVertex2TCoords tCoordsVertex = tCoordsVertices[j];
                core::vector2df uv2 = tCoordsVertex.TCoords2;
                assMesh->mTextureCoords[1][j] = aiVector3D(uv2.X, uv2.Y, 0);
            }
            if (verticesType == video::EVT_TANGENTS)
            {
                video::S3DVertexTangents tangentsVertex = tangentsVertices[j];
                core::vector3df tangent = tangentsVertex.Tangent;
                core::vector3df binormal = tangentsVertex.Binormal;

                assMesh->mTangents[j] = aiVector3D(tangent.X, tangent.Y, tangent.Z);
                assMesh->mBitangents[j] = aiVector3D(binormal.X, binormal.Y, binormal.Z);
            }
        }

        assMesh->mNumFaces = buffer->getIndexCount() / 3;
        assMesh->mFaces = new aiFace[assMesh->mNumFaces];
        for (unsigned int j = 0; j < assMesh->mNumFaces; ++j)
        {
            aiFace face;
            face.mNumIndices = 3;
            face.mIndices = new unsigned int[3];
            face.mIndices[0] = buffer->getIndices()[3 * j + 0];
            face.mIndices[1] = buffer->getIndices()[3 * j + 1];
            face.mIndices[2] = buffer->getIndices()[3 * j + 2];
            assMesh->mFaces[j] = face;
        }

        scene->mMaterials[i] = new aiMaterial();
        scene->mMaterials[i]->mNumProperties = 0;
        assMesh->mMaterialIndex = i;

        video::SMaterial mat = buffer->getMaterial();

        aiColor3D diffuseColor = IrrToAssimpColor(mat.DiffuseColor);
        aiColor3D ambiantColor = IrrToAssimpColor(mat.AmbientColor);
        aiColor3D emissiveColor = IrrToAssimpColor(mat.EmissiveColor);
        aiColor3D specularColor = IrrToAssimpColor(mat.SpecularColor);
        float shininess = mat.Shininess;

        scene->mMaterials[i]->AddProperty(&diffuseColor, 1, AI_MATKEY_COLOR_DIFFUSE);
        scene->mMaterials[i]->AddProperty(&ambiantColor, 1, AI_MATKEY_COLOR_AMBIENT);
        scene->mMaterials[i]->AddProperty(&emissiveColor, 1, AI_MATKEY_COLOR_EMISSIVE);
        scene->mMaterials[i]->AddProperty(&specularColor, 1, AI_MATKEY_COLOR_SPECULAR);
        scene->mMaterials[i]->AddProperty(&shininess, 1, AI_MATKEY_SHININESS);

        if (mat.getTexture(0))
        {
            aiString textureName = aiString(mat.getTexture(0)->getName().getPath().c_str());
            scene->mMaterials[i]->AddProperty(&textureName, AI_MATKEY_TEXTURE_DIFFUSE(0));
        }
        if (mat.getTexture(1))
        {
            // Normal map
            if (   mat.MaterialType == video::EMT_NORMAL_MAP_SOLID
                || mat.MaterialType == video::EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR
                || mat.MaterialType == video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA
                || mat.MaterialType == video::EMT_PARALLAX_MAP_SOLID
                || mat.MaterialType == video::EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR
                || mat.MaterialType == video::EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA)
            {
                aiString textureName = aiString(mat.getTexture(1)->getName().getPath().c_str());
                scene->mMaterials[i]->AddProperty(&textureName, AI_MATKEY_TEXTURE_NORMALS(0));
            }

        }


        scene->mMeshes[i] = assMesh;
    }

    exporter.Export(scene, format.c_str(), filename.c_str(), aiProcess_FlipUVs);

    delete scene;
}
// Load Config
void CoreConfig::loadConfig(irr::core::stringc config_file)
{
	try{
		// Create an XML Document Stream,
		// Loads the /Data/previews.dpr snapshot file
		TiXmlDocument tagDoc(config_file.c_str());
		
		// Check if XML Document Stream was created,
		// If not return.
		if (!tagDoc.LoadFile()) return;

		// Create Initial XML Document Fields
		TiXmlHandle hDoc(&tagDoc);
		TiXmlElement* pElem;
		TiXmlHandle hRoot(0);
		TiXmlElement* pElementNode;
		core::stringw str_val;

		// Get First Element
		pElem=hDoc.FirstChildElement().Element();

		// Check if Preview Element was created,
		// If not return.
		if (!pElem) return;

		// Get First Child
		TiXmlNode* pNode=pElem->FirstChild();

		// Get BasicInfo Element Node
		pElementNode = pNode->ToElement();

		// Set Data
		pElementNode->QueryIntAttribute("res_x", &_resx);
		pElementNode->QueryIntAttribute("res_y", &_resy);

		str_val = pElementNode->Attribute( "add" );
		if(str_val == "true")
			_additive = true;
		else
			_additive = false;

		str_val = pElementNode->Attribute( "fs" );
		if(str_val == "true")
			_fullscreen = true;
		else
			_fullscreen = false;

		str_val = pElementNode->Attribute( "aa" );
		if(str_val == "true")
			_aa = true;
		else
			_aa = false;

		str_val = pElementNode->Attribute( "vsync" );
		if(str_val == "true")
			_vsync = true;
		else
			_vsync = false;

		str_val = pElementNode->Attribute( "driver" );
		if(str_val == "dx9")
			_driverType = video::EDT_DIRECT3D9;
		else if(str_val == "dx8")
			_driverType = video::EDT_DIRECT3D8;
		else if(str_val == "gl")
			_driverType = video::EDT_OPENGL;
		else if(str_val == "sw")
			_driverType = video::EDT_SOFTWARE;
		else if(str_val == "bv")
			_driverType = video::EDT_BURNINGSVIDEO;
		else if(str_val == "null")
			_driverType = video::EDT_NULL;

		// Clear XML Document Cache
		tagDoc.Clear();

	}
	catch(std::exception& e)
    {
		fprintf(stderr, "An exception has occurred: %s\n", e.what());
    }
}
示例#10
0
void NBEFileParser::save(Project* project,irr::core::stringc file){
	std::ofstream myfile (file.c_str());
	if (myfile.is_open()){
		myfile << "MINETEST NODEBOX EDITOR\n";
		myfile << "PARSER 1\n";
		myfile << "NAME ";
		if (project->name == "")
			myfile << "test";
		else
			myfile << project->name.c_str();
		myfile << "\n\n";

		int a = 1;
		list<Node*>* nodes = project->GetList();
		for (irr::core::list<Node*>::Iterator it=nodes->begin();it!=nodes->end();it++){
			printf("Looping...\n");
			Node* node = *it;
			myfile << "NODE ";
			if (node->name == ""){
				myfile << "Node";
				myfile << a;
			}else
				myfile << node->name.c_str();
			myfile << "\n";
			myfile << "POSITION ";
			myfile << node->getPosition().X;
			myfile << " ";
			myfile << node->getPosition().Y;
			myfile << " ";
			myfile << node->getPosition().Z;
			myfile << "\n";

			std::vector<NodeBox*> boxes = node->GetBoxes();
			for (std::vector<NodeBox*>::const_iterator it = boxes.begin();
					it != boxes.end();
					++it) {
				NodeBox* box = *it;
				myfile << "NODEBOX ";
				myfile << box->name.c_str();
				myfile << " ";
				myfile << box->one.X;
				myfile << " ";
				myfile << box->one.Y;
				myfile << " ";
				myfile << box->one.Z;
				myfile << " ";
				myfile << box->two.X;
				myfile << " ";
				myfile << box->two.Y;
				myfile << " ";
				myfile << box->two.Z;
				myfile << "\n";
			}

			myfile << "END NODE";
			a++;
		}

		myfile.close();
	}else
		printf("Unable to write to file\n");
}