25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

180 satır
6.3 KiB

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