BabylonExporter.ShadowGenerator.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections.Generic;
  2. using Autodesk.Max;
  3. using BabylonExport.Entities;
  4. namespace Max2Babylon
  5. {
  6. partial class BabylonExporter
  7. {
  8. private BabylonShadowGenerator ExportShadowGenerator(IINode lightNode, BabylonScene babylonScene)
  9. {
  10. var maxLight = (lightNode.ObjectRef as ILightObject);
  11. var babylonShadowGenerator = new BabylonShadowGenerator();
  12. RaiseMessage("Exporting shadow map", 2);
  13. babylonShadowGenerator.lightId = lightNode.GetGuid().ToString();
  14. babylonShadowGenerator.mapSize = maxLight.GetMapSize(0, Tools.Forever);
  15. babylonShadowGenerator.bias = lightNode.GetFloatProperty("babylonjs_shadows_bias", 0.00005f);
  16. babylonShadowGenerator.forceBackFacesOnly = lightNode.GetBoolProperty("babylonjs_forcebackfaces");
  17. var shadowsType = lightNode.GetStringProperty("babylonjs_shadows_type", "Blurred ESM");
  18. switch (shadowsType)
  19. {
  20. case "Hard shadows":
  21. break;
  22. case "Poisson Sampling":
  23. babylonShadowGenerator.usePoissonSampling = true;
  24. break;
  25. case "ESM":
  26. babylonShadowGenerator.useExponentialShadowMap = true;
  27. break;
  28. case"Blurred ESM":
  29. babylonShadowGenerator.useBlurExponentialShadowMap = true;
  30. babylonShadowGenerator.blurScale = lightNode.GetFloatProperty("babylonjs_shadows_blurScale", 2);
  31. babylonShadowGenerator.blurBoxOffset = lightNode.GetFloatProperty("babylonjs_shadows_blurBoxOffset", 1);
  32. break;
  33. }
  34. var list = new List<string>();
  35. var inclusion = maxLight.ExclList.TestFlag(1); //NT_INCLUDE
  36. var checkExclusionList = maxLight.ExclList.TestFlag(4); //NT_AFFECT_SHADOWCAST
  37. foreach (var meshNode in Loader.Core.RootNode.NodesListBySuperClass(SClass_ID.Geomobject))
  38. {
  39. #if MAX2017
  40. if (meshNode.CastShadows)
  41. #else
  42. if (meshNode.CastShadows == 1)
  43. #endif
  44. {
  45. var inList = maxLight.ExclList.FindNode(meshNode) != -1;
  46. if (!checkExclusionList || (inList && inclusion) || (!inList && !inclusion))
  47. {
  48. list.Add(meshNode.GetGuid().ToString());
  49. }
  50. }
  51. }
  52. babylonShadowGenerator.renderList = list.ToArray();
  53. babylonScene.ShadowGeneratorsList.Add(babylonShadowGenerator);
  54. return babylonShadowGenerator;
  55. }
  56. }
  57. }