diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SOPMaterial.cs | 219 |
1 files changed, 192 insertions, 27 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SOPMaterial.cs b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs index d38ef61..e4b9380 100644 --- a/OpenSim/Region/Framework/Scenes/SOPMaterial.cs +++ b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs | |||
@@ -26,10 +26,12 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Text; |
30 | using System.Runtime.InteropServices; | ||
31 | using System.Security.Cryptography; // for computing md5 hash | ||
32 | using OpenSim.Framework; | ||
30 | using OpenMetaverse; | 33 | using OpenMetaverse; |
31 | using OpenMetaverse.StructuredData; | 34 | using OpenMetaverse.StructuredData; |
32 | using OpenSim.Framework; | ||
33 | 35 | ||
34 | namespace OpenSim.Region.Framework.Scenes | 36 | namespace OpenSim.Region.Framework.Scenes |
35 | { | 37 | { |
@@ -93,38 +95,74 @@ namespace OpenSim.Region.Framework.Scenes | |||
93 | } | 95 | } |
94 | } | 96 | } |
95 | 97 | ||
98 | [StructLayout(LayoutKind.Sequential)] | ||
96 | public class FaceMaterial | 99 | public class FaceMaterial |
97 | { | 100 | { |
98 | public UUID ID; | 101 | // ll material data |
99 | public UUID NormalMapID = UUID.Zero; | 102 | public byte DiffuseAlphaMode = 1; |
100 | public float NormalOffsetX = 0.0f; | 103 | public byte AlphaMaskCutoff = 0; |
101 | public float NormalOffsetY = 0.0f; | 104 | public byte SpecularLightExponent = 51; |
102 | public float NormalRepeatX = 1.0f; | 105 | public byte EnvironmentIntensity = 0; |
103 | public float NormalRepeatY = 1.0f; | 106 | // need to have 4 bytes here |
104 | public float NormalRotation = 0.0f; | 107 | public float NormalOffsetX = 0.0f; |
105 | 108 | public float NormalOffsetY = 0.0f; | |
106 | public UUID SpecularMapID = UUID.Zero; | 109 | public float NormalRepeatX = 1.0f; |
107 | public float SpecularOffsetX = 0.0f; | 110 | public float NormalRepeatY = 1.0f; |
108 | public float SpecularOffsetY = 0.0f; | 111 | public float NormalRotation = 0.0f; |
109 | public float SpecularRepeatX = 1.0f; | 112 | |
110 | public float SpecularRepeatY = 1.0f; | 113 | public float SpecularOffsetX = 0.0f; |
111 | public float SpecularRotation = 0.0f; | 114 | public float SpecularOffsetY = 0.0f; |
112 | 115 | public float SpecularRepeatX = 1.0f; | |
113 | public Color4 SpecularLightColor = new Color4(255,255,255,255); | 116 | public float SpecularRepeatY = 1.0f; |
114 | public Byte SpecularLightExponent = 51; | 117 | public float SpecularRotation = 0.0f; |
115 | public Byte EnvironmentIntensity = 0; | 118 | |
116 | public Byte DiffuseAlphaMode = 1; | 119 | public byte SpecularLightColorR = 255; |
117 | public Byte AlphaMaskCutoff = 0; | 120 | public byte SpecularLightColorG = 255; |
121 | public byte SpecularLightColorB = 255; | ||
122 | public byte SpecularLightColorA = 255; | ||
123 | // data size 12 ints so far | ||
124 | public UUID NormalMapID = UUID.Zero; | ||
125 | public UUID SpecularMapID = UUID.Zero; | ||
126 | |||
127 | // other data | ||
128 | public UUID ID; | ||
129 | private int inthash; | ||
130 | private bool validinthash; | ||
118 | 131 | ||
119 | public FaceMaterial() | 132 | public FaceMaterial() |
120 | { } | 133 | { } |
121 | 134 | ||
122 | public FaceMaterial(UUID pID, OSDMap mat) | 135 | public FaceMaterial(FaceMaterial other) |
136 | { | ||
137 | if(other == null) | ||
138 | return; | ||
139 | |||
140 | DiffuseAlphaMode = other.DiffuseAlphaMode; | ||
141 | AlphaMaskCutoff = other.AlphaMaskCutoff; | ||
142 | SpecularLightExponent = other.SpecularLightExponent; | ||
143 | EnvironmentIntensity = other.EnvironmentIntensity; | ||
144 | NormalOffsetX = other.NormalOffsetX; | ||
145 | NormalOffsetY = other.NormalOffsetY; | ||
146 | NormalRepeatX = other.NormalRepeatX; | ||
147 | NormalRepeatY = other.NormalRepeatY; | ||
148 | NormalRotation = other.NormalRotation; | ||
149 | SpecularOffsetX = other.SpecularOffsetX; | ||
150 | SpecularOffsetY = other.SpecularOffsetY; | ||
151 | SpecularRepeatX = other.SpecularRepeatX; | ||
152 | SpecularRepeatY = other.SpecularRepeatY; | ||
153 | SpecularRotation = other.SpecularRotation; | ||
154 | SpecularLightColorR = other.SpecularLightColorR; | ||
155 | SpecularLightColorG = other.SpecularLightColorG; | ||
156 | SpecularLightColorB = other.SpecularLightColorB; | ||
157 | NormalMapID = other.NormalMapID; | ||
158 | SpecularMapID = other.SpecularMapID; | ||
159 | } | ||
160 | |||
161 | public FaceMaterial(OSDMap mat) | ||
123 | { | 162 | { |
124 | ID = pID; | ||
125 | if(mat == null) | 163 | if(mat == null) |
126 | return; | 164 | return; |
127 | float scale = 0.0001f; | 165 | const float scale = 0.0001f; |
128 | NormalMapID = mat["NormMap"].AsUUID(); | 166 | NormalMapID = mat["NormMap"].AsUUID(); |
129 | NormalOffsetX = scale * (float)mat["NormOffsetX"].AsReal(); | 167 | NormalOffsetX = scale * (float)mat["NormOffsetX"].AsReal(); |
130 | NormalOffsetY = scale * (float)mat["NormOffsetY"].AsReal(); | 168 | NormalOffsetY = scale * (float)mat["NormOffsetY"].AsReal(); |
@@ -138,14 +176,88 @@ namespace OpenSim.Region.Framework.Scenes | |||
138 | SpecularRepeatX = scale * (float)mat["SpecRepeatX"].AsReal(); | 176 | SpecularRepeatX = scale * (float)mat["SpecRepeatX"].AsReal(); |
139 | SpecularRepeatY = scale * (float)mat["SpecRepeatY"].AsReal(); | 177 | SpecularRepeatY = scale * (float)mat["SpecRepeatY"].AsReal(); |
140 | SpecularRotation = scale * (float)mat["SpecRotation"].AsReal(); | 178 | SpecularRotation = scale * (float)mat["SpecRotation"].AsReal(); |
179 | |||
180 | Color4 SpecularLightColortmp = mat["SpecColor"].AsColor4(); // we can read as color4 | ||
181 | SpecularLightColorR = (byte)(SpecularLightColortmp.R); | ||
182 | SpecularLightColorG = (byte)(SpecularLightColortmp.G); | ||
183 | SpecularLightColorB = (byte)(SpecularLightColortmp.B); | ||
141 | 184 | ||
142 | SpecularLightColor = mat["SpecColor"].AsColor4(); | ||
143 | SpecularLightExponent = (Byte)mat["SpecExp"].AsUInteger(); | 185 | SpecularLightExponent = (Byte)mat["SpecExp"].AsUInteger(); |
144 | EnvironmentIntensity = (Byte)mat["EnvIntensity"].AsUInteger(); | 186 | EnvironmentIntensity = (Byte)mat["EnvIntensity"].AsUInteger(); |
145 | DiffuseAlphaMode = (Byte)mat["DiffuseAlphaMode"].AsUInteger(); | 187 | DiffuseAlphaMode = (Byte)mat["DiffuseAlphaMode"].AsUInteger(); |
146 | AlphaMaskCutoff = (Byte)mat["AlphaMaskCutoff"].AsUInteger(); | 188 | AlphaMaskCutoff = (Byte)mat["AlphaMaskCutoff"].AsUInteger(); |
147 | } | 189 | } |
148 | 190 | ||
191 | public void genID() | ||
192 | { | ||
193 | string lslx = toLLSDxml(); | ||
194 | Byte[] data = System.Text.Encoding.ASCII.GetBytes(lslx); | ||
195 | using (var md5 = MD5.Create()) | ||
196 | ID = new UUID(md5.ComputeHash(data), 0); | ||
197 | } | ||
198 | |||
199 | public unsafe override int GetHashCode() | ||
200 | { | ||
201 | if(!validinthash) | ||
202 | { | ||
203 | unchecked | ||
204 | { | ||
205 | // if you don't like this, don't read... | ||
206 | int* ptr; | ||
207 | fixed(byte* ptrbase = &DiffuseAlphaMode) | ||
208 | { | ||
209 | ptr = (int*)ptrbase; | ||
210 | inthash = *ptr; | ||
211 | for(int i = 0; i < 11; i++) | ||
212 | inthash ^= *ptr++; | ||
213 | } | ||
214 | fixed(Guid* ptrbase = &NormalMapID.Guid) | ||
215 | { | ||
216 | ptr = (int*)ptrbase; | ||
217 | for(int i = 0; i < 16; i++) | ||
218 | inthash ^= ptr[i]; | ||
219 | } | ||
220 | fixed(Guid* ptrbase = &SpecularMapID.Guid) | ||
221 | { | ||
222 | ptr = (int*)ptrbase; | ||
223 | for(int i = 0; i < 16; i++) | ||
224 | inthash ^= ptr[i]; | ||
225 | } | ||
226 | } | ||
227 | validinthash = true; | ||
228 | } | ||
229 | return inthash; | ||
230 | } | ||
231 | |||
232 | public override bool Equals(Object o) | ||
233 | { | ||
234 | if(o == null || !(o is FaceMaterial)) | ||
235 | return false; | ||
236 | |||
237 | FaceMaterial other = (FaceMaterial)o; | ||
238 | return ( | ||
239 | DiffuseAlphaMode == other.DiffuseAlphaMode | ||
240 | && AlphaMaskCutoff == other.AlphaMaskCutoff | ||
241 | && SpecularLightExponent == other.SpecularLightExponent | ||
242 | && EnvironmentIntensity == other.EnvironmentIntensity | ||
243 | && NormalMapID == other.NormalMapID | ||
244 | && NormalOffsetX == other.NormalOffsetX | ||
245 | && NormalOffsetY == other.NormalOffsetY | ||
246 | && NormalRepeatX == other.NormalRepeatX | ||
247 | && NormalRepeatY == other.NormalRepeatY | ||
248 | && NormalRotation == other.NormalRotation | ||
249 | && SpecularMapID == other.SpecularMapID | ||
250 | && SpecularOffsetX == other.SpecularOffsetX | ||
251 | && SpecularOffsetY == other.SpecularOffsetY | ||
252 | && SpecularRepeatX == other.SpecularRepeatX | ||
253 | && SpecularRepeatY == other.SpecularRepeatY | ||
254 | && SpecularRotation == other.SpecularRotation | ||
255 | && SpecularLightColorR == other.SpecularLightColorR | ||
256 | && SpecularLightColorG == other.SpecularLightColorG | ||
257 | && SpecularLightColorB == other.SpecularLightColorB | ||
258 | ); | ||
259 | } | ||
260 | |||
149 | public OSDMap toOSD() | 261 | public OSDMap toOSD() |
150 | { | 262 | { |
151 | OSDMap mat = new OSDMap(); | 263 | OSDMap mat = new OSDMap(); |
@@ -165,7 +277,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
165 | mat["SpecRepeatY"] = (int) (scale * SpecularRepeatY); | 277 | mat["SpecRepeatY"] = (int) (scale * SpecularRepeatY); |
166 | mat["SpecRotation"] = (int) (scale * SpecularRotation); | 278 | mat["SpecRotation"] = (int) (scale * SpecularRotation); |
167 | 279 | ||
168 | mat["SpecColor"] = SpecularLightColor; | 280 | OSDArray carray = new OSDArray(4); |
281 | carray.Add(SpecularLightColorR); | ||
282 | carray.Add(SpecularLightColorG); | ||
283 | carray.Add(SpecularLightColorB); | ||
284 | carray.Add(255); // solid color | ||
285 | mat["SpecColor"] = carray; | ||
169 | mat["SpecExp"] = SpecularLightExponent; | 286 | mat["SpecExp"] = SpecularLightExponent; |
170 | mat["EnvIntensity"] = EnvironmentIntensity; | 287 | mat["EnvIntensity"] = EnvironmentIntensity; |
171 | mat["DiffuseAlphaMode"] = DiffuseAlphaMode; | 288 | mat["DiffuseAlphaMode"] = DiffuseAlphaMode; |
@@ -173,5 +290,53 @@ namespace OpenSim.Region.Framework.Scenes | |||
173 | 290 | ||
174 | return mat; | 291 | return mat; |
175 | } | 292 | } |
293 | |||
294 | public string toLLSDxml(StringBuilder sb = null) | ||
295 | { | ||
296 | const float scale = 10000f; | ||
297 | bool fullLLSD = false; | ||
298 | if(sb == null) | ||
299 | { | ||
300 | |||
301 | sb = LLSDxmlEncode.Start(1024,false); | ||
302 | fullLLSD = true; | ||
303 | } | ||
304 | |||
305 | LLSDxmlEncode.AddMap(sb); | ||
306 | LLSDxmlEncode.AddElem("NormMap", NormalMapID, sb); | ||
307 | LLSDxmlEncode.AddElem("NormOffsetX", (int) (scale * NormalOffsetX + 0.5f), sb); | ||
308 | LLSDxmlEncode.AddElem("NormOffsetY", (int) (scale * NormalOffsetY + 0.5f), sb); | ||
309 | LLSDxmlEncode.AddElem("NormRepeatX", (int) (scale * NormalRepeatX + 0.5f), sb); | ||
310 | LLSDxmlEncode.AddElem("NormRepeatY", (int) (scale * NormalRepeatY + 0.5f), sb); | ||
311 | LLSDxmlEncode.AddElem("NormRotation", (int) (scale * NormalRotation + 0.5f), sb); | ||
312 | |||
313 | LLSDxmlEncode.AddElem("SpecMap", SpecularMapID, sb); | ||
314 | LLSDxmlEncode.AddElem("SpecOffsetX", (int) (scale * SpecularOffsetX + 0.5f), sb); | ||
315 | LLSDxmlEncode.AddElem("SpecOffsetY", (int) (scale * SpecularOffsetY + 0.5f), sb); | ||
316 | LLSDxmlEncode.AddElem("SpecRepeatX", (int) (scale * SpecularRepeatX + 0.5f), sb); | ||
317 | LLSDxmlEncode.AddElem("SpecRepeatY", (int) (scale * SpecularRepeatY + 0.5f), sb); | ||
318 | LLSDxmlEncode.AddElem("SpecRotation", (int) (scale * SpecularRotation + 0.5f), sb); | ||
319 | |||
320 | LLSDxmlEncode.AddArray("SpecColor", sb); | ||
321 | LLSDxmlEncode.AddElem(SpecularLightColorR, sb); | ||
322 | LLSDxmlEncode.AddElem(SpecularLightColorG, sb); | ||
323 | LLSDxmlEncode.AddElem(SpecularLightColorB, sb); | ||
324 | LLSDxmlEncode.AddElem(255, sb); | ||
325 | LLSDxmlEncode.AddEndArray(sb); | ||
326 | |||
327 | LLSDxmlEncode.AddElem("SpecExp", SpecularLightExponent, sb); | ||
328 | LLSDxmlEncode.AddElem("EnvIntensity", EnvironmentIntensity, sb); | ||
329 | LLSDxmlEncode.AddElem("DiffuseAlphaMode", DiffuseAlphaMode, sb); | ||
330 | LLSDxmlEncode.AddElem("AlphaMaskCutoff", AlphaMaskCutoff, sb); | ||
331 | |||
332 | LLSDxmlEncode.AddEndMap(sb); | ||
333 | |||
334 | if(fullLLSD) | ||
335 | { | ||
336 | return LLSDxmlEncode.End(sb); | ||
337 | } | ||
338 | else | ||
339 | return String.Empty; // ignored if appending | ||
340 | } | ||
176 | } | 341 | } |
177 | } \ No newline at end of file | 342 | } \ No newline at end of file |