diff options
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/Scene.cs | 144 |
1 files changed, 143 insertions, 1 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 3c9f91b..798c9ad 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs | |||
@@ -998,9 +998,11 @@ namespace OpenSim.Region.Environment.Scenes | |||
998 | // Cannot create a map for a nonexistant heightmap yet. | 998 | // Cannot create a map for a nonexistant heightmap yet. |
999 | if (Heightmap == null) | 999 | if (Heightmap == null) |
1000 | return; | 1000 | return; |
1001 | 1001 | ||
1002 | if (terrain == null) | 1002 | if (terrain == null) |
1003 | { | 1003 | { |
1004 | int tc = System.Environment.TickCount; | ||
1005 | m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain"); | ||
1004 | Bitmap mapbmp = new Bitmap(256, 256); | 1006 | Bitmap mapbmp = new Bitmap(256, 256); |
1005 | double[,] hm = Heightmap.GetDoubles(); | 1007 | double[,] hm = Heightmap.GetDoubles(); |
1006 | 1008 | ||
@@ -1129,6 +1131,146 @@ namespace OpenSim.Region.Environment.Scenes | |||
1129 | //tc = System.Environment.TickCount - tc; | 1131 | //tc = System.Environment.TickCount - tc; |
1130 | //m_log.Info("[MAPTILE]: Completed One row in " + tc + " ms"); | 1132 | //m_log.Info("[MAPTILE]: Completed One row in " + tc + " ms"); |
1131 | } | 1133 | } |
1134 | m_log.Info("[MAPTILE]: Generating Maptile Step 1: Done in " + (System.Environment.TickCount - tc) + " ms"); | ||
1135 | |||
1136 | bool drawPrimVolume = true; | ||
1137 | |||
1138 | |||
1139 | try | ||
1140 | { | ||
1141 | IConfig startupConfig = m_config.Configs["Startup"]; | ||
1142 | drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", true); | ||
1143 | } | ||
1144 | catch (Exception) | ||
1145 | { | ||
1146 | m_log.Warn("Failed to load StarupConfg"); | ||
1147 | } | ||
1148 | |||
1149 | |||
1150 | if (drawPrimVolume) | ||
1151 | { | ||
1152 | tc = System.Environment.TickCount; | ||
1153 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); | ||
1154 | List<EntityBase> objs = GetEntities(); | ||
1155 | |||
1156 | lock (objs) | ||
1157 | { | ||
1158 | foreach (EntityBase obj in objs) | ||
1159 | { | ||
1160 | // Only draw the contents of SceneObjectGroup | ||
1161 | if (obj is SceneObjectGroup) | ||
1162 | { | ||
1163 | SceneObjectGroup mapdot = (SceneObjectGroup)obj; | ||
1164 | Color mapdotspot = Color.Gray; // Default color when prim color is white | ||
1165 | // Loop over prim in group | ||
1166 | foreach (SceneObjectPart part in mapdot.Children.Values) | ||
1167 | { | ||
1168 | // Draw if the object is at least 1 meter wide in any direction | ||
1169 | if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f) | ||
1170 | { | ||
1171 | LLColor texcolor = part.Shape.Textures.DefaultTexture.RGBA; | ||
1172 | int colorr = 255 - (int)(texcolor.R * 255f); | ||
1173 | int colorg = 255 - (int)(texcolor.G * 255f); | ||
1174 | int colorb = 255 - (int)(texcolor.B * 255f); | ||
1175 | |||
1176 | if (colorr == 255 && colorg == 255 && colorb == 255) | ||
1177 | { } | ||
1178 | else | ||
1179 | { | ||
1180 | try | ||
1181 | { | ||
1182 | // If the color gets goofy somehow, skip it *shakes fist at LLColor | ||
1183 | mapdotspot = Color.FromArgb(colorr, colorg, colorb); | ||
1184 | } | ||
1185 | catch (ArgumentException) | ||
1186 | { | ||
1187 | } | ||
1188 | } | ||
1189 | |||
1190 | LLVector3 pos = part.GetWorldPosition(); | ||
1191 | |||
1192 | // skip prim outside of retion | ||
1193 | if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f) | ||
1194 | continue; | ||
1195 | |||
1196 | // skip prim in non-finite position | ||
1197 | if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) || Single.IsInfinity(pos.X) | ||
1198 | || Single.IsInfinity(pos.Y)) | ||
1199 | continue; | ||
1200 | |||
1201 | // Figure out if object is under 256m above the height of the terrain | ||
1202 | bool isBelow256AboveTerrain = false; | ||
1203 | |||
1204 | try | ||
1205 | { | ||
1206 | isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f)); | ||
1207 | } | ||
1208 | catch (Exception) | ||
1209 | { | ||
1210 | } | ||
1211 | |||
1212 | if (isBelow256AboveTerrain) | ||
1213 | { | ||
1214 | // Translate scale by rotation so scale is represented properly when object is rotated | ||
1215 | Vector3 scale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); | ||
1216 | LLQuaternion llrot = part.GetWorldRotation(); | ||
1217 | Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); | ||
1218 | scale = rot * scale; | ||
1219 | |||
1220 | // negative scales don't work in this situation | ||
1221 | scale.x = Math.Abs(scale.x); | ||
1222 | scale.y = Math.Abs(scale.y); | ||
1223 | scale.z = Math.Abs(scale.z); | ||
1224 | |||
1225 | // This scaling isn't very accurate and doesn't take into account the face rotation :P | ||
1226 | int mapdrawstartX = (int)(pos.X - scale.x); | ||
1227 | int mapdrawstartY = (int)(pos.Y - scale.y); | ||
1228 | int mapdrawendX = (int)(pos.X + scale.x); | ||
1229 | int mapdrawendY = (int)(pos.Y + scale.y); | ||
1230 | |||
1231 | // If object is beyond the edge of the map, don't draw it to avoid errors | ||
1232 | if (mapdrawstartX < 0 || mapdrawstartX > 255 || mapdrawendX < 0 || mapdrawendX > 255 | ||
1233 | || mapdrawstartY < 0 || mapdrawstartY > 255 || mapdrawendY < 0 | ||
1234 | || mapdrawendY > 255) | ||
1235 | continue; | ||
1236 | |||
1237 | |||
1238 | int wy = 0; | ||
1239 | |||
1240 | bool breakYN = false; // If we run into an error drawing, break out of the | ||
1241 | // loop so we don't lag to death on error handling | ||
1242 | for (int wx = mapdrawstartX; wx < mapdrawendX; wx++) | ||
1243 | { | ||
1244 | for (wy = mapdrawstartY; wy < mapdrawendY; wy++) | ||
1245 | { | ||
1246 | //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy); | ||
1247 | try | ||
1248 | { | ||
1249 | // Remember, flip the y! | ||
1250 | mapbmp.SetPixel(wx, (255 - wy), mapdotspot); | ||
1251 | } | ||
1252 | catch (ArgumentException) | ||
1253 | { | ||
1254 | breakYN = true; | ||
1255 | } | ||
1256 | |||
1257 | if (breakYN) | ||
1258 | break; | ||
1259 | } | ||
1260 | |||
1261 | if (breakYN) | ||
1262 | break; | ||
1263 | } | ||
1264 | } // Object is within 256m Z of terrain | ||
1265 | } // object is at least a meter wide | ||
1266 | } // loop over group children | ||
1267 | } // entitybase is sceneobject group | ||
1268 | } // foreach loop over entities | ||
1269 | } // lock entities objs | ||
1270 | |||
1271 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (System.Environment.TickCount - tc) + " ms"); | ||
1272 | } // end if drawPrimOnMaptle | ||
1273 | |||
1132 | byte[] data; | 1274 | byte[] data; |
1133 | try | 1275 | try |
1134 | { | 1276 | { |