BabylonExporter.ShadowGenerator.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.usePoissonSampling = maxLight.AbsMapBias >= 1;
  16. var list = new List<string>();
  17. var inclusion = maxLight.ExclList.TestFlag(1); //NT_INCLUDE
  18. var checkExclusionList = maxLight.ExclList.TestFlag(4); //NT_AFFECT_SHADOWCAST
  19. foreach (var meshNode in Loader.Core.RootNode.NodesListBySuperClass(SClass_ID.Geomobject))
  20. {
  21. if (meshNode.CastShadows == 1)
  22. {
  23. var inList = maxLight.ExclList.FindNode(meshNode) != -1;
  24. if (!checkExclusionList || (inList && inclusion) || (!inList && !inclusion))
  25. {
  26. list.Add(meshNode.GetGuid().ToString());
  27. }
  28. }
  29. }
  30. babylonShadowGenerator.renderList = list.ToArray();
  31. babylonScene.ShadowGeneratorsList.Add(babylonShadowGenerator);
  32. return babylonShadowGenerator;
  33. }
  34. }
  35. }