void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
	effects.close();
	for (std::vector<IfcGeom::Material>::const_iterator it = materials.begin(); it != materials.end(); ++it) {
		const std::string& material_name = collada_id((*it).name());
		openMaterial(material_name);
		addInstanceEffect("#" + material_name + "-fx");
		closeMaterial();
	}
	closeLibrary();
}
Beispiel #2
0
void MaterialsExporter::operator()(Material *ma, Object *ob)
{
	std::string name(id_name(ma));

	openMaterial(get_material_id(ma), translate_id(name));

	std::string efid = translate_id(name) + "-effect";
	addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, efid));

	closeMaterial();
}
Beispiel #3
0
void MaterialExporter::doExport()
{
	vgLogDebug("Exporting materials");
	openLibrary();
	
	if( m_exportSettings.getLevel() > GEOMETRY )
	{
		typedef collectedMapType::right_map::const_iterator right_const_iterator;

		for( right_const_iterator right_iter = m_collectedMap.right.begin(), iend = m_collectedMap.right.end();
			 right_iter != iend; ++right_iter )
		{
			vgd::Shp< vge::technique::CollectedMaterial > collectedMaterial = right_iter->first;
			
			if( collectedMaterial->getMaterial() )
			{
				std::string effectName = collectedMaterial->getEffectId();
				std::string materialName = effectName + MATERIAL_ID_SUFFIX;
				collectedMaterial->setMaterialId( materialName );

				openMaterial ( materialName, COLLADABU::Utils::checkNCName(materialName) );
				addInstanceEffect ( "#" + effectName );
				closeMaterial ();
			}
		}
	}
	else
	{
		std::string effectName = "DefaultWhole";
		std::string materialName = effectName + MATERIAL_ID_SUFFIX;

		openMaterial ( materialName, COLLADABU::Utils::checkNCName(materialName) );
		addInstanceEffect ( "#" + effectName );
		closeMaterial ();
	}
	closeLibrary();
}
Beispiel #4
0
void MaterialExporter::add()
{
    char tempStr[1024];

    openLibrary();
    for (int i = 0; i < m_bsp->numShaders; ++i)
    {
        sprintf(tempStr, "material%d", i);
        std::string matId = tempStr;

        sprintf(tempStr, "material%d-fx", i);
        std::string fxId = tempStr;

        openMaterial(matId, matId);
        addInstanceEffect(COLLADASW::URI(EMPTY_STRING, fxId));
        closeMaterial();
    }
    closeLibrary();
}
Beispiel #5
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();
		}
	}

}
    //--------------------------------
    void MaterialExporter::exportMaterial ( MObject shadingEngine )
    {
        // Get the shader object.
        MObject shader = DagHelper::getSourceNodeConnectedTo ( shadingEngine, ATTR_SURFACE_SHADER );

        // Find the actual shader node, since this function received shading sets as input
        MStatus status;
        MFnDependencyNode shaderNode ( shader, &status );
        if ( status != MStatus::kSuccess ) return;

        // Get the name of the current material (this is the maya material id)
        String mayaMaterialId = DocumentExporter::mayaNameToColladaName ( shaderNode.name(), true );

        // Have we seen this shader before, is it already exported?
        MaterialMap::iterator materialMapIter;
        materialMapIter = mMaterialMap.find ( mayaMaterialId );
        if ( materialMapIter != mMaterialMap.end() ) return;

        // This is a new shading engine
        mMaterialMap [mayaMaterialId] = shader;

        // Generate a COLLADA id for the new object
        String colladaMaterialId;

        // Check if there is an extra attribute "colladaId" and use this as export id.
        MString attributeValue;
        DagHelper::getPlugValue ( shader, COLLADA_MATERIAL_ID_ATTRIBUTE_NAME, attributeValue );
        if ( attributeValue != EMPTY_CSTRING )
        {
            // Generate a valid collada name, if necessary.
            colladaMaterialId = DocumentExporter::mayaNameToColladaName ( attributeValue, false );
        }
        else
        {
            // Generate a COLLADA id for the new object
            colladaMaterialId = DocumentExporter::mayaNameToColladaName ( shaderNode.name(), true );
        }
        // Make the id unique and store it.
        colladaMaterialId = mMaterialIdList.addId ( colladaMaterialId );
        mMayaIdColladaMaterialIdMap [mayaMaterialId] = colladaMaterialId;

//         MFnDependencyNode shadingEngineNode ( shadingEngine, &status );
//         if ( status != MStatus::kSuccess ) return;
//         String shadingEngineNodeName = shadingEngineNode.name ().asChar (); // initialParticleSE
//         String shaderNodeName = shaderNode.name ().asChar (); // lambert1
       
        // Check if the material should be written
        if ( mWriteMaterials )
        {
            // Have we exported this shader already?
            std::vector<String>::iterator exportedMaterialsIter;
            exportedMaterialsIter = find ( mExportedMaterials.begin(), mExportedMaterials.end(), colladaMaterialId );

            if ( exportedMaterialsIter == mExportedMaterials.end() )
            {
                // Open a tag for the current material in the collada document
                openMaterial ( colladaMaterialId, mayaMaterialId );

                // Export the reference to the effect and the hardware shader components.
                exportEffectInstance ( mayaMaterialId, colladaMaterialId, shader );

//                 // TODO Export the user defined material extra data from import (extra preservation).
//                 mDocumentExporter->exportExtraData ( shader, COLLADAFW::ExtraKeys::MATERIAL );

                // Closes the current effect tag
                closeMaterial();

                // Push the id of the exported material into the list for the exported materials
                mExportedMaterials.push_back ( colladaMaterialId );
            }
        }
    }