vrshoot

annotate libs/assimp/IFCMaterial.cpp @ 1:e7ca128b8713

looks nice :)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Feb 2014 00:35:22 +0200
parents
children
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2012, assimp team
nuclear@0 6 All rights reserved.
nuclear@0 7
nuclear@0 8 Redistribution and use of this software in source and binary forms,
nuclear@0 9 with or without modification, are permitted provided that the
nuclear@0 10 following conditions are met:
nuclear@0 11
nuclear@0 12 * Redistributions of source code must retain the above
nuclear@0 13 copyright notice, this list of conditions and the
nuclear@0 14 following disclaimer.
nuclear@0 15
nuclear@0 16 * Redistributions in binary form must reproduce the above
nuclear@0 17 copyright notice, this list of conditions and the
nuclear@0 18 following disclaimer in the documentation and/or other
nuclear@0 19 materials provided with the distribution.
nuclear@0 20
nuclear@0 21 * Neither the name of the assimp team, nor the names of its
nuclear@0 22 contributors may be used to endorse or promote products
nuclear@0 23 derived from this software without specific prior
nuclear@0 24 written permission of the assimp team.
nuclear@0 25
nuclear@0 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 37
nuclear@0 38 ----------------------------------------------------------------------
nuclear@0 39 */
nuclear@0 40
nuclear@0 41 /** @file IFCMaterial.cpp
nuclear@0 42 * @brief Implementation of conversion routines to convert IFC materials to aiMaterial
nuclear@0 43 */
nuclear@0 44
nuclear@0 45 #include "AssimpPCH.h"
nuclear@0 46
nuclear@0 47 #ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
nuclear@0 48 #include "IFCUtil.h"
nuclear@0 49
nuclear@0 50 namespace Assimp {
nuclear@0 51 namespace IFC {
nuclear@0 52
nuclear@0 53 // ------------------------------------------------------------------------------------------------
nuclear@0 54 int ConvertShadingMode(const std::string& name)
nuclear@0 55 {
nuclear@0 56 if (name == "BLINN") {
nuclear@0 57 return aiShadingMode_Blinn;
nuclear@0 58 }
nuclear@0 59 else if (name == "FLAT" || name == "NOTDEFINED") {
nuclear@0 60 return aiShadingMode_NoShading;
nuclear@0 61 }
nuclear@0 62 else if (name == "PHONG") {
nuclear@0 63 return aiShadingMode_Phong;
nuclear@0 64 }
nuclear@0 65 IFCImporter::LogWarn("shading mode "+name+" not recognized by Assimp, using Phong instead");
nuclear@0 66 return aiShadingMode_Phong;
nuclear@0 67 }
nuclear@0 68
nuclear@0 69 // ------------------------------------------------------------------------------------------------
nuclear@0 70 void FillMaterial(aiMaterial* mat,const IFC::IfcSurfaceStyle* surf,ConversionData& conv)
nuclear@0 71 {
nuclear@0 72 aiString name;
nuclear@0 73 name.Set((surf->Name? surf->Name.Get() : "IfcSurfaceStyle_Unnamed"));
nuclear@0 74 mat->AddProperty(&name,AI_MATKEY_NAME);
nuclear@0 75
nuclear@0 76 // now see which kinds of surface information are present
nuclear@0 77 BOOST_FOREACH(boost::shared_ptr< const IFC::IfcSurfaceStyleElementSelect > sel2, surf->Styles) {
nuclear@0 78 if (const IFC::IfcSurfaceStyleShading* shade = sel2->ResolveSelectPtr<IFC::IfcSurfaceStyleShading>(conv.db)) {
nuclear@0 79 aiColor4D col_base,col;
nuclear@0 80
nuclear@0 81 ConvertColor(col_base, shade->SurfaceColour);
nuclear@0 82 mat->AddProperty(&col_base,1, AI_MATKEY_COLOR_DIFFUSE);
nuclear@0 83
nuclear@0 84 if (const IFC::IfcSurfaceStyleRendering* ren = shade->ToPtr<IFC::IfcSurfaceStyleRendering>()) {
nuclear@0 85
nuclear@0 86 if (ren->Transparency) {
nuclear@0 87 const float t = 1.f-static_cast<float>(ren->Transparency.Get());
nuclear@0 88 mat->AddProperty(&t,1, AI_MATKEY_OPACITY);
nuclear@0 89 }
nuclear@0 90
nuclear@0 91 if (ren->DiffuseColour) {
nuclear@0 92 ConvertColor(col, *ren->DiffuseColour.Get(),conv,&col_base);
nuclear@0 93 mat->AddProperty(&col,1, AI_MATKEY_COLOR_DIFFUSE);
nuclear@0 94 }
nuclear@0 95
nuclear@0 96 if (ren->SpecularColour) {
nuclear@0 97 ConvertColor(col, *ren->SpecularColour.Get(),conv,&col_base);
nuclear@0 98 mat->AddProperty(&col,1, AI_MATKEY_COLOR_SPECULAR);
nuclear@0 99 }
nuclear@0 100
nuclear@0 101 if (ren->TransmissionColour) {
nuclear@0 102 ConvertColor(col, *ren->TransmissionColour.Get(),conv,&col_base);
nuclear@0 103 mat->AddProperty(&col,1, AI_MATKEY_COLOR_TRANSPARENT);
nuclear@0 104 }
nuclear@0 105
nuclear@0 106 if (ren->ReflectionColour) {
nuclear@0 107 ConvertColor(col, *ren->ReflectionColour.Get(),conv,&col_base);
nuclear@0 108 mat->AddProperty(&col,1, AI_MATKEY_COLOR_REFLECTIVE);
nuclear@0 109 }
nuclear@0 110
nuclear@0 111 const int shading = (ren->SpecularHighlight && ren->SpecularColour)?ConvertShadingMode(ren->ReflectanceMethod):static_cast<int>(aiShadingMode_Gouraud);
nuclear@0 112 mat->AddProperty(&shading,1, AI_MATKEY_SHADING_MODEL);
nuclear@0 113
nuclear@0 114 if (ren->SpecularHighlight) {
nuclear@0 115 if(const EXPRESS::REAL* rt = ren->SpecularHighlight.Get()->ToPtr<EXPRESS::REAL>()) {
nuclear@0 116 // at this point we don't distinguish between the two distinct ways of
nuclear@0 117 // specifying highlight intensities. leave this to the user.
nuclear@0 118 const float e = static_cast<float>(*rt);
nuclear@0 119 mat->AddProperty(&e,1,AI_MATKEY_SHININESS);
nuclear@0 120 }
nuclear@0 121 else {
nuclear@0 122 IFCImporter::LogWarn("unexpected type error, SpecularHighlight should be a REAL");
nuclear@0 123 }
nuclear@0 124 }
nuclear@0 125 }
nuclear@0 126 } /*
nuclear@0 127 else if (const IFC::IfcSurfaceStyleWithTextures* tex = sel2->ResolveSelectPtr<IFC::IfcSurfaceStyleWithTextures>(conv.db)) {
nuclear@0 128 // XXX
nuclear@0 129 } */
nuclear@0 130 }
nuclear@0 131
nuclear@0 132 }
nuclear@0 133
nuclear@0 134 // ------------------------------------------------------------------------------------------------
nuclear@0 135 unsigned int ProcessMaterials(const IFC::IfcRepresentationItem& item, ConversionData& conv)
nuclear@0 136 {
nuclear@0 137 if (conv.materials.empty()) {
nuclear@0 138 aiString name;
nuclear@0 139 std::auto_ptr<aiMaterial> mat(new aiMaterial());
nuclear@0 140
nuclear@0 141 name.Set("<IFCDefault>");
nuclear@0 142 mat->AddProperty(&name,AI_MATKEY_NAME);
nuclear@0 143
nuclear@0 144 const aiColor4D col = aiColor4D(0.6f,0.6f,0.6f,1.0f);
nuclear@0 145 mat->AddProperty(&col,1, AI_MATKEY_COLOR_DIFFUSE);
nuclear@0 146
nuclear@0 147 conv.materials.push_back(mat.release());
nuclear@0 148 }
nuclear@0 149
nuclear@0 150 STEP::DB::RefMapRange range = conv.db.GetRefs().equal_range(item.GetID());
nuclear@0 151 for(;range.first != range.second; ++range.first) {
nuclear@0 152 if(const IFC::IfcStyledItem* const styled = conv.db.GetObject((*range.first).second)->ToPtr<IFC::IfcStyledItem>()) {
nuclear@0 153 BOOST_FOREACH(const IFC::IfcPresentationStyleAssignment& as, styled->Styles) {
nuclear@0 154 BOOST_FOREACH(boost::shared_ptr<const IFC::IfcPresentationStyleSelect> sel, as.Styles) {
nuclear@0 155
nuclear@0 156 if (const IFC::IfcSurfaceStyle* const surf = sel->ResolveSelectPtr<IFC::IfcSurfaceStyle>(conv.db)) {
nuclear@0 157 const std::string side = static_cast<std::string>(surf->Side);
nuclear@0 158 if (side != "BOTH") {
nuclear@0 159 IFCImporter::LogWarn("ignoring surface side marker on IFC::IfcSurfaceStyle: " + side);
nuclear@0 160 }
nuclear@0 161
nuclear@0 162 std::auto_ptr<aiMaterial> mat(new aiMaterial());
nuclear@0 163
nuclear@0 164 FillMaterial(mat.get(),surf,conv);
nuclear@0 165
nuclear@0 166 conv.materials.push_back(mat.release());
nuclear@0 167 return conv.materials.size()-1;
nuclear@0 168 }
nuclear@0 169 }
nuclear@0 170 }
nuclear@0 171 }
nuclear@0 172 }
nuclear@0 173 return 0;
nuclear@0 174 }
nuclear@0 175
nuclear@0 176 } // ! IFC
nuclear@0 177 } // ! Assimp
nuclear@0 178
nuclear@0 179 #endif