1
0

ViewerWater.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections.Generic;
  28. using OpenMetaverse;
  29. using OpenMetaverse.StructuredData;
  30. namespace OpenSim.Framework
  31. {
  32. public class WaterData
  33. {
  34. public UUID normalMap = new UUID("822ded49-9a6c-f61c-cb89-6df54f42cdf4");
  35. public UUID transpTexture = new UUID("2bfd3884-7e27-69b9-ba3a-3e673f680004");
  36. public float blurMultiplier = 0.04f;
  37. public float fresnelOffset = 0.5f;
  38. public float fresnelScale = 0.4f;
  39. public Vector3 normScale = new Vector3(2f, 2f, 2f);
  40. public float scaleAbove = 0.03f;
  41. public float scaleBelow = 0.2f;
  42. public float underWaterFogMod = 0.25f;
  43. public Vector3 waterFogColor = new Vector3(0.0156f, 0.149f, 0.2509f);
  44. public float waterFogDensity = 10;
  45. public Vector2 wave1Dir = new Vector2(1.05f, -0.42f);
  46. public Vector2 wave2Dir = new Vector2(1.11f, -1.16f);
  47. public string Name;
  48. public void FromWLOSD(string name, OSD osd)
  49. {
  50. Vector4 v4tmp;
  51. OSDMap map = osd as OSDMap;
  52. blurMultiplier = map["blurMultiplier"];
  53. fresnelOffset = map["fresnelOffset"];
  54. fresnelScale = map["fresnelScale"];
  55. normScale = map["normScale"];
  56. normalMap = map["normalMap"];
  57. scaleAbove = map["scaleAbove"];
  58. scaleBelow = map["scaleBelow"];
  59. underWaterFogMod = map["underWaterFogMod"];
  60. v4tmp = map["waterFogColor"];
  61. waterFogColor = new Vector3(v4tmp.X, v4tmp.Y, v4tmp.Z);
  62. waterFogDensity = map["waterFogDensity"];
  63. wave1Dir = map["wave1Dir"];
  64. wave2Dir = map["wave2Dir"];
  65. Name = name;
  66. }
  67. public OSDMap ToWLOSD()
  68. {
  69. OSDMap map = new OSDMap();
  70. map["blurMultiplier"] = blurMultiplier;
  71. map["fresnelOffset"] = fresnelOffset;
  72. map["fresnelScale"] = fresnelScale;
  73. map["normScale"] = normScale;
  74. map["normalMap"] = normalMap;
  75. map["scaleAbove"] = scaleAbove;
  76. map["scaleBelow"] = scaleBelow;
  77. map["underWaterFogMod"] = underWaterFogMod;
  78. map["waterFogColor"] = new Vector4(waterFogColor.X, waterFogColor.Y, waterFogColor.Z, 1);
  79. map["waterFogDensity"] = waterFogDensity;
  80. //map["waterFogDensity"] = (float)Math.Pow(2.0f, waterFogDensity);
  81. map["wave1Dir"] = wave1Dir;
  82. map["wave2Dir"] = wave2Dir;
  83. return map;
  84. }
  85. public void FromOSD(string name, OSDMap map)
  86. {
  87. OSD otmp;
  88. if (map.TryGetValue("blur_multiplier", out otmp))
  89. blurMultiplier = otmp;
  90. if (map.TryGetValue("fresnel_offset", out otmp))
  91. fresnelOffset = otmp;
  92. if (map.TryGetValue("fresnel_scale", out otmp))
  93. fresnelScale = otmp;
  94. if (map.TryGetValue("normal_scale", out otmp))
  95. normScale = otmp;
  96. if (map.TryGetValue("normal_map", out otmp))
  97. normalMap = otmp;
  98. if (map.TryGetValue("scale_above", out otmp))
  99. scaleAbove = otmp;
  100. if (map.TryGetValue("scale_below", out otmp))
  101. scaleBelow = otmp;
  102. if (map.TryGetValue("underwater_fog_mod", out otmp))
  103. underWaterFogMod = otmp;
  104. if (map.TryGetValue("water_fog_color", out otmp))
  105. waterFogColor = otmp;
  106. if (map.TryGetValue("water_fog_density", out otmp))
  107. waterFogDensity = otmp;
  108. if (map.TryGetValue("wave1_direction", out otmp))
  109. wave1Dir = otmp;
  110. if (map.TryGetValue("wave2_direction", out otmp))
  111. wave2Dir = otmp;
  112. if (map.TryGetValue("transparent_texture", out otmp))
  113. transpTexture = otmp;
  114. Name = name;
  115. }
  116. public OSDMap ToOSD()
  117. {
  118. OSDMap map = new OSDMap();
  119. map["blur_multiplier"] = blurMultiplier;
  120. map["fresnel_offset"] = fresnelOffset;
  121. map["fresnel_scale"] = fresnelScale;
  122. map["normal_scale"] = normScale;
  123. map["normal_map"] = normalMap;
  124. map["scale_above"] = scaleAbove;
  125. map["scale_below"] = scaleBelow;
  126. map["underwater_fog_mod"] = underWaterFogMod;
  127. map["water_fog_color"] = waterFogColor;
  128. map["water_fog_density"] = waterFogDensity;
  129. map["wave1_direction"] = wave1Dir;
  130. map["wave2_direction"] = wave2Dir;
  131. map["transparent_texture"] = transpTexture;
  132. map["type"] ="water";
  133. return map;
  134. }
  135. public void GatherAssets(Dictionary<UUID, sbyte> uuids)
  136. {
  137. Util.AddToGatheredIds(uuids, normalMap, (sbyte)AssetType.Texture);
  138. Util.AddToGatheredIds(uuids, transpTexture, (sbyte)AssetType.Texture);
  139. }
  140. }
  141. }