示例#1
0
void EffectsExporter::exportEffects(Scene *sce)
{
	this->scene = sce;

	if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
		if (hasEffects(sce)) {
				MaterialFunctor mf;
				openLibrary();
				mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
				closeLibrary();
		}
	}
	else {
		std::set<Object *> uv_textured_obs = bc_getUVTexturedObjects(sce, !this->export_settings->active_uv_only);
		std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
		if (uv_images.size() > 0) {
			openLibrary();
			std::set<Image *>::iterator uv_images_iter;
			for (uv_images_iter = uv_images.begin();
			     uv_images_iter != uv_images.end();
			     uv_images_iter++)
			{

				Image *ima = *uv_images_iter;
				std::string key(id_name(ima));
				key = translate_id(key);
				COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
					key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
					key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
				sampler.setImageId(key);

				openEffect(key + "-effect");
				COLLADASW::EffectProfile ep(mSW);
				ep.setProfileType(COLLADASW::EffectProfile::COMMON);
				ep.setShaderType(COLLADASW::EffectProfile::PHONG);
				ep.setDiffuse(createTexture(ima, key, &sampler), false, "diffuse");
				COLLADASW::ColorOrTexture cot = getcol(0, 0, 0, 1.0f);
				ep.setSpecular(cot, false, "specular");
				ep.openProfile();
				ep.addProfileElements();
				ep.addExtraTechniques(mSW);
				ep.closeProfile();
				closeEffect();
			}
			closeLibrary();
		}
	}
}
示例#2
0
void MaterialsExporter::exportMaterials(Scene *sce)
{
	if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT)
	{
		if (hasMaterials(sce)) {
			openLibrary();

			MaterialFunctor mf;
			mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set);

			closeLibrary();
		}
	}

	else {
		std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
		if (uv_images.size() > 0) {
			openLibrary();
			std::set<Image *>::iterator uv_images_iter;
			for (uv_images_iter = uv_images.begin();
				uv_images_iter != uv_images.end();
				uv_images_iter++) {

				Image *ima = *uv_images_iter;
				std::string matid(id_name(ima));

				openMaterial(get_material_id_from_id(matid), translate_id(matid));
				std::string efid = translate_id(matid) + "-effect";
				addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, efid));
				closeMaterial();
			}
			closeLibrary();
		}
	}

}
示例#3
0
void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only, BC_export_texture_type export_texture_type)
{
	bool all_uv_layers = !active_uv_only;
	COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList();

	if (export_texture_type == BC_TEXTURE_TYPE_UV)
	{
		std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers);
		std::set<Image *>::iterator uv_images_iter;
		for (uv_images_iter = uv_images.begin();
			uv_images_iter != uv_images.end();
			uv_images_iter++) {
			Image *ima = *uv_images_iter;
			std::string matid(id_name(ima));
			matid = get_material_id_from_id(matid);
			std::ostringstream ostr;
			ostr << matid;
			COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));

			// create <bind_vertex_input> for each uv map
			Mesh *me = (Mesh *)ob->data;
			int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE);

			int map_index = 0;
			int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1;
			for (int b = 0; b < totlayer; b++) {
				if (!active_uv_only || b == active_uv_index) {
					char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b);
					im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++));
				}
			}

			iml.push_back(im);
		}
	}

	else {
		for (int a = 0; a < ob->totcol; a++) {
			Material *ma = give_current_material(ob, a + 1);
			if (ma) {
				std::string matid(get_material_id(ma));
				matid = translate_id(matid);
				std::ostringstream ostr;
				ostr << matid;
				COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));

				// create <bind_vertex_input> for each uv map
				Mesh *me = (Mesh *)ob->data;
				int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE);

				int map_index = 0;
				int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1;
				for (int b = 0; b < totlayer; b++) {
					if (!active_uv_only || b == active_uv_index) {
						char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b);
						im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++));
					}
				}

				iml.push_back(im);
			}
		}
	}
}