SOPMaterial.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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;
  28. using System.Collections.Generic;
  29. using OpenMetaverse;
  30. using OpenMetaverse.StructuredData;
  31. using OpenSim.Framework;
  32. namespace OpenSim.Region.Framework.Scenes
  33. {
  34. public static class SOPMaterialData
  35. {
  36. public enum SopMaterial : int // redundante and not in use for now
  37. {
  38. Stone = 0,
  39. Metal = 1,
  40. Glass = 2,
  41. Wood = 3,
  42. Flesh = 4,
  43. Plastic = 5,
  44. Rubber = 6,
  45. light = 7 // compatibility with old viewers
  46. }
  47. private struct MaterialData
  48. {
  49. public float friction;
  50. public float bounce;
  51. public MaterialData(float f, float b)
  52. {
  53. friction = f;
  54. bounce = b;
  55. }
  56. }
  57. private static MaterialData[] m_materialdata = {
  58. new MaterialData(0.8f,0.4f), // Stone
  59. new MaterialData(0.3f,0.4f), // Metal
  60. new MaterialData(0.2f,0.7f), // Glass
  61. new MaterialData(0.6f,0.5f), // Wood
  62. new MaterialData(0.9f,0.3f), // Flesh
  63. new MaterialData(0.4f,0.7f), // Plastic
  64. new MaterialData(0.9f,0.95f), // Rubber
  65. new MaterialData(0.0f,0.0f) // light ??
  66. };
  67. public static Material MaxMaterial
  68. {
  69. get { return (Material)(m_materialdata.Length - 1); }
  70. }
  71. public static float friction(Material material)
  72. {
  73. int indx = (int)material;
  74. if (indx < m_materialdata.Length)
  75. return (m_materialdata[indx].friction);
  76. else
  77. return 0;
  78. }
  79. public static float bounce(Material material)
  80. {
  81. int indx = (int)material;
  82. if (indx < m_materialdata.Length)
  83. return (m_materialdata[indx].bounce);
  84. else
  85. return 0;
  86. }
  87. }
  88. public class FaceMaterial
  89. {
  90. public UUID ID;
  91. public UUID NormalMapID = UUID.Zero;
  92. public float NormalOffsetX = 0.0f;
  93. public float NormalOffsetY = 0.0f;
  94. public float NormalRepeatX = 1.0f;
  95. public float NormalRepeatY = 1.0f;
  96. public float NormalRotation = 0.0f;
  97. public UUID SpecularMapID = UUID.Zero;
  98. public float SpecularOffsetX = 0.0f;
  99. public float SpecularOffsetY = 0.0f;
  100. public float SpecularRepeatX = 1.0f;
  101. public float SpecularRepeatY = 1.0f;
  102. public float SpecularRotation = 0.0f;
  103. public Color4 SpecularLightColor = new Color4(255,255,255,255);
  104. public Byte SpecularLightExponent = 51;
  105. public Byte EnvironmentIntensity = 0;
  106. public Byte DiffuseAlphaMode = 1;
  107. public Byte AlphaMaskCutoff = 0;
  108. public FaceMaterial()
  109. { }
  110. public FaceMaterial(UUID pID, OSDMap mat)
  111. {
  112. ID = pID;
  113. if(mat == null)
  114. return;
  115. float scale = 0.0001f;
  116. NormalMapID = mat["NormMap"].AsUUID();
  117. NormalOffsetX = scale * (float)mat["NormOffsetX"].AsReal();
  118. NormalOffsetY = scale * (float)mat["NormOffsetY"].AsReal();
  119. NormalRepeatX = scale * (float)mat["NormRepeatX"].AsReal();
  120. NormalRepeatY = scale * (float)mat["NormRepeatY"].AsReal();
  121. NormalRotation = scale * (float)mat["NormRotation"].AsReal();
  122. SpecularMapID = mat["SpecMap"].AsUUID();
  123. SpecularOffsetX = scale * (float)mat["SpecOffsetX"].AsReal();
  124. SpecularOffsetY = scale * (float)mat["SpecOffsetY"].AsReal();
  125. SpecularRepeatX = scale * (float)mat["SpecRepeatX"].AsReal();
  126. SpecularRepeatY = scale * (float)mat["SpecRepeatY"].AsReal();
  127. SpecularRotation = scale * (float)mat["SpecRotation"].AsReal();
  128. SpecularLightColor = mat["SpecColor"].AsColor4();
  129. SpecularLightExponent = (Byte)mat["SpecExp"].AsUInteger();
  130. EnvironmentIntensity = (Byte)mat["EnvIntensity"].AsUInteger();
  131. DiffuseAlphaMode = (Byte)mat["DiffuseAlphaMode"].AsUInteger();
  132. AlphaMaskCutoff = (Byte)mat["AlphaMaskCutoff"].AsUInteger();
  133. }
  134. public OSDMap toOSD()
  135. {
  136. OSDMap mat = new OSDMap();
  137. float scale = 10000f;
  138. mat["NormMap"] = NormalMapID;
  139. mat["NormOffsetX"] = (int) (scale * NormalOffsetX);
  140. mat["NormOffsetY"] = (int) (scale * NormalOffsetY);
  141. mat["NormRepeatX"] = (int) (scale * NormalRepeatX);
  142. mat["NormRepeatY"] = (int) (scale * NormalRepeatY);
  143. mat["NormRotation"] = (int) (scale * NormalRotation);
  144. mat["SpecMap"] = SpecularMapID;
  145. mat["SpecOffsetX"] = (int) (scale * SpecularOffsetX);
  146. mat["SpecOffsetY"] = (int) (scale * SpecularOffsetY);
  147. mat["SpecRepeatX"] = (int) (scale * SpecularRepeatX);
  148. mat["SpecRepeatY"] = (int) (scale * SpecularRepeatY);
  149. mat["SpecRotation"] = (int) (scale * SpecularRotation);
  150. mat["SpecColor"] = SpecularLightColor;
  151. mat["SpecExp"] = SpecularLightExponent;
  152. mat["EnvIntensity"] = EnvironmentIntensity;
  153. mat["DiffuseAlphaMode"] = DiffuseAlphaMode;
  154. mat["AlphaMaskCutoff"] = AlphaMaskCutoff;
  155. return mat;
  156. }
  157. }
  158. }