diff options
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | 225 |
1 files changed, 180 insertions, 45 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs index 4934ebd..7b7cce8 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | |||
@@ -41,8 +41,8 @@ using Mono.Addins; | |||
41 | using OpenSim.Framework; | 41 | using OpenSim.Framework; |
42 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
43 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
44 | using OpenSim.Region.PhysicsModules.SharedBase; | 44 | //using OpenSim.Region.PhysicsModules.SharedBase; |
45 | using OpenSim.Services.Interfaces; | 45 | //using OpenSim.Services.Interfaces; |
46 | 46 | ||
47 | using OpenMetaverse; | 47 | using OpenMetaverse; |
48 | using OpenMetaverse.Assets; | 48 | using OpenMetaverse.Assets; |
@@ -51,6 +51,7 @@ using OpenMetaverse.Rendering; | |||
51 | using OpenMetaverse.StructuredData; | 51 | using OpenMetaverse.StructuredData; |
52 | 52 | ||
53 | using WarpRenderer = global::Warp3D.Warp3D; | 53 | using WarpRenderer = global::Warp3D.Warp3D; |
54 | using System.Drawing.Drawing2D; | ||
54 | 55 | ||
55 | namespace OpenSim.Region.CoreModules.World.Warp3DMap | 56 | namespace OpenSim.Region.CoreModules.World.Warp3DMap |
56 | { | 57 | { |
@@ -76,10 +77,17 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
76 | private bool m_texturePrims = true; // true if should texture the rendered prims | 77 | private bool m_texturePrims = true; // true if should texture the rendered prims |
77 | private float m_texturePrimSize = 48f; // size of prim before we consider texturing it | 78 | private float m_texturePrimSize = 48f; // size of prim before we consider texturing it |
78 | private bool m_renderMeshes = false; // true if to render meshes rather than just bounding boxes | 79 | private bool m_renderMeshes = false; // true if to render meshes rather than just bounding boxes |
79 | 80 | private String m_cacheDirectory = ""; | |
80 | private bool m_Enabled = false; | 81 | private bool m_Enabled = false; |
81 | 82 | ||
82 | // private Bitmap lastImage = null; | 83 | // private bool m_enable_date = false; |
84 | // private bool m_enable_regionName = false; | ||
85 | private bool m_enable_regionPosition = false; | ||
86 | private bool m_enable_refreshEveryMonth = false; | ||
87 | // private bool m_enable_HostedBy = false; | ||
88 | // private String m_enable_HostedByText = ""; | ||
89 | |||
90 | // private Bitmap lastImage = null; | ||
83 | private DateTime lastImageTime = DateTime.MinValue; | 91 | private DateTime lastImageTime = DateTime.MinValue; |
84 | 92 | ||
85 | #region Region Module interface | 93 | #region Region Module interface |
@@ -106,7 +114,20 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
106 | = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize); | 114 | = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize); |
107 | m_renderMeshes | 115 | m_renderMeshes |
108 | = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes); | 116 | = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes); |
109 | } | 117 | m_cacheDirectory |
118 | = Util.GetConfigVarFromSections<string>(m_config, "CacheDirectory", configSections, System.IO.Path.Combine(Util.cacheDir(), "MapImageCache")); | ||
119 | |||
120 | |||
121 | // m_enable_date = Util.GetConfigVarFromSections<bool>(m_config, "enableDate", configSections, false); | ||
122 | // m_enable_regionName = Util.GetConfigVarFromSections<bool>(m_config, "enableName", configSections, false); | ||
123 | m_enable_regionPosition = Util.GetConfigVarFromSections<bool>(m_config, "enablePosition", configSections, false); | ||
124 | m_enable_refreshEveryMonth = Util.GetConfigVarFromSections<bool>(m_config, "RefreshEveryMonth", configSections, true); | ||
125 | // m_enable_HostedBy = Util.GetConfigVarFromSections<bool>(m_config, "enableHostedBy", configSections, false); | ||
126 | // m_enable_HostedByText = Util.GetConfigVarFromSections<String>(m_config, "HosterText", configSections, String.Empty); | ||
127 | |||
128 | if (!Directory.Exists(m_cacheDirectory)) | ||
129 | Directory.CreateDirectory(m_cacheDirectory); | ||
130 | } | ||
110 | 131 | ||
111 | public void AddRegion(Scene scene) | 132 | public void AddRegion(Scene scene) |
112 | { | 133 | { |
@@ -149,39 +170,138 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
149 | #endregion | 170 | #endregion |
150 | 171 | ||
151 | #region IMapImageGenerator Members | 172 | #region IMapImageGenerator Members |
152 | 173 | /* | |
153 | public Bitmap CreateMapTile() | 174 | public static string fillInt(int _i, int _l) |
154 | { | 175 | { |
155 | /* this must be on all map, not just its image | 176 | String _return = _i.ToString(); |
156 | if ((DateTime.Now - lastImageTime).TotalSeconds < 3600) | 177 | |
178 | while(_return.Length < _l) | ||
157 | { | 179 | { |
158 | return (Bitmap)lastImage.Clone(); | 180 | _return = 0 + _return; |
159 | } | 181 | } |
160 | */ | ||
161 | 182 | ||
162 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); | 183 | return _return; |
163 | if (renderers.Count > 0) | 184 | } |
185 | |||
186 | public static int getCurrentUnixTime() | ||
187 | { | ||
188 | return (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; | ||
189 | } | ||
190 | |||
191 | public static String unixTimeToDateString(int unixTime) | ||
192 | { | ||
193 | DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); | ||
194 | long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond); | ||
195 | DateTime _date = new DateTime(unixStart.Ticks + unixTimeStampInTicks, System.DateTimeKind.Utc); | ||
196 | |||
197 | return fillInt(_date.Day, 2) + "." + fillInt(_date.Month, 2) + "." + fillInt(_date.Year, 4) + " " + fillInt(_date.Hour, 2) + ":" + fillInt(_date.Minute, 2); | ||
198 | } | ||
199 | |||
200 | private void writeDateOnMap(ref Bitmap _map) | ||
201 | { | ||
202 | RectangleF rectf = new RectangleF(2, 1, 200, 25); | ||
203 | |||
204 | Graphics g = Graphics.FromImage(_map); | ||
205 | g.SmoothingMode = SmoothingMode.AntiAlias; | ||
206 | g.InterpolationMode = InterpolationMode.HighQualityBicubic; | ||
207 | g.PixelOffsetMode = PixelOffsetMode.HighQuality; | ||
208 | g.DrawString(unixTimeToDateString(getCurrentUnixTime()), new Font("Arial", 8), Brushes.White, rectf); | ||
209 | g.Flush(); | ||
210 | } | ||
211 | |||
212 | private void writeNameOnMap(ref Bitmap _map) | ||
213 | { | ||
214 | RectangleF rectf = new RectangleF(2, m_scene.RegionInfo.RegionSizeX - 15, 200, 25); | ||
215 | |||
216 | Graphics g = Graphics.FromImage(_map); | ||
217 | g.SmoothingMode = SmoothingMode.AntiAlias; | ||
218 | g.InterpolationMode = InterpolationMode.HighQualityBicubic; | ||
219 | g.PixelOffsetMode = PixelOffsetMode.HighQuality; | ||
220 | g.DrawString(m_scene.Name, new Font("Arial", 8), Brushes.White, rectf); | ||
221 | g.Flush(); | ||
222 | } | ||
223 | */ | ||
224 | private void writePositionOnMap(ref Bitmap _map) | ||
225 | { | ||
226 | RectangleF rectf = new RectangleF(m_scene.RegionInfo.RegionSizeY - 75, m_scene.RegionInfo.RegionSizeX - 15, 80, 25); | ||
227 | |||
228 | Graphics g = Graphics.FromImage(_map); | ||
229 | g.SmoothingMode = SmoothingMode.AntiAlias; | ||
230 | g.InterpolationMode = InterpolationMode.HighQualityBicubic; | ||
231 | g.PixelOffsetMode = PixelOffsetMode.HighQuality; | ||
232 | g.DrawString("<" + m_scene.RegionInfo.RegionLocX + " " + m_scene.RegionInfo.RegionLocY + ">", new Font("Arial", 8), Brushes.White, rectf); | ||
233 | g.Flush(); | ||
234 | } | ||
235 | /* | ||
236 | private void writeHostedByOnMap(ref Bitmap _map) | ||
237 | { | ||
238 | RectangleF rectf = new RectangleF(2, m_scene.RegionInfo.RegionSizeX - 15, 200, 25); | ||
239 | |||
240 | Graphics g = Graphics.FromImage(_map); | ||
241 | g.SmoothingMode = SmoothingMode.AntiAlias; | ||
242 | g.InterpolationMode = InterpolationMode.HighQualityBicubic; | ||
243 | g.PixelOffsetMode = PixelOffsetMode.HighQuality; | ||
244 | g.DrawString(m_enable_HostedByText, new Font("Arial", 8), Brushes.Gray, rectf); | ||
245 | g.Flush(); | ||
246 | } | ||
247 | */ | ||
248 | public Bitmap CreateMapTile() | ||
249 | { | ||
250 | if ((File.GetCreationTime(System.IO.Path.Combine(m_cacheDirectory, m_scene.RegionInfo.RegionID + ".bmp")).Month != DateTime.Now.Month) && m_enable_refreshEveryMonth == true) | ||
251 | File.Delete(System.IO.Path.Combine(m_cacheDirectory, m_scene.RegionInfo.RegionID + ".bmp")); | ||
252 | |||
253 | if(File.Exists(System.IO.Path.Combine(m_cacheDirectory, m_scene.RegionInfo.RegionID + ".bmp"))) | ||
164 | { | 254 | { |
165 | m_primMesher = RenderingLoader.LoadRenderer(renderers[0]); | 255 | return new Bitmap(System.IO.Path.Combine(m_cacheDirectory, m_scene.RegionInfo.RegionID + ".bmp")); |
166 | } | 256 | } |
257 | else | ||
258 | { | ||
259 | /* this must be on all map, not just its image | ||
260 | if ((DateTime.Now - lastImageTime).TotalSeconds < 3600) | ||
261 | { | ||
262 | return (Bitmap)lastImage.Clone(); | ||
263 | } | ||
264 | */ | ||
167 | 265 | ||
168 | Vector3 camPos = new Vector3( | 266 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); |
169 | m_scene.RegionInfo.RegionSizeX / 2 - 0.5f, | 267 | if (renderers.Count > 0) |
170 | m_scene.RegionInfo.RegionSizeY / 2 - 0.5f, | 268 | { |
171 | 221.7025033688163f); | 269 | m_primMesher = RenderingLoader.LoadRenderer(renderers[0]); |
172 | // Viewport viewing down onto the region | 270 | } |
173 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, | 271 | |
174 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, | 272 | Vector3 camPos = new Vector3( |
175 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY); | 273 | m_scene.RegionInfo.RegionSizeX / 2 - 0.5f, |
176 | 274 | m_scene.RegionInfo.RegionSizeY / 2 - 0.5f, | |
177 | Bitmap tile = CreateMapTile(viewport, false); | 275 | 221.7025033688163f); |
178 | m_primMesher = null; | 276 | // Viewport viewing down onto the region |
179 | return tile; | 277 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, |
180 | /* | 278 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, |
181 | lastImage = tile; | 279 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY); |
182 | lastImageTime = DateTime.Now; | 280 | |
183 | return (Bitmap)lastImage.Clone(); | 281 | Bitmap tile = CreateMapTile(viewport, false); |
184 | */ | 282 | |
283 | // if (m_enable_date) | ||
284 | // writeDateOnMap(ref tile); | ||
285 | |||
286 | // if (m_enable_regionName) | ||
287 | // writeNameOnMap(ref tile); | ||
288 | |||
289 | if (m_enable_regionPosition) | ||
290 | writePositionOnMap(ref tile); | ||
291 | |||
292 | // if (m_enable_HostedBy) | ||
293 | // writeHostedByOnMap(ref tile); | ||
294 | |||
295 | tile.Save(System.IO.Path.Combine(m_cacheDirectory, m_scene.RegionInfo.RegionID + ".bmp")); | ||
296 | m_primMesher = null; | ||
297 | return tile; | ||
298 | |||
299 | /* | ||
300 | lastImage = tile; | ||
301 | lastImageTime = DateTime.Now; | ||
302 | return (Bitmap)lastImage.Clone(); | ||
303 | */ | ||
304 | } | ||
185 | } | 305 | } |
186 | 306 | ||
187 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) | 307 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) |
@@ -271,16 +391,20 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
271 | { | 391 | { |
272 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; | 392 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; |
273 | 393 | ||
274 | renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); | ||
275 | renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX * 0.5f - 0.5f, | ||
276 | waterHeight, | ||
277 | m_scene.RegionInfo.RegionSizeY * 0.5f - 0.5f); | ||
278 | |||
279 | warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); | 394 | warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); |
280 | waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif | 395 | waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif |
281 | waterColorMaterial.setTransparency((byte)((1f - WATER_COLOR.A) * 255f)); | 396 | waterColorMaterial.setTransparency((byte)((1f - WATER_COLOR.A) * 255f)); |
282 | renderer.Scene.addMaterial("WaterColor", waterColorMaterial); | 397 | renderer.Scene.addMaterial("WaterColor", waterColorMaterial); |
283 | renderer.SetObjectMaterial("Water", "WaterColor"); | 398 | |
399 | for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / 256; x++) | ||
400 | { | ||
401 | for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / 256; y++) | ||
402 | { | ||
403 | renderer.AddPlane("Water-" + x + "-" + y, 256); | ||
404 | renderer.Scene.sceneobject("Water-" + x + "-" + y).setPos(256 * x, waterHeight, 256 * y); | ||
405 | renderer.SetObjectMaterial("Water-" + x + "-" + y, "WaterColor"); | ||
406 | } | ||
407 | } | ||
284 | } | 408 | } |
285 | 409 | ||
286 | // Add a terrain to the renderer. | 410 | // Add a terrain to the renderer. |
@@ -428,14 +552,25 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
428 | else // It's sculptie | 552 | else // It's sculptie |
429 | { | 553 | { |
430 | IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); | 554 | IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); |
431 | if(imgDecoder != null) | 555 | if (imgDecoder != null) |
432 | { | 556 | { |
433 | Image sculpt = imgDecoder.DecodeToImage(sculptAsset); | 557 | try |
434 | if(sculpt != null) | 558 | { |
559 | Image sculpt = imgDecoder.DecodeToImage(sculptAsset); | ||
560 | if (sculpt != null) | ||
561 | { | ||
562 | renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, | ||
563 | DetailLevel.Medium); | ||
564 | sculpt.Dispose(); | ||
565 | } | ||
566 | } | ||
567 | catch (Exception e) | ||
435 | { | 568 | { |
436 | renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim,(Bitmap)sculpt, | 569 | Vector3 objectPos = prim.ParentGroup.RootPart.AbsolutePosition; |
437 | DetailLevel.Medium); | 570 | //// TODO - print out owner of SceneObjectPart prim. |
438 | sculpt.Dispose(); | 571 | m_log.Error(string.Format("[WARP 3D IMAGE MODULE]: Failed to decode asset {0} @ {1},{2},{3} - {4}.", |
572 | omvPrim.Sculpt.SculptTexture, objectPos.X, objectPos.Y, objectPos.Z, | ||
573 | prim.ParentGroup.RootPart.Name)); | ||
439 | } | 574 | } |
440 | } | 575 | } |
441 | } | 576 | } |
@@ -615,7 +750,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
615 | } | 750 | } |
616 | catch (Exception e) | 751 | catch (Exception e) |
617 | { | 752 | { |
618 | m_log.Warn(string.Format("[WARP 3D IMAGE MODULE]: Failed to decode asset {0}, exception ", id), e); | 753 | m_log.Debug(string.Format("[WARP 3D IMAGE MODULE]: Failed to decode asset {0}, exception ", id)); |
619 | } | 754 | } |
620 | } | 755 | } |
621 | 756 | ||
@@ -733,7 +868,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
733 | } | 868 | } |
734 | catch (Exception ex) | 869 | catch (Exception ex) |
735 | { | 870 | { |
736 | m_log.WarnFormat( | 871 | m_log.DebugFormat( |
737 | "[WARP 3D IMAGE MODULE]: Error decoding JPEG2000 texture {0} ({1} bytes): {2}", | 872 | "[WARP 3D IMAGE MODULE]: Error decoding JPEG2000 texture {0} ({1} bytes): {2}", |
738 | textureID, j2kData.Length, ex.Message); | 873 | textureID, j2kData.Length, ex.Message); |
739 | 874 | ||