Material.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Urho
  7. {
  8. partial class Material
  9. {
  10. public static Material FromImage(string image)
  11. {
  12. var cache = Application.Current.ResourceCache;
  13. var material = new Material();
  14. material.SetTexture(TextureUnit.Diffuse, cache.GetTexture2D(image));
  15. material.SetTechnique(0, cache.GetTechnique("Techniques/Diff.xml"), 0, 0);
  16. return material;
  17. }
  18. public static Material SkyboxFromImages(
  19. string imagePositiveX,
  20. string imageNegativeX,
  21. string imagePositiveY,
  22. string imageNegativeY,
  23. string imagePositiveZ,
  24. string imageNegativeZ)
  25. {
  26. var cache = Application.Current.ResourceCache;
  27. var material = new Material();
  28. TextureCube cube = new TextureCube();
  29. cube.SetData(CubeMapFace.PositiveX, cache.GetFile(imagePositiveX, false));
  30. cube.SetData(CubeMapFace.NegativeX, cache.GetFile(imageNegativeX, false));
  31. cube.SetData(CubeMapFace.PositiveY, cache.GetFile(imagePositiveY, false));
  32. cube.SetData(CubeMapFace.NegativeY, cache.GetFile(imageNegativeY, false));
  33. cube.SetData(CubeMapFace.PositiveZ, cache.GetFile(imagePositiveZ, false));
  34. cube.SetData(CubeMapFace.NegativeZ, cache.GetFile(imageNegativeZ, false));
  35. material.SetTexture(TextureUnit.Diffuse, cube);
  36. material.SetTechnique(0, cache.GetTechnique("Techniques/DiffSkybox.xml"), 0, 0);
  37. return material;
  38. }
  39. public static Material SkyboxFromImage(string image)
  40. {
  41. return SkyboxFromImages(image, image, image, image, image, image);
  42. }
  43. }
  44. }