nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file IFCMaterial.cpp nuclear@0: * @brief Implementation of conversion routines to convert IFC materials to aiMaterial nuclear@0: */ nuclear@0: nuclear@0: #include "AssimpPCH.h" nuclear@0: nuclear@0: #ifndef ASSIMP_BUILD_NO_IFC_IMPORTER nuclear@0: #include "IFCUtil.h" nuclear@0: nuclear@0: namespace Assimp { nuclear@0: namespace IFC { nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: int ConvertShadingMode(const std::string& name) nuclear@0: { nuclear@0: if (name == "BLINN") { nuclear@0: return aiShadingMode_Blinn; nuclear@0: } nuclear@0: else if (name == "FLAT" || name == "NOTDEFINED") { nuclear@0: return aiShadingMode_NoShading; nuclear@0: } nuclear@0: else if (name == "PHONG") { nuclear@0: return aiShadingMode_Phong; nuclear@0: } nuclear@0: IFCImporter::LogWarn("shading mode "+name+" not recognized by Assimp, using Phong instead"); nuclear@0: return aiShadingMode_Phong; nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: void FillMaterial(aiMaterial* mat,const IFC::IfcSurfaceStyle* surf,ConversionData& conv) nuclear@0: { nuclear@0: aiString name; nuclear@0: name.Set((surf->Name? surf->Name.Get() : "IfcSurfaceStyle_Unnamed")); nuclear@0: mat->AddProperty(&name,AI_MATKEY_NAME); nuclear@0: nuclear@0: // now see which kinds of surface information are present nuclear@0: BOOST_FOREACH(boost::shared_ptr< const IFC::IfcSurfaceStyleElementSelect > sel2, surf->Styles) { nuclear@0: if (const IFC::IfcSurfaceStyleShading* shade = sel2->ResolveSelectPtr(conv.db)) { nuclear@0: aiColor4D col_base,col; nuclear@0: nuclear@0: ConvertColor(col_base, shade->SurfaceColour); nuclear@0: mat->AddProperty(&col_base,1, AI_MATKEY_COLOR_DIFFUSE); nuclear@0: nuclear@0: if (const IFC::IfcSurfaceStyleRendering* ren = shade->ToPtr()) { nuclear@0: nuclear@0: if (ren->Transparency) { nuclear@0: const float t = 1.f-static_cast(ren->Transparency.Get()); nuclear@0: mat->AddProperty(&t,1, AI_MATKEY_OPACITY); nuclear@0: } nuclear@0: nuclear@0: if (ren->DiffuseColour) { nuclear@0: ConvertColor(col, *ren->DiffuseColour.Get(),conv,&col_base); nuclear@0: mat->AddProperty(&col,1, AI_MATKEY_COLOR_DIFFUSE); nuclear@0: } nuclear@0: nuclear@0: if (ren->SpecularColour) { nuclear@0: ConvertColor(col, *ren->SpecularColour.Get(),conv,&col_base); nuclear@0: mat->AddProperty(&col,1, AI_MATKEY_COLOR_SPECULAR); nuclear@0: } nuclear@0: nuclear@0: if (ren->TransmissionColour) { nuclear@0: ConvertColor(col, *ren->TransmissionColour.Get(),conv,&col_base); nuclear@0: mat->AddProperty(&col,1, AI_MATKEY_COLOR_TRANSPARENT); nuclear@0: } nuclear@0: nuclear@0: if (ren->ReflectionColour) { nuclear@0: ConvertColor(col, *ren->ReflectionColour.Get(),conv,&col_base); nuclear@0: mat->AddProperty(&col,1, AI_MATKEY_COLOR_REFLECTIVE); nuclear@0: } nuclear@0: nuclear@0: const int shading = (ren->SpecularHighlight && ren->SpecularColour)?ConvertShadingMode(ren->ReflectanceMethod):static_cast(aiShadingMode_Gouraud); nuclear@0: mat->AddProperty(&shading,1, AI_MATKEY_SHADING_MODEL); nuclear@0: nuclear@0: if (ren->SpecularHighlight) { nuclear@0: if(const EXPRESS::REAL* rt = ren->SpecularHighlight.Get()->ToPtr()) { nuclear@0: // at this point we don't distinguish between the two distinct ways of nuclear@0: // specifying highlight intensities. leave this to the user. nuclear@0: const float e = static_cast(*rt); nuclear@0: mat->AddProperty(&e,1,AI_MATKEY_SHININESS); nuclear@0: } nuclear@0: else { nuclear@0: IFCImporter::LogWarn("unexpected type error, SpecularHighlight should be a REAL"); nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: } /* nuclear@0: else if (const IFC::IfcSurfaceStyleWithTextures* tex = sel2->ResolveSelectPtr(conv.db)) { nuclear@0: // XXX nuclear@0: } */ nuclear@0: } nuclear@0: nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: unsigned int ProcessMaterials(const IFC::IfcRepresentationItem& item, ConversionData& conv) nuclear@0: { nuclear@0: if (conv.materials.empty()) { nuclear@0: aiString name; nuclear@0: std::auto_ptr mat(new aiMaterial()); nuclear@0: nuclear@0: name.Set(""); nuclear@0: mat->AddProperty(&name,AI_MATKEY_NAME); nuclear@0: nuclear@0: const aiColor4D col = aiColor4D(0.6f,0.6f,0.6f,1.0f); nuclear@0: mat->AddProperty(&col,1, AI_MATKEY_COLOR_DIFFUSE); nuclear@0: nuclear@0: conv.materials.push_back(mat.release()); nuclear@0: } nuclear@0: nuclear@0: STEP::DB::RefMapRange range = conv.db.GetRefs().equal_range(item.GetID()); nuclear@0: for(;range.first != range.second; ++range.first) { nuclear@0: if(const IFC::IfcStyledItem* const styled = conv.db.GetObject((*range.first).second)->ToPtr()) { nuclear@0: BOOST_FOREACH(const IFC::IfcPresentationStyleAssignment& as, styled->Styles) { nuclear@0: BOOST_FOREACH(boost::shared_ptr sel, as.Styles) { nuclear@0: nuclear@0: if (const IFC::IfcSurfaceStyle* const surf = sel->ResolveSelectPtr(conv.db)) { nuclear@0: const std::string side = static_cast(surf->Side); nuclear@0: if (side != "BOTH") { nuclear@0: IFCImporter::LogWarn("ignoring surface side marker on IFC::IfcSurfaceStyle: " + side); nuclear@0: } nuclear@0: nuclear@0: std::auto_ptr mat(new aiMaterial()); nuclear@0: nuclear@0: FillMaterial(mat.get(),surf,conv); nuclear@0: nuclear@0: conv.materials.push_back(mat.release()); nuclear@0: return conv.materials.size()-1; nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: } // ! IFC nuclear@0: } // ! Assimp nuclear@0: nuclear@0: #endif