BabylonExporter.ShadowGenerator.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. var shadowsType = lightNode.GetStringProperty("babylonjs_shadows_type", "Blurred Variance");
  17. switch (shadowsType)
  18. {
  19. case "Hard shadows":
  20. break;
  21. case "Poisson Sampling":
  22. babylonShadowGenerator.usePoissonSampling = true;
  23. break;
  24. case "Variance":
  25. babylonShadowGenerator.useVarianceShadowMap = true;
  26. break;
  27. case"Blurred Variance":
  28. babylonShadowGenerator.useBlurVarianceShadowMap = true;
  29. babylonShadowGenerator.blurScale = lightNode.GetFloatProperty("babylonjs_shadows_blurScale", 2);
  30. babylonShadowGenerator.blurBoxOffset = lightNode.GetFloatProperty("babylonjs_shadows_blurBoxOffset", 1);
  31. break;
  32. }
  33. var list = new List<string>();
  34. var inclusion = maxLight.ExclList.TestFlag(1); //NT_INCLUDE
  35. var checkExclusionList = maxLight.ExclList.TestFlag(4); //NT_AFFECT_SHADOWCAST
  36. foreach (var meshNode in Loader.Core.RootNode.NodesListBySuperClass(SClass_ID.Geomobject))
  37. {
  38. if (meshNode.CastShadows == 1)
  39. {
  40. var inList = maxLight.ExclList.FindNode(meshNode) != -1;
  41. if (!checkExclusionList || (inList && inclusion) || (!inList && !inclusion))
  42. {
  43. list.Add(meshNode.GetGuid().ToString());
  44. }
  45. }
  46. }
  47. babylonShadowGenerator.renderList = list.ToArray();
  48. babylonScene.ShadowGeneratorsList.Add(babylonShadowGenerator);
  49. return babylonShadowGenerator;
  50. }
  51. }
  52. }