BabylonExporter.ShadowGenerator.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Variance");
  18. switch (shadowsType)
  19. {
  20. case "Hard shadows":
  21. break;
  22. case "Poisson Sampling":
  23. babylonShadowGenerator.usePoissonSampling = true;
  24. break;
  25. case "Variance":
  26. babylonShadowGenerator.useVarianceShadowMap = true;
  27. break;
  28. case"Blurred Variance":
  29. babylonShadowGenerator.useBlurVarianceShadowMap = 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 (meshNode.CastShadows == 1)
  40. {
  41. var inList = maxLight.ExclList.FindNode(meshNode) != -1;
  42. if (!checkExclusionList || (inList && inclusion) || (!inList && !inclusion))
  43. {
  44. list.Add(meshNode.GetGuid().ToString());
  45. }
  46. }
  47. }
  48. babylonShadowGenerator.renderList = list.ToArray();
  49. babylonScene.ShadowGeneratorsList.Add(babylonShadowGenerator);
  50. return babylonShadowGenerator;
  51. }
  52. }
  53. }