diff options
Initial port of the Warp3D map tile renderer
Diffstat (limited to 'OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs | 588 |
1 files changed, 0 insertions, 588 deletions
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs deleted file mode 100644 index c83ac85..0000000 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs +++ /dev/null | |||
@@ -1,588 +0,0 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Drawing; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenMetaverse; | ||
35 | using OpenMetaverse.Imaging; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | |||
40 | namespace OpenSim.Region.CoreModules.World.WorldMap | ||
41 | { | ||
42 | public enum DrawRoutine | ||
43 | { | ||
44 | Rectangle, | ||
45 | Polygon, | ||
46 | Ellipse | ||
47 | } | ||
48 | |||
49 | public struct face | ||
50 | { | ||
51 | public Point[] pts; | ||
52 | } | ||
53 | |||
54 | public struct DrawStruct | ||
55 | { | ||
56 | public DrawRoutine dr; | ||
57 | public Rectangle rect; | ||
58 | public SolidBrush brush; | ||
59 | public face[] trns; | ||
60 | } | ||
61 | |||
62 | public class MapImageModule : IMapImageGenerator, IRegionModule | ||
63 | { | ||
64 | private static readonly ILog m_log = | ||
65 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
66 | |||
67 | private Scene m_scene; | ||
68 | private IConfigSource m_config; | ||
69 | private IMapTileTerrainRenderer terrainRenderer; | ||
70 | |||
71 | #region IMapImageGenerator Members | ||
72 | |||
73 | public Bitmap CreateMapTile(string gradientmap) | ||
74 | { | ||
75 | bool drawPrimVolume = true; | ||
76 | bool textureTerrain = false; | ||
77 | |||
78 | try | ||
79 | { | ||
80 | IConfig startupConfig = m_config.Configs["Startup"]; | ||
81 | drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", drawPrimVolume); | ||
82 | textureTerrain = startupConfig.GetBoolean("TextureOnMapTile", textureTerrain); | ||
83 | } | ||
84 | catch | ||
85 | { | ||
86 | m_log.Warn("[MAPTILE]: Failed to load StartupConfig"); | ||
87 | } | ||
88 | |||
89 | if (textureTerrain) | ||
90 | { | ||
91 | terrainRenderer = new TexturedMapTileRenderer(); | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | terrainRenderer = new ShadedMapTileRenderer(); | ||
96 | } | ||
97 | terrainRenderer.Initialise(m_scene, m_config); | ||
98 | |||
99 | Bitmap mapbmp = new Bitmap((int)Constants.RegionSize, (int)Constants.RegionSize, System.Drawing.Imaging.PixelFormat.Format24bppRgb); | ||
100 | //long t = System.Environment.TickCount; | ||
101 | //for (int i = 0; i < 10; ++i) { | ||
102 | terrainRenderer.TerrainToBitmap(mapbmp); | ||
103 | //} | ||
104 | //t = System.Environment.TickCount - t; | ||
105 | //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t); | ||
106 | |||
107 | |||
108 | if (drawPrimVolume) | ||
109 | { | ||
110 | DrawObjectVolume(m_scene, mapbmp); | ||
111 | } | ||
112 | |||
113 | return mapbmp; | ||
114 | } | ||
115 | |||
116 | public byte[] WriteJpeg2000Image(string gradientmap) | ||
117 | { | ||
118 | try | ||
119 | { | ||
120 | using (Bitmap mapbmp = CreateMapTile(gradientmap)) | ||
121 | return OpenJPEG.EncodeFromImage(mapbmp, true); | ||
122 | } | ||
123 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
124 | { | ||
125 | m_log.Error("Failed generating terrain map: " + e); | ||
126 | } | ||
127 | |||
128 | return null; | ||
129 | } | ||
130 | |||
131 | #endregion | ||
132 | |||
133 | #region IRegionModule Members | ||
134 | |||
135 | public void Initialise(Scene scene, IConfigSource source) | ||
136 | { | ||
137 | m_scene = scene; | ||
138 | m_config = source; | ||
139 | |||
140 | IConfig startupConfig = m_config.Configs["Startup"]; | ||
141 | if (startupConfig.GetString("MapImageModule", "MapImageModule") != | ||
142 | "MapImageModule") | ||
143 | return; | ||
144 | |||
145 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); | ||
146 | } | ||
147 | |||
148 | public void PostInitialise() | ||
149 | { | ||
150 | } | ||
151 | |||
152 | public void Close() | ||
153 | { | ||
154 | } | ||
155 | |||
156 | public string Name | ||
157 | { | ||
158 | get { return "MapImageModule"; } | ||
159 | } | ||
160 | |||
161 | public bool IsSharedModule | ||
162 | { | ||
163 | get { return false; } | ||
164 | } | ||
165 | |||
166 | #endregion | ||
167 | |||
168 | // TODO: unused: | ||
169 | // private void ShadeBuildings(Bitmap map) | ||
170 | // { | ||
171 | // lock (map) | ||
172 | // { | ||
173 | // lock (m_scene.Entities) | ||
174 | // { | ||
175 | // foreach (EntityBase entity in m_scene.Entities.Values) | ||
176 | // { | ||
177 | // if (entity is SceneObjectGroup) | ||
178 | // { | ||
179 | // SceneObjectGroup sog = (SceneObjectGroup) entity; | ||
180 | // | ||
181 | // foreach (SceneObjectPart primitive in sog.Children.Values) | ||
182 | // { | ||
183 | // int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); | ||
184 | // int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); | ||
185 | // int w = (int) primitive.Scale.X; | ||
186 | // int h = (int) primitive.Scale.Y; | ||
187 | // | ||
188 | // int dx; | ||
189 | // for (dx = x; dx < x + w; dx++) | ||
190 | // { | ||
191 | // int dy; | ||
192 | // for (dy = y; dy < y + h; dy++) | ||
193 | // { | ||
194 | // if (x < 0 || y < 0) | ||
195 | // continue; | ||
196 | // if (x >= map.Width || y >= map.Height) | ||
197 | // continue; | ||
198 | // | ||
199 | // map.SetPixel(dx, dy, Color.DarkGray); | ||
200 | // } | ||
201 | // } | ||
202 | // } | ||
203 | // } | ||
204 | // } | ||
205 | // } | ||
206 | // } | ||
207 | // } | ||
208 | |||
209 | private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp) | ||
210 | { | ||
211 | int tc = 0; | ||
212 | double[,] hm = whichScene.Heightmap.GetDoubles(); | ||
213 | tc = Environment.TickCount; | ||
214 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); | ||
215 | EntityBase[] objs = whichScene.GetEntities(); | ||
216 | Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>(); | ||
217 | //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>(); | ||
218 | List<float> z_sortheights = new List<float>(); | ||
219 | List<uint> z_localIDs = new List<uint>(); | ||
220 | |||
221 | lock (objs) | ||
222 | { | ||
223 | foreach (EntityBase obj in objs) | ||
224 | { | ||
225 | // Only draw the contents of SceneObjectGroup | ||
226 | if (obj is SceneObjectGroup) | ||
227 | { | ||
228 | SceneObjectGroup mapdot = (SceneObjectGroup)obj; | ||
229 | Color mapdotspot = Color.Gray; // Default color when prim color is white | ||
230 | |||
231 | // Loop over prim in group | ||
232 | foreach (SceneObjectPart part in mapdot.Parts) | ||
233 | { | ||
234 | if (part == null) | ||
235 | continue; | ||
236 | |||
237 | // Draw if the object is at least 1 meter wide in any direction | ||
238 | if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f) | ||
239 | { | ||
240 | // Try to get the RGBA of the default texture entry.. | ||
241 | // | ||
242 | try | ||
243 | { | ||
244 | // get the null checks out of the way | ||
245 | // skip the ones that break | ||
246 | if (part == null) | ||
247 | continue; | ||
248 | |||
249 | if (part.Shape == null) | ||
250 | continue; | ||
251 | |||
252 | if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass) | ||
253 | continue; // eliminates trees from this since we don't really have a good tree representation | ||
254 | // if you want tree blocks on the map comment the above line and uncomment the below line | ||
255 | //mapdotspot = Color.PaleGreen; | ||
256 | |||
257 | Primitive.TextureEntry textureEntry = part.Shape.Textures; | ||
258 | |||
259 | if (textureEntry == null || textureEntry.DefaultTexture == null) | ||
260 | continue; | ||
261 | |||
262 | Color4 texcolor = textureEntry.DefaultTexture.RGBA; | ||
263 | |||
264 | // Not sure why some of these are null, oh well. | ||
265 | |||
266 | int colorr = 255 - (int)(texcolor.R * 255f); | ||
267 | int colorg = 255 - (int)(texcolor.G * 255f); | ||
268 | int colorb = 255 - (int)(texcolor.B * 255f); | ||
269 | |||
270 | if (!(colorr == 255 && colorg == 255 && colorb == 255)) | ||
271 | { | ||
272 | //Try to set the map spot color | ||
273 | try | ||
274 | { | ||
275 | // If the color gets goofy somehow, skip it *shakes fist at Color4 | ||
276 | mapdotspot = Color.FromArgb(colorr, colorg, colorb); | ||
277 | } | ||
278 | catch (ArgumentException) | ||
279 | { | ||
280 | } | ||
281 | } | ||
282 | } | ||
283 | catch (IndexOutOfRangeException) | ||
284 | { | ||
285 | // Windows Array | ||
286 | } | ||
287 | catch (ArgumentOutOfRangeException) | ||
288 | { | ||
289 | // Mono Array | ||
290 | } | ||
291 | |||
292 | Vector3 pos = part.GetWorldPosition(); | ||
293 | |||
294 | // skip prim outside of retion | ||
295 | if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f) | ||
296 | continue; | ||
297 | |||
298 | // skip prim in non-finite position | ||
299 | if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) || | ||
300 | Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y)) | ||
301 | continue; | ||
302 | |||
303 | // Figure out if object is under 256m above the height of the terrain | ||
304 | bool isBelow256AboveTerrain = false; | ||
305 | |||
306 | try | ||
307 | { | ||
308 | isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f)); | ||
309 | } | ||
310 | catch (Exception) | ||
311 | { | ||
312 | } | ||
313 | |||
314 | if (isBelow256AboveTerrain) | ||
315 | { | ||
316 | // Translate scale by rotation so scale is represented properly when object is rotated | ||
317 | Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); | ||
318 | Vector3 scale = new Vector3(); | ||
319 | Vector3 tScale = new Vector3(); | ||
320 | Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z); | ||
321 | |||
322 | Quaternion llrot = part.GetWorldRotation(); | ||
323 | Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); | ||
324 | scale = lscale * rot; | ||
325 | |||
326 | // negative scales don't work in this situation | ||
327 | scale.X = Math.Abs(scale.X); | ||
328 | scale.Y = Math.Abs(scale.Y); | ||
329 | scale.Z = Math.Abs(scale.Z); | ||
330 | |||
331 | // This scaling isn't very accurate and doesn't take into account the face rotation :P | ||
332 | int mapdrawstartX = (int)(pos.X - scale.X); | ||
333 | int mapdrawstartY = (int)(pos.Y - scale.Y); | ||
334 | int mapdrawendX = (int)(pos.X + scale.X); | ||
335 | int mapdrawendY = (int)(pos.Y + scale.Y); | ||
336 | |||
337 | // If object is beyond the edge of the map, don't draw it to avoid errors | ||
338 | if (mapdrawstartX < 0 || mapdrawstartX > ((int)Constants.RegionSize - 1) || mapdrawendX < 0 || mapdrawendX > ((int)Constants.RegionSize - 1) | ||
339 | || mapdrawstartY < 0 || mapdrawstartY > ((int)Constants.RegionSize - 1) || mapdrawendY < 0 | ||
340 | || mapdrawendY > ((int)Constants.RegionSize - 1)) | ||
341 | continue; | ||
342 | |||
343 | #region obb face reconstruction part duex | ||
344 | Vector3[] vertexes = new Vector3[8]; | ||
345 | |||
346 | // float[] distance = new float[6]; | ||
347 | Vector3[] FaceA = new Vector3[6]; // vertex A for Facei | ||
348 | Vector3[] FaceB = new Vector3[6]; // vertex B for Facei | ||
349 | Vector3[] FaceC = new Vector3[6]; // vertex C for Facei | ||
350 | Vector3[] FaceD = new Vector3[6]; // vertex D for Facei | ||
351 | |||
352 | tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z); | ||
353 | scale = ((tScale * rot)); | ||
354 | vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
355 | // vertexes[0].x = pos.X + vertexes[0].x; | ||
356 | //vertexes[0].y = pos.Y + vertexes[0].y; | ||
357 | //vertexes[0].z = pos.Z + vertexes[0].z; | ||
358 | |||
359 | FaceA[0] = vertexes[0]; | ||
360 | FaceB[3] = vertexes[0]; | ||
361 | FaceA[4] = vertexes[0]; | ||
362 | |||
363 | tScale = lscale; | ||
364 | scale = ((tScale * rot)); | ||
365 | vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
366 | |||
367 | // vertexes[1].x = pos.X + vertexes[1].x; | ||
368 | // vertexes[1].y = pos.Y + vertexes[1].y; | ||
369 | //vertexes[1].z = pos.Z + vertexes[1].z; | ||
370 | |||
371 | FaceB[0] = vertexes[1]; | ||
372 | FaceA[1] = vertexes[1]; | ||
373 | FaceC[4] = vertexes[1]; | ||
374 | |||
375 | tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z); | ||
376 | scale = ((tScale * rot)); | ||
377 | |||
378 | vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
379 | |||
380 | //vertexes[2].x = pos.X + vertexes[2].x; | ||
381 | //vertexes[2].y = pos.Y + vertexes[2].y; | ||
382 | //vertexes[2].z = pos.Z + vertexes[2].z; | ||
383 | |||
384 | FaceC[0] = vertexes[2]; | ||
385 | FaceD[3] = vertexes[2]; | ||
386 | FaceC[5] = vertexes[2]; | ||
387 | |||
388 | tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z); | ||
389 | scale = ((tScale * rot)); | ||
390 | vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
391 | |||
392 | //vertexes[3].x = pos.X + vertexes[3].x; | ||
393 | // vertexes[3].y = pos.Y + vertexes[3].y; | ||
394 | // vertexes[3].z = pos.Z + vertexes[3].z; | ||
395 | |||
396 | FaceD[0] = vertexes[3]; | ||
397 | FaceC[1] = vertexes[3]; | ||
398 | FaceA[5] = vertexes[3]; | ||
399 | |||
400 | tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z); | ||
401 | scale = ((tScale * rot)); | ||
402 | vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
403 | |||
404 | // vertexes[4].x = pos.X + vertexes[4].x; | ||
405 | // vertexes[4].y = pos.Y + vertexes[4].y; | ||
406 | // vertexes[4].z = pos.Z + vertexes[4].z; | ||
407 | |||
408 | FaceB[1] = vertexes[4]; | ||
409 | FaceA[2] = vertexes[4]; | ||
410 | FaceD[4] = vertexes[4]; | ||
411 | |||
412 | tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z); | ||
413 | scale = ((tScale * rot)); | ||
414 | vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
415 | |||
416 | // vertexes[5].x = pos.X + vertexes[5].x; | ||
417 | // vertexes[5].y = pos.Y + vertexes[5].y; | ||
418 | // vertexes[5].z = pos.Z + vertexes[5].z; | ||
419 | |||
420 | FaceD[1] = vertexes[5]; | ||
421 | FaceC[2] = vertexes[5]; | ||
422 | FaceB[5] = vertexes[5]; | ||
423 | |||
424 | tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z); | ||
425 | scale = ((tScale * rot)); | ||
426 | vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
427 | |||
428 | // vertexes[6].x = pos.X + vertexes[6].x; | ||
429 | // vertexes[6].y = pos.Y + vertexes[6].y; | ||
430 | // vertexes[6].z = pos.Z + vertexes[6].z; | ||
431 | |||
432 | FaceB[2] = vertexes[6]; | ||
433 | FaceA[3] = vertexes[6]; | ||
434 | FaceB[4] = vertexes[6]; | ||
435 | |||
436 | tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z); | ||
437 | scale = ((tScale * rot)); | ||
438 | vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
439 | |||
440 | // vertexes[7].x = pos.X + vertexes[7].x; | ||
441 | // vertexes[7].y = pos.Y + vertexes[7].y; | ||
442 | // vertexes[7].z = pos.Z + vertexes[7].z; | ||
443 | |||
444 | FaceD[2] = vertexes[7]; | ||
445 | FaceC[3] = vertexes[7]; | ||
446 | FaceD[5] = vertexes[7]; | ||
447 | #endregion | ||
448 | |||
449 | //int wy = 0; | ||
450 | |||
451 | //bool breakYN = false; // If we run into an error drawing, break out of the | ||
452 | // loop so we don't lag to death on error handling | ||
453 | DrawStruct ds = new DrawStruct(); | ||
454 | ds.brush = new SolidBrush(mapdotspot); | ||
455 | //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY); | ||
456 | |||
457 | ds.trns = new face[FaceA.Length]; | ||
458 | |||
459 | for (int i = 0; i < FaceA.Length; i++) | ||
460 | { | ||
461 | Point[] working = new Point[5]; | ||
462 | working[0] = project(FaceA[i], axPos); | ||
463 | working[1] = project(FaceB[i], axPos); | ||
464 | working[2] = project(FaceD[i], axPos); | ||
465 | working[3] = project(FaceC[i], axPos); | ||
466 | working[4] = project(FaceA[i], axPos); | ||
467 | |||
468 | face workingface = new face(); | ||
469 | workingface.pts = working; | ||
470 | |||
471 | ds.trns[i] = workingface; | ||
472 | } | ||
473 | |||
474 | z_sort.Add(part.LocalId, ds); | ||
475 | z_localIDs.Add(part.LocalId); | ||
476 | z_sortheights.Add(pos.Z); | ||
477 | |||
478 | //for (int wx = mapdrawstartX; wx < mapdrawendX; wx++) | ||
479 | //{ | ||
480 | //for (wy = mapdrawstartY; wy < mapdrawendY; wy++) | ||
481 | //{ | ||
482 | //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy); | ||
483 | //try | ||
484 | //{ | ||
485 | // Remember, flip the y! | ||
486 | // mapbmp.SetPixel(wx, (255 - wy), mapdotspot); | ||
487 | //} | ||
488 | //catch (ArgumentException) | ||
489 | //{ | ||
490 | // breakYN = true; | ||
491 | //} | ||
492 | |||
493 | //if (breakYN) | ||
494 | // break; | ||
495 | //} | ||
496 | |||
497 | //if (breakYN) | ||
498 | // break; | ||
499 | //} | ||
500 | } // Object is within 256m Z of terrain | ||
501 | } // object is at least a meter wide | ||
502 | } // loop over group children | ||
503 | } // entitybase is sceneobject group | ||
504 | } // foreach loop over entities | ||
505 | |||
506 | float[] sortedZHeights = z_sortheights.ToArray(); | ||
507 | uint[] sortedlocalIds = z_localIDs.ToArray(); | ||
508 | |||
509 | // Sort prim by Z position | ||
510 | Array.Sort(sortedZHeights, sortedlocalIds); | ||
511 | |||
512 | Graphics g = Graphics.FromImage(mapbmp); | ||
513 | |||
514 | for (int s = 0; s < sortedZHeights.Length; s++) | ||
515 | { | ||
516 | if (z_sort.ContainsKey(sortedlocalIds[s])) | ||
517 | { | ||
518 | DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]]; | ||
519 | for (int r = 0; r < rectDrawStruct.trns.Length; r++) | ||
520 | { | ||
521 | g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts); | ||
522 | } | ||
523 | //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect); | ||
524 | } | ||
525 | } | ||
526 | |||
527 | g.Dispose(); | ||
528 | } // lock entities objs | ||
529 | |||
530 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms"); | ||
531 | return mapbmp; | ||
532 | } | ||
533 | |||
534 | private Point project(Vector3 point3d, Vector3 originpos) | ||
535 | { | ||
536 | Point returnpt = new Point(); | ||
537 | //originpos = point3d; | ||
538 | //int d = (int)(256f / 1.5f); | ||
539 | |||
540 | //Vector3 topos = new Vector3(0, 0, 0); | ||
541 | // float z = -point3d.z - topos.z; | ||
542 | |||
543 | returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d); | ||
544 | returnpt.Y = (int)(((int)Constants.RegionSize - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d))); | ||
545 | |||
546 | return returnpt; | ||
547 | } | ||
548 | |||
549 | // TODO: unused: | ||
550 | // #region Deprecated Maptile Generation. Adam may update this | ||
551 | // private Bitmap TerrainToBitmap(string gradientmap) | ||
552 | // { | ||
553 | // Bitmap gradientmapLd = new Bitmap(gradientmap); | ||
554 | // | ||
555 | // int pallete = gradientmapLd.Height; | ||
556 | // | ||
557 | // Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); | ||
558 | // Color[] colours = new Color[pallete]; | ||
559 | // | ||
560 | // for (int i = 0; i < pallete; i++) | ||
561 | // { | ||
562 | // colours[i] = gradientmapLd.GetPixel(0, i); | ||
563 | // } | ||
564 | // | ||
565 | // lock (m_scene.Heightmap) | ||
566 | // { | ||
567 | // ITerrainChannel copy = m_scene.Heightmap; | ||
568 | // for (int y = 0; y < copy.Height; y++) | ||
569 | // { | ||
570 | // for (int x = 0; x < copy.Width; x++) | ||
571 | // { | ||
572 | // // 512 is the largest possible height before colours clamp | ||
573 | // int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); | ||
574 | // | ||
575 | // // Handle error conditions | ||
576 | // if (colorindex > pallete - 1 || colorindex < 0) | ||
577 | // bmp.SetPixel(x, copy.Height - y - 1, Color.Red); | ||
578 | // else | ||
579 | // bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); | ||
580 | // } | ||
581 | // } | ||
582 | // ShadeBuildings(bmp); | ||
583 | // return bmp; | ||
584 | // } | ||
585 | // } | ||
586 | // #endregion | ||
587 | } | ||
588 | } | ||