Light.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "Common.h"
  2. #include <cassert>
  3. //==============================================================================
  4. void exportLight(
  5. const aiLight& light,
  6. std::fstream& file)
  7. {
  8. if(light.mType != aiLightSource_POINT || light.mType != aiLightSource_SPOT)
  9. {
  10. LOGW("Skipping light %s. Unsupported type\n", light.mName.C_Str());
  11. return;
  12. }
  13. file << "\t<light>\n";
  14. file << "\t\t<name>" << light.mName.C_Str() << "</name>\n";
  15. file << "\t\t<diffuseColor>"
  16. << light.mColorDiffuse[0] << " "
  17. << light.mColorDiffuse[1] << " "
  18. << light.mColorDiffuse[2] << " "
  19. << light.mColorDiffuse[3]
  20. << "</diffuseColor>\n";
  21. file << "\t\t<specularColor>"
  22. << light.mColorSpecular[0] << " "
  23. << light.mColorSpecular[1] << " "
  24. << light.mColorSpecular[2] << " "
  25. << light.mColorSpecular[3]
  26. << "</specularColor>\n";
  27. aiMatrix4x4 trf;
  28. aiMatrix4x4::Translation(light.mPosition, trf);
  29. switch(light.mType)
  30. {
  31. case aiLightSource_POINT:
  32. {
  33. file << "\t\t<type>point</type>\n";
  34. // At this point I want the radius and have the attenuation factors
  35. // att = Ac + Al*d + Aq*d^2. When d = r then att = 0.0. Also if we
  36. // assume that Ac is 0 then:
  37. // 0 = Al*r + Aq*r^2. Solving by r is easy
  38. float r = -light.mAttenuationLinear / light.mAttenuationQuadratic;
  39. file << "\t\t<radius>" << r << "</radius>\n";
  40. break;
  41. }
  42. case aiLightSource_SPOT:
  43. file << "\t\t<type>spot</type>\n";
  44. break;
  45. default:
  46. assert(0);
  47. break;
  48. }
  49. // <transform>
  50. file << "\t\t<transform>";
  51. for(uint32_t i = 0; i < 16; i++)
  52. {
  53. file << trf[i] << " ";
  54. }
  55. file << "</transform>\n";
  56. file << "\t</light>\n";
  57. }