Material.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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, CoreAssets.Techniques.Diff, 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, CoreAssets.Techniques.DiffSkybox, 0, 0);
  37. material.CullMode = CullMode.None;
  38. return material;
  39. }
  40. public static Material SkyboxFromImage(string image)
  41. {
  42. return SkyboxFromImages(image, image, image, image, image, image);
  43. }
  44. }
  45. }