diff options
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SOPMaterial.cs | 82 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 88 |
2 files changed, 170 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SOPMaterial.cs b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs index 651c52e..0e9f228 100644 --- a/OpenSim/Region/Framework/Scenes/SOPMaterial.cs +++ b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using OpenMetaverse; | 30 | using OpenMetaverse; |
31 | using OpenMetaverse.StructuredData; | ||
31 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
32 | 33 | ||
33 | namespace OpenSim.Region.Framework.Scenes | 34 | namespace OpenSim.Region.Framework.Scenes |
@@ -90,6 +91,87 @@ namespace OpenSim.Region.Framework.Scenes | |||
90 | else | 91 | else |
91 | return 0; | 92 | return 0; |
92 | } | 93 | } |
94 | } | ||
95 | |||
96 | public class FaceMaterial | ||
97 | { | ||
98 | public UUID ID; | ||
99 | public UUID NormalMapID = UUID.Zero; | ||
100 | public float NormalOffsetX = 1.0f; | ||
101 | public float NormalOffsetY = 1.0f; | ||
102 | public float NormalRepeatX = 0.0f; | ||
103 | public float NormalRepeatY = 0.0f; | ||
104 | public float NormalRotation = 0.0f; | ||
105 | |||
106 | public UUID SpecularMapID = UUID.Zero; | ||
107 | public float SpecularOffsetX = 1.0f; | ||
108 | public float SpecularOffsetY = 1.0f; | ||
109 | public float SpecularRepeatX = 0.0f; | ||
110 | public float SpecularRepeatY = 0.0f; | ||
111 | public float SpecularRotation = 0.0f; | ||
112 | |||
113 | public Color4 SpecularLightColor = new Color4(255,255,255,255); | ||
114 | public Byte SpecularLightExponent = 51; | ||
115 | public Byte EnvironmentIntensity = 0; | ||
116 | public Byte DiffuseAlphaMode = 1; | ||
117 | public Byte AlphaMaskCutoff = 0; | ||
118 | |||
119 | public FaceMaterial() | ||
120 | { } | ||
121 | |||
122 | public FaceMaterial(UUID pID, OSDMap mat) | ||
123 | { | ||
124 | ID = pID; | ||
125 | if(mat == null) | ||
126 | return; | ||
127 | float scale = 0.0001f; | ||
128 | NormalMapID = mat["NormMap"].AsUUID(); | ||
129 | NormalOffsetX = scale * (float)mat["NormOffsetX"].AsReal(); | ||
130 | NormalOffsetY = scale * (float)mat["NormOffsetY"].AsReal(); | ||
131 | NormalRepeatX = scale * (float)mat["NormRepeatX"].AsReal(); | ||
132 | NormalRepeatY = scale * (float)mat["NormRepeatY"].AsReal(); | ||
133 | NormalRotation = scale * (float)mat["NormRotation"].AsReal(); | ||
134 | |||
135 | SpecularMapID = mat["SpecMap"].AsUUID(); | ||
136 | SpecularOffsetX = scale * (float)mat["SpecOffsetX"].AsReal(); | ||
137 | SpecularOffsetY = scale * (float)mat["SpecOffsetY"].AsReal(); | ||
138 | SpecularRepeatX = scale * (float)mat["SpecRepeatX"].AsReal(); | ||
139 | SpecularRepeatY = scale * (float)mat["SpecRepeatY"].AsReal(); | ||
140 | SpecularRotation = scale * (float)mat["SpecRotation"].AsReal(); | ||
93 | 141 | ||
142 | SpecularLightColor = mat["SpecColor"].AsColor4(); | ||
143 | SpecularLightExponent = (Byte)mat["SpecExp"].AsUInteger(); | ||
144 | EnvironmentIntensity = (Byte)mat["EnvIntensity"].AsUInteger(); | ||
145 | DiffuseAlphaMode = (Byte)mat["DiffuseAlphaMode"].AsUInteger(); | ||
146 | AlphaMaskCutoff = (Byte)mat["AlphaMaskCutoff"].AsUInteger(); | ||
147 | } | ||
148 | |||
149 | public OSDMap toOSD() | ||
150 | { | ||
151 | OSDMap mat = new OSDMap(); | ||
152 | float scale = 10000f; | ||
153 | |||
154 | mat["NormMap"] = NormalMapID; | ||
155 | mat["NormOffsetX"] = (int) (scale * NormalOffsetX); | ||
156 | mat["NormOffsetY"] = (int) (scale * NormalOffsetY); | ||
157 | mat["NormRepeatX"] = (int) (scale * NormalRepeatX); | ||
158 | mat["NormRepeatY"] = (int) (scale * NormalRepeatY); | ||
159 | mat["NormRotation"] = (int) (scale * NormalRotation); | ||
160 | |||
161 | mat["SpecMap"] = SpecularMapID; | ||
162 | mat["SpecOffsetX"] = (int) (scale * SpecularOffsetX); | ||
163 | mat["SpecOffsetY"] = (int) (scale * SpecularOffsetY); | ||
164 | mat["SpecRepeatX"] = (int) (scale * SpecularRepeatX); | ||
165 | mat["SpecRepeatY"] = (int) (scale * SpecularRepeatY); | ||
166 | mat["SpecRotation"] = (int) (scale * SpecularRotation); | ||
167 | |||
168 | mat["SpecColor"] = SpecularLightColor; | ||
169 | mat["SpecExp"] = SpecularLightExponent; | ||
170 | mat["EnvIntensity"] = EnvironmentIntensity; | ||
171 | mat["DiffuseAlphaMode"] = DiffuseAlphaMode; | ||
172 | mat["AlphaMaskCutoff"] = AlphaMaskCutoff; | ||
173 | |||
174 | return mat; | ||
175 | } | ||
94 | } | 176 | } |
95 | } \ No newline at end of file | 177 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 31be2fb..6cbdf0a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -11298,6 +11298,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11298 | } | 11298 | } |
11299 | break; | 11299 | break; |
11300 | 11300 | ||
11301 | case (int)ScriptBaseClass.PRIM_NORMAL: | ||
11302 | case (int)ScriptBaseClass.PRIM_SPECULAR: | ||
11303 | case (int)ScriptBaseClass.PRIM_ALPHA_MODE: | ||
11304 | if (remain < 1) | ||
11305 | return new LSL_List(); | ||
11306 | |||
11307 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
11308 | tex = part.Shape.Textures; | ||
11309 | if (face == ScriptBaseClass.ALL_SIDES) | ||
11310 | { | ||
11311 | for (face = 0; face < GetNumberOfSides(part); face++) | ||
11312 | { | ||
11313 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | ||
11314 | getLSLFaceMaterial(ref res, code, texface); | ||
11315 | } | ||
11316 | } | ||
11317 | else | ||
11318 | { | ||
11319 | if (face >= 0 && face < GetNumberOfSides(part)) | ||
11320 | { | ||
11321 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | ||
11322 | getLSLFaceMaterial(ref res, code, texface); | ||
11323 | } | ||
11324 | } | ||
11325 | break; | ||
11326 | |||
11301 | case (int)ScriptBaseClass.PRIM_LINK_TARGET: | 11327 | case (int)ScriptBaseClass.PRIM_LINK_TARGET: |
11302 | 11328 | ||
11303 | // TODO: Should be issuing a runtime script warning in this case. | 11329 | // TODO: Should be issuing a runtime script warning in this case. |
@@ -11311,6 +11337,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11311 | return new LSL_List(); | 11337 | return new LSL_List(); |
11312 | } | 11338 | } |
11313 | 11339 | ||
11340 | private void getLSLFaceMaterial(ref LSL_List res, int code, Primitive.TextureEntryFace texface) | ||
11341 | { | ||
11342 | UUID matID = texface.MaterialID; | ||
11343 | if(matID != UUID.Zero) | ||
11344 | { | ||
11345 | AssetBase MatAsset = World.AssetService.Get(matID.ToString()); | ||
11346 | if(MatAsset != null) | ||
11347 | { | ||
11348 | Byte[] data = MatAsset.Data; | ||
11349 | OSDMap osdmat = (OSDMap)OSDParser.DeserializeLLSDXml(data); | ||
11350 | if(osdmat != null && osdmat.ContainsKey("NormMap")) | ||
11351 | { | ||
11352 | FaceMaterial mat = new FaceMaterial(matID, osdmat); | ||
11353 | if(code == ScriptBaseClass.PRIM_NORMAL) | ||
11354 | { | ||
11355 | res.Add(new LSL_String(mat.NormalMapID.ToString())); | ||
11356 | res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0)); | ||
11357 | res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0)); | ||
11358 | res.Add(new LSL_Float(mat.NormalRotation)); | ||
11359 | } | ||
11360 | else if(code == ScriptBaseClass.PRIM_SPECULAR ) | ||
11361 | { | ||
11362 | res.Add(new LSL_String(mat.SpecularMapID.ToString())); | ||
11363 | res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0)); | ||
11364 | res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0)); | ||
11365 | res.Add(new LSL_Vector(mat.SpecularLightColor.R, mat.SpecularLightColor.G, mat.SpecularLightColor.B)); | ||
11366 | res.Add(new LSL_Integer(mat.SpecularLightExponent)); | ||
11367 | res.Add(new LSL_Integer(mat.EnvironmentIntensity)); | ||
11368 | } | ||
11369 | else if(code == ScriptBaseClass.PRIM_ALPHA_MODE) | ||
11370 | { | ||
11371 | res.Add(new LSL_Integer(mat.DiffuseAlphaMode)); | ||
11372 | res.Add(new LSL_Integer(mat.AlphaMaskCutoff)); | ||
11373 | } | ||
11374 | return; | ||
11375 | } | ||
11376 | } | ||
11377 | matID = UUID.Zero; | ||
11378 | } | ||
11379 | if(matID == UUID.Zero) | ||
11380 | { | ||
11381 | if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR ) | ||
11382 | { | ||
11383 | res.Add(new LSL_String(UUID.Zero.ToString())); | ||
11384 | res.Add(new LSL_Vector(1.0, 1.0, 0)); | ||
11385 | res.Add(new LSL_Vector(0, 0, 0)); | ||
11386 | res.Add(new LSL_Float(0)); | ||
11387 | |||
11388 | if(code == (int)ScriptBaseClass.PRIM_SPECULAR) | ||
11389 | { | ||
11390 | res.Add(new LSL_Vector(1.0, 1.0, 1.0)); | ||
11391 | res.Add(new LSL_Integer(51)); | ||
11392 | res.Add(new LSL_Integer(0)); | ||
11393 | } | ||
11394 | } | ||
11395 | else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE) | ||
11396 | { | ||
11397 | res.Add(new LSL_Integer(1)); | ||
11398 | res.Add(new LSL_Integer(0)); | ||
11399 | } | ||
11400 | } | ||
11401 | } | ||
11314 | 11402 | ||
11315 | public LSL_List llGetPrimMediaParams(int face, LSL_List rules) | 11403 | public LSL_List llGetPrimMediaParams(int face, LSL_List rules) |
11316 | { | 11404 | { |